mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 08:00:50 +00:00
add label
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@213 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
53
src/widget/label.c
Normal file
53
src/widget/label.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
static int create(MwWidget handle) {
|
||||
MwSetDefault(handle);
|
||||
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
|
||||
|
||||
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, 0, text);
|
||||
|
||||
MwLLFreeColor(text);
|
||||
MwLLFreeColor(base);
|
||||
}
|
||||
|
||||
MwClassRec MwLabelClassRec = {
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* mouse_move */
|
||||
NULL, /* mouse_up */
|
||||
NULL /* mouse_down */
|
||||
};
|
||||
MwClass MwLabelClass = &MwLabelClassRec;
|
||||
Reference in New Issue
Block a user