Subversion Repositories Kolibri OS

Rev

Rev 8465 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. // BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
  2. // Writed by maxcodehack and superturbocat2001
  3.  
  4. #include <kos32sys1.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <clayer/boxlib.h>
  8. #include <stdio.h>
  9.  
  10. #define WIN_W 640
  11. #define WIN_H 563
  12.  
  13. #define ED_BUFF_LEN 50
  14. #define TEXT_SIZE 0x10000000
  15. #define SCROLL_BUTTON_SIZE 15
  16. #define SCROLL_MAX_LEN 215
  17. #define BLACK 0x000000
  18. #define WHITE 0xFFFFFF
  19. #define BLUE  0x0000FF
  20.  
  21. uint32_t wheels;
  22. char* title = "Boxlib example";
  23. char ed_buff[ED_BUFF_LEN];
  24.  
  25.  
  26. scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555};
  27. progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
  28. edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus};
  29. check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0};
  30.  
  31. void draw_window(){
  32.         BeginDraw();
  33.         DrawWindow(215,100,WIN_W,WIN_H,title, 0x858585, 0x34);    
  34.                 edit_box_draw(&ed);
  35.                 check_box_draw2(&output_off);
  36.                 if(!output_off.flags)
  37.                 {
  38.                         draw_text_sys(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE);
  39.                 }
  40.                 scrollbar_v_draw(&scroll);
  41.         progressbar_draw(&pg);
  42.         EndDraw();
  43. }
  44.  
  45. //// EVENTMASK
  46. #define EVM_REDRAW        1
  47. #define EVM_KEY           2
  48. #define EVM_BUTTON        4
  49. #define EVM_EXIT          8
  50. #define EVM_BACKGROUND    16
  51. #define EVM_MOUSE         32
  52. #define EVM_IPC           64
  53. #define EVM_STACK         128
  54. #define EVM_DEBUG         256
  55. #define EVM_STACK2        512
  56. #define EVM_MOUSE_FILTER  0x80000000
  57. #define EVM_CURSOR_FILTER 0x40000000
  58. //// EVENTMASK
  59.  
  60.  
  61. int main()
  62. {
  63.         kolibri_boxlib_init();
  64.         init_checkbox2(&output_off);
  65.         set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE+EVM_MOUSE_FILTER);
  66.         while(1)
  67.         {
  68.                 switch(GetOsEvent())
  69.                 {
  70.                         case KOLIBRI_EVENT_BUTTON:
  71.                                 if (get_os_button() == 1) exit(0);
  72.                                 break;
  73.                  
  74.                         case KOLIBRI_EVENT_KEY:
  75.                                 edit_box_key(&ed, get_key().val);
  76.                 draw_window();
  77.                                 break;
  78.                          
  79.                         case KOLIBRI_EVENT_REDRAW:
  80.                                 draw_window();
  81.                                 break;
  82.                         case KOLIBRI_EVENT_MOUSE:
  83.                                 edit_box_mouse(&ed);
  84.                                 scrollbar_v_mouse(&scroll);
  85.                                 pg.value = scroll.position;
  86.                                 progressbar_draw(&pg);
  87.                                 check_box_mouse2(&output_off);
  88.                                 unsigned int scroll_strong = 10;
  89.                 wheels = GetMouseWheels();
  90.                                 if(wheels & 0xFFFF)
  91.                 {
  92.                                         if((short)wheels > 0){
  93.                                                 scroll.position += scroll_strong;
  94.                                                 if(scroll.position>scroll.max_area-scroll.cur_area)
  95.                                                 {
  96.                                                         scroll.position=scroll.max_area-scroll.cur_area;
  97.                                                 }
  98.                                         }
  99.                     else if((short)wheels < 0 && scroll.position > 0){
  100.                                 scroll.position -= scroll_strong;
  101.                                                 if((int)scroll.position<0){
  102.                                                         scroll.position=0;
  103.                                                 }
  104.                                         }
  105.                         scrollbar_v_draw(&scroll);
  106.                 }
  107.                                 break;
  108.                 }
  109.         }
  110. }
  111.