version dialog

This commit is contained in:
Nishi 2026-05-10 07:03:11 +09:00
commit 7d96c216bd
Signed by: nishi
GPG key ID: 27EF69B208EB9343
17 changed files with 291288 additions and 1 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
*.make
Makefile
/midas
*.o
*.a

2
external/ppr vendored

@ -1 +1 @@
Subproject commit 1eb90f4df80009a402875561e74d1547e0a65c92
Subproject commit 7927d5114a764edd2f447d20ca65f834b20c4e0c

7
external/stb/pmake.js vendored Normal file
View file

@ -0,0 +1,7 @@
function main(){
const stb = new pmake.LibraryProject("stb");
stb.sources = ["stb_ds.c"];
stb.includes = ["."];
pmake.register(stb);
}

2
external/stb/stb_ds.c vendored Normal file
View file

@ -0,0 +1,2 @@
#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"

1895
external/stb/stb_ds.h vendored Normal file

File diff suppressed because it is too large Load diff

2
format.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
clang-format --verbose -i pmake.js `find src "(" -name "*.c" -or -name "*.h" ")" -and -not -path "src/icon/*"`

7
icon.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
for i in icon/*.png; do
NAME=`echo $i | sed 's/^icon\///' | sed 's/\.png$//'`
echo '#include <midas.h>' > src/icon/$NAME.c
echo "" >> src/icon/$NAME.c
../milsko/tools/icon-converter $i icon_$NAME >> src/icon/$NAME.c
done

BIN
icon/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icon/midas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 KiB

BIN
icon/midas.psd Normal file

Binary file not shown.

25
pmake.js Normal file
View file

@ -0,0 +1,25 @@
function main(){
pmake.subdirectory("external/ppr");
pmake.subdirectory("external/stb");
const IDE = new pmake.ExecutableProject("midas");
IDE.sources = fs.glob("src/*.c", "src/icon/*.c");
IDE.includes = ["src", main.milsko + "/include"];
IDE.libdirs = [main.milsko + "/src", main.milsko + "/lib"];
IDE.libraries = ["stb", "ppr", "Mw"];
pmake.register(IDE);
}
main.milsko = "/usr/local";
(function(){
opt = new pmake.Option("with-milsko=PATH");
opt.category = "General";
opt.description = "Specify path to milsko";
opt.action = function(value){
main.milsko = value;
};
pmake.register(opt);
})();

70
src/dir.c Normal file
View file

@ -0,0 +1,70 @@
#include <midas.h>
#ifdef _WIN32
#include <windows.h>
#endif
struct direntry {
struct ppr_dirent d;
struct ppr_stat s;
char* path;
};
static int sort_de(const void* _a, const void* _b) {
struct direntry* a = (struct direntry*)_a;
struct direntry* b = (struct direntry*)_b;
if(PPR_S_ISDIR(a->s.st_mode) && !PPR_S_ISDIR(b->s.st_mode)) return -1;
if(!PPR_S_ISDIR(a->s.st_mode) && PPR_S_ISDIR(b->s.st_mode)) return 1;
return strcmp(a->d.d_name, b->d.d_name);
}
static void dir_recursion(const char* path, const char* path2, void* tv) {
PPR_DIR* dir;
struct ppr_dirent* d;
struct direntry* de = NULL;
int i;
tv = MwTreeViewAdd(fileview, tv, NULL, path2);
if(path != path2) MwTreeViewSetOpened(fileview, tv, 0);
if((dir = ppr_opendir(path)) != NULL) {
while((d = ppr_readdir(dir)) != NULL) {
struct direntry new_de;
if(d->d_name[0] == '.') continue;
new_de.path = ppr_strvacat(path, "/", d->d_name, NULL);
new_de.d = *d;
ppr_stat(new_de.path, &new_de.s);
arrput(de, new_de);
}
}
if(de != NULL) {
qsort(de, arrlen(de), sizeof(*de), sort_de);
for(i = 0; i < arrlen(de); i++) {
char* p = ppr_strvacat(de[i].d.d_name, PPR_S_ISDIR(de[i].s.st_mode) ? "/" : "", NULL);
dir_recursion(de[i].path, p, tv);
free(p);
free(de[i].path);
}
arrfree(de);
}
}
void dir_scan(const char* dir) {
char real[2048];
void* e;
#ifdef _WIN32
GetFullPathName(dir, 2048, real, NULL);
#else
realpath(dir, real);
#endif
dir_recursion(real, real, NULL);
}

197
src/gui.c Normal file
View file

@ -0,0 +1,197 @@
#define _MILSKO
#include <midas.h>
MwWidget window, menu = NULL, fileview = NULL, editor = NULL, console = NULL;
static void image_draw_inject(MwWidget handle) {
char version[128];
MwPoint p, p2;
MwLLColor c = MwParseColor(handle, "#fff");
MwLLColor cd = MwParseColor(handle, "#222");
MwFLFont f = MwFLBuildFont(0);
handle->bgcolor = MwParseColor(handle, "#888");
sprintf(version, "Version %s\n\n\xc2\xa9 Pyrite development team", VERSION);
p.x = MwGetInteger(handle, MwNwidth) - 16;
p.y = MwGetInteger(handle, MwNheight) - 16 - MwTextHeight(handle, f, version) / 2;
p2 = p;
p.x += 1;
p.y += 1;
MwDrawText(handle, f, &p, version, MwALIGNMENT_END, cd);
p = p2;
MwDrawText(handle, f, &p, version, MwALIGNMENT_END, c);
MwLLFreeColor(handle->bgcolor);
handle->bgcolor = NULL;
MwLLFreeColor(cd);
MwLLFreeColor(c);
}
static void MWAPI resize(MwWidget handle, void* user, void* client) {
int ww = MwGetInteger(window, MwNwidth);
int wh = MwGetInteger(window, MwNheight);
int x, y, w, h;
int padding = 5;
if(menu == NULL) menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
ww -= padding * 2;
wh -= MwGetInteger(menu, MwNheight) + padding * 2;
x = padding;
y = padding + MwGetInteger(menu, MwNheight);
w = (ww - padding) * 0.3;
h = (wh - padding) * 0.8;
if(fileview == NULL) {
fileview = MwCreateWidget(MwTreeViewClass, "fileview", window, x, y, w, h);
} else {
MwVaApply(fileview,
MwNx, x,
MwNy, y,
MwNwidth, w,
MwNheight, h,
NULL);
}
x = x + w + padding;
y = padding + MwGetInteger(menu, MwNheight);
w = (ww - padding) * 0.7;
h = (wh - padding) * 0.8;
if(editor == NULL) {
editor = MwCreateWidget(MwFrameClass, "editor", window, x, y, w, h);
MwSetInteger(editor, MwNhasBorder, 1);
} else {
MwVaApply(editor,
MwNx, x,
MwNy, y,
MwNwidth, w,
MwNheight, h,
NULL);
}
x = padding;
y = y + h + padding;
w = ww;
h = (wh - padding) * 0.2;
if(console == NULL) {
console = MwCreateWidget(MwListBoxClass, "console", window, x, y, w, h);
} else {
MwVaApply(console,
MwNx, x,
MwNy, y,
MwNwidth, w,
MwNheight, h,
NULL);
}
}
void gui_init(void) {
MwRect rc;
int w, h;
MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
MwNtitle, "Midas",
NULL);
MwVaApply(window,
MwNiconPixmap, MwLoadIcon(window, icon_icon),
NULL);
MwGetScreenSize(window, &rc);
w = MwGetInteger(window, MwNwidth);
h = MwGetInteger(window, MwNheight);
if(rc.width >= 1280 && rc.height >= 1024) {
w = 1024;
h = 768;
} else if(rc.width >= 1024 && rc.height >= 768) {
w = 800;
h = 600;
} else {
w = 640;
h = 480;
}
MwVaApply(window,
MwNx, (rc.width - w) / 2,
MwNy, (rc.height - h) / 2,
MwNwidth, w,
MwNheight, h,
NULL);
MwTimeSleep(50);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
resize(window, NULL, NULL);
gui_version();
}
static void version_ok_activate(MwWidget handle, void* user, void* client) {
int i;
MwWidget* children = MwGetChildren(user);
for(i = 0; children[i] != NULL; i++) {
if(MwGetClass(children[i]) == MwImageClass) {
MwLLPixmap px = MwGetVoid(children[i], MwNpixmap);
MwVaApply(children[i],
MwNpixmap, NULL,
NULL);
MwLLDestroyPixmap(px);
break;
}
}
MwDestroyWidget(user);
}
void gui_version(void) {
MwWidget version, image, ok;
MwRect rc;
int x = MwGetInteger(window, MwNx);
int y = MwGetInteger(window, MwNy);
int ww = MwGetInteger(window, MwNwidth);
int wh = MwGetInteger(window, MwNheight);
int bsh = 48;
int bh = bsh / 2;
int w = 640;
int h = 426 + bh;
MwLLPixmap px = MwLoadIcon(window, icon_midas);
MwSizeHints sh;
sh.min_width = sh.max_width = w;
sh.min_height = sh.max_height = h;
MwGetScreenSize(window, &rc);
version = MwVaCreateWidget(MwWindowClass, "window", NULL, x + (ww - w) / 2, y + (wh - h) / 2, w, h,
MwNtitle, "Version information",
MwNsizeHints, &sh,
NULL);
image = MwVaCreateWidget(MwImageClass, "image", version, 0, 0, w, h - bsh,
MwNpixmap, px,
NULL);
image->draw_inject = image_draw_inject;
ok = MwVaCreateWidget(MwButtonClass, "btn", version, w - bh * 4 - (bsh - bh) / 2, h - bsh + (bsh - bh) / 2, bh * 4, bh,
MwNtext, "OK",
NULL);
MwAddUserHandler(ok, MwNactivateHandler, version_ok_activate, version);
MwReparent(version, window);
}
void gui_loop(void) {
MwLoop(window);
}

16390
src/icon/icon.c Normal file

File diff suppressed because it is too large Load diff

272646
src/icon/midas.c Normal file

File diff suppressed because it is too large Load diff

13
src/main.c Normal file
View file

@ -0,0 +1,13 @@
#include <midas.h>
int main(int argc, char** argv) {
ppr_init();
gui_init();
dir_scan(".");
gui_loop();
ppr_uninit();
}

28
src/midas.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef __MIDAS_H__
#define __MIDAS_H__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <Mw/Milsko.h>
#include <ppr.h>
#include <stb_ds.h>
#define VERSION "0.0"
/* icons */
extern MwU32 icon_icon[];
extern MwU32 icon_midas[];
/* gui.c */
extern MwWidget window, menu, fileview, editor, console;
void gui_init(void);
void gui_version(void);
void gui_loop(void);
/* dir.c */
void dir_scan(const char* dir);
#endif