better layout

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@343 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-15 13:58:56 +00:00
parent d3a951abd5
commit ba9b6750d5
19 changed files with 10 additions and 8 deletions

25
examples/basic/checkbox.c Normal file
View File

@@ -0,0 +1,25 @@
/* $Id$ */
#include <Mw/Milsko.h>
int main() {
MwWidget window = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 8 + 16 + 8 + 16 * 10 + 8, 8 + 16 + 8 + 16 + 8,
MwNtitle, "checkbox",
NULL);
MwVaCreateWidget(MwCheckBoxClass, "cb1", window, 8, 8, 16, 16,
NULL);
MwVaCreateWidget(MwCheckBoxClass, "cb2", window, 8, 8 + 16 + 8, 16, 16,
MwNchecked, 1,
NULL);
MwVaCreateWidget(MwLabelClass, "lab1", window, 8 + 16 + 8, 8, 16 * 10, 16,
MwNtext, "lorem ipsum 1",
MwNalignment, MwALIGNMENT_BEGINNING,
NULL);
MwVaCreateWidget(MwLabelClass, "lab2", window, 8 + 16 + 8, 8 + 16 + 8, 16 * 10, 16,
MwNtext, "lorem ipsum 2",
MwNalignment, MwALIGNMENT_BEGINNING,
NULL);
MwLoop(window);
}

93
examples/basic/example.c Normal file
View File

@@ -0,0 +1,93 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwWidget window, menu, button, button2, button3, button4;
void handler(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
(void)user_data;
(void)call_data;
printf("hello world!\n");
}
void resize(MwWidget handle, void* user_data, void* call_data) {
unsigned int w, h, mh;
(void)user_data;
(void)call_data;
w = MwGetInteger(handle, MwNwidth);
h = MwGetInteger(handle, MwNheight) - (mh = MwGetInteger(menu, MwNheight));
MwVaApply(button,
MwNy, 50 + mh,
MwNwidth, w - 50 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button2,
MwNx, 50 + (w - 50 * 2) / 3 * 0,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
NULL);
MwVaApply(button3,
MwNx, 50 + (w - 50 * 2) / 3 * 1,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
NULL);
MwVaApply(button4,
MwNx, 50 + (w - 50 * 2) / 3 * 2,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
NULL);
}
int main() {
MwMenu m, m2;
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 400,
MwNtitle, "hello world",
NULL);
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
MwNtext, "lorem ipsum",
NULL);
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#f66",
NULL);
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#6f6",
NULL);
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#66f",
NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
m = MwMenuAdd(menu, NULL, "test 1");
m2 = MwMenuAdd(menu, m, "test 2");
MwMenuAdd(menu, m2, "test 3");
MwMenuAdd(menu, m2, "test 4");
MwMenuAdd(menu, m2, "test 5");
m2 = MwMenuAdd(menu, m, "test 6");
MwMenuAdd(menu, m2, "test 7");
MwMenuAdd(menu, m2, "test 8");
m2 = MwMenuAdd(menu, m, "test 9");
MwMenuAdd(menu, m2, "test 10");
m2 = MwMenuAdd(menu, m2, "test 11");
MwMenuAdd(menu, m2, "test 12");
MwMenuAdd(menu, m2, "test 13");
MwMenuAdd(menu, NULL, "?test 14");
MwLoop(window);
}

30
examples/basic/image.c Normal file
View File

@@ -0,0 +1,30 @@
/* $Id$ */
#include <Mw/Milsko.h>
int main() {
MwWidget window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
MwNtitle, "image image",
NULL);
MwWidget image = MwCreateWidget(MwImageClass, "image", window, 50, 50, 200, 400);
MwWidget image2 = MwCreateWidget(MwImageClass, "image", window, 250, 50, 200, 200);
MwWidget image3 = MwCreateWidget(MwImageClass, "image", window, 250, 250, 200, 200);
MwLLPixmap px = MwLoadImage(window, "examples/picture.png");
MwLLPixmap px2 = MwLoadImage(window, "examples/picture.jpg");
MwLLPixmap px3 = MwLoadImage(window, "resource/logo.png");
MwVaApply(window,
MwNiconPixmap, px,
NULL);
MwVaApply(image,
MwNpixmap, px,
NULL);
MwVaApply(image2,
MwNpixmap, px2,
NULL);
MwVaApply(image3,
MwNpixmap, px3,
NULL);
MwLoop(window);
}

32
examples/basic/listbox.c Normal file
View File

@@ -0,0 +1,32 @@
/* $Id$ */
#include <Mw/Milsko.h>
#include "../harvard.c"
MwWidget wmain;
void destroy(MwWidget handle, void* user, void* call) {
MwDestroyWidget(user);
}
void activate(MwWidget handle, void* user, void* call) {
char msg[256];
MwWidget msgbox;
sprintf(msg, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
}
int main() {
MwWidget lb;
wmain = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
MwNtitle, "listbox",
NULL);
lb = MwCreateWidget(MwListBoxClass, "listbox", wmain, 5, 5, 630, 470);
MwAddUserHandler(lb, MwNactivateHandler, activate, NULL);
MwListBoxInsertMultiple(lb, -1, (char**)harvard, sizeof(harvard) / sizeof(harvard[0]) - 1);
MwLoop(wmain);
}

