mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-12 04:13:28 +00:00
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@525 b9cfdab3-6d41-4d17-bbe4-086880011989
65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
/* $Id$ */
|
|
#include <Mw/Milsko.h>
|
|
|
|
static int create(MwWidget handle) {
|
|
MwSetDefault(handle);
|
|
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
|
|
MwSetInteger(handle, MwNbold, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void draw(MwWidget handle) {
|
|
MwRect r;
|
|
MwPoint p;
|
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
|
int align;
|
|
const char* str = MwGetText(handle, MwNtext);
|
|
|
|
if(str == NULL) str = "";
|
|
|
|
r.x = 0;
|
|
r.y = 0;
|
|
r.width = MwGetInteger(handle, MwNwidth);
|
|
r.height = MwGetInteger(handle, MwNheight);
|
|
|
|
MwDrawRect(handle, &r, base);
|
|
|
|
align = MwGetInteger(handle, MwNalignment);
|
|
if(align == MwALIGNMENT_CENTER) {
|
|
p.x = r.width / 2;
|
|
} else if(align == MwALIGNMENT_BEGINNING) {
|
|
p.x = MwTextWidth(handle, str) / 2;
|
|
} else if(align == MwALIGNMENT_END) {
|
|
p.x = r.width - MwTextWidth(handle, str) / 2;
|
|
}
|
|
p.y = r.height / 2;
|
|
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
|
|
|
|
MwLLFreeColor(text);
|
|
MwLLFreeColor(base);
|
|
}
|
|
|
|
static void prop_change(MwWidget handle, const char* key) {
|
|
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle);
|
|
}
|
|
|
|
MwClassRec MwLabelClassRec = {
|
|
create, /* create */
|
|
NULL, /* destroy */
|
|
draw, /* draw */
|
|
NULL, /* click */
|
|
NULL, /* parent_resize */
|
|
prop_change, /* prop_change */
|
|
NULL, /* mouse_move */
|
|
NULL, /* mouse_up */
|
|
NULL, /* mouse_down */
|
|
NULL, /* key */
|
|
NULL, /* execute */
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL};
|
|
MwClass MwLabelClass = &MwLabelClassRec;
|