refactor font api

This commit is contained in:
Nishi 2026-04-06 17:29:09 +09:00
commit 0de09207a4
Signed by: nishi
GPG key ID: 27EF69B208EB9343
31 changed files with 12209 additions and 6149 deletions

View file

@ -176,29 +176,31 @@ MWDECL void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int in
/*!
* @brief Draws a text
* @param handle Widget
* @param ttf TTF, NULLable
* @param point Center point of the text
* @param text Text
* @param bold Bold
* @param align Align
* @param color Color
*/
MWDECL void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
MWDECL void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color);
/*!
* @brief Calculates a text width
* @param handle Widget
* @param text Text
* @param font Font, NULLable
* @return Text width
*/
MWDECL int MwTextWidth(MwWidget handle, const char* text);
MWDECL int MwTextWidth(MwWidget handle, MwFLFont font, const char* text);
/*!
* @brief Calculates a text height
* @param handle Widget
* @param text Text
* @param font Font, NULLable
* @return Text height
*/
MWDECL int MwTextHeight(MwWidget handle, const char* text);
MWDECL int MwTextHeight(MwWidget handle, MwFLFont font, const char* text);
/* color.c */

View file

@ -177,6 +177,10 @@ struct _MwLLTextDispatchTable {
void (*fontFree)(void* handle);
};
#define MwFLFlagMonospace (1 << 0)
#define MwFLFlagBold (1 << 1)
#define MwFLBuildFont(x) ((MwFLFont)(void*)(size_t)(x))
#ifdef __cplusplus
extern "C" {
#endif
@ -246,9 +250,9 @@ MWDECL int MWFL_FT2Setup(void);
MWDECL int MwFL_STBTTSetup(void);
#endif
MWDECL int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwWidget handle, const char* text);
MWDECL int (*MwFLTextHeight)(MwWidget handle, int count);
MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size);
MWDECL void (*MwFLFontFree)(void* handle);

View file

@ -42,6 +42,26 @@ MWDECL unsigned char MwBoldTTFData[];
*/
MWDECL unsigned int MwBoldTTFDataSize;
/*!
* @brief Default monospace TTF font data
*/
MWDECL unsigned char MwMonospaceTTFData[];
/*!
* @brief Default monospace TTF font size
*/
MWDECL unsigned int MwMonospaceTTFDataSize;
/*!
* @brief Default bold monospace TTF font data
*/
MWDECL unsigned char MwBoldMonospaceTTFData[];
/*!
* @brief Default bold monospace TTF font size
*/
MWDECL unsigned int MwBoldMonospaceTTFDataSize;
#ifdef __cplusplus
}
#endif

View file

@ -42,6 +42,7 @@
#define MwNroundness "Iroundness"
#define MwNisRounded "IisRounded"
#define MwNdarkTheme "IdarkTheme"
#define MwNuseMonospace "IuseMonospace"
#define MwNtitle "Stitle"
#define MwNtext "Stext"
@ -56,6 +57,8 @@
#define MwNfont "Vfont"
#define MwNboldFont "VboldFont"
#define MwNbackgroundPixmap "VbackgroundPixmap"
#define MwNmonospaceFont "VmonospaceFont"
#define MwNboldMonospaceFont "VboldMonospaceFont"
#define MwNactivateHandler "Cactivate" /* NULL/int* (MwListBox)/void* (MwTreeView) */
#define MwNresizeHandler "Cresize" /* NULL */

View file

@ -104,6 +104,8 @@ struct _MwWidget {
void* root_font;
void* root_boldfont;
void* root_monofont;
void* root_boldmonofont;
int berserk;
};

View file

@ -111,6 +111,9 @@
<struct defname="MwSizeHints" pointer="yes" name="sizeHints" />
<pointer name="font" />
<pointer name="boldFont" />
<pixmap name="backgroundPixmap" />
<pointer name="monospaceFont" />
<pointer name="boldMonospaceFont" />
<handler name="activate" />
<handler name="resize" />

View file

