mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-20 23:37:33 +09:00
Dactyloidae Milsko Widget initial commit
This commit is contained in:
parent
2e7355c0ef
commit
91b45c0d14
410 changed files with 204246 additions and 0 deletions
7
widget/milsko/milskosrc/examples/CMakeLists.txt
Normal file
7
widget/milsko/milskosrc/examples/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
add_subdirectory(basic)
|
||||
if(${MW_TRY_OPENGL})
|
||||
add_subdirectory(gldemos)
|
||||
endif()
|
||||
if(${MW_TRY_VULKAN})
|
||||
add_subdirectory(vkdemos)
|
||||
endif()
|
||||
26
widget/milsko/milskosrc/examples/basic/CMakeLists.txt
Normal file
26
widget/milsko/milskosrc/examples/basic/CMakeLists.txt
Normal file
|
|
@ -0,0 +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()
|
||||
74
widget/milsko/milskosrc/examples/basic/box.c
Normal file
74
widget/milsko/milskosrc/examples/basic/box.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
185
widget/milsko/milskosrc/examples/basic/calculator.c
Normal file
185
widget/milsko/milskosrc/examples/basic/calculator.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
28
widget/milsko/milskosrc/examples/basic/checkbox.c
Normal file
28
widget/milsko/milskosrc/examples/basic/checkbox.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
78
widget/milsko/milskosrc/examples/basic/clipboard.c
Normal file
78
widget/milsko/milskosrc/examples/basic/clipboard.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
48
widget/milsko/milskosrc/examples/basic/colorpicker.c
Normal file
48
widget/milsko/milskosrc/examples/basic/colorpicker.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
22
widget/milsko/milskosrc/examples/basic/combobox.c
Normal file
22
widget/milsko/milskosrc/examples/basic/combobox.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
160
widget/milsko/milskosrc/examples/basic/example.c
Normal file
160
widget/milsko/milskosrc/examples/basic/example.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
70
widget/milsko/milskosrc/examples/basic/filechooser.c
Normal file
70
widget/milsko/milskosrc/examples/basic/filechooser.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
42
widget/milsko/milskosrc/examples/basic/image.c
Normal file
42
widget/milsko/milskosrc/examples/basic/image.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
61
widget/milsko/milskosrc/examples/basic/listbox.c
Normal file
61
widget/milsko/milskosrc/examples/basic/listbox.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
57
widget/milsko/milskosrc/examples/basic/messagebox.c
Normal file
57
widget/milsko/milskosrc/examples/basic/messagebox.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
326
widget/milsko/milskosrc/examples/basic/periodic.c
Normal file
326
widget/milsko/milskosrc/examples/basic/periodic.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
18
widget/milsko/milskosrc/examples/basic/progressbar.c
Normal file
18
widget/milsko/milskosrc/examples/basic/progressbar.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
28
widget/milsko/milskosrc/examples/basic/radiobox.c
Normal file
28
widget/milsko/milskosrc/examples/basic/radiobox.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
95
widget/milsko/milskosrc/examples/basic/rotate.c
Normal file
95
widget/milsko/milskosrc/examples/basic/rotate.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
20
widget/milsko/milskosrc/examples/basic/scrollbar.c
Normal file
20
widget/milsko/milskosrc/examples/basic/scrollbar.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
23
widget/milsko/milskosrc/examples/basic/sevensegment.c
Normal file
23
widget/milsko/milskosrc/examples/basic/sevensegment.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
52
widget/milsko/milskosrc/examples/basic/subwindow.c
Normal file
52
widget/milsko/milskosrc/examples/basic/subwindow.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
43
widget/milsko/milskosrc/examples/basic/tab.c
Normal file
43
widget/milsko/milskosrc/examples/basic/tab.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
50
widget/milsko/milskosrc/examples/basic/treeview.c
Normal file
50
widget/milsko/milskosrc/examples/basic/treeview.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
42
widget/milsko/milskosrc/examples/basic/viewport.c
Normal file
42
widget/milsko/milskosrc/examples/basic/viewport.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
27
widget/milsko/milskosrc/examples/gldemos/CMakeLists.txt
Normal file
27
widget/milsko/milskosrc/examples/gldemos/CMakeLists.txt
Normal file
|
|
@ -0,0 +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()
|
||||
158
widget/milsko/milskosrc/examples/gldemos/boing.c
Normal file
158
widget/milsko/milskosrc/examples/gldemos/boing.c
Normal file
|
|
@ -0,0 +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;
|
||||
}
|
||||
169
widget/milsko/milskosrc/examples/gldemos/clock.c
Normal file
169
widget/milsko/milskosrc/examples/gldemos/clock.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
93
widget/milsko/milskosrc/examples/gldemos/cube.c
Normal file
93
widget/milsko/milskosrc/examples/gldemos/cube.c
Normal file
|
|
@ -0,0 +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;
|
||||
}
|
||||
243
widget/milsko/milskosrc/examples/gldemos/gears.c
Normal file
243
widget/milsko/milskosrc/examples/gldemos/gears.c
Normal file
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
73
widget/milsko/milskosrc/examples/gldemos/glutlayer.c
Normal file
73
widget/milsko/milskosrc/examples/gldemos/glutlayer.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
88
widget/milsko/milskosrc/examples/gldemos/triangle.c
Normal file
88
widget/milsko/milskosrc/examples/gldemos/triangle.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
138
widget/milsko/milskosrc/examples/gldemos/tripaint.c
Normal file
138
widget/milsko/milskosrc/examples/gldemos/tripaint.c
Normal file
|
|
@ -0,0 +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);
|
||||
}
|
||||
722
widget/milsko/milskosrc/examples/harvard.c
Normal file
722
widget/milsko/milskosrc/examples/harvard.c
Normal file
|
|
@ -0,0 +1,722 @@
|
|||
const char* harvard[] = {
|
||||
"The birch canoe slid on the smooth planks. ",
|
||||
"Glue the sheet to the dark blue background.",
|
||||
"It's easy to tell the depth of a well. ",
|
||||
"These days a chicken leg is a rare dish. ",
|
||||
"Rice is often served in round bowls.",
|
||||
"The juice of lemons makes fine punch. ",
|
||||
"The box was thrown beside the parked truck. ",
|
||||
"The hogs were fed chopped corn and garbage. ",
|
||||
"Four hours of steady work faced us. ",
|
||||
"A large size in stockings is hard to sell. ",
|
||||
"The boy was there when the sun rose.",
|
||||
"A rod is used to catch pink salmon. ",
|
||||
"The source of the huge river is the clear spring. ",
|
||||
"Kick the ball straight and follow through.",
|
||||
"Help the woman get back to her feet. ",
|
||||
"A pot of tea helps to pass the evening. ",
|
||||
"Smoky fires lack flame and heat. ",
|
||||
"The soft cushion broke the man's fall. ",
|
||||
"The salt breeze came across from the sea. ",
|
||||
"The girl at the booth sold fifty bonds. ",
|
||||
"The small pup gnawed a hole in the sock. ",
|
||||
"The fish twisted and turned on the bent hook. ",
|
||||
"Press the pants and sew a button on the vest. ",
|
||||
"The swan dive was far short of perfect. ",
|
||||
"The beauty of the view stunned the young boy. ",
|
||||
"Two blue fish swam in the tank. ",
|
||||
"Her purse was full of useless trash. ",
|
||||
"The colt reared and threw the tall rider. ",
|
||||
"It snowed, rained, and hailed the same morning. ",
|
||||
"Read verse out loud for pleasure.",
|
||||
"Hoist the load to your left shoulder. ",
|
||||
"Take the winding path to reach the lake. ",
|
||||
"Note closely the size of the gas tank. ",
|
||||
"Wipe the grease off his dirty face. ",
|
||||
"Mend the coat before you go out. ",
|
||||
"The wrist was badly strained and hung limp. ",
|
||||
"The stray cat gave birth to kittens. ",
|
||||
"The young girl gave no clear response. ",
|
||||
"The meal was cooked before the bell rang.",
|
||||
"What joy there is in living. ",
|
||||
"A king ruled the state in the early days. ",
|
||||
"The ship was torn apart on the sharp reef. ",
|
||||
"Sickness kept him home the third week. ",
|
||||
"The wide road shimmered in the hot sun. ",
|
||||
"The lazy cow lay in the cool grass. ",
|
||||
"Lift the square stone over the fence. ",
|
||||
"The rope will bind the seven books at once. ",
|
||||
"Hop over the fence and plunge in. ",
|
||||
"The friendly gang left the drug store. ",
|
||||
"Mesh wire keeps chicks inside. ",
|
||||
"The frosty air passed through the coat. ",
|
||||
"The crooked maze failed to fool the mouse. ",
|
||||
"Adding fast leads to wrong sums. ",
|
||||
"The show was a flop from the very start. ",
|
||||
"A saw is a tool used for making boards.",
|
||||
"The wagon moved on well oiled wheels.",
|
||||
"March the soldiers past the next hill. ",
|
||||
"A cup of sugar makes sweet fudge. ",
|
||||
"Place a rosebush near the porch steps. ",
|
||||
"Both lost their lives in the raging storm. ",
|
||||
"We talked of the side show in the circus.",
|
||||
"Use a pencil to write the first draft.",
|
||||
"He ran half way to the hardware store. ",
|
||||
"The clock struck to mark the third period.",
|
||||
"A small creek cut across the field.",
|
||||
"Cars and busses stalled in snow drifts.",
|
||||
"The set of china hit the floor with a crash. ",
|
||||
"This is a grand season for hikes on the road.",
|
||||
"The dune rose from the edge of the water. ",
|
||||
"Those words were the cue for the actor to leave.",
|
||||
"A yacht slid around the point into the bay.",
|
||||
"The two met while playing on the sand.",
|
||||
"The ink stain dried on the finished page.",
|
||||
"The walled town was seized without a fight. ",
|
||||
"The lease ran out in sixteen weeks. ",
|
||||
"A tame squirrel makes a nice pet. ",
|
||||
"The horn of the car woke the sleeping cop. ",
|
||||
"The heart beat strongly and with firm strokes. ",
|
||||
"The pearl was worn in a thin silver ring. ",
|
||||
"The fruit peel was cut in thick slices.",
|
||||
"The Navy attacked the big task force.",
|
||||
"See the cat glaring at the scared mouse. ",
|
||||
"There are more than two factors here.",
|
||||
"The hat brim was wide and too droopy.",
|
||||
"The lawyer tried to lose his case.",
|
||||
"The grass curled around the fence post.",
|
||||
"Cut the pie into large parts.",
|
||||
"Men strive but seldom get rich. ",
|
||||
"Always close the barn door tight.",
|
||||
"He lay prone and hardly moved a limb.",
|
||||
"The slush lay deep along the street. ",
|
||||
"A wisp of cloud hung in the blue air. ",
|
||||
"A pound of sugar costs more than eggs.",
|
||||
"The fin was sharp and cut the clear water.",
|
||||
"The play seems dull and quite stupid.",
|
||||
"Bail the boat to stop it from sinking.",
|
||||
"The term ended in late june that year.",
|
||||
"A Tusk is used to make costly gifts.",
|
||||
"Ten pins were set in order.",
|
||||
"The bill was paid every third week.",
|
||||
"Oak is strong and also gives shade.",
|
||||
"Cats and Dogs each hate the other.",
|
||||
"The pipe began to rust while new.",
|
||||
"Open the crate but don't break the glass.",
|
||||
"Add the sum to the product of these three.",
|
||||
"Thieves who rob friends deserve jail.",
|
||||
"The ripe taste of cheese improves with age.",
|
||||
"Act on these orders with great speed.",
|
||||
"The hog crawled under the high fence.",
|
||||
"Move the vat over the hot fire.",
|
||||
"The bark of the pine tree was shiny and dark.",
|
||||
"Leaves turn brown and yellow in the fall. ",
|
||||
"The pennant waved when the wind blew.",
|
||||
"Split the log with a quick, sharp blow.",
|
||||
"Burn peat after the logs give out.",
|
||||
"He ordered peach pie with ice cream.",
|
||||
"Weave the carpet on the right hand side.",
|
||||
"Hemp is a weed found in parts of the tropics.",
|
||||
"A lame back kept his score low.",
|
||||
"We find joy in the simplest things.",
|
||||
"Type out three lists of orders.",
|
||||
"The harder he tried the less he got done.",
|
||||
"The boss ran the show with a watchful eye.",
|
||||
"The cup cracked and spilled its contents.",
|
||||
"Paste can cleanse the most dirty brass.",
|
||||
"The slang word for raw whiskey is booze.",
|
||||
"It caught its hind paw in a rusty trap.",
|
||||
"The wharf could be seen at the farther shore.",
|
||||
"Feel the heat of the weak dying flame.",
|
||||
"The tiny girl took off her hat.",
|
||||
"A cramp is no small danger on a swim.",
|
||||
"He said the same phrase thirty times.",
|
||||
"Pluck the bright rose without leaves.",
|
||||
"Two plus seven is less than ten.",
|
||||
"The glow deepened in the eyes of the sweet girl.",
|
||||
"Bring your problems to the wise chief.",
|
||||
"Write a fond note to the friend you cherish.",
|
||||
"Clothes and lodging are free to new men.",
|
||||
"We frown when events take a bad turn.",
|
||||
"Port is a strong wine with a smoky taste.",
|
||||
"The young kid jumped the rusty gate.",
|
||||
"Guess the result from the first scores. ",
|
||||
"A salt pickle tastes fine with ham.",
|
||||
"The just claim got the right verdict.",
|
||||
"Those thistles bend in a high wind.",
|
||||
"Pure bred poodles have curls.",
|
||||
"The tree top waved in a graceful way. ",
|
||||
"The spot on the blotter was made by green ink. ",
|
||||
"Mud was spattered on the front of his white shirt.",
|
||||
"The cigar burned a hole in the desk top. ",
|
||||
"The empty flask stood on the tin tray.",
|
||||
"A speedy man can beat this track mark. ",
|
||||
"He broke a new shoelace that day.",
|
||||
"The coffee stand is too high for the couch. ",
|
||||
"The urge to write short stories is rare. ",
|
||||
"The pencils have all been used.",
|
||||
"The pirates seized the crew of the lost ship.",
|
||||
"We tried to replace the coin but failed. ",
|
||||
"She sewed the torn coat quite neatly. ",
|
||||
"The sofa cushion is red and of light weight.",
|
||||
"The jacket hung on the back of the wide chair.",
|
||||
"At that high level the air is pure.",
|
||||
"Drop the two when you add the figures.",
|
||||
"A filing case is now hard to buy.",
|
||||
"An abrupt start does not win the prize. ",
|
||||
"Wood is best for making toys and blocks.",
|
||||
"The office paint was a dull, sad tan.",
|
||||
"He knew the skill of the great young actress.",
|
||||
"A rag will soak up spilled water.",
|
||||
"A shower of dirt fell from the hot pipes.",
|
||||
"Steam hissed from the broken valve. ",
|
||||
"The child almost hurt the small dog.",
|
||||
"There was a sound of dry leaves outside.",
|
||||
"The sky that morning was clear and bright blue.",
|
||||
"Torn scraps littered the stone floor.",
|
||||
"Sunday is the best part of the week. ",
|
||||
"The doctor cured him with these pills.",
|
||||
"The new girl was fired today at noon.",
|
||||
"They felt gay when the ship arrived in port.",
|
||||
"Add the store's account to the last cent.",
|
||||
"Acid burns holes in wool cloth.",
|
||||
"Fairy tales should be fun to write.",
|
||||
"Eight miles of woodland burned to waste.",
|
||||
"The third act was dull and tired the players.",
|
||||
"A young child should not suffer fright.",
|
||||
"Add the column and put the sum here.",
|
||||
"We admire and love a good cook.",
|
||||
"There the flood mark is ten inches.",
|
||||
"He carved a head from the round block of marble.",
|
||||
"She has a smart way of wearing clothes.",
|
||||
"The fruit of a fig tree is apple shaped.",
|
||||
"Corn cobs can be used to kindle a fire. ",
|
||||
"Where were they when the noise started.",
|
||||
"The paper box is full of thumb tacks.",
|
||||
"Sell your gift to a buyer at a good gain.",
|
||||
"The tongs lay beside the ice pail.",
|
||||
"The petals fall with the next puff of wind.",
|
||||
"Bring your best compass to the third class.",
|
||||
"They could laugh although they were sad.",
|
||||
"Farmers came in to thresh the oat crop.",
|
||||
"The brown house was on fire to the attic.",
|
||||
"The lure is used to catch trout and flounder.",
|
||||
"Float the soap on top of the bath water.",
|
||||
"A blue crane is a tall wading bird.",
|
||||
"A fresh start will work such wonders.",
|
||||
"The club rented the rink for the fifth night.",
|
||||
"After the dance, they went straight home.",
|
||||
"The hostess taught the new maid to serve.",
|
||||
"He wrote his last novel there at the inn.",
|
||||
"Even the worst will beat his low score.",
|
||||
"The cement had dried when he moved it.",
|
||||
"The loss of the second ship was hard to take.",
|
||||
"The fly made its way along the wall.",
|
||||
"Do that with a wooden stick.",
|
||||
"Live wires should be kept covered.",
|
||||
"The large house had hot water taps.",
|
||||
"It is hard to erase blue or red ink.",
|
||||
"Write at once or you may forget it.",
|
||||
"The doorknob was made of bright clean brass.",
|
||||
"The wreck occurred by the bank on Main Street.",
|
||||
"A pencil with black lead writes best.",
|
||||
"Coax a young calf to drink from a bucket.",
|
||||
"Schools for ladies teach charm and grace.",
|
||||
"The lamp shone with a steady green flame.",
|
||||
"They took the axe and the saw to the forest.",
|
||||
"The ancient coin was quite dull and worn.",
|
||||
"The shaky barn fell with a loud crash. ",
|
||||
"Jazz and swing fans like fast music.",
|
||||
"Rake the rubbish up and then burn it.",
|
||||
"Slash the gold cloth into fine ribbons.",
|
||||
"Try to have the court decide the case.",
|
||||
"They are pushed back each time they attack.",
|
||||
"He broke his ties with groups of former friends.",
|
||||
"They floated on the raft to sun their white backs.",
|
||||
"The map had an X that meant nothing.",
|
||||
"Whitings are small fish caught in nets.",
|
||||
"Some ads serve to cheat buyers.",
|
||||
"Jerk the rope and the bell rings weakly.",
|
||||
"A waxed floor makes us lose balance.",
|
||||
"Madam, this is the best brand of corn.",
|
||||
"On the islands the sea breeze is soft and mild.",
|
||||
"The play began as soon as we sat down.",
|
||||
"This will lead the world to more sound and fury.",
|
||||
"Add salt before you fry the egg.",
|
||||
"The rush for funds reached its peak Tuesday.",
|
||||
"The birch looked stark white and lonesome.",
|
||||
"The box is held by a bright red snapper.",
|
||||
"To make pure ice, you freeze water.",
|
||||
"The first worm gets snapped early.",
|
||||
"Jump the fence and hurry up the bank.",
|
||||
"Yell and clap as the curtain slides back.",
|
||||
"They are men who walk the middle of the road.",
|
||||
"Both brothers wear the same size.",
|
||||
"In some form or other we need fun.",
|
||||
"The prince ordered his head chopped off.",
|
||||
"The houses are built of red clay bricks.",
|
||||
"Ducks fly north but lack a compass.",
|
||||
"Fruit flavors are used in fizz drinks.",
|
||||
"These pills do less good than others.",
|
||||
"Canned pears lack full flavor.",
|
||||
"The dark pot hung in the front closet.",
|
||||
"Carry the pail to the wall and spill it there.",
|
||||
"The train brought our hero to the big town.",
|
||||
"We are sure that one war is enough.",
|
||||
"Gray paint stretched for miles around.",
|
||||
"The rude laugh filled the empty room.",
|
||||
"High seats are best for football fans.",
|
||||
"Tea served from the brown jug is tasty.",
|
||||
"A dash of pepper spoils beef stew.",
|
||||
"A zestful food is the hot-cross bun.",
|
||||
"The horse trotted around the field at a brisk pace.",
|
||||
"Find the twin who stole the pearl necklace.",
|
||||
"Cut the cord that binds the box tightly.",
|
||||
"The red tape bound the smuggled food.",
|
||||
"Look in the corner to find the tan shirt.",
|
||||
"The cold drizzle will halt the bond drive.",
|
||||
"Nine men were hired to dig the ruins.",
|
||||
"The junk yard had a mouldy smell.",
|
||||
"The flint sputtered and lit a pine torch.",
|
||||
"Soak the cloth and drown the sharp odor.",
|
||||
"The shelves were bare of both jam or crackers.",
|
||||
"A joy to every child is the swan boat.",
|
||||
"All sat frozen and watched the screen.",
|
||||
"A cloud of dust stung his tender eyes.",
|
||||
"To reach the end he needs much courage.",
|
||||
"Shape the clay gently into block form.",
|
||||
"A ridge on a smooth surface is a bump or flaw.",
|
||||
"Hedge apples may stain your hands green.",
|
||||
"Quench your thirst, then eat the crackers.",
|
||||
"Tight curls get limp on rainy days.",
|
||||
"The mute muffled the high tones of the horn.",
|
||||
"The gold ring fits only a pierced ear.",
|
||||
"The old pan was covered with hard fudge.",
|
||||
"Watch the log float in the wide river.",
|
||||
"The node on the stalk of wheat grew daily.",
|
||||
"The heap of fallen leaves was set on fire.",
|
||||
"Write fast if you want to finish early.",
|
||||
"His shirt was clean but one button was gone.",
|
||||
"The barrel of beer was a brew of malt and hops.",
|
||||
"Tin cans are absent from store shelves.",
|
||||
"Slide the box into that empty space.",
|
||||
"The plant grew large and green in the window.",
|
||||
"The beam dropped down on the workman's head.",
|
||||
"Pink clouds floated with the breeze.",
|
||||
"She danced like a swan, tall and graceful.",
|
||||
"The tube was blown and the tire flat and useless.",
|
||||
"It is late morning on the old wall clock.",
|
||||
"Let's all join as we sing the last chorus.",
|
||||
"The last switch cannot be turned off.",
|
||||
"The fight will end in just six minutes.",
|
||||
"The store walls were lined with colored frocks.",
|
||||
"The peace league met to discuss their plans. ",
|
||||
"The rise to fame of a person takes luck.",
|
||||
"Paper is scarce, so write with much care.",
|
||||
"The quick fox jumped on the sleeping cat.",
|
||||
"The nozzle of the fire hose was bright brass.",
|
||||
"Screw the round cap on as tight as needed.",
|
||||
"Time brings us many changes.",
|
||||
"The purple tie was ten years old.",
|
||||
"Men think and plan and sometimes act.",
|
||||
"Fill the ink jar with sticky glue.",
|
||||
"He smoke a big pipe with strong contents.",
|
||||
"We need grain to keep our mules healthy.",
|
||||
"Pack the records in a neat thin case.",
|
||||
"The crunch of feet in the snow was the only sound.",
|
||||
"The copper bowl shone in the sun's rays.",
|
||||
"Boards will warp unless kept dry. ",
|
||||
"The plush chair leaned against the wall. ",
|
||||
"Glass will clink when struck by metal.",
|
||||
"Bathe and relax in the cool green grass.",
|
||||
"Nine rows of soldiers stood in a line.",
|
||||
"The beach is dry and shallow at low tide.",
|
||||
"The idea is to sew both edges straight.",
|
||||
"The kitten chased the dog down the street.",
|
||||
"Pages bound in cloth make a book.",
|
||||
"Try to trace the fine lines of the painting.",
|
||||
"Women form less than half of the group. ",
|
||||
"The zones merge in the central part of town.",
|
||||
"A gem in the rough needs work to polish.",
|
||||
"Code is used when secrets are sent.",
|
||||
"Most of the news is easy for us to hear.",
|
||||
"He used the lathe to make brass objects.",
|
||||
"The vane on top of the pole revolved in the wind.",
|
||||
"Mince pie is a dish served to children.",
|
||||
"The clan gathered on each dull night.",
|
||||
"Let it burn, it gives us warmth and comfort.",
|
||||
"A castle built from sand fails to endure.",
|
||||
"A child's wit saved the day for us.",
|
||||
"Tack the strip of carpet to the worn floor.",
|
||||
"Next Tuesday we must vote.",
|
||||
"Pour the stew from the pot into the plate.",
|
||||
"Each penny shone like new.",
|
||||
"The man went to the woods to gather sticks.",
|
||||
"The dirt piles were lines along the road.",
|
||||
"The logs fell and tumbled into the clear stream.",
|
||||
"Just hoist it up and take it away.",
|
||||
"A ripe plum is fit for a king's palate.",
|
||||
"Our plans right now are hazy. ",
|
||||
"Brass rings are sold by these natives.",
|
||||
"It takes a good trap to capture a bear.",
|
||||
"Feed the white mouse some flower seeds.",
|
||||
"The thaw came early and freed the stream.",
|
||||
"He took the lead and kept it the whole distance.",
|
||||
"The key you designed will fit the lock.",
|
||||
"Plead to the council to free the poor thief.",
|
||||
"Better hash is made of rare beef.",
|
||||
"This plank was made for walking on .",
|
||||
"The lake sparkled in the red hot sun.",
|
||||
"He crawled with care along the ledge.",
|
||||
"Tend the sheep while the dog wanders.",
|
||||
"It takes a lot of help to finish these.",
|
||||
"Mark the spot with a sign painted red.",
|
||||
"Take two shares as a fair profit. ",
|
||||
"The fur of cats goes by many names.",
|
||||
"North winds bring colds and fevers.",
|
||||
"He asks no person to vouch for him.",
|
||||
"Go now and come here later.",
|
||||
"A sash of gold silk will trim her dress.",
|
||||
"Soap can wash most dirt away.",
|
||||
"That move means the game is over.",
|
||||
"He wrote down a long list of items.",
|
||||
"A siege will crack the strong defense.",
|
||||
"Grape juice and water mix well.",
|
||||
"Roads are paved with sticky tar.",
|
||||
"Fake stones shine but cost little.",
|
||||
"The drip of the rain made a pleasant sound. ",
|
||||
"Smoke poured out of every crack. ",
|
||||
"Serve the hot rum to the tired heroes.",
|
||||
"Much of the story makes good sense. ",
|
||||
"The sun came up to light the eastern sky.",
|
||||
"Heave the line over the port side.",
|
||||
"A lathe cuts and trims any wood.",
|
||||
"It's a dense crowd in two distinct ways.",
|
||||
"His hip struck the knee of the next player.",
|
||||
"The stale smell of old beer lingers.",
|
||||
"The desk was firm on the shaky floor.",
|
||||
"It takes heat to bring out the odor.",
|
||||
"Beef is scarcer than some lamb.",
|
||||
"Raise the sail and steer the ship northward.",
|
||||
"A cone costs five cents on Mondays.",
|
||||
"A pod is what peas always grow in.",
|
||||
"Jerk that dart from the cork target.",
|
||||
"No cement will hold hard wood.",
|
||||
"We now have a new base for shipping.",
|
||||
"A list of names is carved around the base.",
|
||||
"The sheep were led home by a dog.",
|
||||
"Three for a dime, the young peddler cried.",
|
||||
"The sense of smell is better than that of touch.",
|
||||
"No hardship seemed to make him sad.",
|
||||
"Grace makes up for lack of beauty.",
|
||||
"Nudge gently but wake her now.",
|
||||
"The news struck doubt into restless minds.",
|
||||
"Once we stood beside the shore.",
|
||||
"A chink in the wall allowed a draft to blow.",
|
||||
"Fasten two pins on each side.",
|
||||
"A cold dip restores health and zest.",
|
||||
"He takes the oath of office each March.",
|
||||
"The sand drifts over the sills of the old house.",
|
||||
"The point of the steel pen was bent and twisted.",
|
||||
"There is a lag between thought and act.",
|
||||
"Seed is needed to plant the spring corn.",
|
||||
"Draw the chart with heavy black lines.",
|
||||
"The boy owed his pal thirty cents.",
|
||||
"The chap slipped into the crowd and was lost.",
|
||||
"Hats are worn to tea and not to dinner.",
|
||||
"The ramp led up to the wide highway.",
|
||||
"Beat the dust from the rug onto the lawn.",
|
||||
"Say it slowly but make it ring clear.",
|
||||
"The straw nest housed five robins.",
|
||||
"Screen the porch with woven straw mats.",
|
||||
"This horse will nose his way to the finish.",
|
||||
"The dry wax protects the deep scratch.",
|
||||
"He picked up the dice for a second roll.",
|
||||
"These coins will be needed to pay his debt.",
|
||||
"The nag pulled the frail cart along.",
|
||||
"Twist the valve and release hot steam.",
|
||||
"The vamp of the shoe had a gold buckle.",
|
||||
"The smell of burned rags itches my nose.",
|
||||
"New pants lack cuffs and pockets.",
|
||||
"The marsh will freeze when cold enough.",
|
||||
"They slice the sausage thin with a knife.",
|
||||
"The bloom of the rose lasts a few days.",
|
||||
"A gray mare walked before the colt.",
|
||||
"Breakfast buns are fine with a hot drink.",
|
||||
"Bottles hold four kinds of rum.",
|
||||
"The man wore a feather in his felt hat.",
|
||||
"He wheeled the bike past the winding road.",
|
||||
"Drop the ashes on the worn old rug.",
|
||||
"The desk and both chairs were painted tan.",
|
||||
"Throw out the used paper cup and plate.",
|
||||
"A clean neck means a neat collar.",
|
||||
"The couch cover and hall drapes were blue.",
|
||||
"The stems of the tall glasses cracked and broke.",
|
||||
"The wall phone rang loud and often.",
|
||||
"The clothes dried on a thin wooden rack.",
|
||||
"Turn out the lantern which gives us light.",
|
||||
"The cleat sank deeply into the soft turf.",
|
||||
"The bills were mailed promptly on the tenth of the month.",
|
||||
"To have is better than to wait and hope.",
|
||||
"The price is fair for a good antique clock.",
|
||||
"The music played on while they talked.",
|
||||
"Dispense with a vest on a day like this.",
|
||||
"The bunch of grapes was pressed into wine.",
|
||||
"He sent the figs, but kept the ripe cherries.",
|
||||
"The hinge on the door creaked with old age.",
|
||||
"The screen before the fire kept in the sparks.",
|
||||
"Fly by night and you waste little time.",
|
||||
"Thick glasses helped him read the print.",
|
||||
"Birth and death marks the limits of life.",
|
||||
"The chair looked strong but had no bottom.",
|
||||
"The kite flew wildly in the high wind.",
|
||||
"A fur muff is stylish once more.",
|
||||
"The tin box held priceless stones.",
|
||||
"We need an end of all such matter.",
|
||||
"The case was puzzling to the old and wise.",
|
||||
"The bright lanterns were gay on the dark lawn.",
|
||||
"We don't get much money but we have fun.",
|
||||
"The youth drove with zest, but little skill.",
|
||||
"Five years he lived with a shaggy dog.",
|
||||
"A fence cuts through the corner lot.",
|
||||
"The way to save money is not to spend much.",
|
||||
"Shut the hatch before the waves push it in.",
|
||||
"The odor of spring makes young hearts jump.",
|
||||
"Crack the walnut with your sharp side teeth.",
|
||||
"He offered proof in the form of a large chart.",
|
||||
"Send the stuff in a thick paper bag.",
|
||||
"A quart of milk is water for the most part.",
|
||||
"They told wild tales to frighten him.",
|
||||
"The three story house was built of stone.",
|
||||
"In the rear of the ground floor was a large passage.",
|
||||
"A man in a blue sweater sat at the desk.",
|
||||
"Oats are a food eaten by horse and man.",
|
||||
"Their eyelids droop for want of sleep.",
|
||||
"A sip of tea revives his tired friend.",
|
||||
"There are many ways to do these things.",
|
||||
"Tuck the sheet under the edge of the mat.",
|
||||
"A force equal to that would move the earth.",
|
||||
"We like to see clear weather.",
|
||||
"The work of the tailor is seen on each side.",
|
||||
"Take a chance and win a china doll.",
|
||||
"Shake the dust from your shoes, stranger.",
|
||||
"She was kind to sick old people.",
|
||||
"The square wooden crate was packed to be shipped.",
|
||||
"The dusty bench stood by the stone wall.",
|
||||
"We dress to suit the weather of most days.",
|
||||
"Smile when you say nasty words.",
|
||||
"A bowl of rice is free with chicken stew.",
|
||||
"The water in this well is a source of good health.",
|
||||
"Take shelter in this tent, but keep still.",
|
||||
"That guy is the writer of a few banned books.",
|
||||
"The little tales they tell are false.",
|
||||
"The door was barred, locked, and bolted as well.",
|
||||
"Ripe pears are fit for a queen's table.",
|
||||
"A big wet stain was on the round carpet.",
|
||||
"The kite dipped and swayed, but stayed aloft.",
|
||||
"The pleasant hours fly by much too soon.",
|
||||
"The room was crowded with a wild mob.",
|
||||
"This strong arm shall shield your honor.",
|
||||
"She blushed when he gave her a white orchid.",
|
||||
"The beetle droned in the hot June sun.",
|
||||
"Press the pedal with your left foot.",
|
||||
"Neat plans fail without luck.",
|
||||
"The black trunk fell from the landing.",
|
||||
"The bank pressed for payment of the debt.",
|
||||
"The theft of the pearl pin was kept secret.",
|
||||
"Shake hands with this friendly child.",
|
||||
"The vast space stretched into the far distance.",
|
||||
"A rich farm is rare in this sandy waste.",
|
||||
"His wide grin earned many friends.",
|
||||
"Flax makes a fine brand of paper.",
|
||||
"Hurdle the pit with the aid of a long pole.",
|
||||
"A strong bid may scare your partner stiff.",
|
||||
"Even a just cause needs power to win.",
|
||||
"Peep under the tent and see the clowns.",
|
||||
"The leaf drifts along with a slow spin.",
|
||||
"Cheap clothes are flashy but don't last.",
|
||||
"A thing of small note can cause despair.",
|
||||
"Flood the mails with requests for this book.",
|
||||
"A thick coat of black paint covered all.",
|
||||
"The pencil was cut to be sharp at both ends.",
|
||||
"Those last words were a strong statement.",
|
||||
"He wrote his name boldly at the top of the sheet.",
|
||||
"Dill pickles are sour but taste fine.",
|
||||
"Down that road is the way to the grain farmer.",
|
||||
"Either mud or dust are found at all times.",
|
||||
"The best method is to fix it in place with clips.",
|
||||
"If you mumble your speech will be lost.",
|
||||
"At night the alarm roused him from a deep sleep.",
|
||||
"Read just what the meter says.",
|
||||
"Fill your pack with bright trinkets for the poor.",
|
||||
"The small red neon lamp went out.",
|
||||
"Clams are small, round, soft, and tasty.",
|
||||
"The fan whirled its round blades softly.",
|
||||
"The line where the edges join was clean.",
|
||||
"Breathe deep and smell the piny air.",
|
||||
"It matters not if he reads these words or those.",
|
||||
"A brown leather bag hung from its strap.",
|
||||
"A toad and a frog are hard to tell apart.",
|
||||
"A white silk jacket goes with any shoes.",
|
||||
"A break in the dam almost caused a flood.",
|
||||
"Paint the sockets in the wall dull green.",
|
||||
"The child crawled into the dense grass.",
|
||||
"Bribes fail where honest men work.",
|
||||
"Trample the spark, else the flames will spread.",
|
||||
"The hilt of the sword was carved with fine designs.",
|
||||
"A round hole was drilled through the thin board.",
|
||||
"Footprints showed the path he took up the beach.",
|
||||
"She was waiting at my front lawn.",
|
||||
"A vent near the edge brought in fresh air.",
|
||||
"Prod the old mule with a crooked stick.",
|
||||
"It is a band of steel three inches wide.",
|
||||
"The pipe ran almost the length of the ditch.",
|
||||
"It was hidden from sight by a mass of leaves and shrubs.",
|
||||
"The weight of the package was seen on the high scale.",
|
||||
"Wake and rise, and step into the green outdoors.",
|
||||
"The green light in the brown box flickered.",
|
||||
"The brass tube circled the high wall.",
|
||||
"The lobes of her ears were pierced to hold rings.",
|
||||
"Hold the hammer near the end to drive the nail.",
|
||||
"Next Sunday is the twelfth of the month.",
|
||||
"Every word and phrase he speaks is true.",
|
||||
"He put his last cartridge into the gun and fired.",
|
||||
"They took their kids from the public school.",
|
||||
"Drive the screw straight into the wood.",
|
||||
"Keep the hatch tight and the watch constant.",
|
||||
"Sever the twine with a quick snip of the knife.",
|
||||
"Paper will dry out when wet.",
|
||||
"Slide the catch back and open the desk.",
|
||||
"Help the weak to preserve their strength.",
|
||||
"A sullen smile gets few friends.",
|
||||
"Stop whistling and watch the boys march.",
|
||||
"Jerk the cord, and out tumbles the gold.",
|
||||
"Slide the tray across the glass top.",
|
||||
"The cloud moved in a stately way and was gone.",
|
||||
"Light maple makes for a swell room.",
|
||||
"Set the piece here and say nothing.",
|
||||
"Dull stories make her laugh.",
|
||||
"A stiff cord will do to fasten your shoe.",
|
||||
"Get the trust fund to the bank early.",
|
||||
"Choose between the high road and the low.",
|
||||
"A plea for funds seems to come again.",
|
||||
"He lent his coat to the tall gaunt stranger.",
|
||||
"There is a strong chance it will happen once more.",
|
||||
"The duke left the park in a silver coach.",
|
||||
"Greet the new guests and leave quickly.",
|
||||
"When the frost has come it is time for turkey.",
|
||||
"Sweet words work better than fierce.",
|
||||
"A thin stripe runs down the middle.",
|
||||
"A six comes up more often than a ten.",
|
||||
"Lush ferns grow on the lofty rocks.",
|
||||
"The ram scared the school children off.",
|
||||
"The team with the best timing looks good.",
|
||||
"The farmer swapped his horse for a brown ox.",
|
||||
"Sit on the perch and tell the others what to do.",
|
||||
"A steep trail is painful for our feet.",
|
||||
"The early phase of life moves fast.",
|
||||
"Green moss grows on the northern side.",
|
||||
"Tea in thin china has a sweet taste.",
|
||||
"Pitch the straw through the door of the stable.",
|
||||
"The latch on the back gate needed a nail.",
|
||||
"The goose was brought straight from the old market.",
|
||||
"The sink is the thing in which we pile dishes.",
|
||||
"A whiff of it will cure the most stubborn cold.",
|
||||
"The facts don't always show who is right.",
|
||||
"She flaps her cape as she parades the street.",
|
||||
"The loss of the cruiser was a blow to the fleet.",
|
||||
"Loop the braid to the left and then over.",
|
||||
"Plead with the lawyer to drop the lost cause.",
|
||||
"Calves thrive on tender spring grass.",
|
||||
"Post no bills on this office wall.",
|
||||
"Tear a thin sheet from the yellow pad.",
|
||||
"A cruise in warm waters in a sleek yacht is fun.",
|
||||
"A streak of color ran down the left edge.",
|
||||
"It was done before the boy could see it.",
|
||||
"Crouch before you jump or miss the mark.",
|
||||
"Pack the kits and don't forget the salt.",
|
||||
"The square peg will settle in the round hole.",
|
||||
"Fine soap saves tender skin.",
|
||||
"Poached eggs and tea must suffice.",
|
||||
"Bad nerves are jangled by a door slam.",
|
||||
"Ship maps are different from those for planes.",
|
||||
"Dimes showered down from all sides.",
|
||||
"They sang the same tunes at each party.",
|
||||
"The sky in the west is tinged with orange red.",
|
||||
"The pods of peas ferment in bare fields.",
|
||||
"The horse balked and threw the tall rider.",
|
||||
"The hitch between the horse and cart broke.",
|
||||
"Pile the coal high in the shed corner.",
|
||||
"A gold vase is both rare and costly.",
|
||||
"The knife was hung inside its bright sheath.",
|
||||
"The rarest spice comes from the far East.",
|
||||
"The roof should be tilted at a sharp slant.",
|
||||
"A smatter of French is worse than none.",
|
||||
"The mule trod the treadmill day and night.",
|
||||
"The aim of the contest is to raise a great fund.",
|
||||
"To send it now in large amounts is bad.",
|
||||
"There is a fine hard tang in salty air.",
|
||||
"Cod is the main business of the north shore.",
|
||||
"The slab was hewn from heavy blocks of slate.",
|
||||
"Dunk the stale biscuits into strong drink.",
|
||||
"Hang tinsel from both branches.",
|
||||
"Cap the jar with a tight brass cover.",
|
||||
"The poor boy missed the boat again.",
|
||||
"Be sure to set that lamp firmly in the hole.",
|
||||
"Pick a card and slip it under the pack.",
|
||||
"A round mat will cover the dull spot.",
|
||||
"The first part of the plan needs changing.",
|
||||
"A good book informs of what we ought to know.",
|
||||
"The mail comes in three batches per day.",
|
||||
"You cannot brew tea in a cold pot.",
|
||||
"Dots of light betrayed the black cat.",
|
||||
"Put the chart on the mantel and tack it down.",
|
||||
"The night shift men rate extra pay.",
|
||||
"The red paper brightened the dim stage.",
|
||||
"See the player scoot to third base.",
|
||||
"Slide the bill between the two leaves.",
|
||||
"Many hands help get the job done.",
|
||||
"We don't like to admit our small faults.",
|
||||
"No doubt about the way the wind blows.",
|
||||
"Dig deep in the earth for pirate's gold.",
|
||||
"The steady drip is worse than a drenching rain.",
|
||||
"A flat pack takes less luggage space.",
|
||||
"Green ice frosted the punch bowl.",
|
||||
"A stuffed chair slipped from the moving van.",
|
||||
"The stitch will serve but needs to be shortened.",
|
||||
"A thin book fits in the side pocket.",
|
||||
"The gloss on top made it unfit to read.",
|
||||
"The hail pattered on the burnt brown grass.",
|
||||
"Seven seals were stamped on great sheets.",
|
||||
"Our troops are set to strike heavy blows.",
|
||||
"The store was jammed before the sale could start.",
|
||||
"It was a bad error on the part of the new judge.",
|
||||
"One step more and the board will collapse.",
|
||||
"Take the match and strike it against your shoe.",
|
||||
"The pot boiled but the contents failed to jell.",
|
||||
"The baby puts his right foot in his mouth.",
|
||||
"The bombs left most of the town in ruins.",
|
||||
"Stop and stare at the hard working man.",
|
||||
"The streets are narrow and full of sharp turns.",
|
||||
"The pup jerked the leash as he saw a feline shape.",
|
||||
"Open your book to the first page.",
|
||||
"Fish evade the net and swim off.",
|
||||
"Dip the pail once and let it settle.",
|
||||
"Will you please answer that phone.",
|
||||
"The big red apple fell to the ground.",
|
||||
"The curtain rose and the show was on.",
|
||||
"The young prince became heir to the throne.",
|
||||
"He sent the boy on a short errand.",
|
||||
"Leave now and you will arrive on time.",
|
||||
"The corner store was robbed last night.",
|
||||
"A gold ring will please most any girl.",
|
||||
"The long journey home took a year.",
|
||||
"She saw a cat in the neighbor's house.",
|
||||
"A pink shell was found on the sandy beach.",
|
||||
"Small children came to see him.",
|
||||
"The grass and bushes were wet with dew.",
|
||||
"The blind man counted his old coins.",
|
||||
"A severe storm tore down the barn.",
|
||||
"She called his name many times.",
|
||||
"When you hear the bell, come quickly.",
|
||||
NULL};
|
||||
BIN
widget/milsko/milskosrc/examples/picture.jpg
Normal file
BIN
widget/milsko/milskosrc/examples/picture.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
BIN
widget/milsko/milskosrc/examples/picture.png
Normal file
BIN
widget/milsko/milskosrc/examples/picture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
30
widget/milsko/milskosrc/examples/vkdemos/CMakeLists.txt
Normal file
30
widget/milsko/milskosrc/examples/vkdemos/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
file(
|
||||
GLOB
|
||||
EXAMPLES_VULKAN_SOURCES
|
||||
*.c
|
||||
)
|
||||
find_package(Vulkan)
|
||||
|
||||
if(${Vulkan_FOUND})
|
||||
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()
|
||||
endif()
|
||||
BIN
widget/milsko/milskosrc/examples/vkdemos/triangle.frag.spv
Normal file
BIN
widget/milsko/milskosrc/examples/vkdemos/triangle.frag.spv
Normal file
Binary file not shown.
BIN
widget/milsko/milskosrc/examples/vkdemos/triangle.vert.spv
Normal file
BIN
widget/milsko/milskosrc/examples/vkdemos/triangle.vert.spv
Normal file
Binary file not shown.
629
widget/milsko/milskosrc/examples/vkdemos/vulkan.c
Normal file
629
widget/milsko/milskosrc/examples/vkdemos/vulkan.c
Normal file
|
|
@ -0,0 +1,629 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/Vulkan.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#ifdef HAS_VK_ENUM_STRING_HELPER
|
||||
#include <vulkan/vk_enum_string_helper.h>
|
||||
#else
|
||||
char buffer[512];
|
||||
|
||||
char* string_VkResult(VkResult res) {
|
||||
MwStringPrintIntoBuffer(buffer, 512, "%d", res);
|
||||
|
||||
return &buffer[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
MwWidget window, vulkan;
|
||||
int ow = 300;
|
||||
int oh = 250;
|
||||
|
||||
double timer = 0;
|
||||
|
||||
PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr;
|
||||
VkInstance instance;
|
||||
VkDevice device;
|
||||
VkPhysicalDevice physicalDevice;
|
||||
VkSurfaceKHR surface;
|
||||
VkQueue graphicsQueue;
|
||||
VkQueue presentQueue;
|
||||
uint32_t* graphicsQueueIndex;
|
||||
uint32_t* presentQueueIndex;
|
||||
|
||||
VkSwapchainKHR swapchain;
|
||||
VkImage* swapchainImages;
|
||||
VkImageView* swapchainImageView;
|
||||
uint32_t swapchainImageViewCount;
|
||||
uint32_t currentImageIndex;
|
||||
uint32_t frameNumber;
|
||||
|
||||
VkFence* fences;
|
||||
VkSemaphore* renderFinishedSemaphores;
|
||||
VkSemaphore* imageAvaliableSemaphores;
|
||||
|
||||
VkFramebuffer* framebuffers;
|
||||
|
||||
VkPipeline pipeline;
|
||||
VkCommandBuffer* cmdBuffers;
|
||||
VkRenderPass renderPass;
|
||||
|
||||
VkResult res;
|
||||
|
||||
VkSwapchainCreateInfoKHR swapchainCreateInfo = {};
|
||||
|
||||
#define MAX_FRAMES_IN_FLIGHT swapchainImageViewCount
|
||||
|
||||
// convienence macro for loading a vulkan function pointer into memory
|
||||
#define LOAD_VK_FUNCTION(name) \
|
||||
PFN_##name _##name = (PFN_##name)_vkGetInstanceProcAddr(instance, #name); \
|
||||
assert(_##name);
|
||||
|
||||
void MWAPI tick(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {};
|
||||
VkRenderPassBeginInfo renderPassInfo = {};
|
||||
VkSubmitInfo submitInfo = {};
|
||||
VkPresentInfoKHR presentInfo = {};
|
||||
|
||||
VkClearValue clearColor = {{{sin(timer) / 10., cos(timer) / 10., atan(timer) / 10., 1.0f}}};
|
||||
uint32_t vertexCount = 3;
|
||||
uint32_t instanceCount = 1;
|
||||
timer += (float)(rand() % 1000) / 1000.;
|
||||
|
||||
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT};
|
||||
|
||||
LOAD_VK_FUNCTION(vkCreateFence);
|
||||
LOAD_VK_FUNCTION(vkWaitForFences);
|
||||
LOAD_VK_FUNCTION(vkResetFences);
|
||||
LOAD_VK_FUNCTION(vkResetCommandBuffer);
|
||||
LOAD_VK_FUNCTION(vkBeginCommandBuffer);
|
||||
LOAD_VK_FUNCTION(vkEndCommandBuffer);
|
||||
LOAD_VK_FUNCTION(vkQueueSubmit);
|
||||
LOAD_VK_FUNCTION(vkAcquireNextImageKHR);
|
||||
LOAD_VK_FUNCTION(vkQueuePresentKHR);
|
||||
LOAD_VK_FUNCTION(vkCreateSwapchainKHR);
|
||||
|
||||
LOAD_VK_FUNCTION(vkCmdBeginRenderPass);
|
||||
LOAD_VK_FUNCTION(vkCmdEndRenderPass);
|
||||
LOAD_VK_FUNCTION(vkCmdDraw);
|
||||
LOAD_VK_FUNCTION(vkCmdBindPipeline);
|
||||
|
||||
if((res = _vkWaitForFences(device, 1, &fences[frameNumber], VK_TRUE, UINT64_MAX)) != VK_SUCCESS) {
|
||||
printf("error waiting on fence: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if((res = _vkResetFences(device, 1, &fences[frameNumber])) != VK_SUCCESS) {
|
||||
printf("error resetting fence: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
swapchainRetry:
|
||||
if((res = _vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, imageAvaliableSemaphores[frameNumber], NULL, ¤tImageIndex)) != VK_SUCCESS) {
|
||||
if(res == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
if(_vkCreateSwapchainKHR(device, &swapchainCreateInfo, NULL, &swapchain) != VK_SUCCESS) {
|
||||
printf("failed to create swapchain: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
};
|
||||
goto swapchainRetry;
|
||||
}
|
||||
};
|
||||
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.pNext = NULL;
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
beginInfo.pInheritanceInfo = NULL;
|
||||
|
||||
if((res = _vkResetCommandBuffer(cmdBuffers[frameNumber], 0)) != VK_SUCCESS) {
|
||||
printf("error beginning command buffer record: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if((res = _vkBeginCommandBuffer(cmdBuffers[frameNumber], &beginInfo)) != VK_SUCCESS) {
|
||||
printf("error beginning command buffer record: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
renderPassInfo.pNext = NULL;
|
||||
renderPassInfo.renderPass = renderPass;
|
||||
renderPassInfo.framebuffer = framebuffers[frameNumber];
|
||||
renderPassInfo.renderArea.offset = (VkOffset2D){0, 0};
|
||||
renderPassInfo.renderArea.extent = (VkExtent2D){(uint32_t)ow, (uint32_t)oh};
|
||||
renderPassInfo.clearValueCount = 1;
|
||||
renderPassInfo.pClearValues = &clearColor;
|
||||
|
||||
_vkCmdBeginRenderPass(cmdBuffers[frameNumber], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
_vkCmdBindPipeline(cmdBuffers[frameNumber], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||
|
||||
_vkCmdDraw(cmdBuffers[frameNumber], vertexCount, instanceCount, 0, 0);
|
||||
|
||||
_vkCmdEndRenderPass(cmdBuffers[frameNumber]);
|
||||
|
||||
if((res = _vkEndCommandBuffer(cmdBuffers[frameNumber])) != VK_SUCCESS) {
|
||||
printf("error recording command buffer: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.pNext = NULL;
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &imageAvaliableSemaphores[frameNumber];
|
||||
submitInfo.pWaitDstStageMask = waitStages;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &cmdBuffers[frameNumber];
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = &renderFinishedSemaphores[frameNumber];
|
||||
|
||||
if((res = _vkQueueSubmit(graphicsQueue, 1, &submitInfo, fences[frameNumber])) != VK_SUCCESS) {
|
||||
printf("error submitting command buffer: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
|
||||
presentInfo.waitSemaphoreCount = 1;
|
||||
presentInfo.pWaitSemaphores = &renderFinishedSemaphores[frameNumber];
|
||||
presentInfo.swapchainCount = 1;
|
||||
presentInfo.pSwapchains = &swapchain;
|
||||
presentInfo.pImageIndices = ¤tImageIndex;
|
||||
|
||||
presentInfo.pResults = NULL; // Optional
|
||||
|
||||
_vkQueuePresentKHR(presentQueue, &presentInfo);
|
||||
|
||||
// frameNumber = currentImageIndex;
|
||||
frameNumber = (frameNumber + 1) % (MAX_FRAMES_IN_FLIGHT);
|
||||
}
|
||||
|
||||
void vulkan_setup(MwWidget handle) {
|
||||
FILE* vertFile;
|
||||
FILE* fragFile;
|
||||
void* vertBuf;
|
||||
void* fragBuf;
|
||||
size_t vertFileSize;
|
||||
size_t fragFileSize;
|
||||
size_t amountRead;
|
||||
|
||||
uint32_t i;
|
||||
VkViewport viewport = {};
|
||||
VkRect2D scissor = {};
|
||||
VkCommandPool cmdPool = VK_NULL_HANDLE;
|
||||
VkResult res = 0;
|
||||
VkShaderModule fragShaderModule;
|
||||
VkShaderModule vertShaderModule;
|
||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||
VkAttachmentDescription colorAttachment = {};
|
||||
VkAttachmentReference colorAttachmentRef = {};
|
||||
VkSubpassDescription subpass = {};
|
||||
|
||||
VkRenderPassCreateInfo renderPassInfo = {};
|
||||
VkShaderModuleCreateInfo vertInfo = {};
|
||||
VkShaderModuleCreateInfo fragInfo = {};
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
|
||||
VkPipelineShaderStageCreateInfo fragShaderStageInfo = {};
|
||||
VkPipelineShaderStageCreateInfo shaderStages[2] = {};
|
||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
|
||||
VkPipelineViewportStateCreateInfo viewportState = {};
|
||||
VkPipelineRasterizationStateCreateInfo rasterizer = {};
|
||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
|
||||
VkPipelineColorBlendStateCreateInfo colorBlending = {};
|
||||
VkGraphicsPipelineCreateInfo pipelineInfo = {};
|
||||
VkFramebufferCreateInfo framebufferInfo = {};
|
||||
VkCommandBufferAllocateInfo allocInfo = {};
|
||||
VkCommandPoolCreateInfo poolInfo = {};
|
||||
VkImageViewCreateInfo imageViewCreateInfo = {};
|
||||
VkSemaphoreCreateInfo semaphoreInfo = {};
|
||||
VkFenceCreateInfo fenceInfo = {};
|
||||
|
||||
int err = 0;
|
||||
_vkGetInstanceProcAddr = MwVulkanGetField(handle, MwVULKANFIELD_GETINSTANCEPROCADDR, &err);
|
||||
instance = MwVulkanGetField(handle, MwVULKANFIELD_INSTANCE, &err);
|
||||
device = MwVulkanGetField(handle, MwVULKANFIELD_LOGICALDEVICE, &err);
|
||||
physicalDevice = MwVulkanGetField(handle, MwVULKANFIELD_PHYSICALDEVICE, &err);
|
||||
graphicsQueue = MwVulkanGetField(handle, MwVULKANFIELD_GRAPHICSQUEUE, &err);
|
||||
presentQueue = MwVulkanGetField(handle, MwVULKANFIELD_PRESENTQUEUE, &err);
|
||||
surface = MwVulkanGetField(handle, MwVULKANFIELD_SURFACE, &err);
|
||||
presentQueueIndex = MwVulkanGetField(handle, MwVULKANFIELD_PRESENTQUEUEINDEX, &err);
|
||||
graphicsQueueIndex = MwVulkanGetField(handle, MwVULKANFIELD_GRAPHICSQUEUEINDEX, &err);
|
||||
|
||||
LOAD_VK_FUNCTION(vkCreateShaderModule);
|
||||
LOAD_VK_FUNCTION(vkCreatePipelineLayout);
|
||||
LOAD_VK_FUNCTION(vkCreateGraphicsPipelines);
|
||||
LOAD_VK_FUNCTION(vkCreateCommandPool);
|
||||
LOAD_VK_FUNCTION(vkCreateFramebuffer);
|
||||
LOAD_VK_FUNCTION(vkAllocateCommandBuffers);
|
||||
LOAD_VK_FUNCTION(vkCreateFence);
|
||||
LOAD_VK_FUNCTION(vkCreateSemaphore);
|
||||
LOAD_VK_FUNCTION(vkCreateSwapchainKHR);
|
||||
LOAD_VK_FUNCTION(vkGetSwapchainImagesKHR);
|
||||
LOAD_VK_FUNCTION(vkCreateImageView);
|
||||
LOAD_VK_FUNCTION(vkCreateRenderPass);
|
||||
|
||||
// create a swapchain
|
||||
swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
swapchainCreateInfo.surface = surface;
|
||||
swapchainCreateInfo.minImageCount = 3;
|
||||
swapchainCreateInfo.imageFormat = VK_FORMAT_B8G8R8A8_SRGB;
|
||||
swapchainCreateInfo.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
swapchainCreateInfo.imageExtent = (VkExtent2D){.width = ow, .height = oh},
|
||||
swapchainCreateInfo.imageArrayLayers = 1,
|
||||
swapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
// th is how we specify no transformation.
|
||||
swapchainCreateInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
swapchainCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
swapchainCreateInfo.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
// we don't care about the color of pixels that are obscured.
|
||||
swapchainCreateInfo.clipped = VK_TRUE;
|
||||
swapchainCreateInfo.oldSwapchain = NULL;
|
||||
|
||||
if(*graphicsQueueIndex != *presentQueueIndex) {
|
||||
swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||
swapchainCreateInfo.queueFamilyIndexCount = 2;
|
||||
|
||||
uint32_t indices[] = {
|
||||
*graphicsQueueIndex,
|
||||
*presentQueueIndex,
|
||||
};
|
||||
swapchainCreateInfo.pQueueFamilyIndices = indices;
|
||||
} else {
|
||||
swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
swapchainCreateInfo.queueFamilyIndexCount = 0;
|
||||
swapchainCreateInfo.pQueueFamilyIndices = NULL;
|
||||
}
|
||||
|
||||
if(_vkCreateSwapchainKHR(device, &swapchainCreateInfo, NULL, &swapchain) != VK_SUCCESS) {
|
||||
printf("failed to create swapchain: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
};
|
||||
|
||||
imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
imageViewCreateInfo.format = swapchainCreateInfo.imageFormat;
|
||||
imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_R;
|
||||
imageViewCreateInfo.components.g = VK_COMPONENT_SWIZZLE_G;
|
||||
imageViewCreateInfo.components.b = VK_COMPONENT_SWIZZLE_B;
|
||||
imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_A;
|
||||
imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
imageViewCreateInfo.subresourceRange.baseMipLevel = 0;
|
||||
imageViewCreateInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||
imageViewCreateInfo.subresourceRange.baseArrayLayer = 0;
|
||||
imageViewCreateInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
|
||||
if(_vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageViewCount, NULL) != VK_SUCCESS) {
|
||||
printf("failed to get swapchain images: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
swapchainImages = malloc(sizeof(VkImage) * MAX_FRAMES_IN_FLIGHT);
|
||||
swapchainImageView = malloc(sizeof(VkImageView) * MAX_FRAMES_IN_FLIGHT);
|
||||
_vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageViewCount, swapchainImages);
|
||||
for(i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
imageViewCreateInfo.image = swapchainImages[i];
|
||||
if(_vkCreateImageView(device, &imageViewCreateInfo, NULL, &swapchainImageView[i]) != VK_SUCCESS) {
|
||||
printf("failed to get swapchain images: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a Render Pass.
|
||||
colorAttachment.flags = 0;
|
||||
colorAttachment.format = swapchainCreateInfo.imageFormat;
|
||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
colorAttachmentRef.attachment = 0;
|
||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
subpass.flags = 0;
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.inputAttachmentCount = 0;
|
||||
subpass.pInputAttachments = NULL;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = &colorAttachmentRef;
|
||||
subpass.pResolveAttachments = NULL;
|
||||
subpass.pDepthStencilAttachment = NULL;
|
||||
subpass.preserveAttachmentCount = 0;
|
||||
subpass.pPreserveAttachments = NULL;
|
||||
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
renderPassInfo.pNext = NULL;
|
||||
renderPassInfo.flags = 0;
|
||||
renderPassInfo.attachmentCount = 1;
|
||||
renderPassInfo.pAttachments = &colorAttachment;
|
||||
renderPassInfo.subpassCount = 1;
|
||||
renderPassInfo.pSubpasses = &subpass;
|
||||
renderPassInfo.dependencyCount = 0;
|
||||
renderPassInfo.pDependencies = NULL;
|
||||
|
||||
if((res = _vkCreateRenderPass(device, &renderPassInfo, NULL, &renderPass)) != VK_SUCCESS) {
|
||||
printf("error creating the render pass: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Create the Vertex Shader Module.
|
||||
vertFile = fopen("triangle.vert.spv", "rb");
|
||||
if(vertFile == NULL) vertFile = fopen("examples/vkdemos/triangle.vert.spv", "rb");
|
||||
fragFile = fopen("triangle.frag.spv", "rb");
|
||||
if(fragFile == NULL) fragFile = fopen("examples/vkdemos/triangle.frag.spv", "rb");
|
||||
|
||||
fseek(vertFile, 0L, SEEK_END);
|
||||
vertFileSize = ftell(vertFile);
|
||||
rewind(vertFile);
|
||||
vertBuf = malloc(vertFileSize);
|
||||
memset(vertBuf, 0, vertFileSize);
|
||||
amountRead = fread(vertBuf, 1, vertFileSize, vertFile);
|
||||
printf("triangle.vert.spv: read %zu bytes\n", amountRead);
|
||||
|
||||
vertInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
vertInfo.pNext = NULL;
|
||||
vertInfo.flags = 0;
|
||||
vertInfo.codeSize = amountRead;
|
||||
vertInfo.pCode = vertBuf;
|
||||
|
||||
if(_vkCreateShaderModule(device, &vertInfo, NULL, &vertShaderModule) != VK_SUCCESS) {
|
||||
printf("failed to create the shader module: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Create the Fragment Shader Module.
|
||||
fseek(fragFile, 0L, SEEK_END);
|
||||
fragFileSize = ftell(fragFile);
|
||||
rewind(fragFile);
|
||||
fragBuf = malloc(fragFileSize);
|
||||
memset(fragBuf, 0, fragFileSize);
|
||||
amountRead = fread(fragBuf, 1, fragFileSize, fragFile);
|
||||
printf("triangle.frag.spv: read %zu bytes\n", amountRead);
|
||||
|
||||
fragInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
fragInfo.pNext = NULL;
|
||||
fragInfo.flags = 0;
|
||||
fragInfo.codeSize = amountRead;
|
||||
fragInfo.pCode = fragBuf;
|
||||
|
||||
if(_vkCreateShaderModule(device, &fragInfo, NULL, &fragShaderModule) != VK_SUCCESS) {
|
||||
printf("error creating the shader module: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Create Pipeline Layout.
|
||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
pipelineLayoutInfo.pNext = NULL;
|
||||
pipelineLayoutInfo.flags = 0;
|
||||
pipelineLayoutInfo.setLayoutCount = 0;
|
||||
pipelineLayoutInfo.pSetLayouts = NULL;
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 0;
|
||||
|
||||
if((res = _vkCreatePipelineLayout(device, &pipelineLayoutInfo, NULL, &pipelineLayout)) != VK_SUCCESS) {
|
||||
printf("error creating the pipeline layout: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
vertShaderStageInfo.pNext = NULL;
|
||||
vertShaderStageInfo.flags = 0;
|
||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
vertShaderStageInfo.module = vertShaderModule;
|
||||
vertShaderStageInfo.pName = "main";
|
||||
vertShaderStageInfo.pSpecializationInfo = NULL;
|
||||
|
||||
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
fragShaderStageInfo.pNext = NULL;
|
||||
fragShaderStageInfo.flags = 0;
|
||||
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
fragShaderStageInfo.module = fragShaderModule;
|
||||
fragShaderStageInfo.pName = "main";
|
||||
fragShaderStageInfo.pSpecializationInfo = NULL;
|
||||
|
||||
shaderStages[0] = vertShaderStageInfo;
|
||||
shaderStages[1] = fragShaderStageInfo;
|
||||
|
||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
vertexInputInfo.pNext = NULL;
|
||||
vertexInputInfo.flags = 0;
|
||||
vertexInputInfo.vertexBindingDescriptionCount = 0;
|
||||
vertexInputInfo.pVertexBindingDescriptions = NULL;
|
||||
vertexInputInfo.vertexAttributeDescriptionCount = 0;
|
||||
vertexInputInfo.pVertexAttributeDescriptions = NULL;
|
||||
|
||||
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
inputAssembly.pNext = NULL;
|
||||
inputAssembly.flags = 0;
|
||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
inputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||
|
||||
viewport.x = 0.0f;
|
||||
viewport.y = 0.0f;
|
||||
viewport.width = (float)ow;
|
||||
viewport.height = (float)oh;
|
||||
viewport.minDepth = 0.0f;
|
||||
viewport.maxDepth = 1.0f;
|
||||
|
||||
scissor.offset = (VkOffset2D){0, 0};
|
||||
scissor.extent = (VkExtent2D){(uint32_t)viewport.width, (uint32_t)viewport.height};
|
||||
|
||||
viewportState = (VkPipelineViewportStateCreateInfo){};
|
||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||
viewportState.viewportCount = 1;
|
||||
viewportState.pViewports = &viewport;
|
||||
viewportState.scissorCount = 1;
|
||||
viewportState.pScissors = &scissor;
|
||||
|
||||
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||
rasterizer.pNext = NULL;
|
||||
rasterizer.flags = 0;
|
||||
rasterizer.depthClampEnable = VK_FALSE;
|
||||
rasterizer.rasterizerDiscardEnable = VK_FALSE;
|
||||
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||
rasterizer.depthBiasEnable = VK_FALSE;
|
||||
rasterizer.depthBiasConstantFactor = 0.0;
|
||||
rasterizer.depthBiasClamp = 0.0;
|
||||
rasterizer.depthBiasSlopeFactor = 0.0;
|
||||
rasterizer.lineWidth = 1.0f;
|
||||
|
||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||
multisampling.pNext = NULL;
|
||||
multisampling.flags = 0;
|
||||
multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
multisampling.sampleShadingEnable = VK_FALSE;
|
||||
multisampling.minSampleShading = 0.0;
|
||||
multisampling.pSampleMask = NULL;
|
||||
multisampling.alphaToCoverageEnable = VK_FALSE;
|
||||
multisampling.alphaToOneEnable = VK_FALSE;
|
||||
|
||||
colorBlendAttachment.blendEnable = VK_FALSE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
colorBlending.pNext = NULL;
|
||||
colorBlending.flags = 0;
|
||||
colorBlending.logicOpEnable = VK_FALSE;
|
||||
colorBlending.logicOp = VK_LOGIC_OP_COPY;
|
||||
colorBlending.attachmentCount = 1;
|
||||
colorBlending.pAttachments = &colorBlendAttachment;
|
||||
colorBlending.blendConstants[0] = 0.0f;
|
||||
colorBlending.blendConstants[1] = 0.0f;
|
||||
colorBlending.blendConstants[2] = 0.0f;
|
||||
colorBlending.blendConstants[3] = 0.0f;
|
||||
|
||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
pipelineInfo.pNext = NULL;
|
||||
pipelineInfo.flags = 0;
|
||||
pipelineInfo.stageCount = 2;
|
||||
pipelineInfo.pStages = shaderStages;
|
||||
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
||||
pipelineInfo.pInputAssemblyState = &inputAssembly;
|
||||
pipelineInfo.pTessellationState = NULL;
|
||||
pipelineInfo.pViewportState = &viewportState;
|
||||
pipelineInfo.pRasterizationState = &rasterizer;
|
||||
pipelineInfo.pMultisampleState = &multisampling;
|
||||
pipelineInfo.pDepthStencilState = NULL;
|
||||
pipelineInfo.pColorBlendState = &colorBlending;
|
||||
pipelineInfo.pDynamicState = NULL;
|
||||
pipelineInfo.layout = pipelineLayout;
|
||||
pipelineInfo.renderPass = renderPass;
|
||||
pipelineInfo.subpass = 0;
|
||||
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
pipelineInfo.basePipelineIndex = 0;
|
||||
|
||||
if((res = _vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &pipeline)) != VK_SUCCESS) {
|
||||
printf("failed to create graphics pipeline: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
framebuffers = malloc(sizeof(VkFramebuffer) * MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.pNext = NULL;
|
||||
framebufferInfo.flags = 0;
|
||||
framebufferInfo.renderPass = renderPass;
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.width = ow;
|
||||
framebufferInfo.height = oh;
|
||||
framebufferInfo.layers = 1;
|
||||
for(i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
framebufferInfo.pAttachments = &swapchainImageView[i];
|
||||
if((res = _vkCreateFramebuffer(device, &framebufferInfo, NULL, &framebuffers[i])) != VK_SUCCESS) {
|
||||
printf("error creating the frame buffer: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Create Command Pool.
|
||||
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
poolInfo.pNext = NULL;
|
||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
poolInfo.queueFamilyIndex = *graphicsQueueIndex;
|
||||
|
||||
if((res = _vkCreateCommandPool(device, &poolInfo, NULL, &cmdPool)) != VK_SUCCESS) {
|
||||
printf("error creating the command pool: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Create Command Buffer to record draw commands.
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.pNext = NULL;
|
||||
allocInfo.commandPool = cmdPool;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
cmdBuffers = malloc(sizeof(VkCommandBuffer) * MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
for(i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
if((res = _vkAllocateCommandBuffers(device, &allocInfo, &cmdBuffers[i])) != VK_SUCCESS) {
|
||||
printf("error allocating the command buffers: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
fenceInfo.pNext = 0;
|
||||
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||
|
||||
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
semaphoreInfo.pNext = 0;
|
||||
semaphoreInfo.flags = VK_SEMAPHORE_TYPE_BINARY;
|
||||
|
||||
imageAvaliableSemaphores = malloc(sizeof(VkSemaphore) * MAX_FRAMES_IN_FLIGHT);
|
||||
renderFinishedSemaphores = malloc(sizeof(VkSemaphore) * MAX_FRAMES_IN_FLIGHT);
|
||||
fences = malloc(sizeof(VkFence) * MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
for(i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
if(_vkCreateSemaphore(device, &semaphoreInfo, NULL, &imageAvaliableSemaphores[i]) != VK_SUCCESS) {
|
||||
printf("error creating fence: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
if(_vkCreateSemaphore(device, &semaphoreInfo, NULL, &renderFinishedSemaphores[i]) != VK_SUCCESS) {
|
||||
printf("error creating fence: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
if(_vkCreateFence(device, &fenceInfo, NULL, &fences[i]) != VK_SUCCESS) {
|
||||
printf("error creating fence: %s\n", string_VkResult(res));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
if(!MwVulkanSupported()) {
|
||||
printf("Vulkan not found or unsupported on target platform.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 450,
|
||||
MwNtitle, "hello world",
|
||||
NULL);
|
||||
|
||||
vulkan = MwVaCreateWidget(MwVulkanClass, "vulkan", window, 50, 50, ow, oh,
|
||||
MwNvulkanExtension, VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
|
||||
vulkan_setup(vulkan);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue