Subversion Repositories Kolibri OS

Rev

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