Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef INCLUDE_GUI_H
  2. #define INCLUDE_GUI_H
  3. #print "[include <gui.h>]\n"
  4.  
  5. #ifndef INCLUDE_KOLIBRI_H
  6. #include "../lib/kolibri.h"
  7. #endif
  8.  
  9. #ifndef INCLUDE_STRING_H
  10. #include "../lib/strings.h"
  11. #endif
  12.  
  13. :void DrawRectangle(dword x,y,w,h,color1)
  14. {
  15.         if (w<=0) || (h<=0) return;
  16.         DrawBar(x,y,w,1,color1);
  17.         DrawBar(x,y+h,w,1,color1);
  18.         DrawBar(x,y,1,h,color1);
  19.         DrawBar(x+w,y,1,h+1,color1);
  20. }
  21.  
  22. :void DrawWideRectangle(dword x,y,w,h,boder,color1)
  23. {
  24.         if (w<=0) || (h<=0) return;
  25.         DrawBar(x, y, w, boder, color1);
  26.         DrawBar(x, y+h-boder, w, boder, color1);
  27.         DrawBar(x, y+boder, boder, h-boder-boder, color1);
  28.         DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1);
  29. }
  30.  
  31. :void DrawRectangle3D(dword x,y,w,h,color1,color2)
  32. {
  33.         if (w<=0) || (h<=0) return;
  34.         DrawBar(x,y,w+1,1,color1);
  35.         DrawBar(x,y+1,1,h-1,color1);
  36.         DrawBar(x+w,y+1,1,h,color2);
  37.         DrawBar(x,y+h,w,1,color2);
  38. }
  39.  
  40. :void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
  41. {
  42.         if (id>0) DefineButton(x,y,w,h,id,color_b);
  43.         WriteText(-strlen(text)*6+w/2+x+1,h/2-3+y,0x80,color_t,text);
  44. }
  45.  
  46. :void WriteTextCenter(dword x,y,w,color_t,text)
  47. {
  48.         WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
  49. }
  50.  
  51. :void DrawCircle(int x, y, r, color)
  52. {
  53.         int i;
  54.         float px=0, py=r, ii = r * 3.1415926 * 2;
  55.         FOR (i = 0; i < ii; i++)
  56.         {
  57.         PutPixel(px + x, y - py, color);
  58.         px = py / r + px;
  59.         py = -px / r + py;
  60.         }
  61. }
  62.  
  63. :void CheckBox(dword x,y,w,h, bt_id, text, graph_color, text_color, is_checked)
  64. {
  65.         DefineButton(x-1, y-1, strlen(text)*6 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, graph_color);
  66.         WriteText(x+w+8, h / 2 + y -3, 0x80, text_color, text);
  67.         DrawRectangle(x, y, w, h, graph_color);
  68.         if (is_checked == 0)
  69.         {
  70.                 DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
  71.                 DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
  72.         }
  73.         else if (is_checked == 1)
  74.         {
  75.                 DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
  76.                 DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
  77.                 DrawBar(x+3, y+3, w-5, h-5, graph_color);
  78.         }
  79.         else if (is_checked == 2) //not active
  80.         {
  81.                 DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
  82.                 DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
  83.                 DrawBar(x+3, y+3, w-5, h-5, 0x888888);
  84.         }
  85. }
  86.  
  87. :void MoreLessBox(dword x,y,s, bt_id_more, bt_id_less, colors_pointer, value, text)
  88. {
  89.         #define VALUE_FIELD_W 26;
  90.         ESI = colors_pointer;
  91.         system.color.work_graph = ESI.COLORS.work_graph;
  92.         system.color.work_text = ESI.COLORS.work_text;
  93.         system.color.work_button = ESI.COLORS.work_button;
  94.         system.color.work_button_text = ESI.COLORS.work_button_text;
  95.  
  96.         DrawRectangle(x, y, VALUE_FIELD_W, s, system.color.work_graph);
  97.         DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, s-2, 0xDDDddd, 0xffffff);
  98.         DrawBar(x+2, y+2, VALUE_FIELD_W-3, s-3, 0xffffff);
  99.         WriteText(x+6, s / 2 + y -3, 0x80, 0x000000, itoa(value));
  100.  
  101.         DrawCaptButton(VALUE_FIELD_W + x + 1,     y, s, s, bt_id_more, system.color.work_button, system.color.work_button_text, "+");
  102.         DrawCaptButton(VALUE_FIELD_W + x + s + 2, y, s, s, bt_id_less, system.color.work_button, system.color.work_button_text, "-");
  103.         WriteText(x+VALUE_FIELD_W+s+s+10, s / 2 + y -3, 0x80, system.color.work_text, text);
  104. }
  105.  
  106. :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
  107. {
  108.         int progress_w;
  109.         static int fill_old;
  110.            
  111.         //if (progress_percent<=0) {DrawBar(st_x,st_y, st_x + st_w + fill_old + 15,st_h+1, col_fon); fill_old=0; return;}
  112.         if (progress_percent<=0) || (progress_percent>=100) return;
  113.        
  114.         DrawRectangle(st_x, st_y, st_w,st_h, col_border);
  115.         DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
  116.  
  117.         if (progress_percent>0) && (progress_percent<=100)
  118.         {
  119.                 progress_w = st_w - 3 * progress_percent / 100;
  120.                 DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
  121.                 DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
  122.         }
  123. }
  124.  
  125. :void DrawLink(dword x,y,font_type,btn_id, inscription)
  126. {
  127.         int w;
  128.         WriteText(x,y,font_type,0x4E00E7,inscription);
  129.         if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*7;
  130.         DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
  131.         DrawBar(x,y+8,w,1,0x4E00E7);
  132. }
  133.  
  134. :void PutShadow(dword x,y,w,h,skinned,strength)
  135. {
  136.         proc_info wForm;
  137.         dword shadow_buf, skin_height;
  138.         shadow_buf = mem_Alloc(w*h*3);
  139.         GetProcessInfo(#wForm, SelfInfo);
  140.         CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
  141.         ShadowImage(shadow_buf, w, h, strength);
  142.         _PutImage(x,y,w,h,shadow_buf);
  143.         mem_Free(shadow_buf);
  144. }
  145.  
  146. :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
  147. {
  148.         DrawRectangle(x,y,w,h,col_border);
  149.         DrawBar(x+1,y+1,w-1,1,0xFFFfff);
  150.         DrawBar(x+1,y+2,1,h-2,0xFFFfff);
  151.         if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
  152.         DrawPopupShadow(x,y,w,h-1,skinned);
  153. }
  154.  
  155. :void DrawPopupShadow(dword x,y,w,h,skinned)
  156. {
  157.         PutShadow(w+x+1,y,1,h+2,skinned,2);
  158.         PutShadow(w+x+2,y+1,1,h+2,skinned,1);
  159.         PutShadow(x,y+h+2,w+2,1,skinned,2);
  160.         PutShadow(x+1,y+h+3,w+1,1,skinned,1);
  161. }
  162.  
  163. :void GrayScaleImage(dword color_image, w, h)
  164. {
  165.         dword i,gray,to,rr,gg,bb;
  166.         to = w*h*3 + color_image;
  167.         for (i = color_image; i < to; i+=3)
  168.         {
  169.                 rr = DSBYTE[i];
  170.                 gg = DSBYTE[i+1];
  171.                 bb = DSBYTE[i+2];
  172.                 gray = rr*rr;
  173.                 gray += gg*gg;
  174.                 gray += bb*bb;
  175.                 gray = sqrt(gray) / 3;
  176.                 DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
  177.         }
  178. }
  179.  
  180. :void ShadowImage(dword color_image, w, h, strength)
  181. {
  182.         dword col, to;
  183.         strength = 10 - strength;
  184.         to = w*h*3 + color_image;
  185.         for ( ; color_image < to; color_image++)
  186.         {
  187.                 col = strength * DSBYTE[color_image] / 10;
  188.                 DSBYTE[color_image] = col;
  189.         }
  190. }
  191.  
  192. :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
  193. {
  194.         dword next_word_pointer = strchr(text_pointer, '\n');
  195.         if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
  196.         ESBYTE[next_word_pointer] = NULL;
  197.         WriteText(dword x, y, byte fontType, dword color, text_pointer);
  198.         ESBYTE[next_word_pointer] = '\n';
  199. }
  200.  
  201. #endif