generate pkgconfig file (don't commit yet i fucked it up)
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
4b6eae99dc
commit
c705d2b98c
375 changed files with 203503 additions and 203476 deletions
|
|
@ -1,7 +1,7 @@
|
|||
add_subdirectory(basic)
|
||||
if(${MW_TRY_OPENGL})
|
||||
add_subdirectory(gldemos)
|
||||
endif()
|
||||
if(${MW_TRY_VULKAN})
|
||||
add_subdirectory(vkdemos)
|
||||
endif()
|
||||
add_subdirectory(basic)
|
||||
if(${MW_TRY_OPENGL})
|
||||
add_subdirectory(gldemos)
|
||||
endif()
|
||||
if(${MW_TRY_VULKAN})
|
||||
add_subdirectory(vkdemos)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
file(
|
||||
GLOB
|
||||
EXAMPLES_BASIC_SOURCES
|
||||
*.c
|
||||
)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES Retro)
|
||||
add_application(${TARGET} ${PATH})
|
||||
else()
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
endif()
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
file(
|
||||
GLOB
|
||||
EXAMPLES_BASIC_SOURCES
|
||||
*.c
|
||||
)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES Retro)
|
||||
add_application(${TARGET} ${PATH})
|
||||
else()
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
endif()
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
|
|
|||
|
|
@ -1,74 +1,74 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, box;
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
MwVaApply(box,
|
||||
MwNwidth, ww,
|
||||
MwNheight, wh,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget box2, box3, box4;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 600, 200,
|
||||
MwNtitle, "box",
|
||||
NULL);
|
||||
|
||||
box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0,
|
||||
MwNpadding, 10,
|
||||
MwNmargin, 10,
|
||||
NULL);
|
||||
|
||||
box2 = MwVaCreateWidget(MwBoxClass, "box2", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
|
||||
box3 = MwVaCreateWidget(MwBoxClass, "box3", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
|
||||
box4 = MwVaCreateWidget(MwBoxClass, "box4", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
MwNfixedSize, 40,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn1", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#a00",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn2", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#0a0",
|
||||
MwNratio, 2,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn3", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#00a",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn4", box3, 0, 0, 0, 0,
|
||||
MwNbackground, "#a0a",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn5", box4, 0, 0, 0, 0,
|
||||
MwNbackground, "#0aa",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, box;
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
MwVaApply(box,
|
||||
MwNwidth, ww,
|
||||
MwNheight, wh,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget box2, box3, box4;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 600, 200,
|
||||
MwNtitle, "box",
|
||||
NULL);
|
||||
|
||||
box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0,
|
||||
MwNpadding, 10,
|
||||
MwNmargin, 10,
|
||||
NULL);
|
||||
|
||||
box2 = MwVaCreateWidget(MwBoxClass, "box2", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
|
||||
box3 = MwVaCreateWidget(MwBoxClass, "box3", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
|
||||
box4 = MwVaCreateWidget(MwBoxClass, "box4", box, 0, 0, 0, 0,
|
||||
MwNmargin, 10,
|
||||
MwNorientation, MwVERTICAL,
|
||||
MwNfixedSize, 40,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn1", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#a00",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn2", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#0a0",
|
||||
MwNratio, 2,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn3", box2, 0, 0, 0, 0,
|
||||
MwNbackground, "#00a",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn4", box3, 0, 0, 0, 0,
|
||||
MwNbackground, "#a0a",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwButtonClass, "btn5", box4, 0, 0, 0, 0,
|
||||
MwNbackground, "#0aa",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,185 +1,185 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget widgets[18];
|
||||
MwWidget inp;
|
||||
|
||||
/* probably enough for most tasks */
|
||||
double stack[512];
|
||||
int sp = 0;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* client, void* user) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight) - MwGetInteger(inp, MwNheight);
|
||||
int i;
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNwidth, ww,
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
|
||||
int x = i % 4;
|
||||
int y = i / 4;
|
||||
if(widgets[i] != NULL) {
|
||||
MwVaApply(widgets[i],
|
||||
MwNwidth, ww / 4,
|
||||
MwNheight, wh / 5,
|
||||
MwNx, ww / 4 * x,
|
||||
MwNy, wh / 5 * y + MwGetInteger(inp, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI activate(MwWidget handle, void* client, void* user) {
|
||||
const char* n = MwGetText(handle, MwNtext);
|
||||
|
||||
if(('0' <= n[0] && n[0] <= '9') || n[0] == '.') {
|
||||
const char* s = MwGetText(inp, MwNtext);
|
||||
char* r;
|
||||
|
||||
if(n[0] == '.' && s != NULL) {
|
||||
int i;
|
||||
for(i = 0; s[i] != 0; i++) {
|
||||
if(s[i] == '.') return;
|
||||
}
|
||||
}
|
||||
|
||||
if(s == NULL) s = "";
|
||||
|
||||
r = MwStringConcat(s, n);
|
||||
MwVaApply(inp,
|
||||
MwNtext, r,
|
||||
NULL);
|
||||
free(r);
|
||||
} else if(n[0] == 'E') {
|
||||
const char* s = MwGetText(inp, MwNtext);
|
||||
|
||||
if(s != NULL) {
|
||||
stack[sp++] = atof(s);
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
}
|
||||
} else if(n[0] == 'C') {
|
||||
MwVaApply(inp,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
} else if(n[0] == '+' || n[0] == '-' || n[0] == '*' || n[0] == '/') {
|
||||
if(sp >= 2) {
|
||||
double sv = stack[--sp];
|
||||
double fv = stack[--sp];
|
||||
double v;
|
||||
char buf[256];
|
||||
|
||||
if(n[0] == '+') {
|
||||
v = fv + sv;
|
||||
} else if(n[0] == '-') {
|
||||
v = fv - sv;
|
||||
} else if(n[0] == '*') {
|
||||
v = fv * sv;
|
||||
} else if(n[0] == '/') {
|
||||
v = fv / sv;
|
||||
}
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 256, "%g", v);
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNtext, buf,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) widgets[i] = NULL;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 150, 150,
|
||||
MwNtitle, "Calculator",
|
||||
NULL);
|
||||
|
||||
inp = MwCreateWidget(MwEntryClass, "entry", w, 0, 0, 0, 24);
|
||||
|
||||
widgets[0] = MwVaCreateWidget(MwButtonClass, "7", w, 0, 0, 0, 0,
|
||||
MwNtext, "7",
|
||||
NULL);
|
||||
|
||||
widgets[1] = MwVaCreateWidget(MwButtonClass, "8", w, 0, 0, 0, 0,
|
||||
MwNtext, "8",
|
||||
NULL);
|
||||
|
||||
widgets[2] = MwVaCreateWidget(MwButtonClass, "9", w, 0, 0, 0, 0,
|
||||
MwNtext, "9",
|
||||
NULL);
|
||||
|
||||
widgets[3] = MwVaCreateWidget(MwButtonClass, "/", w, 0, 0, 0, 0,
|
||||
MwNtext, "/",
|
||||
NULL);
|
||||
|
||||
widgets[4] = MwVaCreateWidget(MwButtonClass, "4", w, 0, 0, 0, 0,
|
||||
MwNtext, "4",
|
||||
NULL);
|
||||
|
||||
widgets[5] = MwVaCreateWidget(MwButtonClass, "5", w, 0, 0, 0, 0,
|
||||
MwNtext, "5",
|
||||
NULL);
|
||||
|
||||
widgets[6] = MwVaCreateWidget(MwButtonClass, "6", w, 0, 0, 0, 0,
|
||||
MwNtext, "6",
|
||||
NULL);
|
||||
|
||||
widgets[7] = MwVaCreateWidget(MwButtonClass, "*", w, 0, 0, 0, 0,
|
||||
MwNtext, "*",
|
||||
NULL);
|
||||
|
||||
widgets[8] = MwVaCreateWidget(MwButtonClass, "1", w, 0, 0, 0, 0,
|
||||
MwNtext, "1",
|
||||
NULL);
|
||||
|
||||
widgets[9] = MwVaCreateWidget(MwButtonClass, "2", w, 0, 0, 0, 0,
|
||||
MwNtext, "2",
|
||||
NULL);
|
||||
|
||||
widgets[10] = MwVaCreateWidget(MwButtonClass, "3", w, 0, 0, 0, 0,
|
||||
MwNtext, "3",
|
||||
NULL);
|
||||
|
||||
widgets[11] = MwVaCreateWidget(MwButtonClass, "-", w, 0, 0, 0, 0,
|
||||
MwNtext, "-",
|
||||
NULL);
|
||||
|
||||
widgets[12] = MwVaCreateWidget(MwButtonClass, "0", w, 0, 0, 0, 0,
|
||||
MwNtext, "0",
|
||||
NULL);
|
||||
|
||||
widgets[13] = MwVaCreateWidget(MwButtonClass, ".", w, 0, 0, 0, 0,
|
||||
MwNtext, ".",
|
||||
NULL);
|
||||
|
||||
widgets[16] = MwVaCreateWidget(MwButtonClass, "E", w, 0, 0, 0, 0,
|
||||
MwNtext, "E",
|
||||
NULL);
|
||||
|
||||
widgets[15] = MwVaCreateWidget(MwButtonClass, "+", w, 0, 0, 0, 0,
|
||||
MwNtext, "+",
|
||||
NULL);
|
||||
|
||||
widgets[17] = MwVaCreateWidget(MwButtonClass, "C", w, 0, 0, 0, 0,
|
||||
MwNtext, "C",
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
|
||||
if(widgets[i] != NULL) MwAddUserHandler(widgets[i], MwNactivateHandler, activate, NULL);
|
||||
}
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(w, NULL, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget widgets[18];
|
||||
MwWidget inp;
|
||||
|
||||
/* probably enough for most tasks */
|
||||
double stack[512];
|
||||
int sp = 0;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* client, void* user) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight) - MwGetInteger(inp, MwNheight);
|
||||
int i;
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNwidth, ww,
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
|
||||
int x = i % 4;
|
||||
int y = i / 4;
|
||||
if(widgets[i] != NULL) {
|
||||
MwVaApply(widgets[i],
|
||||
MwNwidth, ww / 4,
|
||||
MwNheight, wh / 5,
|
||||
MwNx, ww / 4 * x,
|
||||
MwNy, wh / 5 * y + MwGetInteger(inp, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI activate(MwWidget handle, void* client, void* user) {
|
||||
const char* n = MwGetText(handle, MwNtext);
|
||||
|
||||
if(('0' <= n[0] && n[0] <= '9') || n[0] == '.') {
|
||||
const char* s = MwGetText(inp, MwNtext);
|
||||
char* r;
|
||||
|
||||
if(n[0] == '.' && s != NULL) {
|
||||
int i;
|
||||
for(i = 0; s[i] != 0; i++) {
|
||||
if(s[i] == '.') return;
|
||||
}
|
||||
}
|
||||
|
||||
if(s == NULL) s = "";
|
||||
|
||||
r = MwStringConcat(s, n);
|
||||
MwVaApply(inp,
|
||||
MwNtext, r,
|
||||
NULL);
|
||||
free(r);
|
||||
} else if(n[0] == 'E') {
|
||||
const char* s = MwGetText(inp, MwNtext);
|
||||
|
||||
if(s != NULL) {
|
||||
stack[sp++] = atof(s);
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
}
|
||||
} else if(n[0] == 'C') {
|
||||
MwVaApply(inp,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
} else if(n[0] == '+' || n[0] == '-' || n[0] == '*' || n[0] == '/') {
|
||||
if(sp >= 2) {
|
||||
double sv = stack[--sp];
|
||||
double fv = stack[--sp];
|
||||
double v;
|
||||
char buf[256];
|
||||
|
||||
if(n[0] == '+') {
|
||||
v = fv + sv;
|
||||
} else if(n[0] == '-') {
|
||||
v = fv - sv;
|
||||
} else if(n[0] == '*') {
|
||||
v = fv * sv;
|
||||
} else if(n[0] == '/') {
|
||||
v = fv / sv;
|
||||
}
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 256, "%g", v);
|
||||
|
||||
MwVaApply(inp,
|
||||
MwNtext, buf,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) widgets[i] = NULL;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 150, 150,
|
||||
MwNtitle, "Calculator",
|
||||
NULL);
|
||||
|
||||
inp = MwCreateWidget(MwEntryClass, "entry", w, 0, 0, 0, 24);
|
||||
|
||||
widgets[0] = MwVaCreateWidget(MwButtonClass, "7", w, 0, 0, 0, 0,
|
||||
MwNtext, "7",
|
||||
NULL);
|
||||
|
||||
widgets[1] = MwVaCreateWidget(MwButtonClass, "8", w, 0, 0, 0, 0,
|
||||
MwNtext, "8",
|
||||
NULL);
|
||||
|
||||
widgets[2] = MwVaCreateWidget(MwButtonClass, "9", w, 0, 0, 0, 0,
|
||||
MwNtext, "9",
|
||||
NULL);
|
||||
|
||||
widgets[3] = MwVaCreateWidget(MwButtonClass, "/", w, 0, 0, 0, 0,
|
||||
MwNtext, "/",
|
||||
NULL);
|
||||
|
||||
widgets[4] = MwVaCreateWidget(MwButtonClass, "4", w, 0, 0, 0, 0,
|
||||
MwNtext, "4",
|
||||
NULL);
|
||||
|
||||
widgets[5] = MwVaCreateWidget(MwButtonClass, "5", w, 0, 0, 0, 0,
|
||||
MwNtext, "5",
|
||||
NULL);
|
||||
|
||||
widgets[6] = MwVaCreateWidget(MwButtonClass, "6", w, 0, 0, 0, 0,
|
||||
MwNtext, "6",
|
||||
NULL);
|
||||
|
||||
widgets[7] = MwVaCreateWidget(MwButtonClass, "*", w, 0, 0, 0, 0,
|
||||
MwNtext, "*",
|
||||
NULL);
|
||||
|
||||
widgets[8] = MwVaCreateWidget(MwButtonClass, "1", w, 0, 0, 0, 0,
|
||||
MwNtext, "1",
|
||||
NULL);
|
||||
|
||||
widgets[9] = MwVaCreateWidget(MwButtonClass, "2", w, 0, 0, 0, 0,
|
||||
MwNtext, "2",
|
||||
NULL);
|
||||
|
||||
widgets[10] = MwVaCreateWidget(MwButtonClass, "3", w, 0, 0, 0, 0,
|
||||
MwNtext, "3",
|
||||
NULL);
|
||||
|
||||
widgets[11] = MwVaCreateWidget(MwButtonClass, "-", w, 0, 0, 0, 0,
|
||||
MwNtext, "-",
|
||||
NULL);
|
||||
|
||||
widgets[12] = MwVaCreateWidget(MwButtonClass, "0", w, 0, 0, 0, 0,
|
||||
MwNtext, "0",
|
||||
NULL);
|
||||
|
||||
widgets[13] = MwVaCreateWidget(MwButtonClass, ".", w, 0, 0, 0, 0,
|
||||
MwNtext, ".",
|
||||
NULL);
|
||||
|
||||
widgets[16] = MwVaCreateWidget(MwButtonClass, "E", w, 0, 0, 0, 0,
|
||||
MwNtext, "E",
|
||||
NULL);
|
||||
|
||||
widgets[15] = MwVaCreateWidget(MwButtonClass, "+", w, 0, 0, 0, 0,
|
||||
MwNtext, "+",
|
||||
NULL);
|
||||
|
||||
widgets[17] = MwVaCreateWidget(MwButtonClass, "C", w, 0, 0, 0, 0,
|
||||
MwNtext, "C",
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
|
||||
if(widgets[i] != NULL) MwAddUserHandler(widgets[i], MwNactivateHandler, activate, NULL);
|
||||
}
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(w, NULL, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
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);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,78 +1,78 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, instructions, text1, text2, cur_text;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
|
||||
unsigned int w, h;
|
||||
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
w = MwGetInteger(handle, MwNwidth);
|
||||
h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwVaApply(instructions,
|
||||
MwNy, 50,
|
||||
MwNwidth, w - 50 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(text1,
|
||||
MwNy, 150,
|
||||
MwNwidth, w - 25 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(text2,
|
||||
MwNy, 250,
|
||||
MwNwidth, w - 25 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
}
|
||||
static void MWAPI clipboard(MwWidget handle, void* user_data, void* call_data) {
|
||||
char* clipboard = call_data;
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
|
||||
if(clipboard != NULL) {
|
||||
MwVaApply(cur_text, MwNtext, clipboard, NULL);
|
||||
MwForceRender(cur_text);
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
|
||||
cur_text = text1;
|
||||
MwGetClipboard(handle, MwCLIPBOARD_MAIN);
|
||||
cur_text = text2;
|
||||
MwGetClipboard(handle, MwCLIPBOARD_PRIMARY);
|
||||
MwForceRender(window);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 400,
|
||||
MwNtitle, "clipboard",
|
||||
NULL);
|
||||
instructions = MwVaCreateWidget(MwLabelClass, "button", window, 50, 50, 300, 125,
|
||||
MwNtext, "clipboard contents will show up below.",
|
||||
NULL);
|
||||
text1 = MwVaCreateWidget(MwLabelClass, "label", window, 25, 150, 300, 75,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
text2 = MwVaCreateWidget(MwLabelClass, "label2", window, 25, 250, 300, 75,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
|
||||
cur_text = text1;
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(window, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(instructions, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(cur_text, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, instructions, text1, text2, cur_text;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
|
||||
unsigned int w, h;
|
||||
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
w = MwGetInteger(handle, MwNwidth);
|
||||
h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwVaApply(instructions,
|
||||
MwNy, 50,
|
||||
MwNwidth, w - 50 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(text1,
|
||||
MwNy, 150,
|
||||
MwNwidth, w - 25 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(text2,
|
||||
MwNy, 250,
|
||||
MwNwidth, w - 25 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
}
|
||||
static void MWAPI clipboard(MwWidget handle, void* user_data, void* call_data) {
|
||||
char* clipboard = call_data;
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
|
||||
if(clipboard != NULL) {
|
||||
MwVaApply(cur_text, MwNtext, clipboard, NULL);
|
||||
MwForceRender(cur_text);
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
|
||||
cur_text = text1;
|
||||
MwGetClipboard(handle, MwCLIPBOARD_MAIN);
|
||||
cur_text = text2;
|
||||
MwGetClipboard(handle, MwCLIPBOARD_PRIMARY);
|
||||
MwForceRender(window);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 400,
|
||||
MwNtitle, "clipboard",
|
||||
NULL);
|
||||
instructions = MwVaCreateWidget(MwLabelClass, "button", window, 50, 50, 300, 125,
|
||||
MwNtext, "clipboard contents will show up below.",
|
||||
NULL);
|
||||
text1 = MwVaCreateWidget(MwLabelClass, "label", window, 25, 150, 300, 75,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
text2 = MwVaCreateWidget(MwLabelClass, "label2", window, 25, 250, 300, 75,
|
||||
MwNtext, "",
|
||||
NULL);
|
||||
|
||||
cur_text = text1;
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(window, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(instructions, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(cur_text, MwNclipboardHandler, clipboard, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,48 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
char hexColor[8];
|
||||
MwRGB* rgb = call_data;
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
|
||||
rgb->red &= 0xff;
|
||||
rgb->green &= 0xff;
|
||||
rgb->blue &= 0xff;
|
||||
MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
|
||||
MwSetText(window, MwNbackground, hexColor);
|
||||
}
|
||||
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
MwWidget cpicker = MwColorPicker(window, "cpicker");
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(cpicker, MwNcolorChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||
MwNtext, "change window background",
|
||||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
char hexColor[8];
|
||||
MwRGB* rgb = call_data;
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
|
||||
rgb->red &= 0xff;
|
||||
rgb->green &= 0xff;
|
||||
rgb->blue &= 0xff;
|
||||
MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
|
||||
MwSetText(window, MwNbackground, hexColor);
|
||||
}
|
||||
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
MwWidget cpicker = MwColorPicker(window, "cpicker");
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(cpicker, MwNcolorChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||
MwNtext, "change window background",
|
||||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget w, cb;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 320 + 5, 5 + 24 + 5,
|
||||
MwNtitle, "combobox",
|
||||
NULL);
|
||||
|
||||
cb = MwCreateWidget(MwComboBoxClass, "combobox", w, 5, 5, 320, 24);
|
||||
|
||||
MwComboBoxAdd(cb, -1, "wow!");
|
||||
MwComboBoxAdd(cb, -1, "insert");
|
||||
MwComboBoxAdd(cb, -1, "cool");
|
||||
MwComboBoxAdd(cb, -1, "text");
|
||||
MwComboBoxAdd(cb, -1, "here");
|
||||
MwComboBoxAdd(cb, -1, "!!!");
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget w, cb;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 320 + 5, 5 + 24 + 5,
|
||||
MwNtitle, "combobox",
|
||||
NULL);
|
||||
|
||||
cb = MwCreateWidget(MwComboBoxClass, "combobox", w, 5, 5, 320, 24);
|
||||
|
||||
MwComboBoxAdd(cb, -1, "wow!");
|
||||
MwComboBoxAdd(cb, -1, "insert");
|
||||
MwComboBoxAdd(cb, -1, "cool");
|
||||
MwComboBoxAdd(cb, -1, "text");
|
||||
MwComboBoxAdd(cb, -1, "here");
|
||||
MwComboBoxAdd(cb, -1, "!!!");
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,160 +1,160 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, menu, button, button2, button3, button4, button5, button6, button7;
|
||||
|
||||
void MWAPI handler(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
printf("hello world!\n");
|
||||
}
|
||||
|
||||
void MWAPI handler_theme(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNdarkTheme, MwGetInteger(window, MwNdarkTheme) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI handler_look(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNmodernLook, MwGetInteger(window, MwNmodernLook) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI handler_font(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNbitmapFont, MwGetInteger(window, MwNbitmapFont) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI 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) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button2,
|
||||
MwNx, 50 + (w - 50 * 2) / 4,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 2,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(button7,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 3,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(button4,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button5,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button6,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwMenu m, m2;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
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, 100, 125,
|
||||
MwNtext, "theme",
|
||||
NULL);
|
||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 50, 100, 125,
|
||||
MwNtext, "look",
|
||||
NULL);
|
||||
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "font",
|
||||
NULL);
|
||||
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#f66",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button5 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#6f6",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button6 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#66f",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button7 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "disabled",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);
|
||||
MwAddUserHandler(button2, MwNactivateHandler, handler_look, NULL);
|
||||
MwAddUserHandler(button3, MwNactivateHandler, handler_font, NULL);
|
||||
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button5, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button6, MwNactivateHandler, handler, NULL);
|
||||
|
||||
resize(window, NULL, 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);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, menu, button, button2, button3, button4, button5, button6, button7;
|
||||
|
||||
void MWAPI handler(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
printf("hello world!\n");
|
||||
}
|
||||
|
||||
void MWAPI handler_theme(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNdarkTheme, MwGetInteger(window, MwNdarkTheme) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI handler_look(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNmodernLook, MwGetInteger(window, MwNmodernLook) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI handler_font(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(window,
|
||||
MwNbitmapFont, MwGetInteger(window, MwNbitmapFont) == 0 ? 1 : 0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI 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) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button2,
|
||||
MwNx, 50 + (w - 50 * 2) / 4,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 2,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(button7,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 3,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(button4,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button5,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button6,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwMenu m, m2;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
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, 100, 125,
|
||||
MwNtext, "theme",
|
||||
NULL);
|
||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 50, 100, 125,
|
||||
MwNtext, "look",
|
||||
NULL);
|
||||
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "font",
|
||||
NULL);
|
||||
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#f66",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button5 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#6f6",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button6 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#66f",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button7 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "disabled",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);
|
||||
MwAddUserHandler(button2, MwNactivateHandler, handler_look, NULL);
|
||||
MwAddUserHandler(button3, MwNactivateHandler, handler_font, NULL);
|
||||
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button5, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button6, MwNactivateHandler, handler, NULL);
|
||||
|
||||
resize(window, NULL, 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +1,70 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
MwWidget mb;
|
||||
|
||||
MwBool fpicker_wait = MwFALSE;
|
||||
MwBool msgbox_wait = MwFALSE;
|
||||
|
||||
void MWAPI ok(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
msgbox_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
mb = MwMessageBox(handle, call_data, "File chosen", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||
|
||||
(void)user_data;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
|
||||
msgbox_wait = MwTRUE;
|
||||
|
||||
while(msgbox_wait) {
|
||||
MwStep(mb);
|
||||
}
|
||||
|
||||
fpicker_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
fpicker = MwFileChooserEx(handle, "file chooser", 0);
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(fpicker, MwNfileChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(fpicker, MwNbackground, MwGetInteger(fpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
|
||||
fpicker_wait = MwTRUE;
|
||||
|
||||
while(fpicker_wait) {
|
||||
MwStep(fpicker);
|
||||
}
|
||||
|
||||
MwDestroyWidget(fpicker);
|
||||
MwDestroyWidget(mb);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||
MwNtext, "select file",
|
||||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
MwWidget mb;
|
||||
|
||||
MwBool fpicker_wait = MwFALSE;
|
||||
MwBool msgbox_wait = MwFALSE;
|
||||
|
||||
void MWAPI ok(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
msgbox_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
mb = MwMessageBox(handle, call_data, "File chosen", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||
|
||||
(void)user_data;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
|
||||
msgbox_wait = MwTRUE;
|
||||
|
||||
while(msgbox_wait) {
|
||||
MwStep(mb);
|
||||
}
|
||||
|
||||
fpicker_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
fpicker = MwFileChooserEx(handle, "file chooser", 0);
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(fpicker, MwNfileChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(fpicker, MwNbackground, MwGetInteger(fpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
|
||||
fpicker_wait = MwTRUE;
|
||||
|
||||
while(fpicker_wait) {
|
||||
MwStep(fpicker);
|
||||
}
|
||||
|
||||
MwDestroyWidget(fpicker);
|
||||
MwDestroyWidget(mb);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||
MwNtext, "select file",
|
||||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window, image, image2, image3;
|
||||
MwLLPixmap px, px2, px3;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, "image image",
|
||||
NULL);
|
||||
image = MwCreateWidget(MwImageClass, "image", window, 50, 50, 200, 400);
|
||||
image2 = MwCreateWidget(MwImageClass, "image", window, 250, 50, 200, 200);
|
||||
image3 = MwCreateWidget(MwImageClass, "image", window, 250, 250, 200, 200);
|
||||
px = MwLoadImage(window, "examples/picture.png");
|
||||
px2 = MwLoadImage(window, "examples/picture.jpg");
|
||||
px3 = MwLoadImage(window, "resource/logo/logo.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(window, "../examples/picture.png");
|
||||
if(px2 == NULL) px2 = MwLoadImage(window, "../examples/picture.jpg");
|
||||
if(px3 == NULL) px3 = MwLoadImage(window, "../resource/logo/logo.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(window, "picture.png");
|
||||
if(px2 == NULL) px2 = MwLoadImage(window, "picture.jpg");
|
||||
if(px3 == NULL) px3 = MwLoadImage(window, "logo.png");
|
||||
|
||||
MwVaApply(window,
|
||||
MwNiconPixmap, px,
|
||||
NULL);
|
||||
|
||||
MwVaApply(image,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
MwVaApply(image2,
|
||||
MwNpixmap, px2,
|
||||
NULL);
|
||||
MwVaApply(image3,
|
||||
MwNpixmap, px3,
|
||||
NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window, image, image2, image3;
|
||||
MwLLPixmap px, px2, px3;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, "image image",
|
||||
NULL);
|
||||
image = MwCreateWidget(MwImageClass, "image", window, 50, 50, 200, 400);
|
||||
image2 = MwCreateWidget(MwImageClass, "image", window, 250, 50, 200, 200);
|
||||
image3 = MwCreateWidget(MwImageClass, "image", window, 250, 250, 200, 200);
|
||||
px = MwLoadImage(window, "examples/picture.png");
|
||||
px2 = MwLoadImage(window, "examples/picture.jpg");
|
||||
px3 = MwLoadImage(window, "resource/logo/logo.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(window, "../examples/picture.png");
|
||||
if(px2 == NULL) px2 = MwLoadImage(window, "../examples/picture.jpg");
|
||||
if(px3 == NULL) px3 = MwLoadImage(window, "../resource/logo/logo.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(window, "picture.png");
|
||||
if(px2 == NULL) px2 = MwLoadImage(window, "picture.jpg");
|
||||
if(px3 == NULL) px3 = MwLoadImage(window, "logo.png");
|
||||
|
||||
MwVaApply(window,
|
||||
MwNiconPixmap, px,
|
||||
NULL);
|
||||
|
||||
MwVaApply(image,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
MwVaApply(image2,
|
||||
MwNpixmap, px2,
|
||||
NULL);
|
||||
MwVaApply(image3,
|
||||
MwNpixmap, px3,
|
||||
NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,61 +1,61 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#include "../harvard.c"
|
||||
|
||||
MwWidget w_main;
|
||||
|
||||
void MWAPI destroy(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user, void* call) {
|
||||
char msg[256];
|
||||
MwWidget msgbox;
|
||||
|
||||
(void)user;
|
||||
|
||||
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
|
||||
|
||||
msgbox = MwMessageBox(w_main, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget lb;
|
||||
int len = sizeof(harvard) / sizeof(harvard[0]) - 1;
|
||||
int i;
|
||||
int index;
|
||||
MwLLPixmap px;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w_main = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
|
||||
MwNtitle, "listbox",
|
||||
NULL);
|
||||
lb = MwCreateWidget(MwListBoxClass, "listbox", w_main, 5, 5, 630, 470);
|
||||
|
||||
px = MwLoadIcon(lb, MwIconInfo);
|
||||
|
||||
MwSetInteger(lb, MwNleftPadding, 20);
|
||||
|
||||
index = MwListBoxSet(lb, -1, 0, "Harvard sentence");
|
||||
MwListBoxSet(lb, index, -1, "Length");
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
char sz[16];
|
||||
MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
|
||||
index = MwListBoxSet(lb, -1, 0, harvard[i]);
|
||||
MwListBoxSet(lb, index, -1, sz);
|
||||
MwListBoxSetIcon(lb, index, px);
|
||||
}
|
||||
|
||||
MwAddUserHandler(lb, MwNlistBoxActivateHandler, activate, NULL);
|
||||
MwVaApply(lb,
|
||||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
MwListBoxSetWidth(lb, 0, -128);
|
||||
|
||||
MwLoop(w_main);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#include "../harvard.c"
|
||||
|
||||
MwWidget w_main;
|
||||
|
||||
void MWAPI destroy(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user, void* call) {
|
||||
char msg[256];
|
||||
MwWidget msgbox;
|
||||
|
||||
(void)user;
|
||||
|
||||
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
|
||||
|
||||
msgbox = MwMessageBox(w_main, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget lb;
|
||||
int len = sizeof(harvard) / sizeof(harvard[0]) - 1;
|
||||
int i;
|
||||
int index;
|
||||
MwLLPixmap px;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w_main = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
|
||||
MwNtitle, "listbox",
|
||||
NULL);
|
||||
lb = MwCreateWidget(MwListBoxClass, "listbox", w_main, 5, 5, 630, 470);
|
||||
|
||||
px = MwLoadIcon(lb, MwIconInfo);
|
||||
|
||||
MwSetInteger(lb, MwNleftPadding, 20);
|
||||
|
||||
index = MwListBoxSet(lb, -1, 0, "Harvard sentence");
|
||||
MwListBoxSet(lb, index, -1, "Length");
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
char sz[16];
|
||||
MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
|
||||
index = MwListBoxSet(lb, -1, 0, harvard[i]);
|
||||
MwListBoxSet(lb, index, -1, sz);
|
||||
MwListBoxSetIcon(lb, index, px);
|
||||
}
|
||||
|
||||
MwAddUserHandler(lb, MwNlistBoxActivateHandler, activate, NULL);
|
||||
MwVaApply(lb,
|
||||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
MwListBoxSetWidth(lb, 0, -128);
|
||||
|
||||
MwLoop(w_main);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +1,57 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
void MWAPI ok(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI spawn(MwWidget handle, void* user, void* call) {
|
||||
MwWidget mb = MwMessageBox(user, "news has arrived!", "title", MwMB_ICONNEWS | MwMB_BUTTONOK);
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
|
||||
void MWAPI spawn2(MwWidget handle, void* user, void* call) {
|
||||
MwWidget mb = MwMessageBox(user, "something went wrong!", "title", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
|
||||
void MWAPI spawn3(MwWidget handle, void* user, void* call) {
|
||||
int i;
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
for(i = 0; i <= MwMB_ICONCLOCK; i++) {
|
||||
MwWidget mb = MwMessageBox(user, "messagebox test", "title", i | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget msg, btn, btn2, btn3;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
msg = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 300, 100, MwNtitle, "test", NULL);
|
||||
btn = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8, 300 - 16, (100 - 16) / 2, MwNtext, "press me!", NULL);
|
||||
btn2 = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8 + (100 - 16) / 2, (300 - 16) / 2, (100 - 16) / 2, MwNtext, "press me!", NULL);
|
||||
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);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
void MWAPI ok(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI spawn(MwWidget handle, void* user, void* call) {
|
||||
MwWidget mb = MwMessageBox(user, "news has arrived!", "title", MwMB_ICONNEWS | MwMB_BUTTONOK);
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
|
||||
void MWAPI spawn2(MwWidget handle, void* user, void* call) {
|
||||
MwWidget mb = MwMessageBox(user, "something went wrong!", "title", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
|
||||
void MWAPI spawn3(MwWidget handle, void* user, void* call) {
|
||||
int i;
|
||||
|
||||
(void)handle;
|
||||
(void)call;
|
||||
|
||||
for(i = 0; i <= MwMB_ICONCLOCK; i++) {
|
||||
MwWidget mb = MwMessageBox(user, "messagebox test", "title", i | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget msg, btn, btn2, btn3;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
msg = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 300, 100, MwNtitle, "test", NULL);
|
||||
btn = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8, 300 - 16, (100 - 16) / 2, MwNtext, "press me!", NULL);
|
||||
btn2 = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8 + (100 - 16) / 2, (300 - 16) / 2, (100 - 16) / 2, MwNtext, "press me!", NULL);
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,326 +1,326 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define Columns 5
|
||||
#define Padding 20
|
||||
#define PaddingContent 2
|
||||
|
||||
MwWidget window, menu, table;
|
||||
MwMenu e;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(window, MwNwidth);
|
||||
int h = MwGetInteger(window, MwNheight);
|
||||
|
||||
MwVaApply(table,
|
||||
MwNx, Padding,
|
||||
MwNy, MwGetInteger(menu, MwNheight) + Padding,
|
||||
MwNwidth, w - Padding * 2,
|
||||
MwNheight, h - MwGetInteger(menu, MwNheight) - Padding * 2,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void MWAPI resize_content(MwWidget handle, void* user, void* call) {
|
||||
MwWidget* ws = MwGetChildren(handle);
|
||||
if(ws != NULL) {
|
||||
int pw = MwGetInteger(ws[0], "IpWidth");
|
||||
int ph = MwGetInteger(ws[0], "IpHeight");
|
||||
|
||||
if(pw < 0) {
|
||||
pw += MwGetInteger(handle, MwNwidth);
|
||||
} else if(pw == 0) {
|
||||
pw = MwGetInteger(handle, MwNwidth);
|
||||
}
|
||||
|
||||
if(ph < 0) {
|
||||
ph += MwGetInteger(handle, MwNheight);
|
||||
} else if(ph == 0) {
|
||||
ph = MwGetInteger(handle, MwNheight);
|
||||
}
|
||||
|
||||
MwVaApply(ws[0],
|
||||
MwNx, (MwGetInteger(handle, MwNwidth) - pw) / 2,
|
||||
MwNy, (MwGetInteger(handle, MwNheight) - ph) / 2,
|
||||
MwNwidth, pw,
|
||||
MwNheight, ph,
|
||||
NULL);
|
||||
|
||||
free(ws);
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI resize_frame(MwWidget handle, void* user, void* call) {
|
||||
MwWidget* ws = MwGetChildren(handle);
|
||||
if(ws != NULL) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
if(ws[0] != NULL) {
|
||||
MwVaApply(ws[0],
|
||||
MwNx, MwDefaultBorderWidth(handle) + PaddingContent,
|
||||
MwNy, MwDefaultBorderWidth(handle) + PaddingContent,
|
||||
MwNwidth, w - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
|
||||
MwNheight, h - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
|
||||
NULL);
|
||||
}
|
||||
free(ws);
|
||||
}
|
||||
}
|
||||
|
||||
static MwWidget frame(const char* name, int width, int height, MwClass cl, ...) {
|
||||
MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0,
|
||||
MwNhasBorder, 1,
|
||||
MwNinverted, 1,
|
||||
NULL);
|
||||
MwWidget table = MwVaCreateWidget(MwBoxClass, "table", f, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||
MwNtext, name,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
MwNfixedSize, 20,
|
||||
NULL);
|
||||
va_list va;
|
||||
|
||||
if(cl != NULL) {
|
||||
MwWidget frame = MwCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0);
|
||||
MwWidget w;
|
||||
|
||||
va_start(va, cl);
|
||||
w = MwVaListCreateWidget(cl, "widget", frame, 0, 0, 0, 0, va);
|
||||
va_end(va);
|
||||
|
||||
MwVaApply(w,
|
||||
"IpWidth", width,
|
||||
"IpHeight", height,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(frame, MwNresizeHandler, resize_content, NULL);
|
||||
|
||||
MwVaApply(f,
|
||||
"VhandledWidget", w,
|
||||
MwNcolumnSpan, MwGetInteger(w, MwNcolumnSpan),
|
||||
MwNrowSpan, MwGetInteger(w, MwNrowSpan),
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwAddUserHandler(f, MwNresizeHandler, resize_frame, NULL);
|
||||
|
||||
resize_frame(f, NULL, NULL);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static MwWidget child(MwWidget w) {
|
||||
return MwGetVoid(w, "VhandledWidget");
|
||||
}
|
||||
|
||||
static void MWAPI menu_handler(MwWidget handle, void* user, void* call) {
|
||||
if(call == e) MwDestroyWidget(window);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i, j;
|
||||
MwWidget f, w, b;
|
||||
MwLLPixmap px;
|
||||
int index;
|
||||
MwMenu m, m2;
|
||||
void* v;
|
||||
MwRect rc;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 800, 800,
|
||||
MwNtitle, "Milsko Periodic Table",
|
||||
NULL);
|
||||
|
||||
MwGetScreenSize(window, &rc);
|
||||
if(rc.height < 800) {
|
||||
MwVaApply(window,
|
||||
MwNx, (rc.width - (rc.height - 64)) / 2,
|
||||
MwNy, (rc.height - (rc.height - 64)) / 2,
|
||||
MwNwidth, rc.height - 64,
|
||||
MwNheight, rc.height - 64,
|
||||
NULL);
|
||||
}
|
||||
|
||||
px = MwLoadIcon(window, MwIconError);
|
||||
|
||||
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "File");
|
||||
MwMenuAdd(menu, m, "New");
|
||||
MwMenuAdd(menu, m, "Open");
|
||||
MwMenuAdd(menu, m, "Save");
|
||||
MwMenuAdd(menu, m, "Save As");
|
||||
MwMenuAdd(menu, m, "Print");
|
||||
e = MwMenuAdd(menu, m, "Exit");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "Edit");
|
||||
MwMenuAdd(menu, m, "Undo");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Cut");
|
||||
MwMenuAdd(menu, m, "Copy");
|
||||
MwMenuAdd(menu, m, "Paste");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Clear");
|
||||
MwMenuAdd(menu, m, "Delete");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "View");
|
||||
MwMenuAdd(menu, m, "Stack");
|
||||
MwMenuAdd(menu, m, "Tile");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Day");
|
||||
MwMenuAdd(menu, m, "Week");
|
||||
MwMenuAdd(menu, m, "Month");
|
||||
MwMenuAdd(menu, m, "Year");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "Options");
|
||||
m2 = MwMenuAdd(menu, m, "Font");
|
||||
MwMenuAdd(menu, m2, "Small");
|
||||
MwMenuAdd(menu, m2, "Medium");
|
||||
MwMenuAdd(menu, m2, "Large");
|
||||
m2 = MwMenuAdd(menu, m, "Direction");
|
||||
MwMenuAdd(menu, m2, "Up");
|
||||
MwMenuAdd(menu, m2, "Down");
|
||||
MwMenuAdd(menu, m2, "Left");
|
||||
MwMenuAdd(menu, m2, "Right");
|
||||
MwMenuAdd(menu, m, "Case Sensitive");
|
||||
MwMenuAdd(menu, m, "Word Wrap");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "?Help");
|
||||
MwMenuAdd(menu, m, "On Context");
|
||||
MwMenuAdd(menu, m, "On Window");
|
||||
MwMenuAdd(menu, m, "Tutorial");
|
||||
MwMenuAdd(menu, m, "On Version");
|
||||
|
||||
MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL);
|
||||
|
||||
table = MwVaCreateWidget(MwTableClass, "table", window, 0, 0, 0, 0,
|
||||
MwNwaitLayout, 1,
|
||||
MwNcolumns, 5,
|
||||
NULL);
|
||||
|
||||
f = frame("Button", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Press me",
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn_disabled", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Cannot press me",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||
MwNbold, 1,
|
||||
MwNtext, "The Periodic Table of Milsko Widgets",
|
||||
MwNcolumnSpan, Columns - 2,
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
f = frame(i == 0 ? "CheckBox" : "RadioBox", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||
MwNmargin, PaddingContent,
|
||||
NULL);
|
||||
w = child(f);
|
||||
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
MwNfixedSize, 16,
|
||||
NULL);
|
||||
for(j = 0; j < 6; j++) MwVaCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0, MwNdisabled, (j == 5) ? 1 : 0, NULL);
|
||||
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
for(j = 0; j < 6; j++) {
|
||||
char buf[32];
|
||||
sprintf(buf, "%sBox %d", i == 0 ? "Check" : "Radio", j + 1);
|
||||
MwVaCreateWidget(MwLabelClass, "label", b, 0, 0, 0, 0,
|
||||
MwNtext, buf,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
f = frame("Calendar", -PaddingContent, -PaddingContent, MwCalendarClass,
|
||||
MwNscale, 1,
|
||||
NULL);
|
||||
|
||||
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
|
||||
w = child(f);
|
||||
MwComboBoxAdd(w, -1, "Hello!");
|
||||
|
||||
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
|
||||
|
||||
f = frame("Image", -PaddingContent, -PaddingContent, MwImageClass,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
|
||||
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
|
||||
MwNtext, "Epic text\nNewline can be used too!",
|
||||
NULL);
|
||||
|
||||
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
|
||||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
w = child(f);
|
||||
index = MwListBoxSet(w, -1, 0, "Epic title...");
|
||||
index = MwListBoxSet(w, -1, 0, "Hello");
|
||||
|
||||
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
|
||||
|
||||
f = frame("ProgressBar", -PaddingContent, 24, MwProgressBarClass,
|
||||
MwNvalue, 25,
|
||||
NULL);
|
||||
|
||||
f = frame("ScrollBar", -PaddingContent, 16, MwScrollBarClass,
|
||||
MwNorientation, MwHORIZONTAL,
|
||||
NULL);
|
||||
|
||||
f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL);
|
||||
|
||||
f = frame("SubWindow", -PaddingContent, -PaddingContent, MwViewportClass,
|
||||
MwNcolumnSpan, 2,
|
||||
NULL);
|
||||
w = child(f);
|
||||
MwViewportSetSize(w, 512, 512);
|
||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 32, 32, 256, 128,
|
||||
MwNtitle, "Sub window",
|
||||
NULL);
|
||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 64, 64, 256, 128,
|
||||
MwNtitle, "Sub window 2",
|
||||
NULL);
|
||||
|
||||
f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass,
|
||||
MwNcolumnSpan, 2,
|
||||
NULL);
|
||||
w = child(f);
|
||||
MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00");
|
||||
MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0");
|
||||
MwSetText(MwTabAdd(w, "GHI"), MwNbackground, "#00f");
|
||||
|
||||
f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL);
|
||||
w = child(f);
|
||||
v = MwTreeViewAdd(w, NULL, NULL, "abc");
|
||||
v = MwTreeViewAdd(w, v, NULL, "def");
|
||||
v = MwTreeViewAdd(w, v, NULL, "ghi");
|
||||
|
||||
f = frame("Viewport", -PaddingContent, -PaddingContent, MwViewportClass, NULL);
|
||||
w = child(f);
|
||||
MwViewportSetSize(w, 256, 256);
|
||||
MwVaCreateWidget(MwButtonClass, "btn", MwViewportGetViewport(w), 64, 64, 128, 128,
|
||||
MwNtext, "Thing",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwVaApply(table,
|
||||
MwNwaitLayout, 0,
|
||||
NULL);
|
||||
|
||||
MwLoop(window);
|
||||
|
||||
MwLLDestroyPixmap(px);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define Columns 5
|
||||
#define Padding 20
|
||||
#define PaddingContent 2
|
||||
|
||||
MwWidget window, menu, table;
|
||||
MwMenu e;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(window, MwNwidth);
|
||||
int h = MwGetInteger(window, MwNheight);
|
||||
|
||||
MwVaApply(table,
|
||||
MwNx, Padding,
|
||||
MwNy, MwGetInteger(menu, MwNheight) + Padding,
|
||||
MwNwidth, w - Padding * 2,
|
||||
MwNheight, h - MwGetInteger(menu, MwNheight) - Padding * 2,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void MWAPI resize_content(MwWidget handle, void* user, void* call) {
|
||||
MwWidget* ws = MwGetChildren(handle);
|
||||
if(ws != NULL) {
|
||||
int pw = MwGetInteger(ws[0], "IpWidth");
|
||||
int ph = MwGetInteger(ws[0], "IpHeight");
|
||||
|
||||
if(pw < 0) {
|
||||
pw += MwGetInteger(handle, MwNwidth);
|
||||
} else if(pw == 0) {
|
||||
pw = MwGetInteger(handle, MwNwidth);
|
||||
}
|
||||
|
||||
if(ph < 0) {
|
||||
ph += MwGetInteger(handle, MwNheight);
|
||||
} else if(ph == 0) {
|
||||
ph = MwGetInteger(handle, MwNheight);
|
||||
}
|
||||
|
||||
MwVaApply(ws[0],
|
||||
MwNx, (MwGetInteger(handle, MwNwidth) - pw) / 2,
|
||||
MwNy, (MwGetInteger(handle, MwNheight) - ph) / 2,
|
||||
MwNwidth, pw,
|
||||
MwNheight, ph,
|
||||
NULL);
|
||||
|
||||
free(ws);
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI resize_frame(MwWidget handle, void* user, void* call) {
|
||||
MwWidget* ws = MwGetChildren(handle);
|
||||
if(ws != NULL) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
if(ws[0] != NULL) {
|
||||
MwVaApply(ws[0],
|
||||
MwNx, MwDefaultBorderWidth(handle) + PaddingContent,
|
||||
MwNy, MwDefaultBorderWidth(handle) + PaddingContent,
|
||||
MwNwidth, w - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
|
||||
MwNheight, h - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
|
||||
NULL);
|
||||
}
|
||||
free(ws);
|
||||
}
|
||||
}
|
||||
|
||||
static MwWidget frame(const char* name, int width, int height, MwClass cl, ...) {
|
||||
MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0,
|
||||
MwNhasBorder, 1,
|
||||
MwNinverted, 1,
|
||||
NULL);
|
||||
MwWidget table = MwVaCreateWidget(MwBoxClass, "table", f, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||
MwNtext, name,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
MwNfixedSize, 20,
|
||||
NULL);
|
||||
va_list va;
|
||||
|
||||
if(cl != NULL) {
|
||||
MwWidget frame = MwCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0);
|
||||
MwWidget w;
|
||||
|
||||
va_start(va, cl);
|
||||
w = MwVaListCreateWidget(cl, "widget", frame, 0, 0, 0, 0, va);
|
||||
va_end(va);
|
||||
|
||||
MwVaApply(w,
|
||||
"IpWidth", width,
|
||||
"IpHeight", height,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(frame, MwNresizeHandler, resize_content, NULL);
|
||||
|
||||
MwVaApply(f,
|
||||
"VhandledWidget", w,
|
||||
MwNcolumnSpan, MwGetInteger(w, MwNcolumnSpan),
|
||||
MwNrowSpan, MwGetInteger(w, MwNrowSpan),
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwAddUserHandler(f, MwNresizeHandler, resize_frame, NULL);
|
||||
|
||||
resize_frame(f, NULL, NULL);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static MwWidget child(MwWidget w) {
|
||||
return MwGetVoid(w, "VhandledWidget");
|
||||
}
|
||||
|
||||
static void MWAPI menu_handler(MwWidget handle, void* user, void* call) {
|
||||
if(call == e) MwDestroyWidget(window);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i, j;
|
||||
MwWidget f, w, b;
|
||||
MwLLPixmap px;
|
||||
int index;
|
||||
MwMenu m, m2;
|
||||
void* v;
|
||||
MwRect rc;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 800, 800,
|
||||
MwNtitle, "Milsko Periodic Table",
|
||||
NULL);
|
||||
|
||||
MwGetScreenSize(window, &rc);
|
||||
if(rc.height < 800) {
|
||||
MwVaApply(window,
|
||||
MwNx, (rc.width - (rc.height - 64)) / 2,
|
||||
MwNy, (rc.height - (rc.height - 64)) / 2,
|
||||
MwNwidth, rc.height - 64,
|
||||
MwNheight, rc.height - 64,
|
||||
NULL);
|
||||
}
|
||||
|
||||
px = MwLoadIcon(window, MwIconError);
|
||||
|
||||
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "File");
|
||||
MwMenuAdd(menu, m, "New");
|
||||
MwMenuAdd(menu, m, "Open");
|
||||
MwMenuAdd(menu, m, "Save");
|
||||
MwMenuAdd(menu, m, "Save As");
|
||||
MwMenuAdd(menu, m, "Print");
|
||||
e = MwMenuAdd(menu, m, "Exit");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "Edit");
|
||||
MwMenuAdd(menu, m, "Undo");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Cut");
|
||||
MwMenuAdd(menu, m, "Copy");
|
||||
MwMenuAdd(menu, m, "Paste");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Clear");
|
||||
MwMenuAdd(menu, m, "Delete");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "View");
|
||||
MwMenuAdd(menu, m, "Stack");
|
||||
MwMenuAdd(menu, m, "Tile");
|
||||
MwMenuAdd(menu, m, "----");
|
||||
MwMenuAdd(menu, m, "Day");
|
||||
MwMenuAdd(menu, m, "Week");
|
||||
MwMenuAdd(menu, m, "Month");
|
||||
MwMenuAdd(menu, m, "Year");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "Options");
|
||||
m2 = MwMenuAdd(menu, m, "Font");
|
||||
MwMenuAdd(menu, m2, "Small");
|
||||
MwMenuAdd(menu, m2, "Medium");
|
||||
MwMenuAdd(menu, m2, "Large");
|
||||
m2 = MwMenuAdd(menu, m, "Direction");
|
||||
MwMenuAdd(menu, m2, "Up");
|
||||
MwMenuAdd(menu, m2, "Down");
|
||||
MwMenuAdd(menu, m2, "Left");
|
||||
MwMenuAdd(menu, m2, "Right");
|
||||
MwMenuAdd(menu, m, "Case Sensitive");
|
||||
MwMenuAdd(menu, m, "Word Wrap");
|
||||
|
||||
m = MwMenuAdd(menu, NULL, "?Help");
|
||||
MwMenuAdd(menu, m, "On Context");
|
||||
MwMenuAdd(menu, m, "On Window");
|
||||
MwMenuAdd(menu, m, "Tutorial");
|
||||
MwMenuAdd(menu, m, "On Version");
|
||||
|
||||
MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL);
|
||||
|
||||
table = MwVaCreateWidget(MwTableClass, "table", window, 0, 0, 0, 0,
|
||||
MwNwaitLayout, 1,
|
||||
MwNcolumns, 5,
|
||||
NULL);
|
||||
|
||||
f = frame("Button", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Press me",
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn_disabled", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Cannot press me",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||
MwNbold, 1,
|
||||
MwNtext, "The Periodic Table of Milsko Widgets",
|
||||
MwNcolumnSpan, Columns - 2,
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
f = frame(i == 0 ? "CheckBox" : "RadioBox", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||
MwNmargin, PaddingContent,
|
||||
NULL);
|
||||
w = child(f);
|
||||
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
MwNfixedSize, 16,
|
||||
NULL);
|
||||
for(j = 0; j < 6; j++) MwVaCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0, MwNdisabled, (j == 5) ? 1 : 0, NULL);
|
||||
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
for(j = 0; j < 6; j++) {
|
||||
char buf[32];
|
||||
sprintf(buf, "%sBox %d", i == 0 ? "Check" : "Radio", j + 1);
|
||||
MwVaCreateWidget(MwLabelClass, "label", b, 0, 0, 0, 0,
|
||||
MwNtext, buf,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
f = frame("Calendar", -PaddingContent, -PaddingContent, MwCalendarClass,
|
||||
MwNscale, 1,
|
||||
NULL);
|
||||
|
||||
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
|
||||
w = child(f);
|
||||
MwComboBoxAdd(w, -1, "Hello!");
|
||||
|
||||
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
|
||||
|
||||
f = frame("Image", -PaddingContent, -PaddingContent, MwImageClass,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
|
||||
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
|
||||
MwNtext, "Epic text\nNewline can be used too!",
|
||||
NULL);
|
||||
|
||||
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
|
||||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
w = child(f);
|
||||
index = MwListBoxSet(w, -1, 0, "Epic title...");
|
||||
index = MwListBoxSet(w, -1, 0, "Hello");
|
||||
|
||||
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
|
||||
|
||||
f = frame("ProgressBar", -PaddingContent, 24, MwProgressBarClass,
|
||||
MwNvalue, 25,
|
||||
NULL);
|
||||
|
||||
f = frame("ScrollBar", -PaddingContent, 16, MwScrollBarClass,
|
||||
MwNorientation, MwHORIZONTAL,
|
||||
NULL);
|
||||
|
||||
f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL);
|
||||
|
||||
f = frame("SubWindow", -PaddingContent, -PaddingContent, MwViewportClass,
|
||||
MwNcolumnSpan, 2,
|
||||
NULL);
|
||||
w = child(f);
|
||||
MwViewportSetSize(w, 512, 512);
|
||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 32, 32, 256, 128,
|
||||
MwNtitle, "Sub window",
|
||||
NULL);
|
||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 64, 64, 256, 128,
|
||||
MwNtitle, "Sub window 2",
|
||||
NULL);
|
||||
|
||||
f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass,
|
||||
MwNcolumnSpan, 2,
|
||||
NULL);
|
||||
w = child(f);
|
||||
MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00");
|
||||
MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0");
|
||||
MwSetText(MwTabAdd(w, "GHI"), MwNbackground, "#00f");
|
||||
|
||||
f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL);
|
||||
w = child(f);
|
||||
v = MwTreeViewAdd(w, NULL, NULL, "abc");
|
||||
v = MwTreeViewAdd(w, v, NULL, "def");
|
||||
v = MwTreeViewAdd(w, v, NULL, "ghi");
|
||||
|
||||
f = frame("Viewport", -PaddingContent, -PaddingContent, MwViewportClass, NULL);
|
||||
w = child(f);
|
||||
MwViewportSetSize(w, 256, 256);
|
||||
MwVaCreateWidget(MwButtonClass, "btn", MwViewportGetViewport(w), 64, 64, 128, 128,
|
||||
MwNtext, "Thing",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwVaApply(table,
|
||||
MwNwaitLayout, 0,
|
||||
NULL);
|
||||
|
||||
MwLoop(window);
|
||||
|
||||
MwLLDestroyPixmap(px);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget w, p;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 640 + 5, 5 + 32 + 5,
|
||||
MwNtitle, "progress bar",
|
||||
NULL);
|
||||
p = MwVaCreateWidget(MwProgressBarClass, "progress", w, 5, 5, 640, 32,
|
||||
MwNvalue, 25,
|
||||
NULL);
|
||||
|
||||
(void)p;
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget w, p;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 640 + 5, 5 + 32 + 5,
|
||||
MwNtitle, "progress bar",
|
||||
NULL);
|
||||
p = MwVaCreateWidget(MwProgressBarClass, "progress", w, 5, 5, 640, 32,
|
||||
MwNvalue, 25,
|
||||
NULL);
|
||||
|
||||
(void)p;
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 8 + 16 + 8 + 16 * 10 + 8, 8 + 16 + 8 + 16 + 8,
|
||||
MwNtitle, "radiobox",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwRadioBoxClass, "cb1", window, 8, 8, 16, 16,
|
||||
NULL);
|
||||
MwVaCreateWidget(MwRadioBoxClass, "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);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 8 + 16 + 8 + 16 * 10 + 8, 8 + 16 + 8 + 16 + 8,
|
||||
MwNtitle, "radiobox",
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwRadioBoxClass, "cb1", window, 8, 8, 16, 16,
|
||||
NULL);
|
||||
MwVaCreateWidget(MwRadioBoxClass, "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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,95 +1,95 @@
|
|||
/* 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 MWAPI 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 MWAPI 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;
|
||||
int i;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, (ww = 500), (wh = 500),
|
||||
MwNtitle, "rotate",
|
||||
NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
/* 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 MWAPI 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 MWAPI 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;
|
||||
int i;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, (ww = 500), (wh = 500),
|
||||
MwNtitle, "rotate",
|
||||
NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
int i;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, "main",
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < 500 / 16; i++) {
|
||||
MwVaCreateWidget(MwScrollBarClass, "scroll", window, 16 * i, 0, 16, 500,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
int i;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, "main",
|
||||
NULL);
|
||||
|
||||
for(i = 0; i < 500 / 16; i++) {
|
||||
MwVaCreateWidget(MwScrollBarClass, "scroll", window, 16 * i, 0, 16, 500,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget wnd, label;
|
||||
int W = 480, H = 40;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
wnd = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, W, H,
|
||||
MwNtitle, "seven segment",
|
||||
NULL);
|
||||
|
||||
label = MwVaCreateWidget(MwLabelClass, "label", wnd, 0, 0, W, H,
|
||||
MwNtext, " 123456:78.90 abcdef",
|
||||
MwNsevenSegment, 1,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
MwNlength, 8,
|
||||
NULL);
|
||||
|
||||
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
|
||||
|
||||
MwLoop(wnd);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
int main() {
|
||||
MwWidget wnd, label;
|
||||
int W = 480, H = 40;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
wnd = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, W, H,
|
||||
MwNtitle, "seven segment",
|
||||
NULL);
|
||||
|
||||
label = MwVaCreateWidget(MwLabelClass, "label", wnd, 0, 0, W, H,
|
||||
MwNtext, " 123456:78.90 abcdef",
|
||||
MwNsevenSegment, 1,
|
||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||
MwNlength, 8,
|
||||
NULL);
|
||||
|
||||
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
|
||||
|
||||
MwLoop(wnd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#define Shift 16
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
MwWidget f = MwSubWindowGetFrame(handle);
|
||||
MwVaApply(user,
|
||||
MwNwidth, MwGetInteger(f, MwNwidth),
|
||||
MwNheight, MwGetInteger(f, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
MwLLPixmap px[6];
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 800, 600,
|
||||
MwNtitle, "subwindow",
|
||||
NULL);
|
||||
|
||||
px[0] = MwLoadIcon(w, MwIconClock);
|
||||
px[1] = MwLoadIcon(w, MwIconError);
|
||||
px[2] = MwLoadIcon(w, MwIconInfo);
|
||||
px[3] = MwLoadIcon(w, MwIconNews);
|
||||
px[4] = MwLoadIcon(w, MwIconNote);
|
||||
px[5] = MwLoadIcon(w, MwIconWarning);
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
char buf[32];
|
||||
MwWidget sw, f, img;
|
||||
|
||||
sprintf(buf, "Sub window %d", i);
|
||||
|
||||
sw = MwVaCreateWidget(MwSubWindowClass, "swnd", w, i * Shift, i * Shift, 128, 128,
|
||||
MwNtitle, buf,
|
||||
MwNiconPixmap, px[rand() % 6],
|
||||
NULL);
|
||||
|
||||
f = MwSubWindowGetFrame(sw);
|
||||
|
||||
img = MwVaCreateWidget(MwImageClass, "img", f, 0, 0, MwGetInteger(f, MwNwidth), MwGetInteger(f, MwNheight),
|
||||
MwNpixmap, px[rand() % 6],
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(sw, MwNresizeHandler, resize, img);
|
||||
}
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#define Shift 16
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
MwWidget f = MwSubWindowGetFrame(handle);
|
||||
MwVaApply(user,
|
||||
MwNwidth, MwGetInteger(f, MwNwidth),
|
||||
MwNheight, MwGetInteger(f, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
MwLLPixmap px[6];
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 800, 600,
|
||||
MwNtitle, "subwindow",
|
||||
NULL);
|
||||
|
||||
px[0] = MwLoadIcon(w, MwIconClock);
|
||||
px[1] = MwLoadIcon(w, MwIconError);
|
||||
px[2] = MwLoadIcon(w, MwIconInfo);
|
||||
px[3] = MwLoadIcon(w, MwIconNews);
|
||||
px[4] = MwLoadIcon(w, MwIconNote);
|
||||
px[5] = MwLoadIcon(w, MwIconWarning);
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
char buf[32];
|
||||
MwWidget sw, f, img;
|
||||
|
||||
sprintf(buf, "Sub window %d", i);
|
||||
|
||||
sw = MwVaCreateWidget(MwSubWindowClass, "swnd", w, i * Shift, i * Shift, 128, 128,
|
||||
MwNtitle, buf,
|
||||
MwNiconPixmap, px[rand() % 6],
|
||||
NULL);
|
||||
|
||||
f = MwSubWindowGetFrame(sw);
|
||||
|
||||
img = MwVaCreateWidget(MwImageClass, "img", f, 0, 0, MwGetInteger(f, MwNwidth), MwGetInteger(f, MwNheight),
|
||||
MwNpixmap, px[rand() % 6],
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(sw, MwNresizeHandler, resize, img);
|
||||
}
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget tab;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
MwVaApply(tab,
|
||||
MwNwidth, MwGetInteger(handle, MwNwidth),
|
||||
MwNheight, MwGetInteger(handle, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
MwLLPixmap px[6];
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 800, 600,
|
||||
MwNtitle, "subwindow",
|
||||
NULL);
|
||||
|
||||
tab = MwCreateWidget(MwTabClass, "tab", w, 0, 0, 800, 600);
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
char buf[32];
|
||||
MwWidget sw, f, img;
|
||||
|
||||
sprintf(buf, "Tab %d", i);
|
||||
|
||||
MwTabAdd(tab, buf);
|
||||
}
|
||||
|
||||
MwVaApply(MwTabGetFrame(tab, "Tab 1"),
|
||||
MwNiconPixmap, MwLoadIcon(tab, MwIconWarning),
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(w, NULL, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget tab;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
MwVaApply(tab,
|
||||
MwNwidth, MwGetInteger(handle, MwNwidth),
|
||||
MwNheight, MwGetInteger(handle, MwNheight),
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
int i;
|
||||
MwLLPixmap px[6];
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 800, 600,
|
||||
MwNtitle, "subwindow",
|
||||
NULL);
|
||||
|
||||
tab = MwCreateWidget(MwTabClass, "tab", w, 0, 0, 800, 600);
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
char buf[32];
|
||||
MwWidget sw, f, img;
|
||||
|
||||
sprintf(buf, "Tab %d", i);
|
||||
|
||||
MwTabAdd(tab, buf);
|
||||
}
|
||||
|
||||
MwVaApply(MwTabGetFrame(tab, "Tab 1"),
|
||||
MwNiconPixmap, MwLoadIcon(tab, MwIconWarning),
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(w, NULL, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +1,50 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget wmain;
|
||||
|
||||
void MWAPI destroy(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user, void* call) {
|
||||
char msg[256];
|
||||
MwWidget msgbox;
|
||||
|
||||
(void)user;
|
||||
|
||||
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwTreeViewGet(handle, call));
|
||||
|
||||
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget tv;
|
||||
MwLLPixmap px;
|
||||
int i;
|
||||
void * p = NULL, *r;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
wmain = MwCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 640 + 5, 5 + 480 + 5);
|
||||
tv = MwCreateWidget(MwTreeViewClass, "tree", wmain, 5, 5, 640, 480);
|
||||
|
||||
px = MwLoadIcon(tv, MwIconInfo);
|
||||
|
||||
MwSetInteger(tv, MwNleftPadding, 16);
|
||||
|
||||
MwAddUserHandler(tv, MwNactivateHandler, activate, NULL);
|
||||
|
||||
for(i = 0; i < 10; i++) {
|
||||
void* old = p;
|
||||
|
||||
MwTreeViewAdd(tv, old, px, "World");
|
||||
p = MwTreeViewAdd(tv, old, px, "Hello");
|
||||
if(i == 5) r = p;
|
||||
MwTreeViewAdd(tv, old, px, "Goodbye");
|
||||
}
|
||||
|
||||
MwLoop(wmain);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget wmain;
|
||||
|
||||
void MWAPI destroy(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user, void* call) {
|
||||
char msg[256];
|
||||
MwWidget msgbox;
|
||||
|
||||
(void)user;
|
||||
|
||||
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwTreeViewGet(handle, call));
|
||||
|
||||
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
|
||||
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget tv;
|
||||
MwLLPixmap px;
|
||||
int i;
|
||||
void * p = NULL, *r;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
wmain = MwCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 5 + 640 + 5, 5 + 480 + 5);
|
||||
tv = MwCreateWidget(MwTreeViewClass, "tree", wmain, 5, 5, 640, 480);
|
||||
|
||||
px = MwLoadIcon(tv, MwIconInfo);
|
||||
|
||||
MwSetInteger(tv, MwNleftPadding, 16);
|
||||
|
||||
MwAddUserHandler(tv, MwNactivateHandler, activate, NULL);
|
||||
|
||||
for(i = 0; i < 10; i++) {
|
||||
void* old = p;
|
||||
|
||||
MwTreeViewAdd(tv, old, px, "World");
|
||||
p = MwTreeViewAdd(tv, old, px, "Hello");
|
||||
if(i == 5) r = p;
|
||||
MwTreeViewAdd(tv, old, px, "Goodbye");
|
||||
}
|
||||
|
||||
MwLoop(wmain);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget vp;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwVaApply(vp,
|
||||
MwNwidth, w - 10 - 100,
|
||||
MwNheight, h - 10 - 100,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
MwLLPixmap px;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480, MwNtitle, "test", NULL);
|
||||
|
||||
vp = MwCreateWidget(MwViewportClass, "vp", w, 5 + 50, 5 + 50, 640 - 10 - 100, 480 - 10 - 100);
|
||||
|
||||
px = MwLoadImage(vp, "examples/picture.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(vp, "../examples/picture.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(vp, "picture.png");
|
||||
|
||||
MwVaCreateWidget(MwImageClass, "image", MwViewportGetViewport(vp), 0, 0, 1024, 1024,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
MwViewportSetSize(vp, 1024, 1024);
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget vp;
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwVaApply(vp,
|
||||
MwNwidth, w - 10 - 100,
|
||||
MwNheight, h - 10 - 100,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget w;
|
||||
MwLLPixmap px;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480, MwNtitle, "test", NULL);
|
||||
|
||||
vp = MwCreateWidget(MwViewportClass, "vp", w, 5 + 50, 5 + 50, 640 - 10 - 100, 480 - 10 - 100);
|
||||
|
||||
px = MwLoadImage(vp, "examples/picture.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(vp, "../examples/picture.png");
|
||||
|
||||
if(px == NULL) px = MwLoadImage(vp, "picture.png");
|
||||
|
||||
MwVaCreateWidget(MwImageClass, "image", MwViewportGetViewport(vp), 0, 0, 1024, 1024,
|
||||
MwNpixmap, px,
|
||||
NULL);
|
||||
MwViewportSetSize(vp, 1024, 1024);
|
||||
|
||||
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
|
||||
|
||||
MwLoop(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
file(
|
||||
GLOB
|
||||
EXAMPLES_GL_SOURCES
|
||||
*.c
|
||||
)
|
||||
find_package(OpenGL)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_GL_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
if(${TARGET} STREQUAL "glutlayer")
|
||||
continue()
|
||||
endif()
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
OpenGL::GL OpenGL::GLU
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
file(
|
||||
GLOB
|
||||
EXAMPLES_GL_SOURCES
|
||||
*.c
|
||||
)
|
||||
find_package(OpenGL)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_GL_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
if(${TARGET} STREQUAL "glutlayer")
|
||||
continue()
|
||||
endif()
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
OpenGL::GL OpenGL::GLU
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
|
|
|||
|
|
@ -1,158 +1,158 @@
|
|||
#define TITLE "boing"
|
||||
#include "glutlayer.c"
|
||||
|
||||
/*
|
||||
* Bouncing ball demo.
|
||||
*
|
||||
* This program is in the public domain
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define COS(X) cos((X) * 3.14159 / 180.0)
|
||||
#define SIN(X) sin((X) * 3.14159 / 180.0)
|
||||
|
||||
#define RED 1.0, 0.0, 0.0
|
||||
#define WHITE 1.0, 1.0, 1.0
|
||||
#define CYAN 0.0, 1.0, 1.0
|
||||
|
||||
GLuint Ball;
|
||||
GLenum Mode;
|
||||
GLfloat Zrot = 0.0, Zstep = 6.0;
|
||||
GLfloat Xpos = 0.0, Ypos = 1.0;
|
||||
GLfloat Xvel = 0.2, Yvel = 0.0;
|
||||
GLfloat Xmin = -4.0, Xmax = 4.0;
|
||||
GLfloat Ymin = -3.8, Ymax = 4.0;
|
||||
GLfloat G = -0.1;
|
||||
|
||||
static GLuint make_ball(void) {
|
||||
GLuint list;
|
||||
GLfloat a, b;
|
||||
GLfloat da = 18.0, db = 18.0;
|
||||
GLfloat radius = 1.0;
|
||||
GLuint color;
|
||||
GLfloat x, y, z;
|
||||
|
||||
list = glGenLists(1);
|
||||
|
||||
glNewList(list, GL_COMPILE);
|
||||
|
||||
color = 0;
|
||||
for(a = -90.0; a + da <= 90.0; a += da) {
|
||||
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(b = 0.0; b <= 360.0; b += db) {
|
||||
|
||||
if(color) {
|
||||
glColor3f(RED);
|
||||
} else {
|
||||
glColor3f(WHITE);
|
||||
}
|
||||
|
||||
x = COS(b) * COS(a);
|
||||
y = SIN(b) * COS(a);
|
||||
z = SIN(a);
|
||||
glVertex3f(x, y, z);
|
||||
|
||||
x = radius * COS(b) * COS(a + da);
|
||||
y = radius * SIN(b) * COS(a + da);
|
||||
z = radius * SIN(a + da);
|
||||
glVertex3f(x, y, z);
|
||||
|
||||
color = 1 - color;
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glEndList();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static void reshape(int width, int height) {
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-6.0, 6.0, -6.0, 6.0, -6.0, 6.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
static void draw(void) {
|
||||
GLint i;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(CYAN);
|
||||
glBegin(GL_LINES);
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(i, -5);
|
||||
glVertex2i(i, 5);
|
||||
}
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(-5, i);
|
||||
glVertex2i(5, i);
|
||||
}
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(i, -5);
|
||||
glVertex2f(i * 1.15, -5.9);
|
||||
}
|
||||
glVertex2f(-5.3, -5.35);
|
||||
glVertex2f(5.3, -5.35);
|
||||
glVertex2f(-5.75, -5.9);
|
||||
glVertex2f(5.75, -5.9);
|
||||
glEnd();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(Xpos, Ypos, 0.0);
|
||||
glScalef(2.0, 2.0, 2.0);
|
||||
glRotatef(8.0, 0.0, 0.0, 1.0);
|
||||
glRotatef(90.0, 1.0, 0.0, 0.0);
|
||||
glRotatef(Zrot, 0.0, 0.0, 1.0);
|
||||
|
||||
glCallList(Ball);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
static float vel0 = -100.0;
|
||||
|
||||
Zrot += Zstep;
|
||||
|
||||
Xpos += Xvel;
|
||||
if(Xpos >= Xmax) {
|
||||
Xpos = Xmax;
|
||||
Xvel = -Xvel;
|
||||
Zstep = -Zstep;
|
||||
}
|
||||
if(Xpos <= Xmin) {
|
||||
Xpos = Xmin;
|
||||
Xvel = -Xvel;
|
||||
Zstep = -Zstep;
|
||||
}
|
||||
Ypos += Yvel;
|
||||
Yvel += G;
|
||||
if(Ypos < Ymin) {
|
||||
Ypos = Ymin;
|
||||
if(vel0 == -100.0)
|
||||
vel0 = fabs(Yvel);
|
||||
Yvel = vel0;
|
||||
}
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
Ball = make_ball();
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDisable(GL_DITHER);
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
}
|
||||
#define TITLE "boing"
|
||||
#include "glutlayer.c"
|
||||
|
||||
/*
|
||||
* Bouncing ball demo.
|
||||
*
|
||||
* This program is in the public domain
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define COS(X) cos((X) * 3.14159 / 180.0)
|
||||
#define SIN(X) sin((X) * 3.14159 / 180.0)
|
||||
|
||||
#define RED 1.0, 0.0, 0.0
|
||||
#define WHITE 1.0, 1.0, 1.0
|
||||
#define CYAN 0.0, 1.0, 1.0
|
||||
|
||||
GLuint Ball;
|
||||
GLenum Mode;
|
||||
GLfloat Zrot = 0.0, Zstep = 6.0;
|
||||
GLfloat Xpos = 0.0, Ypos = 1.0;
|
||||
GLfloat Xvel = 0.2, Yvel = 0.0;
|
||||
GLfloat Xmin = -4.0, Xmax = 4.0;
|
||||
GLfloat Ymin = -3.8, Ymax = 4.0;
|
||||
GLfloat G = -0.1;
|
||||
|
||||
static GLuint make_ball(void) {
|
||||
GLuint list;
|
||||
GLfloat a, b;
|
||||
GLfloat da = 18.0, db = 18.0;
|
||||
GLfloat radius = 1.0;
|
||||
GLuint color;
|
||||
GLfloat x, y, z;
|
||||
|
||||
list = glGenLists(1);
|
||||
|
||||
glNewList(list, GL_COMPILE);
|
||||
|
||||
color = 0;
|
||||
for(a = -90.0; a + da <= 90.0; a += da) {
|
||||
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(b = 0.0; b <= 360.0; b += db) {
|
||||
|
||||
if(color) {
|
||||
glColor3f(RED);
|
||||
} else {
|
||||
glColor3f(WHITE);
|
||||
}
|
||||
|
||||
x = COS(b) * COS(a);
|
||||
y = SIN(b) * COS(a);
|
||||
z = SIN(a);
|
||||
glVertex3f(x, y, z);
|
||||
|
||||
x = radius * COS(b) * COS(a + da);
|
||||
y = radius * SIN(b) * COS(a + da);
|
||||
z = radius * SIN(a + da);
|
||||
glVertex3f(x, y, z);
|
||||
|
||||
color = 1 - color;
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glEndList();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static void reshape(int width, int height) {
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-6.0, 6.0, -6.0, 6.0, -6.0, 6.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
static void draw(void) {
|
||||
GLint i;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(CYAN);
|
||||
glBegin(GL_LINES);
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(i, -5);
|
||||
glVertex2i(i, 5);
|
||||
}
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(-5, i);
|
||||
glVertex2i(5, i);
|
||||
}
|
||||
for(i = -5; i <= 5; i++) {
|
||||
glVertex2i(i, -5);
|
||||
glVertex2f(i * 1.15, -5.9);
|
||||
}
|
||||
glVertex2f(-5.3, -5.35);
|
||||
glVertex2f(5.3, -5.35);
|
||||
glVertex2f(-5.75, -5.9);
|
||||
glVertex2f(5.75, -5.9);
|
||||
glEnd();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(Xpos, Ypos, 0.0);
|
||||
glScalef(2.0, 2.0, 2.0);
|
||||
glRotatef(8.0, 0.0, 0.0, 1.0);
|
||||
glRotatef(90.0, 1.0, 0.0, 0.0);
|
||||
glRotatef(Zrot, 0.0, 0.0, 1.0);
|
||||
|
||||
glCallList(Ball);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
static float vel0 = -100.0;
|
||||
|
||||
Zrot += Zstep;
|
||||
|
||||
Xpos += Xvel;
|
||||
if(Xpos >= Xmax) {
|
||||
Xpos = Xmax;
|
||||
Xvel = -Xvel;
|
||||
Zstep = -Zstep;
|
||||
}
|
||||
if(Xpos <= Xmin) {
|
||||
Xpos = Xmin;
|
||||
Xvel = -Xvel;
|
||||
Zstep = -Zstep;
|
||||
}
|
||||
Ypos += Yvel;
|
||||
Yvel += G;
|
||||
if(Ypos < Ymin) {
|
||||
Ypos = Ymin;
|
||||
if(vel0 == -100.0)
|
||||
vel0 = fabs(Yvel);
|
||||
Yvel = vel0;
|
||||
}
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
Ball = make_ball();
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDisable(GL_DITHER);
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,169 +1,169 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
MwWidget window, opengl, ldate, ltime;
|
||||
time_t last = 0;
|
||||
struct tm* tm;
|
||||
int br, bg, bb;
|
||||
int fr, fg, fb;
|
||||
|
||||
double deg2rad(double deg) {
|
||||
return (360.0 - deg) / 180.0 * M_PI;
|
||||
}
|
||||
|
||||
void MWAPI tick(MwWidget handle, void* user, void* call) {
|
||||
time_t t = time(NULL);
|
||||
int i;
|
||||
double rad;
|
||||
int render = 0;
|
||||
int w = MwGetInteger(opengl, MwNwidth);
|
||||
int h = MwGetInteger(opengl, MwNheight);
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
if(last != t) {
|
||||
char* wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
char* mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
char buf[512];
|
||||
tm = localtime(&t);
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 512, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]);
|
||||
MwSetText(ldate, MwNtext, buf);
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 512, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM");
|
||||
MwSetText(ltime, MwNtext, buf);
|
||||
|
||||
render = 1;
|
||||
|
||||
last = t;
|
||||
}
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glClearColor(br / 255.0, bg / 255.0, bb / 255.0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, 0, 100);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glLineWidth(2);
|
||||
for(i = 0; i < 12; i++) {
|
||||
rad = deg2rad(30.0 * i);
|
||||
glPointSize((i % 3) ? 2 : 5);
|
||||
glBegin(GL_POINTS);
|
||||
glColor3f(fr / 255.0, fg / 255.0, fb / 255.0);
|
||||
glVertex2f(cos(rad) * 0.85, sin(rad) * 0.85);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
rad = deg2rad((tm->tm_hour % 12) * 30 + (tm->tm_min / 2) - 90);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(cos(rad) * 0.3, sin(rad) * 0.3);
|
||||
glEnd();
|
||||
|
||||
rad = deg2rad(tm->tm_min * 6 - 90);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(cos(rad) * 0.5, sin(rad) * 0.5);
|
||||
glEnd();
|
||||
|
||||
if(render && w > 0 && h > 0) {
|
||||
unsigned char* buffer = malloc(w * h * 4);
|
||||
MwLLPixmap px;
|
||||
int j;
|
||||
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
for(i = 0; i < h / 2; i++) {
|
||||
for(j = 0; j < w * 4; j++) {
|
||||
unsigned char b = buffer[i * w * 4 + j];
|
||||
|
||||
buffer[i * w * 4 + j] = buffer[(h - i - 1) * w * 4 + j];
|
||||
buffer[(h - i - 1) * w * 4 + j] = b;
|
||||
}
|
||||
}
|
||||
|
||||
px = MwLoadRaw(window, buffer, w, h);
|
||||
MwVaApply(window,
|
||||
MwNiconPixmap, px,
|
||||
NULL);
|
||||
MwLLDestroyPixmap(px);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, w / 5 * 2,
|
||||
MwNheight, h,
|
||||
NULL);
|
||||
|
||||
MwVaApply(ldate,
|
||||
MwNx, w / 5 * 2,
|
||||
MwNwidth, w - w / 5 * 2,
|
||||
MwNheight, h / 2,
|
||||
NULL);
|
||||
|
||||
MwVaApply(ltime,
|
||||
MwNx, w / 5 * 2,
|
||||
MwNy, h / 2,
|
||||
MwNwidth, w - w / 5 * 2,
|
||||
MwNheight, h / 2,
|
||||
NULL);
|
||||
|
||||
glViewport(0, 0, w / 5 * 2, h);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLLColor bgcolor, fgcolor;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 250, 100,
|
||||
MwNtitle, "clock",
|
||||
NULL);
|
||||
|
||||
bgcolor = MwParseColor(window, MwGetText(window, MwNbackground));
|
||||
MwColorGet(bgcolor, &br, &bg, &bb);
|
||||
|
||||
fgcolor = MwParseColor(window, MwGetText(window, MwNforeground));
|
||||
MwColorGet(fgcolor, &fr, &fg, &fb);
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "clock", window, 0, 0, 100, 100);
|
||||
|
||||
ldate = MwVaCreateWidget(MwLabelClass, "date", window, 100, 0, 150, 50,
|
||||
MwNbold, 1,
|
||||
NULL);
|
||||
ltime = MwVaCreateWidget(MwLabelClass, "time", window, 100, 50, 150, 50,
|
||||
MwNbold, 1,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
tick(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
|
||||
MwLLFreeColor(fgcolor);
|
||||
MwLLFreeColor(bgcolor);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
MwWidget window, opengl, ldate, ltime;
|
||||
time_t last = 0;
|
||||
struct tm* tm;
|
||||
int br, bg, bb;
|
||||
int fr, fg, fb;
|
||||
|
||||
double deg2rad(double deg) {
|
||||
return (360.0 - deg) / 180.0 * M_PI;
|
||||
}
|
||||
|
||||
void MWAPI tick(MwWidget handle, void* user, void* call) {
|
||||
time_t t = time(NULL);
|
||||
int i;
|
||||
double rad;
|
||||
int render = 0;
|
||||
int w = MwGetInteger(opengl, MwNwidth);
|
||||
int h = MwGetInteger(opengl, MwNheight);
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
if(last != t) {
|
||||
char* wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
char* mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
char buf[512];
|
||||
tm = localtime(&t);
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 512, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]);
|
||||
MwSetText(ldate, MwNtext, buf);
|
||||
|
||||
MwStringPrintIntoBuffer(buf, 512, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM");
|
||||
MwSetText(ltime, MwNtext, buf);
|
||||
|
||||
render = 1;
|
||||
|
||||
last = t;
|
||||
}
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glClearColor(br / 255.0, bg / 255.0, bb / 255.0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, 0, 100);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glLineWidth(2);
|
||||
for(i = 0; i < 12; i++) {
|
||||
rad = deg2rad(30.0 * i);
|
||||
glPointSize((i % 3) ? 2 : 5);
|
||||
glBegin(GL_POINTS);
|
||||
glColor3f(fr / 255.0, fg / 255.0, fb / 255.0);
|
||||
glVertex2f(cos(rad) * 0.85, sin(rad) * 0.85);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
rad = deg2rad((tm->tm_hour % 12) * 30 + (tm->tm_min / 2) - 90);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(cos(rad) * 0.3, sin(rad) * 0.3);
|
||||
glEnd();
|
||||
|
||||
rad = deg2rad(tm->tm_min * 6 - 90);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(cos(rad) * 0.5, sin(rad) * 0.5);
|
||||
glEnd();
|
||||
|
||||
if(render && w > 0 && h > 0) {
|
||||
unsigned char* buffer = malloc(w * h * 4);
|
||||
MwLLPixmap px;
|
||||
int j;
|
||||
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
for(i = 0; i < h / 2; i++) {
|
||||
for(j = 0; j < w * 4; j++) {
|
||||
unsigned char b = buffer[i * w * 4 + j];
|
||||
|
||||
buffer[i * w * 4 + j] = buffer[(h - i - 1) * w * 4 + j];
|
||||
buffer[(h - i - 1) * w * 4 + j] = b;
|
||||
}
|
||||
}
|
||||
|
||||
px = MwLoadRaw(window, buffer, w, h);
|
||||
MwVaApply(window,
|
||||
MwNiconPixmap, px,
|
||||
NULL);
|
||||
MwLLDestroyPixmap(px);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, w / 5 * 2,
|
||||
MwNheight, h,
|
||||
NULL);
|
||||
|
||||
MwVaApply(ldate,
|
||||
MwNx, w / 5 * 2,
|
||||
MwNwidth, w - w / 5 * 2,
|
||||
MwNheight, h / 2,
|
||||
NULL);
|
||||
|
||||
MwVaApply(ltime,
|
||||
MwNx, w / 5 * 2,
|
||||
MwNy, h / 2,
|
||||
MwNwidth, w - w / 5 * 2,
|
||||
MwNheight, h / 2,
|
||||
NULL);
|
||||
|
||||
glViewport(0, 0, w / 5 * 2, h);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLLColor bgcolor, fgcolor;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 250, 100,
|
||||
MwNtitle, "clock",
|
||||
NULL);
|
||||
|
||||
bgcolor = MwParseColor(window, MwGetText(window, MwNbackground));
|
||||
MwColorGet(bgcolor, &br, &bg, &bb);
|
||||
|
||||
fgcolor = MwParseColor(window, MwGetText(window, MwNforeground));
|
||||
MwColorGet(fgcolor, &fr, &fg, &fb);
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "clock", window, 0, 0, 100, 100);
|
||||
|
||||
ldate = MwVaCreateWidget(MwLabelClass, "date", window, 100, 0, 150, 50,
|
||||
MwNbold, 1,
|
||||
NULL);
|
||||
ltime = MwVaCreateWidget(MwLabelClass, "time", window, 100, 50, 150, 50,
|
||||
MwNbold, 1,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
tick(window, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
|
||||
MwLLFreeColor(fgcolor);
|
||||
MwLLFreeColor(bgcolor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,93 +1,93 @@
|
|||
#define TITLE "cube"
|
||||
#include "glutlayer.c"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
static double deg = 0;
|
||||
|
||||
static void draw(void) {
|
||||
int i;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(deg, 1, 0, 0);
|
||||
glRotatef(deg, 0, 1, 0);
|
||||
glRotatef(deg, 0, 0, 1);
|
||||
|
||||
for(i = 0; i < 6; i++) {
|
||||
if(i == 0)
|
||||
glColor3f(1, 0, 0);
|
||||
if(i == 1)
|
||||
glColor3f(0, 1, 0);
|
||||
if(i == 2)
|
||||
glColor3f(1, 1, 0);
|
||||
if(i == 3)
|
||||
glColor3f(0, 0, 1);
|
||||
if(i == 4)
|
||||
glColor3f(1, 0, 1);
|
||||
if(i == 5)
|
||||
glColor3f(0, 1, 1);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0, 1, 0);
|
||||
glVertex3f(-1, 1, -1);
|
||||
glVertex3f(-1, 1, 1);
|
||||
glVertex3f(1, 1, 1);
|
||||
glVertex3f(1, 1, -1);
|
||||
glEnd();
|
||||
|
||||
if(i < 3)
|
||||
glRotatef(90, 0, 0, 1);
|
||||
if(i == 3)
|
||||
glRotatef(90, 1, 0, 0);
|
||||
if(i == 4)
|
||||
glRotatef(180, 0, 0, 1);
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
deg += 1.0;
|
||||
}
|
||||
|
||||
static void reshape(int width, int height) {
|
||||
GLfloat lpos[4];
|
||||
|
||||
lpos[0] = 1;
|
||||
lpos[1] = 1;
|
||||
lpos[2] = 1;
|
||||
lpos[3] = 0;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60, (double)width / height, 1, 100);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
}
|
||||
#define TITLE "cube"
|
||||
#include "glutlayer.c"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
static double deg = 0;
|
||||
|
||||
static void draw(void) {
|
||||
int i;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(deg, 1, 0, 0);
|
||||
glRotatef(deg, 0, 1, 0);
|
||||
glRotatef(deg, 0, 0, 1);
|
||||
|
||||
for(i = 0; i < 6; i++) {
|
||||
if(i == 0)
|
||||
glColor3f(1, 0, 0);
|
||||
if(i == 1)
|
||||
glColor3f(0, 1, 0);
|
||||
if(i == 2)
|
||||
glColor3f(1, 1, 0);
|
||||
if(i == 3)
|
||||
glColor3f(0, 0, 1);
|
||||
if(i == 4)
|
||||
glColor3f(1, 0, 1);
|
||||
if(i == 5)
|
||||
glColor3f(0, 1, 1);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0, 1, 0);
|
||||
glVertex3f(-1, 1, -1);
|
||||
glVertex3f(-1, 1, 1);
|
||||
glVertex3f(1, 1, 1);
|
||||
glVertex3f(1, 1, -1);
|
||||
glEnd();
|
||||
|
||||
if(i < 3)
|
||||
glRotatef(90, 0, 0, 1);
|
||||
if(i == 3)
|
||||
glRotatef(90, 1, 0, 0);
|
||||
if(i == 4)
|
||||
glRotatef(180, 0, 0, 1);
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
deg += 1.0;
|
||||
}
|
||||
|
||||
static void reshape(int width, int height) {
|
||||
GLfloat lpos[4];
|
||||
|
||||
lpos[0] = 1;
|
||||
lpos[1] = 1;
|
||||
lpos[2] = 1;
|
||||
lpos[3] = 0;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60, (double)width / height, 1, 100);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,243 +1,243 @@
|
|||
#define TITLE "gears"
|
||||
#include "glutlayer.c"
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
/* Conversion to GLUT by Mark J. Kilgard */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear
|
||||
teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth) {
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
|
||||
static void draw(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
angle += 2.0;
|
||||
}
|
||||
|
||||
/* new window size or exposure */
|
||||
static void reshape(int width, int height) {
|
||||
GLfloat h = (GLfloat)height / (GLfloat)width;
|
||||
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
static GLfloat pos[4] =
|
||||
{5.0, 5.0, 10.0, 0.0};
|
||||
static GLfloat red[4] =
|
||||
{0.8, 0.1, 0.0, 1.0};
|
||||
static GLfloat green[4] =
|
||||
{0.0, 0.8, 0.2, 1.0};
|
||||
static GLfloat blue[4] =
|
||||
{0.2, 0.2, 1.0, 1.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
|
||||
if(k == MwKEY_LEFT) {
|
||||
view_roty += 5.0;
|
||||
} else if(k == MwKEY_RIGHT) {
|
||||
view_roty -= 5.0;
|
||||
} else if(k == MwKEY_UP) {
|
||||
view_rotx += 5.0;
|
||||
} else if(k == MwKEY_DOWN) {
|
||||
view_rotx -= 5.0;
|
||||
}
|
||||
}
|
||||
#define TITLE "gears"
|
||||
#include "glutlayer.c"
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
/* Conversion to GLUT by Mark J. Kilgard */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear
|
||||
teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth) {
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for(i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
|
||||
static void draw(void) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void idle(void) {
|
||||
angle += 2.0;
|
||||
}
|
||||
|
||||
/* new window size or exposure */
|
||||
static void reshape(int width, int height) {
|
||||
GLfloat h = (GLfloat)height / (GLfloat)width;
|
||||
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
static void init(void) {
|
||||
static GLfloat pos[4] =
|
||||
{5.0, 5.0, 10.0, 0.0};
|
||||
static GLfloat red[4] =
|
||||
{0.8, 0.1, 0.0, 1.0};
|
||||
static GLfloat green[4] =
|
||||
{0.0, 0.8, 0.2, 1.0};
|
||||
static GLfloat blue[4] =
|
||||
{0.2, 0.2, 1.0, 1.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
static void key(int k) {
|
||||
(void)k;
|
||||
|
||||
if(k == MwKEY_LEFT) {
|
||||
view_roty += 5.0;
|
||||
} else if(k == MwKEY_RIGHT) {
|
||||
view_roty -= 5.0;
|
||||
} else if(k == MwKEY_UP) {
|
||||
view_rotx += 5.0;
|
||||
} else if(k == MwKEY_DOWN) {
|
||||
view_rotx -= 5.0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +1,73 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
static void draw(void);
|
||||
static void idle(void);
|
||||
static void reshape(int width, int height);
|
||||
static void init(void);
|
||||
static void key(int k);
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user, void* client) {
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
draw();
|
||||
idle();
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
int ww, wh;
|
||||
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
ww = MwGetInteger(handle, MwNwidth) - 100;
|
||||
wh = MwGetInteger(handle, MwNheight) - 100;
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, ww,
|
||||
MwNheight, wh,
|
||||
NULL);
|
||||
|
||||
reshape(ww, wh);
|
||||
}
|
||||
|
||||
static void MWAPI key_pressed(MwWidget handle, void* user, void* client) {
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
key(*(int*)client);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, TITLE,
|
||||
NULL);
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, 400, 400);
|
||||
if(!opengl) {
|
||||
MwMessageBox(NULL, "Unable to create OpenGL window.", "Error", MwMB_ICONERROR);
|
||||
} else {
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
init();
|
||||
reshape(400, 400);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
|
||||
|
||||
MwAddTickList(opengl);
|
||||
|
||||
MwAddUserHandler(opengl, MwNkeyHandler, key_pressed, NULL);
|
||||
}
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
static void draw(void);
|
||||
static void idle(void);
|
||||
static void reshape(int width, int height);
|
||||
static void init(void);
|
||||
static void key(int k);
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user, void* client) {
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
draw();
|
||||
idle();
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void MWAPI resize(MwWidget handle, void* user, void* client) {
|
||||
int ww, wh;
|
||||
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
ww = MwGetInteger(handle, MwNwidth) - 100;
|
||||
wh = MwGetInteger(handle, MwNheight) - 100;
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, ww,
|
||||
MwNheight, wh,
|
||||
NULL);
|
||||
|
||||
reshape(ww, wh);
|
||||
}
|
||||
|
||||
static void MWAPI key_pressed(MwWidget handle, void* user, void* client) {
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
key(*(int*)client);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwWidget window;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 500, 500,
|
||||
MwNtitle, TITLE,
|
||||
NULL);
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, 400, 400);
|
||||
if(!opengl) {
|
||||
MwMessageBox(NULL, "Unable to create OpenGL window.", "Error", MwMB_ICONERROR);
|
||||
} else {
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
init();
|
||||
reshape(400, 400);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
|
||||
|
||||
MwAddTickList(opengl);
|
||||
|
||||
MwAddUserHandler(opengl, MwNkeyHandler, key_pressed, NULL);
|
||||
}
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,88 +1,88 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
MwWidget window, opengl, button;
|
||||
int ow, oh;
|
||||
double deg = 0;
|
||||
double dir = 1;
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
|
||||
unsigned int w, h;
|
||||
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
w = MwGetInteger(handle, MwNwidth);
|
||||
h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, (ow = w - 100),
|
||||
MwNheight, (oh = h - 150),
|
||||
NULL);
|
||||
|
||||
MwVaApply(button,
|
||||
MwNy, h - 50 - 50,
|
||||
MwNwidth, ow,
|
||||
MwNheight, 50,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glViewport(0, 0, ow, oh);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(deg, 0, 0, 1);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex2f(0, 0.8);
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex2f(-0.8, -0.8);
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex2f(0.8, -0.8);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
|
||||
deg += 120.0 / (1000.0 / MwWaitMS) * dir;
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
dir = dir == 1 ? -1 : 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 450,
|
||||
MwNtitle, "hello world",
|
||||
NULL);
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 300));
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 350, 300, 50,
|
||||
MwNtext, "Reverse",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, activate, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
MwWidget window, opengl, button;
|
||||
int ow, oh;
|
||||
double deg = 0;
|
||||
double dir = 1;
|
||||
|
||||
void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
|
||||
unsigned int w, h;
|
||||
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
w = MwGetInteger(handle, MwNwidth);
|
||||
h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, (ow = w - 100),
|
||||
MwNheight, (oh = h - 150),
|
||||
NULL);
|
||||
|
||||
MwVaApply(button,
|
||||
MwNy, h - 50 - 50,
|
||||
MwNwidth, ow,
|
||||
MwNheight, 50,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glViewport(0, 0, ow, oh);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(deg, 0, 0, 1);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex2f(0, 0.8);
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex2f(-0.8, -0.8);
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex2f(0.8, -0.8);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
|
||||
deg += 120.0 / (1000.0 / MwWaitMS) * dir;
|
||||
}
|
||||
|
||||
void MWAPI activate(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
dir = dir == 1 ? -1 : 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 450,
|
||||
MwNtitle, "hello world",
|
||||
NULL);
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 300));
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 350, 300, 50,
|
||||
MwNtext, "Reverse",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, activate, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,138 +1,138 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
typedef struct triangle {
|
||||
int points[3 * 2];
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
} triangle_t;
|
||||
|
||||
triangle_t* t = NULL;
|
||||
int ct = 0;
|
||||
int click = 0;
|
||||
int mx, my;
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user, void* call) {
|
||||
int i;
|
||||
int w = MwGetInteger(opengl, MwNwidth);
|
||||
int h = MwGetInteger(opengl, MwNheight);
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, w, h, 0, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
for(i = 0; i < ct + (click == 2 ? 1 : 0); i++) {
|
||||
int j;
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3d(t[i].r, t[i].g, t[i].b);
|
||||
for(j = 0; j < 3; j++) {
|
||||
glVertex2d(t[i].points[j * 2 + 0], t[i].points[j * 2 + 1]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void MWAPI mouse(MwWidget handle, void* user, void* call) {
|
||||
MwMouse* mouse = call;
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
if(mouse->button == MwMOUSE_LEFT) {
|
||||
t[ct].points[click * 2 + 0] = mouse->point.x;
|
||||
t[ct].points[click * 2 + 1] = mouse->point.y;
|
||||
click++;
|
||||
if(click == 1) {
|
||||
t[ct].r = rand() % 65536;
|
||||
t[ct].g = rand() % 65536;
|
||||
t[ct].b = rand() % 65536;
|
||||
|
||||
t[ct].r /= 65535;
|
||||
t[ct].g /= 65535;
|
||||
t[ct].b /= 65535;
|
||||
} else if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = mx;
|
||||
t[ct].points[2 * 2 + 1] = my;
|
||||
} else if(click == 3) {
|
||||
triangle_t* old = t;
|
||||
int i;
|
||||
|
||||
click = 0;
|
||||
ct++;
|
||||
|
||||
t = malloc(sizeof(*t) * (ct + 1));
|
||||
for(i = 0; i < ct; i++) t[i] = old[i];
|
||||
free(old);
|
||||
}
|
||||
} else if(mouse->button == MwMOUSE_RIGHT) {
|
||||
if(click > 0) {
|
||||
click = 0;
|
||||
} else if(ct > 0) {
|
||||
ct--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI mouse_move(MwWidget handle, void* user, void* call) {
|
||||
MwPoint* point = call;
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
mx = point->x;
|
||||
my = point->y;
|
||||
|
||||
if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = point->x;
|
||||
t[ct].points[2 * 2 + 1] = point->y;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwSizeHints hints;
|
||||
MwWidget window, viewport;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
|
||||
MwNtitle, "tripaint",
|
||||
NULL);
|
||||
viewport = MwCreateWidget(MwViewportClass, "viewport", window, 5, 5, 630, 470 - 16 - 5);
|
||||
|
||||
hints.min_width = hints.max_width = 640;
|
||||
hints.min_height = hints.max_height = 480;
|
||||
MwVaApply(window, MwNsizeHints, &hints, NULL);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", window, 5, 470 - 16 + 5, 630, 16,
|
||||
MwNtext, "Press left click to draw triangle, right click to undo",
|
||||
NULL);
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", viewport, 0, 0, 1024, 768);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseDownHandler, mouse, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseMoveHandler, mouse_move, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
MwWidget opengl;
|
||||
|
||||
typedef struct triangle {
|
||||
int points[3 * 2];
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
} triangle_t;
|
||||
|
||||
triangle_t* t = NULL;
|
||||
int ct = 0;
|
||||
int click = 0;
|
||||
int mx, my;
|
||||
|
||||
static void MWAPI tick(MwWidget handle, void* user, void* call) {
|
||||
int i;
|
||||
int w = MwGetInteger(opengl, MwNwidth);
|
||||
int h = MwGetInteger(opengl, MwNheight);
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
(void)call;
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, w, h, 0, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
for(i = 0; i < ct + (click == 2 ? 1 : 0); i++) {
|
||||
int j;
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3d(t[i].r, t[i].g, t[i].b);
|
||||
for(j = 0; j < 3; j++) {
|
||||
glVertex2d(t[i].points[j * 2 + 0], t[i].points[j * 2 + 1]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void MWAPI mouse(MwWidget handle, void* user, void* call) {
|
||||
MwMouse* mouse = call;
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
if(mouse->button == MwMOUSE_LEFT) {
|
||||
t[ct].points[click * 2 + 0] = mouse->point.x;
|
||||
t[ct].points[click * 2 + 1] = mouse->point.y;
|
||||
click++;
|
||||
if(click == 1) {
|
||||
t[ct].r = rand() % 65536;
|
||||
t[ct].g = rand() % 65536;
|
||||
t[ct].b = rand() % 65536;
|
||||
|
||||
t[ct].r /= 65535;
|
||||
t[ct].g /= 65535;
|
||||
t[ct].b /= 65535;
|
||||
} else if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = mx;
|
||||
t[ct].points[2 * 2 + 1] = my;
|
||||
} else if(click == 3) {
|
||||
triangle_t* old = t;
|
||||
int i;
|
||||
|
||||
click = 0;
|
||||
ct++;
|
||||
|
||||
t = malloc(sizeof(*t) * (ct + 1));
|
||||
for(i = 0; i < ct; i++) t[i] = old[i];
|
||||
free(old);
|
||||
}
|
||||
} else if(mouse->button == MwMOUSE_RIGHT) {
|
||||
if(click > 0) {
|
||||
click = 0;
|
||||
} else if(ct > 0) {
|
||||
ct--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void MWAPI mouse_move(MwWidget handle, void* user, void* call) {
|
||||
MwPoint* point = call;
|
||||
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
mx = point->x;
|
||||
my = point->y;
|
||||
|
||||
if(click == 2) {
|
||||
t[ct].points[2 * 2 + 0] = point->x;
|
||||
t[ct].points[2 * 2 + 1] = point->y;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwSizeHints hints;
|
||||
MwWidget window, viewport;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 640, 480,
|
||||
MwNtitle, "tripaint",
|
||||
NULL);
|
||||
viewport = MwCreateWidget(MwViewportClass, "viewport", window, 5, 5, 630, 470 - 16 - 5);
|
||||
|
||||
hints.min_width = hints.max_width = 640;
|
||||
hints.min_height = hints.max_height = 480;
|
||||
MwVaApply(window, MwNsizeHints, &hints, NULL);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", window, 5, 470 - 16 + 5, 630, 16,
|
||||
MwNtext, "Press left click to draw triangle, right click to undo",
|
||||
NULL);
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", viewport, 0, 0, 1024, 768);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseDownHandler, mouse, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseMoveHandler, mouse_move, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
1444
examples/harvard.c
1444
examples/harvard.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,28 +1,28 @@
|
|||
file(
|
||||
GLOB
|
||||
EXAMPLES_VULKAN_SOURCES
|
||||
*.c
|
||||
)
|
||||
find_package(Vulkan)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_VULKAN_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
target_include_directories(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
${Vulkan_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
file(
|
||||
GLOB
|
||||
EXAMPLES_VULKAN_SOURCES
|
||||
*.c
|
||||
)
|
||||
find_package(Vulkan)
|
||||
|
||||
foreach(PATH IN LISTS EXAMPLES_VULKAN_SOURCES)
|
||||
get_filename_component(TARGET ${PATH} NAME_WE)
|
||||
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
|
||||
target_include_directories(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
${Vulkan_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
Mw
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
${TARGET}
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue