Subversion Repositories Kolibri OS

Rev

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