2025-09-28 13:46:18 +00:00
|
|
|
/* $Id$ */
|
2025-09-29 00:10:20 +00:00
|
|
|
#include <Mw/Milsko.h>
|
2025-09-28 13:46:18 +00:00
|
|
|
|
2025-09-29 00:04:04 +00:00
|
|
|
static void create(MwWidget handle) {
|
|
|
|
|
MwSetDefault(handle);
|
2025-09-28 13:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-29 00:04:04 +00:00
|
|
|
static void draw(MwWidget handle) {
|
2025-09-29 04:33:53 +00:00
|
|
|
MwRect r;
|
|
|
|
|
MwPoint point;
|
|
|
|
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
|
|
|
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
|
|
|
|
const char* str = MwGetText(handle, MwNtext);
|
2025-09-30 17:47:03 +00:00
|
|
|
MwLLPixmap px = MwGetVoid(handle, MwNpixmap);
|
2025-09-29 04:33:53 +00:00
|
|
|
|
|
|
|
|
if(str == NULL) str = "";
|
2025-09-28 14:36:24 +00:00
|
|
|
|
|
|
|
|
r.x = 0;
|
|
|
|
|
r.y = 0;
|
2025-09-29 00:04:04 +00:00
|
|
|
r.width = MwGetInteger(handle, MwNwidth);
|
|
|
|
|
r.height = MwGetInteger(handle, MwNheight);
|
2025-09-28 14:36:24 +00:00
|
|
|
|
2025-09-29 02:54:08 +00:00
|
|
|
MwDrawFrame(handle, &r, base, handle->pressed);
|
|
|
|
|
MwDrawRect(handle, &r, base);
|
2025-09-28 21:15:34 +00:00
|
|
|
|
2025-09-30 17:47:03 +00:00
|
|
|
if(px != NULL) {
|
|
|
|
|
int ow = r.width;
|
|
|
|
|
int oh = r.height;
|
2025-09-29 02:54:08 +00:00
|
|
|
|
2025-09-30 17:47:03 +00:00
|
|
|
double sw = (double)ow / px->width;
|
|
|
|
|
double sh = (double)oh / px->height;
|
|
|
|
|
|
|
|
|
|
if(sw < sh) {
|
|
|
|
|
r.width = px->width * sw;
|
|
|
|
|
r.height = px->height * sw;
|
|
|
|
|
} else {
|
|
|
|
|
r.width = px->width * sh;
|
|
|
|
|
r.height = px->height * sh;
|
|
|
|
|
}
|
|
|
|
|
r.width -= 10;
|
|
|
|
|
r.height -= 10;
|
|
|
|
|
|
|
|
|
|
r.x += (double)(ow - r.width) / 2;
|
|
|
|
|
r.y += (double)(oh - r.height) / 2;
|
|
|
|
|
|
|
|
|
|
MwLLDrawPixmap(handle->lowlevel, &r, px);
|
|
|
|
|
} else {
|
|
|
|
|
point.x = r.x + r.width / 2;
|
|
|
|
|
point.y = r.x + r.height / 2;
|
|
|
|
|
|
|
|
|
|
MwDrawText(handle, &point, str, text);
|
|
|
|
|
}
|
2025-09-29 02:54:08 +00:00
|
|
|
|
|
|
|
|
MwLLFreeColor(text);
|
|
|
|
|
MwLLFreeColor(base);
|
2025-09-28 13:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-29 00:04:04 +00:00
|
|
|
static void click(MwWidget handle) {
|
|
|
|
|
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
|
2025-09-28 22:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-29 00:04:04 +00:00
|
|
|
MwClassRec MwButtonClassRec = {
|
2025-09-28 13:46:18 +00:00
|
|
|
create, /* create */
|
|
|
|
|
NULL, /* destroy */
|
|
|
|
|
draw, /* draw */
|
2025-09-28 22:21:51 +00:00
|
|
|
click /* click */
|
2025-09-28 13:46:18 +00:00
|
|
|
};
|
2025-09-29 00:04:04 +00:00
|
|
|
MwClass MwButtonClass = &MwButtonClassRec;
|