Subversion Repositories Kolibri OS

Rev

Rev 9693 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024*20
  2.  
  3. #include "../lib/gui.h"
  4. #include "../lib/clipboard.h"
  5. #include "../lib/patterns/rgb.h"
  6.  
  7. //===================================================//
  8. //                                                   //
  9. //                       DATA                        //
  10. //                                                   //
  11. //===================================================//
  12.  
  13. dword picked_color;
  14. char picked_color_string[7];
  15. char picked_rgb_string[12];
  16.  
  17. #define PICKED_SIZE 48
  18. #define LABEL_RGB_W 97
  19. #define PAD 11
  20. #define PICKED_X PAD + LABEL_RGB_W + PAD
  21.  
  22. #define FORM_W PICKED_X + PICKED_SIZE + PAD + 1
  23. #define FORM_H PAD + PICKED_SIZE + PAD + 3
  24.  
  25. #define BUTTON_CLOSE    1
  26. #define BUTTON_PICK     2
  27. #define BUTTON_COPY_HEX 3
  28. #define BUTTON_COPY_RGB 4
  29.  
  30. #define COLOR_WIN_BG   0xD6D7DA
  31. #define COLOR_PANE_BG  0xFFFfff
  32. #define COLOR_3D_LIGHT 0xADAAA9
  33. #define COLOR_3D_DARK  0x888888
  34.  
  35. //===================================================//
  36. //                                                   //
  37. //                       CODE                        //
  38. //                                                   //
  39. //===================================================//
  40.  
  41. void main()
  42. {
  43.         bool pick_active = true;
  44.         proc_info Form;
  45.         @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
  46.         @SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
  47.         loop() switch(@WaitEvent())
  48.         {
  49.                 case evMouse:
  50.                         mouse.get();                   
  51.                         if (mouse.x>0) && (mouse.x<FORM_W) && (mouse.y>0) && (mouse.y<FORM_H) {
  52.                                 EventDragWindow();
  53.                         } else if (pick_active) {
  54.                                 picked_color = GetPixelColorFromScreen(mouse.x + Form.left, mouse.y + Form.top);
  55.                                 EventUpdateWindowContent();
  56.                                 if (mouse.down) && (mouse.key&MOUSE_LEFT) pick_active = false;
  57.                         }
  58.                         break;
  59.  
  60.                 case evButton:
  61.                         @GetButtonID();
  62.                         if (EAX == BUTTON_CLOSE) ExitProcess();
  63.                         else if (EAX == BUTTON_COPY_HEX) EventCopyHex();
  64.                         else if (EAX == BUTTON_COPY_RGB) EventCopyRgb();
  65.                         else if (EAX == BUTTON_PICK) { pick_active = true; EventActivatePick(); }
  66.                         break;
  67.  
  68.                 case evKey:
  69.                         @GetKeyScancode();
  70.                         if (AL == SCAN_CODE_ESC) @ExitProcess();
  71.                         if (AL == SCAN_CODE_KEY_C) EventCopyHex();
  72.                         break;
  73.                  
  74.                 case evReDraw:
  75.                         DefineUnDragableWindow(215, 100, FORM_W, FORM_H);
  76.                         GetProcessInfo(#Form, SelfInfo);
  77.                         draw_window();
  78.         }
  79. }
  80.  
  81. void draw_window()
  82. {
  83.         DrawRectangle(0, 0, FORM_W, FORM_H, COLOR_3D_DARK);
  84.         DrawRectangle(1, 1, FORM_W-2, FORM_H-2, COLOR_PANE_BG);
  85.         DrawRectangle(2, 2, FORM_W-4, FORM_H-4, COLOR_3D_LIGHT);
  86.         DrawBar(3,3,FORM_W-5,FORM_H-5, COLOR_WIN_BG);
  87.         DrawButton3D(PAD, PAD, 58, 21, BUTTON_COPY_HEX, COLOR_PANE_BG);
  88.         DrawButton3D(PAD, 41, LABEL_RGB_W, 21, BUTTON_COPY_RGB, COLOR_PANE_BG);
  89.         DrawButton3D(PICKED_X-2, PAD, PICKED_SIZE+3, PICKED_SIZE+3, BUTTON_PICK, -1);
  90.         EventUpdateWindowContent();
  91. }
  92.  
  93. int DrawButton3D(dword _x, _y, _w, _h, _id, _col)
  94. {
  95.         DefineHiddenButton(_x+1, _y+1, _w-2, _h-2, _id);
  96.         DrawRectangle3D(_x, _y, _w, _h, COLOR_3D_LIGHT, COLOR_3D_DARK);
  97.         DrawRectangle3D(_x+1, _y+1, _w-2, _h-2, COLOR_PANE_BG, COLOR_PANE_BG);
  98.         if (_col) DrawBar(_x+2, _y+2, _w-2, _h-2, _col);
  99. }
  100.  
  101. //copy of sprintf() => %A
  102. void str2col(dword buf, number)
  103. {
  104.         byte s;
  105.         strcpy(buf,"000000");
  106.         buf+=6;
  107.         while(number)
  108.         {
  109.                 $dec buf
  110.                 s=number&0xF;
  111.                 if(s>9)DSBYTE[buf]='A'+s-10;
  112.                 else DSBYTE[buf]='0'+s;
  113.                 number>>=4;
  114.         }
  115. }
  116.  
  117. void EventUpdateWindowContent()
  118. {
  119.         str2col(#picked_color_string, picked_color);
  120.         rgb.DwordToRgb(picked_color);
  121.        
  122.         WriteTextWithBg(PAD+5, PAD+4, 0xD0, 0x000111, #picked_color_string, COLOR_PANE_BG);
  123.        
  124.         WriteNumber(PAD+04, PAD+PAD+23, 0xD0, 0xff0000, 3<<16, rgb.r);
  125.         WriteNumber(PAD+36, PAD+PAD+23, 0xD0, 0x008000, 3<<16, rgb.g);
  126.         WriteNumber(PAD+67, PAD+PAD+23, 0xD0, 0x0000ff, 3<<16, rgb.b);
  127.  
  128.         DrawBar(PICKED_X, PAD+2, PICKED_SIZE, PICKED_SIZE, picked_color);
  129. }
  130.  
  131. void EventActivatePick()
  132. {
  133.         DrawBar(PICKED_X, PAD+2, PICKED_SIZE, PICKED_SIZE, COLOR_PANE_BG);
  134.         WriteTextWithBg(-4*8+PICKED_SIZE/2+PICKED_X, PICKED_SIZE/2+PAD-5, 0xD0, 0x000111, "Pick", COLOR_PANE_BG);
  135. }
  136.  
  137. void EventCopyHex()
  138. {
  139.         Clipboard__CopyText(#picked_color_string);
  140.         WriteTextWithBg(PAD+5, PAD+4, 0xD0, 0xD100C6, "Copied", COLOR_PANE_BG);
  141.         pause(50);
  142.         draw_window();
  143. }
  144.  
  145. void EventCopyRgb()
  146. {
  147.         strcpy(#picked_rgb_string, "000,000,000");
  148.         rgb2str(#picked_rgb_string, rgb.r);
  149.         rgb2str(#picked_rgb_string+4, rgb.g);
  150.         rgb2str(#picked_rgb_string+8, rgb.b);
  151.         Clipboard__CopyText(#picked_rgb_string);
  152.         WriteTextWithBg(PAD+1, PAD+PAD+23, 0xD0, 0xD100C6, "   Copied   ", COLOR_PANE_BG);
  153.         pause(50);
  154.         draw_window();
  155. }
  156.  
  157. void rgb2str(int _str, _i)
  158. {
  159.         if (_i < 10) {
  160.                 ESBYTE[_str+2] = _i + '0';
  161.         } else if (_i < 100) {
  162.                 //23
  163.                 ESBYTE[_str+1] = _i / 10 + '0';
  164.                 ESBYTE[_str+2] = _i % 10 + '0';
  165.         } else {
  166.                 //123
  167.                 ESBYTE[_str+0] = _i / 100 + '0';
  168.                 ESBYTE[_str+1] = _i / 10 % 10 + '0';
  169.                 ESBYTE[_str+2] = _i % 100 % 10 + '0';
  170.         }
  171. }
  172.  
  173.