Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. // BOXLIB example (scrollbar, progressbar)
  2. // ! without kolibri_gui !
  3. // Writed by maxcodehack
  4. // TCC version is in /programs/develop/ktcc/trunk/samples
  5. #include <kos32sys.h>
  6. #include <stdlib.h>
  7.  
  8. /// BOXLIB
  9. // Modified from C_Layer
  10. // C_Layer variant I don't like
  11. extern int kolibri_boxlib_init(void);
  12. typedef struct __attribute__ ((__packed__)) {
  13.         uint16_t xsize;
  14.     uint16_t xpos;
  15.     uint16_t ysize;
  16.     uint16_t ypos;
  17.     uint32_t btn_height;
  18.     uint32_t type;
  19.     uint32_t max_area;
  20.     uint32_t cur_area;
  21.     uint32_t position;
  22.     uint32_t back_color;
  23.     uint32_t front_color;
  24.     uint32_t line_color;
  25.     uint32_t redraw;
  26.     uint16_t delta;
  27.     uint16_t delta2;
  28.     uint16_t r_size_x;
  29.     uint16_t r_start_x;
  30.     uint16_t r_size_y;
  31.     uint16_t r_start_y;
  32.     uint32_t m_pos;
  33.     uint32_t m_pos2;
  34.     uint32_t m_keys;
  35.     uint32_t run_size;
  36.     uint32_t position2;
  37.     uint32_t work_size;
  38.     uint32_t all_redraw;
  39.     uint32_t ar_offset;
  40. } scrollbar;
  41.  
  42. extern void (*scrollbar_h_draw)(scrollbar*) __attribute__((__stdcall__));
  43. extern void (*scrollbar_h_mouse)(scrollbar*) __attribute__((__stdcall__));
  44. extern void (*scrollbar_v_draw)(scrollbar*) __attribute__((__stdcall__));
  45. extern void (*scrollbar_v_mouse)(scrollbar*) __attribute__((__stdcall__));
  46.  
  47. typedef struct {
  48.         unsigned int value;
  49.     unsigned int left;
  50.     unsigned int top;
  51.     unsigned int width;
  52.     unsigned int height;
  53.     unsigned int style;
  54.     unsigned int min;
  55.     unsigned int max;
  56.     unsigned int back_color;
  57.     unsigned int progress_color;
  58.     unsigned int frame_color;
  59. } progressbar;
  60.  
  61. extern void (*progressbar_draw)(progressbar *) __attribute__((__stdcall__));
  62. extern void (*progressbar_progress)(progressbar *) __attribute__((__stdcall__));
  63. /// BOXLIB
  64.  
  65.  
  66. #define evReDraw  1
  67. #define evKey     2
  68. #define evButton  3
  69. #define evExit    4
  70. #define evDesktop 5
  71. #define evMouse   6
  72. #define evIPC     7
  73. #define evNetwork 8
  74. #define evDebug   9
  75.  
  76. #define WIN_W 640
  77. #define WIN_H 563
  78.  
  79. uint32_t wheels;
  80. char* title = "Boxlib example";
  81. int win_bg_color = 0x858585;
  82. 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};
  83. progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
  84.  
  85. void draw_window(){
  86.         BeginDraw();
  87.         DrawWindow(215,100,WIN_W,WIN_H,title,win_bg_color,0x34);
  88.         scrollbar_v_draw(&scroll);
  89.         progressbar_draw(&pg);
  90.         EndDraw();
  91. }
  92.  
  93. //// EVENTMASK
  94. #define EVM_REDRAW        1
  95. #define EVM_KEY           2
  96. #define EVM_BUTTON        4
  97. #define EVM_EXIT          8
  98. #define EVM_BACKGROUND    16
  99. #define EVM_MOUSE         32
  100. #define EVM_IPC           64
  101. #define EVM_STACK         128
  102. #define EVM_DEBUG         256
  103. #define EVM_STACK2        512
  104. #define EVM_MOUSE_FILTER  0x80000000
  105. #define EVM_CURSOR_FILTER 0x40000000
  106. //// EVENTMASK
  107.  
  108.  
  109. int main()
  110. {
  111.         kolibri_boxlib_init();
  112.        
  113.         set_wanted_events_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  114.         while(1)
  115.         {
  116.                 switch(GetOsEvent())
  117.                 {
  118.                         case evButton:
  119.                                 if (get_os_button() == 1) exit(0);
  120.                                 break;
  121.                  
  122.                         case evKey:
  123.                                 get_key();
  124.                                 break;
  125.                          
  126.                         case evReDraw:
  127.                                 draw_window();
  128.                                 break;
  129.                         case evMouse:
  130.                                 scrollbar_v_mouse(&scroll);
  131.                                
  132.                                 // Wheel scrolling
  133.                                 // Quite unstable
  134.                                 /*
  135.                                 int scroll_strong = 40;
  136.                                 wheels = GetMouseWheels();
  137.                                 if(wheels & 0xFFFF)
  138.                                 {
  139.                                         if((short)wheels > 0 && scroll.position < scroll.max_area - scroll_strong)
  140.                                                 scroll.position += scroll_strong;
  141.                                         else if((short)wheels < 0 && scroll.position > 0)
  142.                                                 scroll.position -= scroll_strong;
  143.                                        
  144.                                         scrollbar_v_draw(&scroll);
  145.                                 }
  146.                                 */
  147.                                 pg.value = scroll.position;
  148.                                 progressbar_draw(&pg);
  149.                                 break;
  150.                 }
  151.         }
  152. }
  153.