Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <types.h>
  3. #include <core.h>
  4. #include <spinlock.h>
  5. #include <link.h>
  6. #include <mm.h>
  7. #include <slab.h>
  8.  
  9.  
  10. slab_cache_t *win_slab;
  11.  
  12. link_t  win_list;
  13.  
  14. window_t *win_slot[256];
  15.  
  16. extern int current_task;
  17.  
  18. void fill_disp_data(int left, int top, int right,
  19.                     int bottom, int slot);
  20.  
  21. void update_disp_data(window_t *win)
  22. {
  23.     do{
  24. //        fill_disp_data(win->wrect.left, win->wrect.top,
  25. //                       win->wrect.right,win->wrect.bottom,
  26. //                       win->slot);
  27.  
  28.  
  29.         __asm__ __volatile__ (
  30.         "call _set_screen \n\t"
  31.         :
  32.         :"b" (win->wrect.left),
  33.         "a" (win->wrect.top),
  34.         "c" (win->wrect.right-win->wrect.left+1),
  35.         "d" (win->wrect.bottom-win->wrect.top+1),
  36.         "S" (win->slot)
  37.         :"edi");
  38.  
  39.         __asm__ __volatile__ (
  40.         ""
  41.         :::"eax", "ebx", "ecx", "edx", "esi");
  42.  
  43.         win = (window_t*)win->link.prev;
  44.     } while(&win->link != &win_list);
  45. }
  46.  
  47. void insert_window(window_t *win)
  48. {
  49.     if( list_empty(&win_list))
  50.         list_prepend(&win->link, &win_list);
  51.     else
  52.     {
  53.         window_t *tmp;
  54.         tmp = (window_t*)win_list.next;
  55.  
  56.         while( &tmp->link != &win_list)
  57.         {
  58.             if(win->style <= tmp->style)
  59.                 break;
  60.             tmp = (window_t*)tmp->link.next;
  61.         }
  62.         list_insert(&win->link, &tmp->link);
  63.     };
  64.     update_disp_data(win);
  65. };
  66.  
  67. u32_t sys_create_window(char *caption, u32_t style,
  68.                         int x, int y, int width, int height)
  69. {
  70.     window_t *win;
  71.     int r, b;
  72.  
  73.     DBG("\ncreate window %s, x %d y %d\n"
  74.         "width %d height %d\n",caption, x,y, width, height);
  75.  
  76.     win = (window_t*)slab_alloc(win_slab,0);
  77.  
  78.     link_initialize(&win->link);
  79.  
  80.     r = x+width-1;
  81.     b = y+height-1;
  82.  
  83.     win->wrect.left = x;
  84.     win->wrect.top = y;
  85.     win->wrect.right = r;
  86.     win->wrect.bottom = b;
  87.  
  88.     win->crect.left = x;
  89.     win->crect.top = y;
  90.     win->crect.right = r;
  91.     win->crect.bottom = b;
  92.  
  93.     win->style = style;
  94.     win->slot  = current_task;
  95.  
  96.     list_initialize(&win->queue);
  97.     win->qflags = 0;
  98.  
  99.     win->caption = caption;
  100.  
  101.     win_slot[current_task] = win;
  102.     return current_task;
  103. }
  104.  
  105. #define QS_PAINT    1
  106.  
  107. bool sys_show_window(u32_t handle)
  108. {
  109.     window_t *win;
  110.  
  111.     win = win_slot[current_task];
  112.  
  113.     insert_window(win);
  114.     win->qflags |= QS_PAINT;
  115.  
  116.     return true;
  117. };
  118.  
  119. void sys_get_event(event_t *ev)
  120. {
  121.     window_t *win;
  122.  
  123.     win = win_slot[current_task];
  124.  
  125.     if(win->qflags & QS_PAINT)
  126.     {
  127.         ev->code = 1;
  128.         ev->win = win->slot;
  129.         ev->val1 = 0;
  130.         ev->val2 = 0;
  131.         ev->x = 0;
  132.         ev->y = 0;
  133.         win->qflags&= ~QS_PAINT;
  134.     };
  135. }
  136.  
  137. static inline draw_bar(int x, int y, int w, int h, u32_t color)
  138. {
  139.     int_draw_bar(x, y, w, h, color);
  140.     __asm__ __volatile__ (
  141.     ""
  142.     :::"ebx", "esi", "edi");
  143. };
  144.  
  145. static inline hline(int x, int y, int w, color_t color)
  146. {
  147.     int_hline(x, y, w, color);
  148.     __asm__ __volatile__ (
  149.     ""
  150.     :::"esi", "edi");
  151. };
  152.  
  153. static inline vline(int x, int y, int h, color_t color)
  154. {
  155.     int_vline(x, y, h, color);
  156.     __asm__ __volatile__ (
  157.     ""
  158.     :::"esi", "edi");
  159. };
  160.  
  161. static inline rectangle(int x, int y, int w, int h, color_t color)
  162. {
  163.     int_rectangle(x, y, w, h, color);
  164.     __asm__ __volatile__ (
  165.     ""
  166.     :::"esi", "edi");
  167. };
  168.  
  169. extern color_t skin_active;
  170.  
  171. void sys_def_window_proc(event_t *ev)
  172. {
  173.     window_t *win;
  174.  
  175.     win = win_slot[current_task];
  176.  
  177.     if(ev->code =1)
  178.     {
  179.         int w, h;
  180.         color_t *skin = &skin_active;
  181.  
  182.         w = win->wrect.right-win->wrect.left+1;
  183.         h = win->wrect.bottom - win->wrect.top+1;
  184.  
  185.         rectangle(win->wrect.left, win->wrect.top,
  186.                  w, h, skin[1]);
  187.  
  188.         rectangle(win->wrect.left+1, win->wrect.top+1,
  189.                  w-2, h-2, skin[2]);
  190.  
  191.         rectangle(win->wrect.left+2, win->wrect.top+2,
  192.                  w-4, h-4, skin[2]);
  193.  
  194.         rectangle(win->wrect.left+3, win->wrect.top+3,
  195.                  w-6, h-6, skin[2]);
  196.  
  197.         rectangle(win->wrect.left+4, win->wrect.top+4,
  198.                  w-8, h-8, skin[0]);
  199.  
  200.  //       draw_bar(win->wrect.left+4, win->wrect.top+4,
  201.  //                w-8, h-8, skin[1]);
  202.  
  203.     };
  204. };
  205.