Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef KOLIBRI_STATICTEXT_H
  2. #define KOLIBRI_STATICTEXT_H
  3.  
  4. typedef enum {
  5.         cp866,  // 6x9
  6.         CP866,  // 8x16
  7.         UTF16,
  8.         UTF8
  9. } encoding_t;
  10.  
  11. typedef struct {
  12.         uint32_t start_xy;
  13.         char *text;
  14.         uint32_t color_flags;
  15.         uint32_t bg_color;
  16. }statictext;
  17.  
  18. typedef struct {
  19.         uint32_t start_xy;
  20.         int32_t number;
  21.         uint32_t color_flags;
  22.         uint32_t bg_color;
  23.         uint16_t width;
  24. }staticnum;
  25.  
  26. statictext* kolibri_statictext(statictext* st, uint32_t xy, char *text, encoding_t enc, int size, color_t font, color_t bg)
  27. {
  28.     st->start_xy = xy;
  29.     st->text = text;
  30.     st->color_flags = 0x80000000; // asciiz
  31.     st->bg_color = bg;
  32.     if(bg & 0xFFFFFF) st->color_flags |= 0x40000000;// use background
  33.     st->color_flags |= ((enc & 1) << 4) | (size & 7) << 24;
  34.     st->color_flags |= font & 0xFFFFFF;
  35.  
  36.     return st;
  37. }
  38.  
  39. statictext* kolibri_statictext_def(statictext* st, uint32_t xy, char *text)
  40. {
  41.     return kolibri_statictext(st, xy, text, 0, 0, kolibri_color_table.color_work_text, 0);
  42. }
  43.  
  44. statictext* kolibri_new_statictext(uint32_t xy, char *text, encoding_t enc, int size, color_t font, color_t bg)
  45. {
  46.     statictext *st = (statictext*)malloc(sizeof(statictext));
  47.  
  48.     return kolibri_statictext(st, xy, text, enc, size, font, bg);
  49. }
  50.  
  51. statictext* kolibri_new_statictext_def(uint32_t xy, char *text)
  52. {
  53.     return kolibri_new_statictext(xy, text, 0, 0, kolibri_color_table.color_work_text, 0);
  54. }
  55.  
  56. __attribute__((__stdcall__))
  57. void statictext_draw(statictext *st)
  58. {
  59.     __asm__ __volatile__(
  60.     "int $0x40"
  61.     ::"a"(4),
  62.       "b"(st->start_xy),
  63.       "c"(st->color_flags),
  64.       "d"(st->text),
  65.       "D"(st->bg_color)
  66.     :);
  67. }
  68.  
  69. inline void gui_add_statictext(kolibri_window *wnd, statictext* st)
  70. {
  71.     kolibri_window_add_element(wnd, KOLIBRI_STATICTEXT, st);
  72. }
  73.  
  74.  
  75.  
  76. staticnum* kolibri_staticnum(staticnum* st, uint32_t xy, int32_t width, int16_t number, encoding_t enc, int size, color_t font, color_t bg)
  77. {
  78.     st->start_xy = xy;
  79.     st->number = number;
  80.     st->color_flags = 0;
  81.     st->bg_color = bg;
  82.     if(bg & 0xFFFFFF) st->color_flags |= 0x40000000;// use background
  83.     st->color_flags |= ((enc & 1) << 4) | (size & 7) << 24;
  84.     st->color_flags |= font & 0xFFFFFF;
  85.     st->width = width;
  86.  
  87.     return st;
  88. }
  89.  
  90. staticnum* kolibri_staticnum_def(staticnum* st, uint32_t xy, int16_t width, int32_t number)
  91. {
  92.     return kolibri_staticnum(st, xy, width, number, 0, 0, kolibri_color_table.color_work_text, 0);
  93. }
  94.  
  95. staticnum* kolibri_new_staticnum(uint32_t xy, int32_t width, int32_t number, encoding_t enc, int size, color_t font, color_t bg)
  96. {
  97.     staticnum *st = (staticnum*)malloc(sizeof(staticnum));
  98.  
  99.     return kolibri_staticnum(st, xy, width, number, enc, size, font, bg);
  100. }
  101.  
  102. staticnum* kolibri_new_staticnum_def(uint32_t xy, int32_t width, int32_t number)
  103. {
  104.     return kolibri_new_staticnum(xy, width, number, cp866, 0, kolibri_color_table.color_work_text, 0);
  105. }
  106.  
  107. inline void gui_add_staticnum(kolibri_window *wnd, staticnum* sn)
  108. {
  109.     kolibri_window_add_element(wnd, KOLIBRI_STATICNUM, sn);
  110. }
  111.  
  112.  
  113. __attribute__((__stdcall__))
  114. void staticnum_draw(staticnum *st)
  115. {
  116.     register uint32_t fmt;
  117.     if (st->width < 0)
  118.         fmt = (-st->width << 16); // leading zeros, decimal
  119.     else
  120.         fmt = (st->width << 16) | 0x80000000; // no leading zeros, decimal
  121.  
  122.     __asm__ __volatile__(
  123.     "int $0x40"
  124.     ::"a"(47),
  125.       "b"(fmt),
  126.       "c"(st->number),
  127.       "d"(st->start_xy),
  128.       "S"(st->color_flags),
  129.       "D"(st->bg_color)
  130.     :);
  131. }
  132.  
  133.  
  134. #endif /* KOLIBRI_STATICTEXT_H */
  135.