Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/ksys.h>
  6.  
  7. ksys_colors_table_t sys_color_table;
  8.  
  9. char statusbar[255];
  10. ksys_thread_t proc_info;
  11. char text_line[255];
  12.  
  13. enum BUTTONS {
  14.     BTN_QUIT = 1,
  15.     BTN_POP = 10,
  16.     BTN_UNLOCK = 11
  17. };
  18.  
  19. #define FONT_W 8
  20. #define FONT_H 14
  21. #define LINES 10
  22.  
  23. void draw_window()
  24. {
  25.     int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36
  26.  
  27.     // start redraw
  28.     _ksys_start_draw();
  29.     // define&draw window
  30.     _ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13);
  31.     _ksys_thread_info(&proc_info, -1);
  32.     F
  33.  
  34.         win_width
  35.         = proc_info.winx_size;
  36.     win_hight = proc_info.winy_size;
  37.  
  38.     _ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button);
  39.     _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // 0x80000000 asciiz
  40.     _ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button);
  41.     _ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text);
  42.  
  43.     // display statusbar
  44.     _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); // 0x80000000 gradient
  45.     _ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text);
  46.  
  47.     // display strings
  48.     for (i = LINES; i > 0; i--) {
  49.         snprintf(text_line, sizeof text_line, "Line[%d]<<Just a text>>", i);
  50.  
  51.         text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size
  52.         _ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text);
  53.         pos_y += FONT_H;
  54.  
  55.         if (pos_y + 29 > win_hight)
  56.             break; // 12 font + 12 statusbar + 5 border
  57.     }
  58.     // end redraw
  59.     _ksys_end_draw();
  60. }
  61.  
  62. int main()
  63. {
  64.     int gui_event;
  65.     uint32_t pressed_button = 0, mouse_button;
  66.     ksys_pos_t mouse_pos;
  67.     strcpy(statusbar, "Program running...Double click on TEXT for details");
  68.  
  69.     _ksys_get_system_colors(&sys_color_table);
  70.     _ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside
  71.  
  72.     do {
  73.         gui_event = _ksys_get_event();
  74.         switch (gui_event) {
  75.         case KSYS_EVENT_NONE:
  76.             break;
  77.         case KSYS_EVENT_REDRAW:
  78.             draw_window();
  79.             break;
  80.         case KSYS_EVENT_KEY:
  81.             break;
  82.         case KSYS_EVENT_BUTTON:
  83.             pressed_button = _ksys_get_button();
  84.             switch (pressed_button) {
  85.             case BTN_POP:
  86.                 strcpy(statusbar, "POP pressed....");
  87.                 draw_window();
  88.                 break;
  89.             case BTN_UNLOCK:
  90.                 strcpy(statusbar, "UNLOCK pressed....");
  91.                 draw_window();
  92.                 break;
  93.             case BTN_QUIT:
  94.                 return 0;
  95.                 break;
  96.             }
  97.             break;
  98.         case KSYS_EVENT_MOUSE:
  99.             mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative
  100.             mouse_button = _ksys_get_mouse_eventstate();
  101.             debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button);
  102.             if (mouse_button & (1 << 24)) // double click
  103.             {
  104.                 int n = (mouse_pos.y - 60) / FONT_H;
  105.                 if (n < 0 || n >= LINES)
  106.                     break;
  107.                 debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
  108.                 sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
  109.                 draw_window();
  110.             }
  111.             break;
  112.         }
  113.     } while (1); /* End of main activity loop */
  114.  
  115.     return 0;
  116. }
  117.