mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-15 13:53:28 +00:00
menu
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@105 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
40
src/draw.c
40
src/draw.c
@@ -3,6 +3,10 @@
|
||||
|
||||
#include "stb_image.h"
|
||||
|
||||
#define FontWidth 7
|
||||
#define FontHeight 14
|
||||
#define FontScale 1
|
||||
|
||||
static int hex(const char* txt, int len) {
|
||||
int i;
|
||||
int r = 0;
|
||||
@@ -124,30 +128,42 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
|
||||
}
|
||||
|
||||
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, MwLLColor color) {
|
||||
int i, x, y, sx, sy, sc = 1;
|
||||
int fw = 7, fh = 14;
|
||||
int i, x, y, sx, sy;
|
||||
MwRect r;
|
||||
|
||||
sx = point->x - strlen(text) * fw * sc / 2;
|
||||
sy = point->y - fh * sc / 2;
|
||||
sx = point->x - strlen(text) * FontWidth * FontScale / 2;
|
||||
sy = point->y - FontHeight * FontScale / 2;
|
||||
|
||||
for(i = 0; text[i] != 0; i++) {
|
||||
for(y = 0; y < fh; y++) {
|
||||
for(x = 0; x < fw; x++) {
|
||||
r.x = sx + x * sc;
|
||||
r.y = sy + y * sc;
|
||||
r.width = sc;
|
||||
r.height = sc;
|
||||
for(y = 0; y < FontHeight; y++) {
|
||||
for(x = 0; x < FontWidth; x++) {
|
||||
r.x = sx + x * FontScale;
|
||||
r.y = sy + y * FontScale;
|
||||
r.width = FontScale;
|
||||
r.height = FontScale;
|
||||
|
||||
if(MwFontData[(unsigned char)text[i]].data[y] & (1 << ((fw - 1) - x))) {
|
||||
if(MwFontData[(unsigned char)text[i]].data[y] & (1 << ((FontWidth - 1) - x))) {
|
||||
MwDrawRect(handle, &r, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
sx += fw * sc;
|
||||
sx += FontWidth * FontScale;
|
||||
}
|
||||
}
|
||||
|
||||
int MwTextWidth(MwWidget handle, const char* text) {
|
||||
(void)handle;
|
||||
|
||||
return strlen(text) * FontWidth * FontScale;
|
||||
}
|
||||
|
||||
int MwTextHeight(MwWidget handle, const char* text) {
|
||||
(void)handle;
|
||||
(void)text;
|
||||
|
||||
return FontHeight * FontScale;
|
||||
}
|
||||
|
||||
MwLLPixmap MwLoadImage(MwWidget handle, const char* path) {
|
||||
int width, height, ch;
|
||||
unsigned char* rgb = stbi_load(path, &width, &height, &ch, 4);
|
||||
|
||||
42
src/menu.c
Normal file
42
src/menu.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
static void set_xywh(MwWidget handle) {
|
||||
int height = 0;
|
||||
|
||||
height += 20;
|
||||
|
||||
MwVaApply(handle,
|
||||
MwNx, 0,
|
||||
MwNy, 0,
|
||||
MwNwidth, MwGetInteger(handle->parent, MwNwidth),
|
||||
MwNheight, height,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void create(MwWidget handle) {
|
||||
MwSetDefault(handle);
|
||||
|
||||
set_xywh(handle);
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
MwRect r;
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.width = MwGetInteger(handle, MwNwidth);
|
||||
r.height = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwDrawFrame(handle, &r, base, 0);
|
||||
MwDrawRect(handle, &r, base);
|
||||
}
|
||||
|
||||
MwClassRec MwMenuClassRec = {
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL /* click */
|
||||
};
|
||||
MwClass MwMenuClass = &MwMenuClassRec;
|
||||
@@ -27,6 +27,9 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
||||
|
||||
MwLLCreateCommon(r);
|
||||
|
||||
if(width < 1) width = 1;
|
||||
if(height < 1) height = 1;
|
||||
|
||||
if(parent == NULL) {
|
||||
r->display = XOpenDisplay(NULL);
|
||||
p = XRootWindow(r->display, XDefaultScreen(r->display));
|
||||
@@ -115,6 +118,9 @@ void MwLLSetXY(MwLL handle, int x, int y) {
|
||||
}
|
||||
|
||||
void MwLLSetWH(MwLL handle, int w, int h) {
|
||||
if(w < 1) w = 1;
|
||||
if(h < 1) h = 1;
|
||||
|
||||
XResizeWindow(handle->display, handle->window, w, h);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user