Subversion Repositories Kolibri OS

Rev

Rev 6193 | Rev 6198 | 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. #ifndef INCLUDE_RGB_H
  14. #include "../lib/patterns/rgb.h"
  15. #endif
  16.  
  17. :void DrawRectangle(dword x,y,w,h,color1)
  18. {
  19.         if (w<=0) || (h<=0) return;
  20.         DrawBar(x,y,w,1,color1);
  21.         DrawBar(x,y+h,w,1,color1);
  22.         DrawBar(x,y,1,h,color1);
  23.         DrawBar(x+w,y,1,h+1,color1);
  24. }
  25.  
  26. :void DrawWideRectangle(dword x,y,w,h,boder,color1)
  27. {
  28.         if (w<=0) || (h<=0) return;
  29.         DrawBar(x, y, w, boder, color1);
  30.         DrawBar(x, y+h-boder, w, boder, color1);
  31.         DrawBar(x, y+boder, boder, h-boder-boder, color1);
  32.         DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1);
  33. }
  34.  
  35. :void DrawRectangle3D(dword x,y,w,h,color1,color2)
  36. {
  37.         if (w<=0) || (h<=0) return;
  38.         DrawBar(x,y,w+1,1,color1);
  39.         DrawBar(x,y+1,1,h-1,color1);
  40.         DrawBar(x+w,y+1,1,h,color2);
  41.         DrawBar(x,y+h,w,1,color2);
  42. }
  43.  
  44. :void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
  45. {
  46.         word tx = -strlen(text)*6+w/2+x+1;
  47.         word ty = h/2-3+y;
  48.         if (id>0) DefineButton(x,y,w,h,id,color_b);
  49.         WriteText(tx+1,ty+1,0x80,MixColors(color_b,0,200),text);
  50.         WriteText(tx,ty,0x80,color_t,text);
  51. }
  52.  
  53. :void WriteTextCenter(dword x,y,w,color_t,text)
  54. {
  55.         WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
  56. }
  57.  
  58. :void DrawCircle(int x, y, r, color)
  59. {
  60.         int i;
  61.         float px=0, py=r, ii = r * 3.1415926 * 2;
  62.         FOR (i = 0; i < ii; i++)
  63.         {
  64.         PutPixel(px + x, y - py, color);
  65.         px = py / r + px;
  66.         py = -px / r + py;
  67.         }
  68. }
  69.  
  70. unsigned char checkbox_flag[507] = {
  71.         0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  72.         0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4,
  73.         0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xDC, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04,
  74.         0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC,
  75.         0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xDC,
  76.         0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xBC, 0x04,
  77.         0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  78.         0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8,
  79.         0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04,
  80.         0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xFA, 0xA5, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  81.         0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4,
  82.         0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xFC, 0xF9, 0xAF, 0xF9, 0x98, 0x04,
  83.         0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xF9,
  84.         0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0,
  85.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04,
  86.         0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF, 0xFC, 0xDC, 0x2C, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD,
  87.         0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  88.         0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF,
  89.         0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  90.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64,
  91.         0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04,
  92.         0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  93.         0xC8, 0x04, 0xFA, 0xA5, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64, 0x04, 0xF7, 0xE0, 0x95, 0xF7, 0xE0,
  94.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04,
  95.         0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9,
  96.         0x98, 0x04, 0xBC, 0x64, 0x04, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  97.         0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04,
  98.         0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  99.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F,
  100.         0x04, 0xF9, 0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04,
  101.         0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9,
  102.         0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04
  103. };
  104.  
  105. :void CheckBox(dword x,y,bt_id, text, is_checked)
  106. {
  107.         byte w=14, h=14;
  108.         DefineButton(x-1, y-1, strlen(text)*8 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, 0);
  109.         WriteText(x+w+8, h / 2 + y -7, 0x90, system.color.work_text, text);
  110.         DrawRectangle(x, y, w, h, system.color.work_graph);
  111.         if (is_checked == 0)
  112.         {
  113.                 DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
  114.                 DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
  115.         }
  116.         else if (is_checked == 1)
  117.         {
  118.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  119.                 _PutImage(x+1, y+1, 13, 13, #checkbox_flag);
  120.         }
  121.         else if (is_checked == 2) //not active
  122.         {
  123.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  124.                 DrawBar(x+3, y+3, w-5, h-5, 0x888888);
  125.         }
  126.         DrawRectangle3D(x-1,y-1,w+2,h+2,system.color.work_dark,system.color.work_light);
  127. }
  128.  
  129. :void MoreLessBox(dword x,y, bt_id_more, bt_id_less, value, text)
  130. {
  131.         #define VALUE_FIELD_W 26
  132.         #define SIZE 18
  133.  
  134.         DrawRectangle(x, y, VALUE_FIELD_W, SIZE, system.color.work_graph);
  135.         DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xDDDddd, 0xffffff);
  136.         DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xffffff);
  137.         WriteText(x+6, SIZE / 2 + y -3, 0x80, 0x000000, itoa(value));
  138.  
  139.         DrawCaptButton(VALUE_FIELD_W + x,     y, SIZE, SIZE, bt_id_more, system.color.work_button, system.color.work_button_text, "+");
  140.         DrawCaptButton(VALUE_FIELD_W + x + SIZE, y, SIZE, SIZE, bt_id_less, system.color.work_button, system.color.work_button_text, "-");
  141.         WriteText(x+VALUE_FIELD_W+SIZE+SIZE+10, SIZE / 2 + y -7, 0x90, system.color.work_text, text);
  142.         DrawRectangle3D(x-1,y-1,VALUE_FIELD_W+SIZE+SIZE+2,SIZE+2,system.color.work_dark,system.color.work_light);
  143. }
  144.  
  145. :void EditBox(dword edit_box_pointer)
  146. {
  147.         dword x,y,w,h;
  148.         ESI = edit_box_pointer;
  149.         x = ESI.edit_box.left;
  150.         y = ESI.edit_box.top;
  151.         w = ESI.edit_box.width+1;
  152.         h = 15;
  153.         DrawRectangle(x-1, y-1, w+2, h+2, 0xFFFfff);
  154.         DrawRectangle3D(x-2, y-2, w+2, h+2, 0xDDDddd, 0xffffff);
  155.         DrawRectangle(x-3, y-3, w+6, h+6, system.color.work_graph);
  156.         DrawRectangle3D(x-4, y-4, w+8, h+8, system.color.work_dark, system.color.work_light);
  157. }
  158.  
  159. :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
  160. {
  161.         int progress_w;
  162.         static int fill_old;
  163.            
  164.         //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;}
  165.         if (progress_percent<=0) || (progress_percent>=100) return;
  166.        
  167.         DrawRectangle(st_x, st_y, st_w,st_h, col_border);
  168.         DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
  169.  
  170.         if (progress_percent>0) && (progress_percent<=100)
  171.         {
  172.                 progress_w = st_w - 3 * progress_percent / 100;
  173.                 DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
  174.                 DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
  175.         }
  176. }
  177.  
  178. :void DrawLink(dword x,y,font_type,btn_id, inscription)
  179. {
  180.         int w;
  181.         WriteText(x,y,font_type,0x4E00E7,inscription);
  182.         if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*7;
  183.         DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
  184.         DrawBar(x,y+8,w,1,0x4E00E7);
  185. }
  186.  
  187. :void PutShadow(dword x,y,w,h,skinned,strength)
  188. {
  189.         proc_info wForm;
  190.         dword shadow_buf, skin_height;
  191.         shadow_buf = mem_Alloc(w*h*3);
  192.         GetProcessInfo(#wForm, SelfInfo);
  193.         CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
  194.         ShadowImage(shadow_buf, w, h, strength);
  195.         _PutImage(x,y,w,h,shadow_buf);
  196.         mem_Free(shadow_buf);
  197. }
  198.  
  199. :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
  200. {
  201.         DrawRectangle(x,y,w,h,col_border);
  202.         DrawBar(x+1,y+1,w-1,1,0xFFFfff);
  203.         DrawBar(x+1,y+2,1,h-2,0xFFFfff);
  204.         if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
  205.         DrawPopupShadow(x,y,w,h-1,skinned);
  206. }
  207.  
  208. :void DrawPopupShadow(dword x,y,w,h,skinned)
  209. {
  210.         PutShadow(w+x+1,y,1,h+2,skinned,2);
  211.         PutShadow(w+x+2,y+1,1,h+2,skinned,1);
  212.         PutShadow(x,y+h+2,w+2,1,skinned,2);
  213.         PutShadow(x+1,y+h+3,w+1,1,skinned,1);
  214. }
  215.  
  216. :void GrayScaleImage(dword color_image, w, h)
  217. {
  218.         dword i,gray,to,rr,gg,bb;
  219.         to = w*h*3 + color_image;
  220.         for (i = color_image; i < to; i+=3)
  221.         {
  222.                 rr = DSBYTE[i];
  223.                 gg = DSBYTE[i+1];
  224.                 bb = DSBYTE[i+2];
  225.                 gray = rr*rr;
  226.                 gray += gg*gg;
  227.                 gray += bb*bb;
  228.                 gray = sqrt(gray) / 3;
  229.                 DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
  230.         }
  231. }
  232.  
  233. :void ShadowImage(dword color_image, w, h, strength)
  234. {
  235.         dword col, to;
  236.         strength = 10 - strength;
  237.         to = w*h*3 + color_image;
  238.         for ( ; color_image < to; color_image++)
  239.         {
  240.                 col = strength * DSBYTE[color_image] / 10;
  241.                 DSBYTE[color_image] = col;
  242.         }
  243. }
  244.  
  245. :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
  246. {
  247.         dword next_word_pointer = strchr(text_pointer, '\n');
  248.         if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
  249.         ESBYTE[next_word_pointer] = NULL;
  250.         WriteText(dword x, y, byte fontType, dword color, text_pointer);
  251.         ESBYTE[next_word_pointer] = '\n';
  252. }
  253.  
  254. //this function increase falue and return it
  255. //useful for list of controls which goes one after one
  256. struct incn
  257. {
  258.         dword n;
  259.         dword inc(dword _addition);
  260. };
  261.  
  262. dword incn::inc(dword _addition)
  263. {
  264.         n+=_addition;
  265.         return n;
  266. }
  267.  
  268. #endif