View File

@@ -0,0 +1,37 @@
/* $Id$ */
#include <Mw/Milsko.h>
void ok(MwWidget handle, void* user, void* call) {
MwDestroyWidget(user);
}
void spawn(MwWidget handle, void* user, void* call) {
MwWidget mb = MwMessageBox(user, "news has arrived!", "title", MwMB_ICONNEWS | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
}
void spawn2(MwWidget handle, void* user, void* call) {
MwWidget mb = MwMessageBox(user, "something went wrong!", "title", MwMB_ICONERROR | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
}
void spawn3(MwWidget handle, void* user, void* call) {
int i;
for(i = 0; i <= 6; i++) {
MwWidget mb = MwMessageBox(user, "messagebox test", "title", i | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
}
}
int main() {
MwWidget msg = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 300, 100, MwNtitle, "test", NULL);
MwWidget btn = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8, 300 - 16, (100 - 16) / 2, MwNtext, "press me!", NULL);
MwWidget btn2 = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8 + (100 - 16) / 2, (300 - 16) / 2, (100 - 16) / 2, MwNtext, "press me!", NULL);
MwWidget btn3 = MwVaCreateWidget(MwButtonClass, "button", msg, 8 + (300 - 16) / 2, 8 + (100 - 16) / 2, (300 - 16) / 2, (100 - 16) / 2, MwNtext, "press me!", NULL);
MwAddUserHandler(btn, MwNactivateHandler, spawn, msg);
MwAddUserHandler(btn2, MwNactivateHandler, spawn2, msg);
MwAddUserHandler(btn3, MwNactivateHandler, spawn3, msg);
MwLoop(msg);
}

92
examples/basic/rotate.c Normal file
View File

@@ -0,0 +1,92 @@
/* $Id$ */
/* this demo does not work well on windows */
#include <Mw/Milsko.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
#define SIZE 100
MwWidget buttons[6];
double deg = 0;
int ww, wh;
void handler(MwWidget w, void* user, void* client) {
int i;
double cdeg = deg;
(void)w;
(void)user;
(void)client;
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++) {
double rad = cdeg / 180 * M_PI;
int x = ww / 2;
int y = wh / 2;
x += cos(rad) * (ww / 2 - SIZE / 2);
y += sin(rad) * (wh / 2 - SIZE / 2);
x -= SIZE / 2;
y -= SIZE / 2;
MwVaApply(buttons[i],
MwNx, x,
MwNy, y,
NULL);
cdeg += 360 / (sizeof(buttons) / sizeof(buttons[0]));
}
deg += 120.0 / (1000.0 / MwWaitMS);
}
void resize(MwWidget w, void* user, void* client) {
(void)w;
(void)user;
(void)client;
ww = MwGetInteger(w, MwNwidth);
wh = MwGetInteger(w, MwNheight);
}
int main() {
MwWidget window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, (ww = 500), (wh = 500),
MwNtitle, "rotate",
NULL);
int i;
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++) {
const char* color = "";
char fgcolor[5];
int j;
if(i == 0) color = "#f66";
if(i == 1) color = "#6f6";
if(i == 2) color = "#ff6";
if(i == 3) color = "#66f";
if(i == 4) color = "#f6f";
if(i == 5) color = "#6ff";
fgcolor[0] = '#';
fgcolor[4] = 0;
for(j = 0; j < 3; j++) {
fgcolor[j + 1] = color[j + 1] == 'f' ? '6' : 'f';
}
buttons[i] = MwVaCreateWidget(MwButtonClass, "button", window, 0, 0, SIZE, SIZE,
MwNbackground, color,
MwNforeground, fgcolor,
MwNtext, "fancy",
NULL);
}
MwAddUserHandler(window, MwNtickHandler, handler, NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwLoop(window);
}

View File

@@ -0,0 +1,18 @@
/* $Id$ */
#include <Mw/Milsko.h>
int main() {
MwWidget window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
MwNtitle, "main",
NULL);
int i;
for(i = 0; i < 500 / 16; i++) {
MwVaCreateWidget(MwScrollBarClass, "scroll", window, 16 * i, 0, 16, 500,
MwNorientation, MwVERTICAL,
NULL);
}
MwLoop(window);
}

29
examples/basic/viewport.c Normal file
View File

@@ -0,0 +1,29 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwWidget vp;
static void resize(MwWidget handle, void* user, void* call) {
int w = MwGetInteger(handle, MwNwidth);
int h = MwGetInteger(handle, MwNheight);
MwVaApply(vp,
MwNwidth, w - 10,
MwNheight, h - 10,
NULL);
}
int main() {
MwWidget w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480, MwNtitle, "test", NULL);
vp = MwCreateWidget(MwViewportClass, "vp", w, 5, 5, 630, 470);
MwVaCreateWidget(MwImageClass, "image", MwViewportGetViewport(vp), 0, 0, 1024, 1024,
MwNpixmap, MwLoadImage(vp, "examples/picture.png"),
NULL);
MwViewportSetSize(vp, 1024, 1024);
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
MwLoop(w);
}