This commit is contained in:
NishiOwO
2026-01-15 05:16:14 +09:00
parent 32f09a9af2
commit 85994d42f1
6 changed files with 104 additions and 74 deletions

View File

@@ -45,7 +45,7 @@ param_set("vulkan", 0);
param_set("vulkan-string-helper", 1);
param_set("shared", 1);
param_set("static", 1);
param_set("examples", 1);
param_set("examples", 1);
my %features = (
"classic-theme" => "use classic theme",
@@ -221,11 +221,12 @@ foreach my $l (@library_targets) {
my $o = $object_suffix;
$o =~ s/\./\\\./g;
if ($l =~ /cocoa/) {
$s =~ s/$o$/.m/;
} else {
$s =~ s/$o$/.c/;
}
if ($l =~ /cocoa/) {
$s =~ s/$o$/.m/;
}
else {
$s =~ s/$o$/.c/;
}
if ($l =~ /^external\//) {
$warn = "";
@@ -236,37 +237,38 @@ foreach my $l (@library_targets) {
}
print(OUT "\n");
print(OUT "\n");
if(param_get("examples")) {
print(OUT "examples: " . join(" ", @examples_targets) . "\n");
print(OUT "\n");
foreach my $l (@examples_targets) {
my $libs = "";
my $s = $l;
my $o = $executable_suffix;
$o =~ s/\./\\\./g;
$s =~ s/$o$//;
if (param_get("examples")) {
print(OUT "examples: " . join(" ", @examples_targets) . "\n");
print(OUT "\n");
foreach my $l (@examples_targets) {
my $libs = "";
my $s = $l;
my $o = $executable_suffix;
$o =~ s/\./\\\./g;
$s =~ s/$o$//;
if (defined($examples_libs{$l})) {
$libs = $examples_libs{$l};
}
if (defined($examples_libs{$l})) {
$libs = $examples_libs{$l};
}
print(OUT
"${l}: ${s}${object_suffix} src/${library_prefix}Mw${library_suffix}\n"
);
if (grep(/^cocoa$/, @backends)) {
print(OUT
" \$(CC) -L./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
} else {
print(OUT
" \$(CC) -L src -Wl,-R./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
}
print(OUT "${s}${object_suffix}: ${s}.c\n");
print(OUT
" \$(CC) -c \$\(INCDIR) -o ${s}${object_suffix} ${s}.c -lMw ${math}\n"
);
}
print(OUT
"${l}: ${s}${object_suffix} src/${library_prefix}Mw${library_suffix}\n"
);
if (grep(/^cocoa$/, @backends)) {
print(OUT
" \$(CC) -L./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
}
else {
print(OUT
" \$(CC) -L src -Wl,-R./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
}
print(OUT "${s}${object_suffix}: ${s}.c\n");
print(OUT
" \$(CC) -c \$\(INCDIR) -o ${s}${object_suffix} ${s}.c -lMw ${math}\n"
);
}
}
print(OUT "\n");
print(OUT "clean:\n");

View File

@@ -101,6 +101,9 @@ struct _MwWidget {
MwWidget* tick_list;
int destroyed;
void* root_font;
void* root_boldfont;
};
#endif

View File

@@ -1,4 +1,4 @@
$library_suffix = ".dylib";
$library_suffix = ".dylib";
set_shared_flag("-dynamiclib");
use_backend("cocoa");

View File

@@ -41,7 +41,7 @@ sub new_example {
}
sub set_shared_flag {
@shared = $_[0];
@shared = $_[0];
}
sub new_object {

View File

@@ -158,7 +158,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->x11.top = 0;
r->x11.toplevel = 0;
}
r->x11.window = XCreateSimpleWindow(r->x11.display, p, px, py, width, height, 0, 0, WhitePixel(r->x11.display, DefaultScreen(r->x11.display)));
r->x11.window = XCreateSimpleWindow(r->x11.display, p, px, py, width, height, 0, 0, WhitePixel(r->x11.display, DefaultScreen(r->x11.display)));
sh.flags = PWinGravity;
sh.win_gravity = StaticGravity;

View File

@@ -114,6 +114,19 @@ static void llclipboardhandler(MwLL handle, void* data) {
MwDispatchUserHandler(h, MwNclipboardHandler, data);
}
/* if both of them are true
* 1. widget class is not NULL
* 2. parent is NULL
* or parent's widget class is NULL
*
* most likely this widget is first *visible* widget
*
* this macro is not used anywhere else - we could expose it if we have to
*
* (nishi)
*/
#define IsFirstVisible(handle) ((handle)->widget_class != NULL && ((handle)->parent == NULL || (handle)->parent->widget_class == NULL))
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
MwWidget h = malloc(sizeof(*h));
@@ -186,6 +199,17 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
MwAddTickList(h);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(IsFirstVisible(h)) {
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
} else
#endif
{
h->root_font = NULL;
h->root_boldfont = NULL;
}
if(h->parent != NULL) MwDispatch(h->parent, children_update);
return h;
@@ -250,6 +274,9 @@ static void MwFreeWidget(MwWidget handle) {
arrfree(handle->destroy_queue);
arrfree(handle->tick_list);
if(handle->root_font != NULL) MwFontFree(handle->root_font);
if(handle->root_boldfont != NULL) MwFontFree(handle->root_boldfont);
free(handle);
}
@@ -507,8 +534,41 @@ const char* MwGetText(MwWidget handle, const char* key) {
return shget(handle->text, key);
}
static void* inherit_void(MwWidget handle, const char* key) {
void* v;
if(handle->parent != NULL && (v = MwGetVoid(handle->parent, key)) != NULL) {
return v;
}
return NULL;
}
void* MwGetVoid(MwWidget handle, const char* key) {
return shget(handle->data, key);
void* v = shget(handle->data, key);
if(v != NULL) return v;
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0) {
v = inherit_void(handle, key);
if(v == NULL) {
MwWidget w = handle;
while(w != NULL && v == NULL) {
if(strcmp(key, MwNfont) == 0) {
v = w->root_font;
} else {
v = w->root_boldfont;
}
w = w->parent;
}
}
}
#endif
return v;
}
void MwVaApply(MwWidget handle, ...) {
@@ -576,43 +636,8 @@ void MwVaListApply(MwWidget handle, va_list va) {
}
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
static void set_font(MwWidget handle) {
void* f;
MwWidget h = handle;
while(h != NULL) {
if((f = MwGetVoid(h, MwNfont)) != NULL) {
MwSetVoid(handle, MwNfont, f);
return;
}
h = h->parent;
}
f = MwFontLoad(MwTTFData, MwTTFDataSize);
MwSetVoid(handle, MwNfont, f);
}
static void set_boldfont(MwWidget handle) {
void* f;
MwWidget h = handle;
while(h != NULL) {
if((f = MwGetVoid(h, MwNboldFont)) != NULL) {
MwSetVoid(handle, MwNboldFont, f);
return;
}
h = h->parent;
}
f = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
MwSetVoid(handle, MwNboldFont, f);
}
#endif
void MwSetDefault(MwWidget handle) {
if(handle->lowlevel != NULL) MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
set_font(handle);
set_boldfont(handle);
#endif
}
void MwHideCursor(MwWidget handle) {