2020-04-10 19:19:52 +03:00
|
|
|
#define MEMSIZE 1024*20
|
2017-06-09 20:43:00 +03:00
|
|
|
|
|
|
|
#include "../lib/gui.h"
|
|
|
|
#include "../lib/clipboard.h"
|
|
|
|
#include "../lib/patterns/rgb.h"
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// DATA //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2020-05-25 17:20:17 +03:00
|
|
|
dword picked_color;
|
|
|
|
char picked_color_string[7];
|
2017-06-09 20:43:00 +03:00
|
|
|
#define FORM_W 167
|
|
|
|
#define FORM_H 60
|
2020-05-25 17:20:17 +03:00
|
|
|
#define PICKED_SIZE 42
|
|
|
|
#define PICKED_PADDING FORM_H - PICKED_SIZE / 2
|
|
|
|
#define PICKED_X FORM_W - PICKED_SIZE - PICKED_PADDING
|
|
|
|
#define BUTTON_CLOSE 1
|
|
|
|
#define BUTTON_COPY 2
|
|
|
|
#define BUTTON_PICK 3
|
2017-06-09 20:43:00 +03:00
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// CODE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2020-05-25 17:20:17 +03:00
|
|
|
bool pick_active = true;
|
2020-04-10 19:19:52 +03:00
|
|
|
proc_info Form;
|
2020-05-25 17:20:17 +03:00
|
|
|
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
|
|
|
|
@SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
|
|
|
|
loop() switch(@WaitEvent())
|
2017-06-09 20:43:00 +03:00
|
|
|
{
|
|
|
|
case evMouse:
|
2020-04-10 19:19:52 +03:00
|
|
|
mouse.get();
|
|
|
|
if (mouse.x>0) && (mouse.x<FORM_W) && (mouse.y>0) && (mouse.y<FORM_H) {
|
2017-06-09 20:43:00 +03:00
|
|
|
EventDragWindow();
|
2020-04-10 19:19:52 +03:00
|
|
|
} else if (pick_active) {
|
2017-06-09 20:43:00 +03:00
|
|
|
picked_color = GetPixelColorFromScreen(mouse.x + Form.left, mouse.y + Form.top);
|
|
|
|
EventUpdateWindowContent();
|
|
|
|
if (mouse.down) && (mouse.key&MOUSE_LEFT) pick_active = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case evButton:
|
2020-05-26 03:17:12 +03:00
|
|
|
@GetButtonID();
|
|
|
|
if (EAX == BUTTON_CLOSE) ExitProcess();
|
|
|
|
if (EAX == BUTTON_COPY) EventCopyHex();
|
|
|
|
if (EAX == BUTTON_PICK) pick_active = true;
|
2017-06-09 20:43:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evKey:
|
2020-05-26 03:17:12 +03:00
|
|
|
@GetKeyScancode();
|
|
|
|
if (AL == SCAN_CODE_ESC) @ExitProcess();
|
|
|
|
if (AL == SCAN_CODE_KEY_C) EventCopyHex();
|
2017-06-09 20:43:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evReDraw:
|
2020-04-10 19:19:52 +03:00
|
|
|
DefineUnDragableWindow(215, 100, FORM_W, FORM_H);
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2017-06-09 20:43:00 +03:00
|
|
|
draw_window();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_window()
|
|
|
|
{
|
|
|
|
DrawRectangle3D(0, 0, FORM_W, FORM_H, 0xCCCccc, 0x888888);
|
|
|
|
DrawRectangle3D(1, 1, FORM_W-2, FORM_H-2, 0xCCCccc, 0x888888);
|
|
|
|
DrawBar(2,2,FORM_W-3,FORM_H-3,0xFFFfff);
|
|
|
|
|
2020-05-25 17:20:17 +03:00
|
|
|
DrawRectangle(PICKED_X-2, PICKED_PADDING-2, PICKED_SIZE+3, PICKED_SIZE+3, 0xCBC6C5);
|
|
|
|
DefineHiddenButton(PICKED_X-1, PICKED_PADDING-1, PICKED_SIZE+1, PICKED_SIZE+1, BUTTON_PICK);
|
2017-06-09 20:43:00 +03:00
|
|
|
|
2020-04-10 19:19:52 +03:00
|
|
|
DrawCopyButton(67, 11, 35, 14);
|
2017-06-09 20:43:00 +03:00
|
|
|
|
|
|
|
EventUpdateWindowContent();
|
|
|
|
}
|
|
|
|
|
2020-04-05 22:29:24 +03:00
|
|
|
//copy of sprintf() => %A
|
|
|
|
void str2col(dword buf, number)
|
|
|
|
{
|
|
|
|
byte s;
|
2020-05-25 17:20:17 +03:00
|
|
|
strlcpy(buf,"000000",6);
|
|
|
|
buf+=6;
|
2020-04-05 22:29:24 +03:00
|
|
|
while(number)
|
|
|
|
{
|
|
|
|
$dec buf
|
|
|
|
s=number&0xF;
|
|
|
|
if(s>9)DSBYTE[buf]='A'+s-10;
|
|
|
|
else DSBYTE[buf]='0'+s;
|
|
|
|
number>>=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 20:43:00 +03:00
|
|
|
void EventUpdateWindowContent()
|
|
|
|
{
|
2020-04-05 22:29:24 +03:00
|
|
|
str2col(#picked_color_string, picked_color);
|
2017-06-09 20:43:00 +03:00
|
|
|
rgb.DwordToRgb(picked_color);
|
2017-10-12 02:19:28 +03:00
|
|
|
|
2020-05-25 17:20:17 +03:00
|
|
|
WriteTextWithBg(12,12, 0xD0, 0x000111, #picked_color_string, 0xFFFfff);
|
2017-06-09 20:43:00 +03:00
|
|
|
|
|
|
|
WriteNumber(12,33, 0xD0, 0xff0000, 3, rgb.r);
|
2020-04-10 19:19:52 +03:00
|
|
|
WriteNumber(44,33, 0xD0, 0x008000, 3, rgb.g);
|
|
|
|
WriteNumber(75,33, 0xD0, 0x0000ff, 3, rgb.b);
|
2017-06-09 20:43:00 +03:00
|
|
|
|
2020-05-25 17:20:17 +03:00
|
|
|
DrawBar(PICKED_X, PICKED_PADDING, PICKED_SIZE, PICKED_SIZE, picked_color);
|
2017-06-09 20:43:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-10 19:19:52 +03:00
|
|
|
void DrawCopyButton(dword _x, _y, _w, _h)
|
2017-06-09 20:43:00 +03:00
|
|
|
{
|
2020-05-25 17:20:17 +03:00
|
|
|
DefineHiddenButton(_x+1, _y+1, _w-2, _h-2, BUTTON_COPY);
|
2020-04-10 19:19:52 +03:00
|
|
|
DrawRectangle(_x, _y, _w, _h, 0x777777);
|
|
|
|
WriteText(_x+6, _h-8/2 + _y, 0x80, 0x555555, "Copy");
|
2017-06-09 20:43:00 +03:00
|
|
|
}
|
|
|
|
|
2017-10-01 14:57:00 +03:00
|
|
|
void EventCopyHex()
|
2017-06-09 20:43:00 +03:00
|
|
|
{
|
2020-05-25 17:20:17 +03:00
|
|
|
Clipboard__CopyText(#picked_color_string);
|
2017-10-01 14:57:00 +03:00
|
|
|
}
|