2025-11-01 03:42:11 +00:00
|
|
|
#include <Mw/Milsko.h>
|
|
|
|
|
|
2025-11-02 19:15:38 +00:00
|
|
|
MwWidget cpicker;
|
|
|
|
|
MwWidget window;
|
|
|
|
|
MwWidget button;
|
|
|
|
|
|
2026-04-22 12:05:49 +09:00
|
|
|
void MWAPI color_callback(MwWidget handle, void* user_data, void* call_data) {
|
2025-11-02 20:42:06 +00:00
|
|
|
char hexColor[8];
|
2025-11-02 20:08:42 +00:00
|
|
|
MwRGB* rgb = call_data;
|
2025-11-02 19:15:38 +00:00
|
|
|
|
2025-11-02 20:08:42 +00:00
|
|
|
(void)handle;
|
|
|
|
|
(void)user_data;
|
|
|
|
|
|
2025-11-03 21:47:21 +00:00
|
|
|
rgb->red &= 0xff;
|
|
|
|
|
rgb->green &= 0xff;
|
|
|
|
|
rgb->blue &= 0xff;
|
2026-03-30 11:19:10 -07:00
|
|
|
MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
|
2025-11-02 19:15:38 +00:00
|
|
|
MwSetText(window, MwNbackground, hexColor);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 12:05:49 +09:00
|
|
|
void MWAPI color_picker(MwWidget handle, void* user_data, void* call_data) {
|
2025-11-02 20:08:42 +00:00
|
|
|
MwWidget cpicker = MwColorPicker(window, "cpicker");
|
|
|
|
|
|
|
|
|
|
(void)handle;
|
|
|
|
|
(void)user_data;
|
|
|
|
|
(void)call_data;
|
|
|
|
|
|
|
|
|
|
MwAddUserHandler(cpicker, MwNcolorChosenHandler, color_callback, NULL);
|
|
|
|
|
|
2026-04-15 03:08:55 -05:00
|
|
|
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
2025-11-02 19:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 03:42:11 +00:00
|
|
|
int main() {
|
2025-11-13 01:30:10 +00:00
|
|
|
MwLibraryInit();
|
|
|
|
|
|
2025-11-02 19:15:38 +00:00
|
|
|
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
|
|
|
|
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
2026-04-15 13:03:24 -07:00
|
|
|
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
2025-11-01 03:42:11 +00:00
|
|
|
|
2025-11-02 19:15:38 +00:00
|
|
|
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
|
|
|
|
MwNtext, "change window background",
|
|
|
|
|
NULL);
|
2026-04-16 08:42:01 +09:00
|
|
|
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
2025-11-01 03:42:11 +00:00
|
|
|
|
2025-11-02 19:15:38 +00:00
|
|
|
MwAddUserHandler(button, MwNactivateHandler, color_picker, NULL);
|
2025-11-01 03:59:45 +00:00
|
|
|
|
2025-11-02 19:15:38 +00:00
|
|
|
MwLoop(window);
|
2025-11-01 03:42:11 +00:00
|
|
|
}
|