Subversion Repositories Kolibri OS

Rev

Rev 8185 | 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. 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};
  24. progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
  25.  
  26. /*
  27. // System colors
  28. struct kolibri_system_colors sys_color;
  29. */
  30.  
  31. void draw_window(){
  32.         BeginDraw();
  33.         DrawWindow(215,100,WIN_W,WIN_H,title, /* sys_color.work_area */ 0x858585, 0x34);
  34.         scrollbar_v_draw(&scroll);
  35.         progressbar_draw(&pg);
  36.         EndDraw();
  37. }
  38.  
  39. //// EVENTMASK
  40. #define EVM_REDRAW        1
  41. #define EVM_KEY           2
  42. #define EVM_BUTTON        4
  43. #define EVM_EXIT          8
  44. #define EVM_BACKGROUND    16
  45. #define EVM_MOUSE         32
  46. #define EVM_IPC           64
  47. #define EVM_STACK         128
  48. #define EVM_DEBUG         256
  49. #define EVM_STACK2        512
  50. #define EVM_MOUSE_FILTER  0x80000000
  51. #define EVM_CURSOR_FILTER 0x40000000
  52. //// EVENTMASK
  53.  
  54.  
  55. int main()
  56. {
  57.         kolibri_boxlib_init();
  58.         /*
  59.         get_system_colors(&sys_color);
  60.         */
  61.         set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  62.         while(1)
  63.         {
  64.                 switch(GetOsEvent())
  65.                 {
  66.                         case evButton:
  67.                                 if (get_os_button() == 1) exit(0);
  68.                                 break;
  69.                  
  70.                         case evKey:
  71.                                 get_key();
  72.                                 break;
  73.                          
  74.                         case evReDraw:
  75.                                 draw_window();
  76.                                 break;
  77.                         case evMouse:
  78.                                 scrollbar_v_mouse(&scroll);
  79.                                
  80.                                 // Wheel scrolling
  81.                                 // Quite unstable
  82.                                 /*
  83.                                 int scroll_strong = 40;
  84.                                 wheels = GetMouseWheels();
  85.                                 if(wheels & 0xFFFF)
  86.                                 {
  87.                                         if((short)wheels > 0 && scroll.position < scroll.max_area - scroll_strong)
  88.                                                 scroll.position += scroll_strong;
  89.                                         else if((short)wheels < 0 && scroll.position > 0)
  90.                                                 scroll.position -= scroll_strong;
  91.                                        
  92.                                         scrollbar_v_draw(&scroll);
  93.                                 }
  94.                                 */
  95.                                 pg.value = scroll.position;
  96.                                 progressbar_draw(&pg);
  97.                                 break;
  98.                 }
  99.         }
  100. }
  101.