default color

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@23 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-09-28 13:28:17 +00:00
parent 6ffbb575e6
commit d5a7bff6fd
7 changed files with 66 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
#include <Milsko/MachDep.h>
#include <Milsko/TypeDefs.h>
#include <Milsko/LowLevel.h>
MILSKODECL MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height);
MILSKODECL void MilskoDestroyWidget(MilskoWidget handle);
@@ -12,6 +13,8 @@ MILSKODECL void MilskoLoop(MilskoWidget handle);
MILSKODECL void MilskoStep(MilskoWidget handle);
MILSKODECL int MilskoPending(MilskoWidget handle);
MILSKODECL MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text);
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);

7
include/Milsko/Default.h Normal file
View File

@@ -0,0 +1,7 @@
/* $Id$ */
#ifndef __MILSKO_DEFAULT_H__
#define __MILSKO_DEFAULT_H__
#define MILSKO_BACKGROUND "#ddd"
#endif

View File

@@ -7,6 +7,7 @@
#include <Milsko/StringDefs.h>
#include <Milsko/TypeDefs.h>
#include <Milsko/Core.h>
#include <Milsko/Default.h>
#include <Milsko/Window.h>

View File

@@ -8,5 +8,6 @@
#define MilskoNheight "Iheight"
#define MilskoNtitle "Stitle"
#define MilskoNbackground "Sbackground"
#endif

View File

@@ -56,6 +56,9 @@ typedef struct _MilskoClass {
MilskoHandler destroy;
MilskoHandler draw;
MilskoHandler click;
MilskoTextKeyValue* text;
MilskoIntegerKeyValue* integer;
} *MilskoClass, MilskoClassRec;
#endif

View File

@@ -162,3 +162,44 @@ void MilskoApply(MilskoWidget handle, ...) {
}
va_end(va);
}
static int hex(const char* txt, int len) {
int i;
int r = 0;
for(i = 0; i < len; i++) {
char c = txt[i];
int n = 0;
if('a' <= c && c <= 'f') {
n = c - 'a' + 10;
} else if('A' <= c && c <= 'F') {
n = c - 'A' + 10;
} else if('0' <= c && c <= '9') {
n = c - '0';
}
r = r << 4;
r |= n;
}
return r;
}
MilskoLLColor MilskoParseColor(MilskoWidget handle, const char* text) {
int r = 0;
int g = 0;
int b = 0;
if(text[0] == '#' && strlen(text) == 4) {
r = hex(text + 1, 1);
g = hex(text + 2, 1);
b = hex(text + 3, 1);
r |= r << 4;
g |= g << 4;
b |= b << 4;
} else if(text[0] == '#' && strlen(text) == 7) {
r = hex(text + 1, 2);
g = hex(text + 3, 2);
b = hex(text + 5, 2);
}
return MilskoLLAllocColor(handle->lowlevel, r, g, b);
}

View File

@@ -1,8 +1,12 @@
/* $Id$ */
#include <Milsko/Milsko.h>
static void create(MilskoWidget handle) {
MilskoSetText(handle, MilskoNbackground, MILSKO_BACKGROUND);
}
static void draw(MilskoWidget handle) {
MilskoLLColor c = MilskoLLAllocColor(handle->lowlevel, 255, 0, 0);
MilskoLLColor c = MilskoParseColor(handle, MilskoGetText(handle, MilskoNbackground));
MilskoPoint p[4];
p[0].x = 0;
@@ -24,7 +28,7 @@ static void draw(MilskoWidget handle) {
MilskoClassRec MilskoWindowClassRec = {
NULL, /* opaque */
NULL, /* create */
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL /* click */