From 1bd37963c8454e90fe776f0b614e2f9132a5cd28 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 30 Nov 2025 08:00:44 +0900 Subject: [PATCH] wip --- CMakeLists.txt | 1 + mimview/CMakeLists.txt | 2 + mimview/main.c | 119 +++++++++++++++++++++++++++++++++++++++++ mimview/mimview.h | 26 +++++++++ mimview/stb_ds.c | 2 + mimview/stb_image.c | 2 + mimview/ui.c | 18 +++++++ 7 files changed, 170 insertions(+) create mode 100644 mimview/CMakeLists.txt create mode 100644 mimview/main.c create mode 100644 mimview/mimview.h create mode 100644 mimview/stb_ds.c create mode 100644 mimview/stb_image.c create mode 100644 mimview/ui.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c20dee6..d07c4d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,3 +7,4 @@ add_subdirectory(mbiff) add_subdirectory(mauplay) add_subdirectory(mcompass) add_subdirectory(mclock) +add_subdirectory(mimview) diff --git a/mimview/CMakeLists.txt b/mimview/CMakeLists.txt new file mode 100644 index 0000000..41f12ca --- /dev/null +++ b/mimview/CMakeLists.txt @@ -0,0 +1,2 @@ +include(MDEBase) +setup_project(mimview ${CMAKE_INSTALL_BINDIR}) diff --git a/mimview/main.c b/mimview/main.c new file mode 100644 index 0000000..d0cd6ef --- /dev/null +++ b/mimview/main.c @@ -0,0 +1,119 @@ +#include "mimview.h" + +#define ButtonWidth 32 +#define ButtonHeight 24 + +MwWidget window, menu, image; +MwLLPixmap pxprojector, pxdata = NULL; +static MwLLPixmap pxprev, pxnext, pxzoomin, pxzoomout; +static MwWidget bprev, bnext, sep, bzoomin, bzoomout; + +static void resize(MwWidget handle, void* user, void* client) { + int y = MwGetInteger(menu, MwNheight); + int ww = MwGetInteger(window, MwNwidth); + int wh = MwGetInteger(window, MwNheight) - y; + int bx = 0; + unsigned char* data; + int iw, ih; + + if(pxdata != NULL) MwLLDestroyPixmap(pxdata); + iw = ww - 10; + ih = wh - 5 - ButtonHeight - 5; + data = malloc(iw * ih * 4); + memset(data, 0, iw * ih * 4); + pxdata = MwLoadRaw(window, data, iw, ih); + free(data); + MwVaApply(image, + MwNpixmap, pxdata, + MwNx, 5, + MwNy, y + 5, + MwNwidth, ww - 10, + MwNheight, wh - 5 - ButtonHeight - 5, + NULL); + + bx = (ww - 10 - (ButtonWidth * 2 + 5) * 2) / 2; + MwVaApply(bprev, + MwNx, bx, + MwNy, y + wh - 5 - ButtonHeight, + MwNwidth, ButtonWidth, + MwNheight, ButtonHeight, + NULL); + MwVaApply(bnext, + MwNx, bx + ButtonWidth + 5, + MwNy, y + wh - 5 - ButtonHeight, + MwNwidth, ButtonWidth, + MwNheight, ButtonHeight, + NULL); + MwVaApply(sep, + MwNx, bx + ButtonWidth + 5 + ButtonWidth, + MwNy, y + wh - 5 - ButtonHeight, + MwNwidth, 10, + MwNheight, ButtonHeight, + NULL); + MwVaApply(bzoomin, + MwNx, bx + ButtonWidth + 5 + ButtonWidth + 10, + MwNy, y + wh - 5 - ButtonHeight, + MwNwidth, ButtonWidth, + MwNheight, ButtonHeight, + NULL); + MwVaApply(bzoomout, + MwNx, bx + ButtonWidth + 5 + ButtonWidth + 10 + ButtonWidth + 5, + MwNy, y + wh - 5 - ButtonHeight, + MwNwidth, ButtonWidth, + MwNheight, ButtonHeight, + NULL); +} + +int main(int argc, char** argv) { + int pad; + MwLibraryInit(); + + window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 320, 240, + MwNtitle, "mimview", + NULL); + menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0); + image = MwCreateWidget(MwImageClass, "image", window, 0, 0, 0, 0); + bprev = MwCreateWidget(MwButtonClass, "prev", window, 0, 0, 0, 0); + bnext = MwCreateWidget(MwButtonClass, "next", window, 0, 0, 0, 0); + sep = MwVaCreateWidget(MwSeparatorClass, "sep", window, 0, 0, 0, 0, + MwNorientation, MwVERTICAL, + NULL); + bzoomin = MwCreateWidget(MwButtonClass, "zoomin", window, 0, 0, 0, 0); + bzoomout = MwCreateWidget(MwButtonClass, "zoomout", window, 0, 0, 0, 0); + + pxprojector = MwLoadImage(window, ICON128DIR "/projector.png"); + pxprev = MwLoadImage(window, ICON16DIR "/previous.png"); + pxnext = MwLoadImage(window, ICON16DIR "/next.png"); + pxzoomin = MwLoadImage(window, ICON16DIR "/zoomin.png"); + pxzoomout = MwLoadImage(window, ICON16DIR "/zoomout.png"); + + pad = ButtonHeight / 2 - 16 / 2 - MwDefaultBorderWidth(window); + + MwVaApply(bprev, + MwNpixmap, pxprev, + MwNpadding, pad, + NULL); + + MwVaApply(bnext, + MwNpixmap, pxnext, + MwNpadding, pad, + NULL); + + MwVaApply(bzoomin, + MwNpixmap, pxzoomout, + MwNpadding, pad, + NULL); + + MwVaApply(bzoomout, + MwNpixmap, pxzoomin, + MwNpadding, pad, + NULL); + + MwAddUserHandler(window, MwNresizeHandler, resize, NULL); + + ui_init(); + + resize(window, NULL, NULL); + + MwLoop(window); +} diff --git a/mimview/mimview.h b/mimview/mimview.h new file mode 100644 index 0000000..98041d7 --- /dev/null +++ b/mimview/mimview.h @@ -0,0 +1,26 @@ +#ifndef __MIMVIEW_H__ +#define __MIMVIEW_H__ + +#define VERSION "0.0.0" + +#include "config.h" + +/* Milsko */ +#include +#include + +/* External */ + +/* Standard */ +#include +#include +#include + +/* main.c */ +extern MwWidget window, menu; +extern MwLLPixmap pxprojector; + +/* ui.c */ +void ui_init(void); + +#endif diff --git a/mimview/stb_ds.c b/mimview/stb_ds.c new file mode 100644 index 0000000..689615c --- /dev/null +++ b/mimview/stb_ds.c @@ -0,0 +1,2 @@ +#define STB_DS_IMPLEMENTATION +#include diff --git a/mimview/stb_image.c b/mimview/stb_image.c new file mode 100644 index 0000000..9177288 --- /dev/null +++ b/mimview/stb_image.c @@ -0,0 +1,2 @@ +#define STB_IMAGE_IMPLEMENTATION +#include diff --git a/mimview/ui.c b/mimview/ui.c new file mode 100644 index 0000000..586aa70 --- /dev/null +++ b/mimview/ui.c @@ -0,0 +1,18 @@ +#include "mimview.h" + +static void* help_about; + +static void menu_menu(MwWidget handle, void* user, void* client) { + if(client == help_about) { + MDEAboutDialog(window, "mimview", VERSION, pxprojector); + } +} + +void ui_init(void) { + void* m; + + m = MwMenuAdd(menu, NULL, "?Help"); + help_about = MwMenuAdd(menu, m, "About"); + + MwAddUserHandler(menu, MwNmenuHandler, menu_menu, NULL); +}