Subversion Repositories Kolibri OS

Rev

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

  1. // BOXLIB EXAMPLE (scrollbar, progressbar)
  2. // Writed by maxcodehack
  3. // GCC version is in /contrib/C_Layer/EXAMPLE/boxlib
  4. #include <kos32sys1.h>
  5. #include <stdlib.h>
  6. #include <clayer/boxlib.h>
  7.  
  8. #define evReDraw  1
  9. #define evKey     2
  10. #define evButton  3
  11. #define evExit    4
  12. #define evDesktop 5
  13. #define evMouse   6
  14. #define evIPC     7
  15. #define evNetwork 8
  16. #define evDebug   9
  17.  
  18. #define WIN_W 640
  19. #define WIN_H 563
  20.  
  21. uint32_t wheels;
  22. char* title = "Boxlib example";
  23. int win_bg_color = 0x858585;
  24. scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, 15, 0,0x707070,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  25. progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
  26.  
  27. void draw_window(){
  28.         BeginDraw();
  29.         DrawWindow(215,100,WIN_W,WIN_H,title,win_bg_color,0x34);
  30.         scrollbar_v_draw(&scroll);
  31.         progressbar_draw(&pg);
  32.         EndDraw();
  33. }
  34.  
  35. //// EVENTMASK
  36. #define EVM_REDRAW        1
  37. #define EVM_KEY           2
  38. #define EVM_BUTTON        4
  39. #define EVM_EXIT          8
  40. #define EVM_BACKGROUND    16
  41. #define EVM_MOUSE         32
  42. #define EVM_IPC           64
  43. #define EVM_STACK         128
  44. #define EVM_DEBUG         256
  45. #define EVM_STACK2        512
  46. #define EVM_MOUSE_FILTER  0x80000000
  47. #define EVM_CURSOR_FILTER 0x40000000
  48. //// EVENTMASK
  49.  
  50.  
  51. int main()
  52. {
  53.         kolibri_boxlib_init();
  54.        
  55.         set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  56.         while(1)
  57.         {
  58.                 switch(GetOsEvent())
  59.                 {
  60.                         case evButton:
  61.                                 if (get_os_button() == 1) exit(0);
  62.                                 break;
  63.                  
  64.                         case evKey:
  65.                                 get_key();
  66.                                 break;
  67.                          
  68.                         case evReDraw:
  69.                                 draw_window();
  70.                                 break;
  71.                         case evMouse:
  72.                                 scrollbar_v_mouse(&scroll);
  73.                                
  74.                                 // Wheel scrolling
  75.                                 // Quite unstable
  76.                                 /*
  77.                                 int scroll_strong = 40;
  78.                                 wheels = GetMouseWheels();
  79.                                 if(wheels & 0xFFFF)
  80.                                 {
  81.                                         if((short)wheels > 0 && scroll.position < scroll.max_area - scroll_strong)
  82.                                                 scroll.position += scroll_strong;
  83.                                         else if((short)wheels < 0 && scroll.position > 0)
  84.                                                 scroll.position -= scroll_strong;
  85.                                        
  86.                                         scrollbar_v_draw(&scroll);
  87.                                 }
  88.                                 */
  89.                                 pg.value = scroll.position;
  90.                                 progressbar_draw(&pg);
  91.                                 break;
  92.                 }
  93.         }
  94. }
  95.