mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-07 09:59:45 +00:00
button
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@28 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -9,5 +9,6 @@
|
||||
MILSKODECL MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text);
|
||||
|
||||
MILSKODECL void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color);
|
||||
MILSKODECL void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color, int invert);
|
||||
|
||||
#endif
|
||||
|
||||
10
src/button.c
10
src/button.c
@@ -6,7 +6,15 @@ static void create(MilskoWidget handle) {
|
||||
}
|
||||
|
||||
static void draw(MilskoWidget handle) {
|
||||
MilskoPoint p[6];
|
||||
MilskoRect r;
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.width = MilskoGetInteger(handle, MilskoNwidth);
|
||||
r.height = MilskoGetInteger(handle, MilskoNheight);
|
||||
|
||||
MilskoDrawFrame(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)), 0);
|
||||
MilskoDrawRect(handle, &r, MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground)));
|
||||
}
|
||||
|
||||
MilskoClassRec MilskoButtonClassRec = {
|
||||
|
||||
@@ -77,6 +77,8 @@ void MilskoDestroyWidget(MilskoWidget handle) {
|
||||
}
|
||||
|
||||
void MilskoStep(MilskoWidget handle) {
|
||||
int i;
|
||||
for(i = 0; i < arrlen(handle->children); i++) MilskoStep(handle->children[i]);
|
||||
MilskoLLNextEvent(handle->lowlevel);
|
||||
}
|
||||
|
||||
@@ -121,6 +123,8 @@ void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
|
||||
char* v = malloc(strlen(value) + 1);
|
||||
strcpy(v, value);
|
||||
|
||||
if(shgeti(handle->text, key) != -1) free(shget(handle->text, key));
|
||||
|
||||
shput(handle->text, key, v);
|
||||
}
|
||||
}
|
||||
|
||||
56
src/draw.c
56
src/draw.c
@@ -59,3 +59,59 @@ void MilskoDrawRect(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color)
|
||||
|
||||
MilskoLLPolygon(handle->lowlevel, p, 4, color);
|
||||
}
|
||||
|
||||
void MilskoDrawFrame(MilskoWidget handle, MilskoRect* rect, MilskoLLColor color, int invert) {
|
||||
MilskoPoint p[6];
|
||||
const int diff = 128;
|
||||
const int border = 4;
|
||||
MilskoLLColor darker = MilskoLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff);
|
||||
MilskoLLColor lighter = MilskoLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff);
|
||||
|
||||
p[0].x = rect->x;
|
||||
p[0].y = rect->y;
|
||||
|
||||
p[1].x = rect->x + rect->width;
|
||||
p[1].y = rect->y;
|
||||
|
||||
p[2].x = rect->x + rect->width - border;
|
||||
p[2].y = rect->y + border;
|
||||
|
||||
p[3].x = rect->x + border;
|
||||
p[3].y = rect->y + border;
|
||||
|
||||
p[4].x = rect->x + border;
|
||||
p[4].y = rect->y + rect->height - border;
|
||||
|
||||
p[5].x = rect->x;
|
||||
p[5].y = rect->y + rect->height;
|
||||
|
||||
MilskoLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter);
|
||||
|
||||
p[0].x = rect->x + rect->width;
|
||||
p[0].y = rect->y;
|
||||
|
||||
p[1].x = rect->x + rect->width - border;
|
||||
p[1].y = rect->y + border;
|
||||
|
||||
p[2].x = rect->x + rect->width - border;
|
||||
p[2].y = rect->y + rect->height - border;
|
||||
|
||||
p[3].x = rect->x + border;
|
||||
p[3].y = rect->y + rect->height - border;
|
||||
|
||||
p[4].x = rect->x;
|
||||
p[4].y = rect->y + rect->height;
|
||||
|
||||
p[5].x = rect->x + rect->height;
|
||||
p[5].y = rect->y + rect->height;
|
||||
|
||||
MilskoLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
|
||||
|
||||
MilskoLLFreeColor(lighter);
|
||||
MilskoLLFreeColor(darker);
|
||||
|
||||
rect->x += border;
|
||||
rect->y += border;
|
||||
rect->width -= border * 2;
|
||||
rect->height -= border * 2;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,14 @@ void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, Mil
|
||||
MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) {
|
||||
MilskoLLColor c = malloc(sizeof(*c));
|
||||
XColor xc;
|
||||
|
||||
if(r > 255) r = 255;
|
||||
if(g > 255) g = 255;
|
||||
if(b > 255) b = 255;
|
||||
if(r < 0) r = 0;
|
||||
if(g < 0) g = 0;
|
||||
if(b < 0) b = 0;
|
||||
|
||||
xc.red = 256 * r;
|
||||
xc.green = 256 * g;
|
||||
xc.blue = 256 * b;
|
||||
|
||||
Reference in New Issue
Block a user