Subversion Repositories Kolibri OS

Rev

Rev 7225 | Rev 7243 | 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.  
  4. #ifndef INCLUDE_KOLIBRI_H
  5. #include "../lib/kolibri.h"
  6. #endif
  7.  
  8. #ifndef INCLUDE_STRING_H
  9. #include "../lib/strings.h"
  10. #endif
  11.  
  12. #ifndef INCLUDE_RGB_H
  13. #include "../lib/patterns/rgb.h"
  14. #endif
  15.  
  16. #ifndef INCLUDE_MATH_H
  17. #include "../lib/math.h"
  18. #endif
  19.  
  20. #include "../lib/gui/tabs.h"
  21. #include "../lib/gui/more_less_box.h"
  22.  
  23. :void DrawRectangle(dword x,y,w,h,color1)
  24. {
  25.         if (w<=0) || (h<=0) return;
  26.         DrawBar(x,y,w,1,color1);
  27.         DrawBar(x,y+h,w,1,color1);
  28.         DrawBar(x,y,1,h,color1);
  29.         DrawBar(x+w,y,1,h+1,color1);
  30. }
  31.  
  32. :void DrawWideRectangle(dword x,y,w,h,boder,color1)
  33. {
  34.         if (w<=0) || (h<=0) return;
  35.         DrawBar(x, y, w, boder, color1);
  36.         DrawBar(x, y+h-boder, w, boder, color1);
  37.         DrawBar(x, y+boder, boder, h-boder-boder, color1);
  38.         DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1);
  39. }
  40.  
  41. :void DrawRectangle3D(dword x,y,w,h,color1,color2)
  42. {
  43.         if (w<=0) || (h<=0) return;
  44.         DrawBar(x,y,w+1,1,color1);
  45.         DrawBar(x,y+1,1,h-1,color1);
  46.         DrawBar(x+w,y+1,1,h,color2);
  47.         DrawBar(x,y+h,w,1,color2);
  48. }
  49.  
  50. :void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
  51. {
  52.         dword tx = -strlen(text)*8+w/2+x;
  53.         dword ty = h/2-7+y;
  54.  
  55.         if (id>0) DefineButton(x,y,w,h,id,color_b);
  56.         WriteText(tx+1,ty+1,0x90,MixColors(color_b,0,230),text);
  57.         WriteText(tx,ty,0x90,color_t,text);
  58. }
  59.  
  60. :int active_button_id = 0;
  61. :int DrawStandartCaptButton(dword x, y, id, text)
  62. {
  63.         #define padding_v 5
  64.         #define padding_h 15
  65.         #define right_margin 12
  66.         #define h padding_v + padding_v + 16 //16 font height
  67.         int tx = x + padding_h;
  68.         int ty = y + padding_v+1;
  69.         int tw = strlen(text)*8;
  70.         int w = tw + padding_h + padding_h;
  71.  
  72.  
  73.         if (id>0) DefineButton(x,y,w,h,id,system.color.work_button);
  74.  
  75.         WriteText(tx+1,ty+1,0x90,MixColors(system.color.work_button,0,230),text);
  76.         WriteText(tx,ty,0x90,system.color.work_button_text,text);
  77.  
  78.         if (active_button_id==id) {
  79.                 DrawBar(tx,ty+15,tw,1, MixColors(system.color.work_button,0,230));
  80.                 DrawBar(tx,ty+14,tw,1, system.color.work_button_text);
  81.         }
  82.  
  83.         return w + right_margin;
  84. }
  85.  
  86. :void ActiveButtonSwitch(int min, max)
  87. {
  88.         active_button_id++;
  89.         if (active_button_id>max) || (active_button_id<max) active_button_id=min;
  90. }
  91.  
  92. :void WriteTextCenter(dword x,y,w,color_t,text)
  93. {
  94.         WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
  95. }
  96.  
  97. :void DrawCircle(int x, y, r, color)
  98. {
  99.         int i;
  100.         float px=0, py=r, ii = r * 3.1415926 * 2;
  101.         FOR (i = 0; i < ii; i++)
  102.         {
  103.         PutPixel(px + x, y - py, color);
  104.         px = py / r + px;
  105.         py = -px / r + py;
  106.         }
  107. }
  108.  
  109. :unsigned char checkbox_flag[507] = {
  110.         0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  111.         0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4,
  112.         0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xDC, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04,
  113.         0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC,
  114.         0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xDC,
  115.         0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xBC, 0x04,
  116.         0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  117.         0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8,
  118.         0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04,
  119.         0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xFA, 0xA5, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  120.         0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4,
  121.         0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xFC, 0xF9, 0xAF, 0xF9, 0x98, 0x04,
  122.         0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xF9,
  123.         0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0,
  124.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04,
  125.         0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF, 0xFC, 0xDC, 0x2C, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD,
  126.         0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  127.         0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF,
  128.         0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  129.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64,
  130.         0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04,
  131.         0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  132.         0xC8, 0x04, 0xFA, 0xA5, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64, 0x04, 0xF7, 0xE0, 0x95, 0xF7, 0xE0,
  133.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04,
  134.         0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9,
  135.         0x98, 0x04, 0xBC, 0x64, 0x04, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  136.         0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04,
  137.         0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  138.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F,
  139.         0x04, 0xF9, 0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04,
  140.         0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9,
  141.         0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04
  142. };
  143.  
  144. :void CheckBox(dword x,y,bt_id, text, is_checked)
  145. {
  146.         byte w=14, h=14;
  147.         DefineButton(x-1, y-1, strlen(text)*8 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, 0);
  148.         EDI = system.color.work;
  149.         WriteText(x+w+8, h / 2 + y -7, 0xD0, system.color.work_text, text);
  150.         DrawRectangle(x, y, w, h, system.color.work_graph);
  151.         if (is_checked == 0)
  152.         {
  153.                 DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
  154.                 DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
  155.         }
  156.         else if (is_checked == 1)
  157.         {
  158.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  159.                 _PutImage(x+1, y+1, 13, 13, #checkbox_flag);
  160.         }
  161.         else if (is_checked == 2) //not active
  162.         {
  163.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  164.                 DrawBar(x+3, y+3, w-5, h-5, 0x888888);
  165.         }
  166.         DrawRectangle3D(x-1,y-1,w+2,h+2,system.color.work_dark,system.color.work_light);
  167. }
  168.  
  169. :void DrawEditBox(dword edit_box_pointer)
  170. {
  171.         dword x,y,w,h,bg;
  172.         ESI = edit_box_pointer;
  173.         x = ESI.edit_box.left;
  174.         y = ESI.edit_box.top;
  175.         w = ESI.edit_box.width+1;
  176.         if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff;
  177.         edit_box_draw  stdcall (edit_box_pointer);
  178.         h = 22;
  179.         DrawRectangle3D(x-1, y-1, w+1, h+1, 0xE7E7E7, bg);
  180.         DrawRectangle(x-2, y-2, w+3, h+3, system.color.work_graph);
  181.         DrawRectangle3D(x-3, y-3, w+5, h+5, system.color.work_dark, system.color.work_light);
  182. }
  183.  
  184. :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
  185. {
  186.         int progress_w;
  187.         static int fill_old;
  188.            
  189.         //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;}
  190.         if (progress_percent<=0) || (progress_percent>=100) return;
  191.        
  192.         DrawRectangle(st_x, st_y, st_w,st_h, col_border);
  193.         DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
  194.  
  195.         if (progress_percent>0) && (progress_percent<=100)
  196.         {
  197.                 progress_w = st_w - 3 * progress_percent / 100;
  198.                 DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
  199.                 DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
  200.         }
  201. }
  202.  
  203. :void DrawLink(dword x,y,font_type,btn_id, inscription)
  204. {
  205.         int w;
  206.         WriteText(x,y,font_type,0x4E00E7,inscription);
  207.         if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*8;
  208.         DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
  209.         DrawBar(x,y+8,w,1,0x4E00E7);
  210. }
  211.  
  212. :void PutShadow(dword x,y,w,h,skinned,strength)
  213. {
  214.         proc_info wForm;
  215.         dword shadow_buf, skin_height;
  216.         shadow_buf = mem_Alloc(w*h*3);
  217.         GetProcessInfo(#wForm, SelfInfo);
  218.         CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
  219.         ShadowImage(shadow_buf, w, h, strength);
  220.         _PutImage(x,y,w,h,shadow_buf);
  221.         mem_Free(shadow_buf);
  222. }
  223.  
  224. :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
  225. {
  226.         DrawRectangle(x,y,w,h,col_border);
  227.         DrawBar(x+1,y+1,w-1,1,0xFFFfff);
  228.         DrawBar(x+1,y+2,1,h-2,0xFFFfff);
  229.         if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
  230.         DrawPopupShadow(x,y,w,h-1,skinned);
  231. }
  232.  
  233. :void DrawPopupShadow(dword x,y,w,h,skinned)
  234. {
  235.         PutShadow(w+x+1,y,1,h+2,skinned,2);
  236.         PutShadow(w+x+2,y+1,1,h+2,skinned,1);
  237.         PutShadow(x,y+h+2,w+2,1,skinned,2);
  238.         PutShadow(x+1,y+h+3,w+1,1,skinned,1);
  239. }
  240.  
  241. :void GrayScaleImage(dword color_image, w, h)
  242. {
  243.         dword i,gray,to,rr,gg,bb;
  244.         to = w*h*3 + color_image;
  245.         for (i = color_image; i < to; i+=3)
  246.         {
  247.                 rr = DSBYTE[i];
  248.                 gg = DSBYTE[i+1];
  249.                 bb = DSBYTE[i+2];
  250.                 gray = rr*rr;
  251.                 gray += gg*gg;
  252.                 gray += bb*bb;
  253.                 gray = sqrt(gray) / 3;
  254.                 DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
  255.         }
  256. }
  257.  
  258. :void ShadowImage(dword color_image, w, h, strength)
  259. {
  260.         dword col, to;
  261.         strength = 10 - strength;
  262.         to = w*h*3 + color_image;
  263.         for ( ; color_image < to; color_image++)
  264.         {
  265.                 col = strength * DSBYTE[color_image] / 10;
  266.                 DSBYTE[color_image] = col;
  267.         }
  268. }
  269.  
  270. :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
  271. {
  272.         dword next_word_pointer = strchr(text_pointer, '\n');
  273.         if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
  274.         ESBYTE[next_word_pointer] = NULL;
  275.         WriteText(dword x, y, byte fontType, dword color, text_pointer);
  276.         ESBYTE[next_word_pointer] = '\n';
  277. }
  278.  
  279. /*
  280. We have a long text and need to show it in block.
  281. Normal line break '\n' must be applied.
  282. Long lines should be breaked by word.
  283. TODO: scroll
  284. */
  285. :int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col)
  286. {
  287.         dword write_start;
  288.         dword buf_end;
  289.         int line_h = 15;
  290.         int label_length_max;
  291.         int write_length;
  292.         bool end_found;
  293.  
  294.         write_start = buf_start;
  295.         buf_end = strlen(buf_start) + buf_start;
  296.         label_length_max  = w / 8; // 8 big font char width
  297.  
  298.         loop()
  299.         {
  300.                 if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col);
  301.                 end_found = false;
  302.                 write_length = strchr(write_start, '\n') - write_start; //search normal line break
  303.                 if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found
  304.                 {
  305.                         if (buf_end - write_start < label_length_max) //check does current line the last
  306.                         {
  307.                                 write_length = buf_end - write_start;
  308.                                 end_found = true;
  309.                         }
  310.                         else
  311.                         {
  312.                                 for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break
  313.                                         if (ESBYTE[write_start+write_length] == ' ') {
  314.                                                 end_found = true;
  315.                                                 break;
  316.                                         }
  317.                                 }
  318.                         }
  319.                         if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max
  320.                 }
  321.                 ESI = write_length; //set text length attribute for WriteText()
  322.                 WriteText(x, y, 0x10, text_col, write_start);
  323.                 // if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) {
  324.                 //      WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|");
  325.                 // }
  326.                 write_start += write_length + 1;
  327.                 y += line_h;
  328.                 if (write_start >= buf_end) break;
  329.         }
  330.         if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col);
  331.         return y+line_h;
  332. }
  333.  
  334.  
  335. //this function increase falue and return it
  336. //useful for list of controls which goes one after one
  337. :struct incn
  338. {
  339.         dword n;
  340.         dword inc(dword _addition);
  341. };
  342.  
  343. :dword incn::inc(dword _addition)
  344. {
  345.         n+=_addition;
  346.         return n;
  347. }
  348.  
  349. //block with hover
  350. struct block {
  351.         int x,y,w,h;
  352.         bool hovered();
  353.         void set_size();
  354. };
  355.  
  356. :bool block::hovered() {
  357.         if ((mouse.x>x) && (mouse.y>y)
  358.         && (mouse.y<y+h) && (mouse.x<x+w))
  359.                 return true;
  360.         return false;
  361. }
  362.  
  363. :void block::set_size(dword _x, _y, _w, _h)
  364. {
  365.         x=_x;
  366.         y=_y;
  367.         w=_w;
  368.         h=_h;
  369. }
  370.  
  371.  
  372.  
  373.  
  374.  
  375. #endif