Subversion Repositories Kolibri OS

Rev

Rev 6271 | Rev 6567 | 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.         dword tx = -strlen(text)*8+w/2+x;
  47.         dword ty = h/2-7+y;
  48.  
  49.         if (id>0) DefineButton(x,y,w,h,id,color_b);
  50.         WriteText(tx+1,ty+1,0x90,MixColors(color_b,0,230),text);
  51.         WriteText(tx,ty,0x90,color_t,text);
  52. }
  53.  
  54. :void WriteTextCenter(dword x,y,w,color_t,text)
  55. {
  56.         WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
  57. }
  58.  
  59. :void DrawCircle(int x, y, r, color)
  60. {
  61.         int i;
  62.         float px=0, py=r, ii = r * 3.1415926 * 2;
  63.         FOR (i = 0; i < ii; i++)
  64.         {
  65.         PutPixel(px + x, y - py, color);
  66.         px = py / r + px;
  67.         py = -px / r + py;
  68.         }
  69. }
  70.  
  71. :unsigned char checkbox_flag[507] = {
  72.         0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  73.         0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xD4,
  74.         0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xDC, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04,
  75.         0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC,
  76.         0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xDC,
  77.         0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xBC, 0x04,
  78.         0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  79.         0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xC8,
  80.         0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xBC, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04,
  81.         0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xFA, 0xA5, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC,
  82.         0xB4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4, 0x04, 0xFC, 0xB4,
  83.         0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xFC, 0xF9, 0xAF, 0xF9, 0x98, 0x04,
  84.         0xFC, 0xB4, 0x04, 0xFC, 0xD4, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xF2, 0xD2, 0xFC, 0xF2, 0xD2, 0xF9,
  85.         0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0,
  86.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04,
  87.         0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF, 0xFC, 0xDC, 0x2C, 0xF9, 0x98, 0x04, 0xFF, 0xFF, 0xFF, 0xFD,
  88.         0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  89.         0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFF, 0xFF, 0xFF,
  90.         0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  91.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xD4, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64,
  92.         0x04, 0xF7, 0xE0, 0x95, 0xFD, 0xFD, 0xF6, 0xFD, 0xFD, 0xF6, 0xF7, 0xE0, 0x95, 0xBC, 0x64, 0x04,
  93.         0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC,
  94.         0xC8, 0x04, 0xFA, 0xA5, 0x04, 0xF9, 0x98, 0x04, 0xBC, 0x64, 0x04, 0xF7, 0xE0, 0x95, 0xF7, 0xE0,
  95.         0x95, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04,
  96.         0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9,
  97.         0x98, 0x04, 0xBC, 0x64, 0x04, 0xBC, 0x64, 0x04, 0xF9, 0x98, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xA9,
  98.         0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F, 0x04, 0xFC, 0xC8, 0x04,
  99.         0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xFA,
  100.         0x9F, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFC, 0xA9, 0x04, 0xFA, 0x9F, 0x04, 0xFA, 0x9F,
  101.         0x04, 0xF9, 0x98, 0x04, 0xFC, 0xB4, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04,
  102.         0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9,
  103.         0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04, 0xF9, 0x98, 0x04
  104. };
  105.  
  106. :void CheckBox(dword x,y,bt_id, text, is_checked)
  107. {
  108.         byte w=14, h=14;
  109.         DefineButton(x-1, y-1, strlen(text)*8 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, 0);
  110.         EDI = system.color.work;
  111.         WriteText(x+w+8, h / 2 + y -7, 0xD0, system.color.work_text, text);
  112.         DrawRectangle(x, y, w, h, system.color.work_graph);
  113.         if (is_checked == 0)
  114.         {
  115.                 DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
  116.                 DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
  117.         }
  118.         else if (is_checked == 1)
  119.         {
  120.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  121.                 _PutImage(x+1, y+1, 13, 13, #checkbox_flag);
  122.         }
  123.         else if (is_checked == 2) //not active
  124.         {
  125.                 DrawWideRectangle(x+1, y+1, w-1, h-1, 2, 0xffffff);
  126.                 DrawBar(x+3, y+3, w-5, h-5, 0x888888);
  127.         }
  128.         DrawRectangle3D(x-1,y-1,w+2,h+2,system.color.work_dark,system.color.work_light);
  129. }
  130.  
  131. :void MoreLessBox(dword x,y, bt_id_more, bt_id_less, value, text)
  132. {
  133.         #define VALUE_FIELD_W 34
  134.         #define SIZE 18
  135.         dword value_text = itoa(value);
  136.  
  137.         DrawRectangle(x, y, VALUE_FIELD_W, SIZE, system.color.work_graph);
  138.         DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xDDDddd, 0xffffff);
  139.         DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xffffff);
  140.         WriteText( -strlen(value_text)+3*8 + x+6, SIZE / 2 + y -6, 0x90, system.color.work_text, value_text);
  141.  
  142.         DrawCaptButton(VALUE_FIELD_W + x,     y, SIZE, SIZE, bt_id_more, system.color.work_button, system.color.work_button_text, "+");
  143.         DrawCaptButton(VALUE_FIELD_W + x + SIZE, y, SIZE, SIZE, bt_id_less, system.color.work_button, system.color.work_button_text, "-");
  144.         EDI = system.color.work;
  145.         WriteText(x+VALUE_FIELD_W+SIZE+SIZE+10, SIZE / 2 + y -7, 0xD0, system.color.work_text, text);
  146.         DrawRectangle3D(x-1,y-1,VALUE_FIELD_W+SIZE+SIZE+2,SIZE+2,system.color.work_dark,system.color.work_light);
  147. }
  148.  
  149. :void DrawEditBox(dword edit_box_pointer)
  150. {
  151.         dword x,y,w,h,bg;
  152.         ESI = edit_box_pointer;
  153.         x = ESI.edit_box.left;
  154.         y = ESI.edit_box.top;
  155.         w = ESI.edit_box.width+1;
  156.         if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff;
  157.         h = 15;
  158.         DrawRectangle(x-1, y-1, w+2, h+2, bg);
  159.         DrawRectangle3D(x-2, y-2, w+2, h+2, 0xDDDddd, bg);
  160.         DrawRectangle(x-3, y-3, w+6, h+6, system.color.work_graph);
  161.         DrawRectangle3D(x-4, y-4, w+8, h+8, system.color.work_dark, system.color.work_light);
  162.         edit_box_draw  stdcall (edit_box_pointer);
  163. }
  164.  
  165. :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
  166. {
  167.         int progress_w;
  168.         static int fill_old;
  169.            
  170.         //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;}
  171.         if (progress_percent<=0) || (progress_percent>=100) return;
  172.        
  173.         DrawRectangle(st_x, st_y, st_w,st_h, col_border);
  174.         DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
  175.  
  176.         if (progress_percent>0) && (progress_percent<=100)
  177.         {
  178.                 progress_w = st_w - 3 * progress_percent / 100;
  179.                 DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
  180.                 DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
  181.         }
  182. }
  183.  
  184. :void DrawLink(dword x,y,font_type,btn_id, inscription)
  185. {
  186.         int w;
  187.         WriteText(x,y,font_type,0x4E00E7,inscription);
  188.         if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*7;
  189.         DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
  190.         DrawBar(x,y+8,w,1,0x4E00E7);
  191. }
  192.  
  193. :void PutShadow(dword x,y,w,h,skinned,strength)
  194. {
  195.         proc_info wForm;
  196.         dword shadow_buf, skin_height;
  197.         shadow_buf = mem_Alloc(w*h*3);
  198.         GetProcessInfo(#wForm, SelfInfo);
  199.         CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
  200.         ShadowImage(shadow_buf, w, h, strength);
  201.         _PutImage(x,y,w,h,shadow_buf);
  202.         mem_Free(shadow_buf);
  203. }
  204.  
  205. :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
  206. {
  207.         DrawRectangle(x,y,w,h,col_border);
  208.         DrawBar(x+1,y+1,w-1,1,0xFFFfff);
  209.         DrawBar(x+1,y+2,1,h-2,0xFFFfff);
  210.         if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
  211.         DrawPopupShadow(x,y,w,h-1,skinned);
  212. }
  213.  
  214. :void DrawPopupShadow(dword x,y,w,h,skinned)
  215. {
  216.         PutShadow(w+x+1,y,1,h+2,skinned,2);
  217.         PutShadow(w+x+2,y+1,1,h+2,skinned,1);
  218.         PutShadow(x,y+h+2,w+2,1,skinned,2);
  219.         PutShadow(x+1,y+h+3,w+1,1,skinned,1);
  220. }
  221.  
  222. :void GrayScaleImage(dword color_image, w, h)
  223. {
  224.         dword i,gray,to,rr,gg,bb;
  225.         to = w*h*3 + color_image;
  226.         for (i = color_image; i < to; i+=3)
  227.         {
  228.                 rr = DSBYTE[i];
  229.                 gg = DSBYTE[i+1];
  230.                 bb = DSBYTE[i+2];
  231.                 gray = rr*rr;
  232.                 gray += gg*gg;
  233.                 gray += bb*bb;
  234.                 gray = sqrt(gray) / 3;
  235.                 DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
  236.         }
  237. }
  238.  
  239. :void ShadowImage(dword color_image, w, h, strength)
  240. {
  241.         dword col, to;
  242.         strength = 10 - strength;
  243.         to = w*h*3 + color_image;
  244.         for ( ; color_image < to; color_image++)
  245.         {
  246.                 col = strength * DSBYTE[color_image] / 10;
  247.                 DSBYTE[color_image] = col;
  248.         }
  249. }
  250.  
  251. :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
  252. {
  253.         dword next_word_pointer = strchr(text_pointer, '\n');
  254.         if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
  255.         ESBYTE[next_word_pointer] = NULL;
  256.         WriteText(dword x, y, byte fontType, dword color, text_pointer);
  257.         ESBYTE[next_word_pointer] = '\n';
  258. }
  259.  
  260. //this function increase falue and return it
  261. //useful for list of controls which goes one after one
  262. struct incn
  263. {
  264.         dword n;
  265.         dword inc(dword _addition);
  266. };
  267.  
  268. dword incn::inc(dword _addition)
  269. {
  270.         n+=_addition;
  271.         return n;
  272. }
  273.  
  274.  
  275. /*=========================================================
  276. ==
  277. ==                   TABS
  278. ==
  279. /========================================================*/
  280.  
  281. #define TAB_PADDING 25
  282. #define TAB_HEIGHT 25
  283.  
  284. :struct _tabs
  285. {
  286.         int active_tab;
  287.         void draw();
  288.         int click();
  289. } tabs;
  290.  
  291. :void _tabs::draw(dword x,y, but_id, text)
  292. {
  293.         dword col_bg, col_text;
  294.         dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
  295.         y -= h;
  296.  
  297.         if (but_id==active_tab)
  298.         {
  299.                 col_bg=system.color.work_button;
  300.                 col_text=system.color.work_button_text;
  301.         }
  302.         else
  303.         {
  304.                 col_bg=system.color.work;
  305.                 col_text=system.color.work_text;
  306.         }
  307.         DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
  308. }
  309.  
  310. :int _tabs::click(int N)
  311. {
  312.         if (N==active_tab) return false;
  313.         active_tab = N;
  314.         return true;
  315. }
  316.  
  317.  
  318.  
  319. #endif