@ -1,10 +1,10 @@
my @enabled_backends=();
my @enabled_backends = ();
if (param_get("wayland")) {
push(@enabled_backends,"wayland");
push(@enabled_backends, "wayland");
}
if (param_get("x11")) {
push(@enabled_backends,"x11");
push(@enabled_backends, "x11");
}
use_backend(@enabled_backends);

View file

@ -3,7 +3,7 @@ new_object("src/*.c");
my $gl_libs = "";
if (param_get("tiny")) {
add_cflags("-Oz");
if(defined($ENV{CC}) && grep(/^clang$/, $ENV{CC})) {
if (defined($ENV{CC}) && grep(/^clang$/, $ENV{CC})) {
add_libs("-flto=thin");
add_cflags("-flto=thin");
}
@ -68,7 +68,7 @@ if (grep(/^cocoa$/, @backends)) {
if (param_get("stb-image")) {
add_cflags("-DUSE_STB_IMAGE");
if(param_get("tiny")) {
if (param_get("tiny")) {
add_cflags("-DSTB_IMAGE_STATIC");
add_cflags("-DSTB_IMAGE_IMPLEMENTATION");
}

Binary file not shown.

Binary file not shown.

View file

@ -18,9 +18,9 @@ void* MwDirectoryOpen(const char* path) {
#ifdef _WIN32
char* p = malloc(strlen(path) + 2 + 1);
strcpy(p, path);
if(strchr(path, '/') != NULL){
if(strchr(path, '/') != NULL) {
strcat(p, "/");
}else{
} else {
strcat(p, "\\");
}
strcat(p, "*");

View file

@ -218,6 +218,8 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
if(IsFirstVisible(h)) {
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
h->root_monofont = MwFontLoad(MwMonospaceTTFData, MwMonospaceTTFDataSize);
h->root_boldmonofont = MwFontLoad(MwBoldMonospaceTTFData, MwBoldMonospaceTTFDataSize);
} else
#endif
{
@ -530,6 +532,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
#endif
if(strcmp(key, MwNisRounded) == 0) return inherit_integer(handle, key, 1);
if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0);
if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0);
}
return shget(handle->integer, key);
}
@ -579,7 +582,7 @@ void* MwGetVoid(MwWidget handle, const char* key) {
if(v != NULL) return v;
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0) {
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0 || strcmp(key, MwNmonospaceFont) == 0 || strcmp(key, MwNboldMonospaceFont) == 0) {
v = inherit_void(handle, key);
if(v == NULL) {
@ -588,8 +591,12 @@ void* MwGetVoid(MwWidget handle, const char* key) {
while(w != NULL && v == NULL) {
if(strcmp(key, MwNfont) == 0) {
v = w->root_font;
} else {
} else if(strcmp(key, MwNboldFont) == 0) {
v = w->root_boldfont;
} else if(strcmp(key, MwNmonospaceFont) == 0) {
v = w->root_monofont;
} else if(strcmp(key, MwNboldMonospaceFont) == 0) {
v = w->root_boldmonofont;
}
w = w->parent;

View file

@ -102,7 +102,7 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
left = 8 + 48 + 8;
}
th = MwTextHeight(handle, text);
th = MwTextHeight(handle, NULL, text);
(void)MwVaCreateWidget(MwLabelClass, "label", window, left, (h - th) / 2, w - left - 8, th,
MwNtext, text,
MwNalignment, MwALIGNMENT_BEGINNING,

3022
src/text/font/boldmonottf.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

3022
src/text/font/monottf.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,9 @@
#include <ft2build.h>
#include FT_FREETYPE_H
static struct {
#define HEIGHT 14
static struct ft_table {
FT_Error (*FT_Init_FreeType)(FT_Library* alibrary);
FT_Error (*FT_New_Memory_Face)(FT_Library library,
const FT_Byte* file_base,
@ -27,17 +29,15 @@ struct _MwFLFont {
FT_Face face;
void* data;
};
static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
@ -51,7 +51,7 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
if(c == '\n') {
x = 0;
y += ttf->face->height * 14 / ttf->face->units_per_EM;
y += ttf->face->height * HEIGHT / ttf->face->units_per_EM;
continue;
}
@ -61,7 +61,7 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * 14 / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
int oy = y + (ttf->face->height * HEIGHT / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * HEIGHT / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
@ -80,12 +80,6 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
@ -93,10 +87,8 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
return 0;
}
static int ft2_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
int tw = 0, mtw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
@ -117,11 +109,8 @@ static int ft2_MwTextWidth(MwWidget handle, const char* text) {
return mtw;
}
static int ft2_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
static int ft2_MwTextHeight(MwFLFont ttf, int count) {
return (ttf->face->height * HEIGHT / ttf->face->units_per_EM) * count;
}
static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
@ -131,7 +120,7 @@ static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
ft_table.FT_Init_FreeType(&ttf->library);
ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, 14);
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, HEIGHT);
return ttf;
}

View file

@ -11,18 +11,16 @@ struct _MwFLFont {
int descent;
};
static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
static int stbtt_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
@ -71,12 +69,6 @@ static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, i
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
@ -84,11 +76,9 @@ static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, i
return 0;
}
static int stbtt_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) {
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
@ -102,10 +92,7 @@ static int stbtt_MwTextWidth(MwWidget handle, const char* text) {
return tw;
}
static int stbtt_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
static int stbtt_MwTextHeight(MwFLFont ttf, int count) {
return (ttf->ascent - ttf->descent) * ttf->scale * count;
}

View file

@ -1,8 +1,8 @@
#include <Mw/Milsko.h>
int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwWidget handle, const char* text) = NULL;
int (*MwFLTextHeight)(MwWidget handle, int count) = NULL;
int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL;
int (*MwFLTextHeight)(MwFLFont font, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size) = NULL;
void (*MwFLFontFree)(void* handle) = NULL;
@ -13,40 +13,91 @@ void (*MwFLFontFree)(void* handle) = NULL;
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color);
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
if(strlen(text) == 0) return;
#ifdef TTF
if(MwFLDrawText)
if(MwGetInteger(handle, MwNbitmapFont) || MwFLDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, color);
static int is_bold(MwWidget handle, MwFLFont ttf) {
size_t u = (size_t)ttf;
int s;
if(u & MwFLFlagBold) return 1;
s = MwGetInteger(handle, MwNbold);
if(s == MwDEFAULT) return 0;
return s;
}
int MwTextWidth(MwWidget handle, const char* text) {
static int is_monospace(MwWidget handle, MwFLFont ttf) {
size_t u = (size_t)ttf;
int s;
if(u & MwFLFlagMonospace) return 1;
s = MwGetInteger(handle, MwNuseMonospace);
if(s == MwDEFAULT) return 0;
return s;
}
#ifdef TTF
static MwFLFont assume_ttf(MwWidget handle, MwFLFont ttf) {
if(MwGetInteger(handle, MwNbitmapFont)) return NULL;
if(is_monospace(handle, ttf)) return is_bold(handle, ttf) ? MwGetVoid(handle, MwNboldMonospaceFont) : MwGetVoid(handle, MwNmonospaceFont);
return is_bold(handle, ttf) ? MwGetVoid(handle, MwNboldFont) : MwGetVoid(handle, MwNfont);
}
#endif
void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color) {
MwPoint p = *point;
if(strlen(text) == 0) return;
#ifdef TTF
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
#endif
if(align == MwALIGNMENT_CENTER) {
p.x -= MwTextWidth(handle, ttf, text) / 2;
} else if(align == MwALIGNMENT_END) {
p.x -= MwTextWidth(handle, ttf, text);
}
#ifdef TTF
if(MwFLDrawText)
if(MwGetInteger(handle, MwNbitmapFont) || ttf == NULL || MwFLDrawText(handle, ttf, &p, text, color))
#endif
bitmap_MwDrawText(handle, &p, text, is_bold(handle, ttf), color);
}
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
if(MwFLTextWidth)
if(!MwGetInteger(handle, MwNbitmapFont) && (st = MwFLTextWidth(handle, text)) != -1) return st;
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextWidth(ttf, text)) != -1) return st;
#else
(void)handle;
(void)ttf;
#endif
return MwUTF8Length(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
#ifdef TTF
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
#else
(void)handle;
(void)text;
(void)ttf;
#endif
while(text[i] != 0) {
int out;
@ -58,7 +109,7 @@ int MwTextHeight(MwWidget handle, const char* text) {
}
#ifdef TTF
if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && (st = MwFLTextHeight(handle, c)) != -1) return st;
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeight(ttf, c)) != -1) return st;
#endif
return FontHeight * c;
}
@ -73,7 +124,7 @@ void MwFontFree(void* handle) {
if(MwFLFontFree) MwFLFontFree(handle);
}
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color) {
int i = 0, x, y, sx, sy;
int tw, th;
unsigned char* px;
@ -81,8 +132,8 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
tw = MwTextWidth(handle, NULL, text);
th = MwTextHeight(handle, NULL, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
@ -128,12 +179,6 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);

View file

@ -77,7 +77,7 @@ static void draw(MwWidget handle) {
point.x = r.x + r.width / 2;
point.y = r.x + r.height / 2;
MwDrawText(handle, &point, str, 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &point, str, MwALIGNMENT_CENTER, text);
}
MwLLFreeColor(text);

View file

@ -51,7 +51,7 @@ static void draw(MwWidget handle) {
p.x = MwDefaultBorderWidth(handle) * 2 + 4;
p.y = MwGetInteger(handle, MwNheight) / 2;
MwDrawText(handle, &p, cb->list[MwGetInteger(handle, MwNvalue)], 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, NULL, &p, cb->list[MwGetInteger(handle, MwNvalue)], MwALIGNMENT_BEGINNING, text);
}
r = rc;
@ -115,11 +115,11 @@ static void click(MwWidget handle) {
MwLLSetCursor(handle->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
for(i = 0; i < arrlen(cb->list); i++) {
int l = MwTextWidth(handle, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
int l = MwTextWidth(handle, NULL, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
if(l > width) width = l;
}
cb->listbox = MwVaCreateWidget(MwListBoxClass, "listbox", handle, 0, MwGetInteger(handle, MwNheight), width, MwTextHeight(handle, "M") * ent + MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, "M") / 4,
cb->listbox = MwVaCreateWidget(MwListBoxClass, "listbox", handle, 0, MwGetInteger(handle, MwNheight), width, MwTextHeight(handle, NULL, "M") * ent + MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, NULL, "M") / 4,
MwNsingleClickSelectable, 1,
NULL);

View file

@ -27,6 +27,7 @@ static void draw(MwWidget handle) {
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
MwFLFont font = MwFLBuildFont(MwFLFlagMonospace);
if(str == NULL) str = "";
r.x = 0;
@ -37,8 +38,8 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, 1, 1);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(str != NULL) {
int w = MwTextWidth(handle, "M");
int h = MwTextHeight(handle, "M");
int w = MwTextWidth(handle, font, "M");
int h = MwTextHeight(handle, font, "M");
MwPoint p;
char* show;
int len;
@ -53,7 +54,7 @@ static void draw(MwWidget handle) {
len = (r.width - p.x * 2) / w;
if(len >= 0) {
if(len > 0) {
show = malloc(len * 4 + 1);
memset(show, 0, len * 4 + 1);
@ -65,13 +66,13 @@ static void draw(MwWidget handle) {
for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*';
}
MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, font, &p, show, MwALIGNMENT_BEGINNING, text);
textlen = (t->cursor - 1) % len + 1;
for(i = 0; i < textlen; i++) show[i] = 'M';
show[i] = 0;
currc.x = p.x + MwTextWidth(handle, show);
currc.x = p.x + MwTextWidth(handle, font, show);
currc.y = (r.height - h) / 2;
currc.width = 1;
currc.height = h;

View file

@ -316,9 +316,9 @@ static void draw(MwWidget handle) {
if(align == MwALIGNMENT_CENTER) {
p.x = r.width / 2;
} else if(align == MwALIGNMENT_BEGINNING) {
p.x = MwTextWidth(handle, str) / 2;
p.x = MwTextWidth(handle, NULL, str) / 2;
} else if(align == MwALIGNMENT_END) {
p.x = r.width - MwTextWidth(handle, str) / 2;
p.x = r.width - MwTextWidth(handle, NULL, str) / 2;
}
p.y = r.height / 2;
@ -326,11 +326,11 @@ static void draw(MwWidget handle) {
p.x += 1;
p.y += 1;
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, shadow);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, shadow);
p.x -= 1;
p.y -= 1;
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, text);
}
MwLLFreeColor(shadow);

View file

@ -129,8 +129,8 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
int h = MwGetInteger(handle, MwNheight);
st = get_first_entry(handle->parent, lb);
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) {
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M") + Padding)) {
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, NULL, "M") + Padding) + 2; i++) {
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, NULL, "M") + Padding)) {
unsigned long t;
int old = MwGetInteger(handle->parent, MwNvalue);
@ -143,7 +143,7 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
lb->click_time = t;
}
y += MwTextHeight(handle, "M") + Padding;
y += MwTextHeight(handle, NULL, "M") + Padding;
}
MwForceRender(lb->frame);
@ -175,11 +175,11 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) {
int h = MwGetInteger(handle, MwNheight);
st = get_first_entry(handle->parent, lb);
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) {
if(y <= p->y && p->y <= (y + MwTextHeight(handle, "M") + Padding)) {
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, NULL, "M") + Padding) + 2; i++) {
if(y <= p->y && p->y <= (y + MwTextHeight(handle, NULL, "M") + Padding)) {
MwSetInteger(handle->parent, MwNvalue, st + i);
}
y += MwTextHeight(handle, "M") + Padding;
y += MwTextHeight(handle, NULL, "M") + Padding;
}
MwForceRender(lb->frame);
@ -216,7 +216,7 @@ static void frame_draw(MwWidget handle) {
st = get_first_entry(handle->parent, lb);
area = r.height - MwDefaultBorderWidth(handle) * 2;
ent = area / (MwTextHeight(handle, "M") + Padding) + 2;
ent = area / (MwTextHeight(handle, NULL, "M") + Padding) + 2;
for(i = st; i < arrlen(lb->list) && i < st + ent; i++) {
int selected = MwGetInteger(handle->parent, MwNvalue) == i ? 1 : 0;
@ -227,20 +227,20 @@ static void frame_draw(MwWidget handle) {
r2.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding);
r2.y = p.y;
r2.width = r.width - r2.x;
r2.height = MwTextHeight(handle, "M") + Padding;
r2.height = MwTextHeight(handle, NULL, "M") + Padding;
MwDrawRect(handle, &r2, text2);
handle->bgcolor = text2;
}
if(lb->list[i].pixmap != NULL) {
MwRect r2;
int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, "M") + Padding)) ? (MwTextHeight(handle, "M") + Padding) : lb->list[i].pixmap->common.height;
int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, NULL, "M") + Padding)) ? (MwTextHeight(handle, NULL, "M") + Padding) : lb->list[i].pixmap->common.height;
r2.x = MwDefaultBorderWidth(handle);
r2.y = p.y + (MwTextHeight(handle, "M") + Padding - h) / 2;
r2.y = p.y + (MwTextHeight(handle, NULL, "M") + Padding - h) / 2;
r2.width = h * lb->list[i].pixmap->common.width / lb->list[i].pixmap->common.height;
r2.height = h;
MwLLDrawPixmap(handle->lowlevel, &r2, lb->list[i].pixmap);
}
p.y += (MwTextHeight(handle, "M") + Padding) / 2;
p.y += (MwTextHeight(handle, NULL, "M") + Padding) / 2;
p.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding);
for(j = 0; j < arrlen(lb->list[i].name); j++) {
char* t = lb->list[i].name[j];
@ -250,8 +250,8 @@ static void frame_draw(MwWidget handle) {
if(t == NULL) t = "";
str = MwStringDuplicate(t);
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, "M")) {
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, "M");
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, NULL, "M")) {
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, NULL, "M");
str[ind] = 0;
if(ind > 3) memset(str + ind - 3, '.', 3);
}
@ -259,26 +259,26 @@ static void frame_draw(MwWidget handle) {
if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle);
if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) {
p.x += 4;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
p.x -= 4;
p.x += get_col_width(lb, j);
} else if(lb->alignment[j] == MwALIGNMENT_CENTER) {
p.x += (get_col_width(lb, j) - l) / 2;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_CENTER, selected ? base2 : text2);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, selected ? base2 : text2);
p.x += (get_col_width(lb, j) - l) / 2;
p.x += l;
} else if(lb->alignment[j] == MwALIGNMENT_END) {
p.x += get_col_width(lb, j);
p.x -= 4;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_END, selected ? base2 : text2);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_END, selected ? base2 : text2);
p.x += 4;
}
free(str);
if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding);
}
p.y += (MwTextHeight(handle, "M") + Padding) / 2;
p.y += (MwTextHeight(handle, NULL, "M") + Padding) / 2;
handle->bgcolor = NULL;
}
@ -297,7 +297,7 @@ static void resize(MwWidget handle) {
int ih, y;
int m = 0;
y = MwGetInteger(handle, MwNhasHeading) ? (MwTextHeight(handle, "M") + MwDefaultBorderWidth(handle) * 2) : 0;
y = MwGetInteger(handle, MwNhasHeading) ? (MwTextHeight(handle, NULL, "M") + MwDefaultBorderWidth(handle) * 2) : 0;
if(lb->vscroll == NULL) {
lb->vscroll = MwVaCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h, NULL);
@ -316,7 +316,7 @@ static void resize(MwWidget handle) {
h -= y;
if(ih <= (h / (MwTextHeight(handle, "M") + Padding))) {
if(ih <= (h / (MwTextHeight(handle, NULL, "M") + Padding))) {
MwLLShow(lb->vscroll->lowlevel, 0);
} else {
MwLLShow(lb->vscroll->lowlevel, 1);
@ -340,7 +340,7 @@ static void resize(MwWidget handle) {
h -= MwDefaultBorderWidth(handle) * 2;
MwVaApply(lb->vscroll,
MwNareaShown, h / (MwTextHeight(handle, "M") + Padding),
MwNareaShown, h / (MwTextHeight(handle, NULL, "M") + Padding),
MwNmaxValue, ih,
NULL);
}
@ -400,7 +400,7 @@ static void draw(MwWidget handle) {
r.x = x;
r.y = 0;
r.width = get_col_width(lb, i);
r.height = MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, "M");
r.height = MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, NULL, "M");
MwDrawFrame(handle, &r, base, 0, 0);
x += MwDefaultBorderWidth(handle);
@ -408,15 +408,15 @@ static void draw(MwWidget handle) {
if(arrlen(lb->alignment) <= i || lb->alignment[i] == MwALIGNMENT_BEGINNING) {
p.x = 4 + x;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_BEGINNING, text);
} else if(lb->alignment[i] == MwALIGNMENT_CENTER) {
p.x = x + r.width / 2;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_CENTER, text);
} else if(lb->alignment[i] == MwALIGNMENT_END) {
p.x = x + r.width - 4;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_END, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_END, text);
}
x += r.width;

View file

@ -8,7 +8,7 @@ static void set_xywh(MwWidget handle) {
int diff = MwDefaultBorderWidth(handle);
diff = 0;
height = MwTextHeight(handle, "M") + 10;
height = MwTextHeight(handle, NULL, "M") + 10;
MwVaApply(handle,
MwNx, -diff,
@ -71,8 +71,8 @@ static void destroy(MwWidget handle) {
#define BEGIN_MENU_LOOP \
for(i = 0; i < arrlen(m->sub); i++) { \
int incr = m->sub[i]->name[0] == '?' ? 1 : 0; \
int tw = MwTextWidth(handle, m->sub[i]->name + incr); \
int th = MwTextHeight(handle, m->sub[i]->name + incr); \
int tw = MwTextWidth(handle, NULL, m->sub[i]->name + incr); \
int th = MwTextHeight(handle, NULL, m->sub[i]->name + incr); \
int in_area; \
\
if(incr) { \
@ -104,7 +104,7 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, 0, MwFALSE);
}
MwDrawText(handle, &p, m->sub[i]->name + incr, m->sub[i]->wsub != NULL || (in_area && handle->pressed) ? 1 : 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, MwFLBuildFont((m->sub[i]->wsub != NULL || (in_area && handle->pressed)) ? MwFLFlagBold : 0), &p, m->sub[i]->name + incr, MwALIGNMENT_BEGINNING, text);
END_MENU_LOOP;
MwLLFreeColor(text);

View file

@ -63,8 +63,8 @@ static void draw(MwWidget handle) {
p.y += 2 + 1;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
int th = MwTextHeight(handle, menu->sub[i]->name);
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
int th = MwTextHeight(handle, NULL, menu->sub[i]->name);
if(menu->sub[i]->wsub != NULL) {
r.x = MwGetInteger(handle, MwNleftPadding);
@ -77,7 +77,7 @@ static void draw(MwWidget handle) {
p.x = 5 + tw / 2 + MwGetInteger(handle, MwNleftPadding);
p.y += th / 2;
MwDrawText(handle, &p, menu->sub[i]->name, menu->sub[i]->wsub != NULL ? 1 : 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, MwFLBuildFont(menu->sub[i]->wsub != NULL ? MwFLFlagBold : 0), &p, menu->sub[i]->name, MwALIGNMENT_CENTER, text);
if(arrlen(menu->sub[i]->sub) > 0) {
MwRect tr;
@ -110,13 +110,13 @@ static void click(MwWidget handle) {
rc.x = 5;
rc.y = 3;
for(i = 0; i < arrlen(menu->sub); i++) {
int tw = MwTextWidth(handle, menu->sub[i]->name);
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
if(tw > ww) ww = tw;
}
rc.width = ww + 15;
for(i = 0; i < arrlen(menu->sub); i++) {
int th = MwTextHeight(handle, menu->sub[i]->name);
int th = MwTextHeight(handle, NULL, menu->sub[i]->name);
rc.height = th;
if(strcmp(menu->sub[i]->name, "----") == 0) {
@ -209,8 +209,8 @@ static void mwSubMenuGetSizeImpl(MwWidget handle, MwMenu menu, MwRect* rect) {
if(strcmp(menu->sub[i]->name, "----") == 0) {
rect->height += 2 + 2;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
rect->height += MwTextHeight(handle, menu->sub[i]->name) + 3;
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
rect->height += MwTextHeight(handle, NULL, menu->sub[i]->name) + 3;
if(tw > rect->width) {
rect->width = tw;
}

View file

@ -30,11 +30,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if((*skip) > 0) {
(*skip)--;
skipped = 1;
if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, "M");
} else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, "M") + 2)) {
if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, NULL, "M");
} else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, NULL, "M") + 2)) {
MwRect r;
p->x += shift;
p->y += MwTextHeight(handle, "M") / 2 + LinePadding;
p->y += MwTextHeight(handle, NULL, "M") / 2 + LinePadding;
if(tree->tree != NULL || shift > LineSpace) {
l[0] = *p;
@ -47,9 +47,9 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
l[0] = *p;
l[0].x -= LineSpace / 2;
l[1] = l[0];
l[0].y -= MwTextHeight(handle, "M") / 2 + LinePadding;
l[0].y -= MwTextHeight(handle, NULL, "M") / 2 + LinePadding;
if(next) {
l[1].y += MwTextHeight(handle, "M") / 2;
l[1].y += MwTextHeight(handle, NULL, "M") / 2;
}
if(draw) MwLLLine(handle->lowlevel, &l[0], text2);
}
@ -57,7 +57,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
r.width = OpenerSize;
r.height = OpenerSize;
r.x = p->x - LineSpace + (LineSpace - r.width) / 2;
r.y = p->y - MwTextHeight(handle, "M") / 2 + (MwTextHeight(handle, "M") - r.height) / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2 + (MwTextHeight(handle, NULL, "M") - r.height) / 2;
if(draw) {
MwLLColor col = tree->opened ? MwLightenColor(handle, base, -8, -8, -8) : base;
MwRect r2 = r;
@ -101,11 +101,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
}
}
if(tree->pixmap != NULL) {
r.height = MwTextHeight(handle, "M");
r.height = MwTextHeight(handle, NULL, "M");
r.width = r.height * tree->pixmap->common.width / tree->pixmap->common.height;
r.x = p->x;
r.y = p->y - MwTextHeight(handle, "M") / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2;
if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);
}
@ -113,16 +113,16 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if(draw) {
if(tree->selected) {
r.x = p->x;
r.y = p->y - MwTextHeight(handle, "M") / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2;
r.width = MwGetInteger(handle, MwNwidth) - MwGetInteger(handle, MwNleftPadding) - shift;
r.height = MwTextHeight(handle, "M");
r.height = MwTextHeight(handle, NULL, "M");
MwDrawRect(handle, &r, text2);
}
handle->bgcolor = tree->selected ? text2 : base2;
MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
MwDrawText(handle, NULL, p, tree->label, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
handle->bgcolor = NULL;
} else {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, tree->label)) && (p->y - MwTextHeight(handle, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, "M") / 2)) {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, NULL, tree->label)) && (p->y - MwTextHeight(handle, NULL, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, NULL, "M") / 2)) {
unsigned long t;
set_all(root, 0);
@ -136,7 +136,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
}
p->x -= MwGetInteger(handle->parent, MwNleftPadding);
p->y += MwTextHeight(handle, "M") / 2;
p->y += MwTextHeight(handle, NULL, "M") / 2;
p->x -= shift;
(*shared)++;
@ -145,7 +145,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
for(i = 0; i < arrlen(tree->tree); i++) {
l[0] = *p;
l[0].x += shift + LineSpace / 2;
l[0].y += MwTextHeight(handle, "M") - (MwTextHeight(handle, "M") - OpenerSize) / 2;
l[0].y += MwTextHeight(handle, NULL, "M") - (MwTextHeight(handle, NULL, "M") - OpenerSize) / 2;
if(tree->tree[i]->tree != NULL) {
l[0].y += OpenerSize / 2;
}
@ -189,7 +189,7 @@ static void frame_draw(MwWidget handle) {
r = r2;
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (r.height / MwTextHeight(handle, "M"))) break;
if(shared > (r.height / MwTextHeight(handle, NULL, "M"))) break;
recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, LineSpace, &skip, &shared, 1, NULL);
}
@ -236,7 +236,7 @@ static void frame_mouse_up(MwWidget handle, void* user, void* call) {
p.x = MwDefaultBorderWidth(tv->frame);
p.y = MwDefaultBorderWidth(tv->frame);
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, "M"))) break;
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, NULL, "M"))) break;
recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, NULL, NULL, &p, 0, LineSpace, &skip, &shared, 0, &tv->pressed);
}
resize(handle->parent);
@ -267,7 +267,7 @@ static void resize(MwWidget handle) {
ih = recursive_length(tv->tree);
if(ih == 0) ih = 1;
if(ih <= (h / (LinePadding + MwTextHeight(handle, "M")))) {
if(ih <= (h / (LinePadding + MwTextHeight(handle, NULL, "M")))) {
MwLLShow(tv->vscroll->lowlevel, 0);
} else {
MwLLShow(tv->vscroll->lowlevel, 1);
@ -292,7 +292,7 @@ static void resize(MwWidget handle) {
}
MwVaApply(tv->vscroll,
MwNareaShown, h / (LinePadding + MwTextHeight(handle, "M")),
MwNareaShown, h / (LinePadding + MwTextHeight(handle, NULL, "M")),
MwNmaxValue, ih,
NULL);
}