format
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@62 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
ed7dc61897
commit
002e721a31
4 changed files with 77 additions and 68 deletions
|
|
@ -62,7 +62,7 @@ lib: src/libMw$(SO)
|
||||||
examples: $(EXAMPLES)
|
examples: $(EXAMPLES)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
clang-format --verbose -i $(shell find src include -name "*.c" -or -name "*.h")
|
clang-format --verbose -i $(shell find src include examples -name "*.c" -or -name "*.h")
|
||||||
|
|
||||||
src/libMw$(SO): $(L_OBJS)
|
src/libMw$(SO): $(L_OBJS)
|
||||||
$(CC) $(L_LDFLAGS) -shared -o $@ $(L_OBJS) $(L_LIBS)
|
$(CC) $(L_LDFLAGS) -shared -o $@ $(L_OBJS) $(L_LIBS)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
MwWidget window, button, button2, button3, button4;
|
MwWidget window, button, button2, button3, button4;
|
||||||
|
|
||||||
void handler(MwWidget handle, void* user_data, void* call_data){
|
void handler(MwWidget handle, void* user_data, void* call_data) {
|
||||||
(void)handle;
|
(void)handle;
|
||||||
(void)user_data;
|
(void)user_data;
|
||||||
(void)call_data;
|
(void)call_data;
|
||||||
|
|
@ -12,7 +12,7 @@ void handler(MwWidget handle, void* user_data, void* call_data){
|
||||||
printf("hello world!\n");
|
printf("hello world!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(MwWidget handle, void* user_data, void* call_data){
|
void resize(MwWidget handle, void* user_data, void* call_data) {
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
|
|
||||||
(void)user_data;
|
(void)user_data;
|
||||||
|
|
@ -22,48 +22,48 @@ void resize(MwWidget handle, void* user_data, void* call_data){
|
||||||
h = MwGetInteger(handle, MwNheight);
|
h = MwGetInteger(handle, MwNheight);
|
||||||
|
|
||||||
MwVaApply(button,
|
MwVaApply(button,
|
||||||
MwNwidth, w - 50 * 2,
|
MwNwidth, w - 50 * 2,
|
||||||
MwNheight, h - 125 - 50 * 3,
|
MwNheight, h - 125 - 50 * 3,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwVaApply(button2,
|
MwVaApply(button2,
|
||||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||||
MwNy, h - 50 - 125,
|
MwNy, h - 50 - 125,
|
||||||
MwNwidth, (w - 50 * 2) / 3,
|
MwNwidth, (w - 50 * 2) / 3,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwVaApply(button3,
|
MwVaApply(button3,
|
||||||
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
||||||
MwNy, h - 50 - 125,
|
MwNy, h - 50 - 125,
|
||||||
MwNwidth, (w - 50 * 2) / 3,
|
MwNwidth, (w - 50 * 2) / 3,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwVaApply(button4,
|
MwVaApply(button4,
|
||||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||||
MwNy, h - 50 - 125,
|
MwNy, h - 50 - 125,
|
||||||
MwNwidth, (w - 50 * 2) / 3,
|
MwNwidth, (w - 50 * 2) / 3,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||||
MwNtitle, "hello world",
|
MwNtitle, "hello world",
|
||||||
NULL);
|
NULL);
|
||||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
NULL);
|
NULL);
|
||||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#f66",
|
MwNbackground, "#f66",
|
||||||
NULL);
|
NULL);
|
||||||
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#6f6",
|
MwNbackground, "#6f6",
|
||||||
NULL);
|
NULL);
|
||||||
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#66f",
|
MwNbackground, "#66f",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||||
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
|
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
MwWidget window, opengl;
|
MwWidget window, opengl;
|
||||||
int ow, oh;
|
int ow, oh;
|
||||||
|
double deg = 0;
|
||||||
|
|
||||||
void resize(MwWidget handle, void* user_data, void* call_data){
|
void resize(MwWidget handle, void* user_data, void* call_data) {
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
|
|
||||||
(void)user_data;
|
(void)user_data;
|
||||||
|
|
@ -17,12 +18,12 @@ void resize(MwWidget handle, void* user_data, void* call_data){
|
||||||
h = MwGetInteger(handle, MwNheight);
|
h = MwGetInteger(handle, MwNheight);
|
||||||
|
|
||||||
MwVaApply(opengl,
|
MwVaApply(opengl,
|
||||||
MwNwidth, (ow = w - 100),
|
MwNwidth, (ow = w - 100),
|
||||||
MwNheight, (oh = h - 100),
|
MwNheight, (oh = h - 100),
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick(MwWidget handle, void* user_data, void* call_data){
|
void tick(MwWidget handle, void* user_data, void* call_data) {
|
||||||
(void)handle;
|
(void)handle;
|
||||||
(void)user_data;
|
(void)user_data;
|
||||||
(void)call_data;
|
(void)call_data;
|
||||||
|
|
@ -39,19 +40,27 @@ void tick(MwWidget handle, void* user_data, void* call_data){
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glRotatef(deg, 0, 0, 1);
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
glColor3f(1, 0, 0); glVertex2f(0, 0.8);
|
glColor3f(1, 0, 0);
|
||||||
glColor3f(0, 1, 0); glVertex2f(-0.8, -0.8);
|
glVertex2f(0, 0.8);
|
||||||
glColor3f(0, 0, 1); glVertex2f(0.8, -0.8);
|
glColor3f(0, 1, 0);
|
||||||
|
glVertex2f(-0.8, -0.8);
|
||||||
|
glColor3f(0, 0, 1);
|
||||||
|
glVertex2f(0.8, -0.8);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
MwOpenGLSwapBuffer(opengl);
|
MwOpenGLSwapBuffer(opengl);
|
||||||
|
|
||||||
|
deg += 120.0 / (1000.0 / MwWaitMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||||
MwNtitle, "hello world",
|
MwNtitle, "hello world",
|
||||||
NULL);
|
NULL);
|
||||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 300));
|
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 50, 50, (ow = 300), (oh = 300));
|
||||||
|
|
||||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||||
|
|
|
||||||
|
|
@ -12,22 +12,22 @@
|
||||||
#define SIZE 100
|
#define SIZE 100
|
||||||
|
|
||||||
MwWidget buttons[6];
|
MwWidget buttons[6];
|
||||||
double deg = 0;
|
double deg = 0;
|
||||||
|
|
||||||
int ww, wh;
|
int ww, wh;
|
||||||
|
|
||||||
void handler(MwWidget w, void* user, void* client){
|
void handler(MwWidget w, void* user, void* client) {
|
||||||
int i;
|
int i;
|
||||||
double cdeg = deg;
|
double cdeg = deg;
|
||||||
|
|
||||||
(void)w;
|
(void)w;
|
||||||
(void)user;
|
(void)user;
|
||||||
(void)client;
|
(void)client;
|
||||||
|
|
||||||
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++){
|
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++) {
|
||||||
double rad = cdeg / 180 * M_PI;
|
double rad = cdeg / 180 * M_PI;
|
||||||
int x = ww / 2;
|
int x = ww / 2;
|
||||||
int y = wh / 2;
|
int y = wh / 2;
|
||||||
|
|
||||||
x += cos(rad) * (ww / 2 - SIZE / 2);
|
x += cos(rad) * (ww / 2 - SIZE / 2);
|
||||||
y += sin(rad) * (wh / 2 - SIZE / 2);
|
y += sin(rad) * (wh / 2 - SIZE / 2);
|
||||||
|
|
@ -36,9 +36,9 @@ void handler(MwWidget w, void* user, void* client){
|
||||||
y -= SIZE / 2;
|
y -= SIZE / 2;
|
||||||
|
|
||||||
MwVaApply(buttons[i],
|
MwVaApply(buttons[i],
|
||||||
MwNx, x,
|
MwNx, x,
|
||||||
MwNy, y,
|
MwNy, y,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
cdeg += 360 / (sizeof(buttons) / sizeof(buttons[0]));
|
cdeg += 360 / (sizeof(buttons) / sizeof(buttons[0]));
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ void handler(MwWidget w, void* user, void* client){
|
||||||
deg += 120.0 / (1000.0 / MwWaitMS);
|
deg += 120.0 / (1000.0 / MwWaitMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(MwWidget w, void* user, void* client){
|
void resize(MwWidget w, void* user, void* client) {
|
||||||
(void)w;
|
(void)w;
|
||||||
(void)user;
|
(void)user;
|
||||||
(void)client;
|
(void)client;
|
||||||
|
|
@ -55,16 +55,16 @@ void resize(MwWidget w, void* user, void* client){
|
||||||
wh = MwGetInteger(w, MwNheight);
|
wh = MwGetInteger(w, MwNheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
MwWidget window = MwVaCreateWidget(MwWindowClass, "window", NULL, 0, 0, (ww = 500), (wh = 500),
|
MwWidget window = MwVaCreateWidget(MwWindowClass, "window", NULL, 0, 0, (ww = 500), (wh = 500),
|
||||||
MwNtitle, "rotate",
|
MwNtitle, "rotate",
|
||||||
NULL);
|
NULL);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++){
|
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++) {
|
||||||
const char* color = "";
|
const char* color = "";
|
||||||
char fgcolor[5];
|
char fgcolor[5];
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if(i == 0) color = "#f66";
|
if(i == 0) color = "#f66";
|
||||||
if(i == 1) color = "#6f6";
|
if(i == 1) color = "#6f6";
|
||||||
|
|
@ -75,15 +75,15 @@ int main(){
|
||||||
|
|
||||||
fgcolor[0] = '#';
|
fgcolor[0] = '#';
|
||||||
fgcolor[4] = 0;
|
fgcolor[4] = 0;
|
||||||
for(j = 0; j < 3; j++){
|
for(j = 0; j < 3; j++) {
|
||||||
fgcolor[j + 1] = color[j + 1] == 'f' ? '6' : 'f';
|
fgcolor[j + 1] = color[j + 1] == 'f' ? '6' : 'f';
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons[i] = MwVaCreateWidget(MwButtonClass, "button", window, 0, 0, SIZE, SIZE,
|
buttons[i] = MwVaCreateWidget(MwButtonClass, "button", window, 0, 0, SIZE, SIZE,
|
||||||
MwNbackground, color,
|
MwNbackground, color,
|
||||||
MwNforeground, fgcolor,
|
MwNforeground, fgcolor,
|
||||||
MwNtext, "fancy",
|
MwNtext, "fancy",
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
MwAddUserHandler(window, MwNtickHandler, handler, NULL);
|
MwAddUserHandler(window, MwNtickHandler, handler, NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue