mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +00:00
funny demo
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@59 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -35,6 +35,8 @@ L_CFLAGS += -DUSE_X11
|
||||
L_OBJS += src/x11.o
|
||||
L_LIBS += -lX11
|
||||
|
||||
E_LIBS += -lm
|
||||
|
||||
SO = .so
|
||||
EXEC =
|
||||
else ifeq ($(WINDOWS),1)
|
||||
@@ -47,7 +49,7 @@ SO = .dll
|
||||
EXEC = .exe
|
||||
endif
|
||||
|
||||
EXAMPLES = examples/example$(EXEC)
|
||||
EXAMPLES = examples/example$(EXEC) examples/rotate$(EXEC)
|
||||
|
||||
.PHONY: all format clean lib examples
|
||||
|
||||
|
||||
93
examples/rotate.c
Normal file
93
examples/rotate.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/* $Id$ */
|
||||
/* this demo does not work well on windows */
|
||||
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
#define SIZE 100
|
||||
|
||||
MwWidget buttons[6];
|
||||
double deg = 0;
|
||||
|
||||
int ww, wh;
|
||||
|
||||
void handler(MwWidget w, void* user, void* client){
|
||||
int i;
|
||||
double cdeg = deg;
|
||||
|
||||
(void)w;
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++){
|
||||
double rad = cdeg / 180 * M_PI;
|
||||
int x = ww / 2;
|
||||
int y = wh / 2;
|
||||
|
||||
x += cos(rad) * (ww / 2 - SIZE / 2);
|
||||
y += sin(rad) * (wh / 2 - SIZE / 2);
|
||||
|
||||
x -= SIZE / 2;
|
||||
y -= SIZE / 2;
|
||||
|
||||
MwVaApply(buttons[i],
|
||||
MwNx, x,
|
||||
MwNy, y,
|
||||
NULL);
|
||||
|
||||
cdeg += 360 / (sizeof(buttons) / sizeof(buttons[0]));
|
||||
}
|
||||
|
||||
deg += 120.0 / (1000.0 / MwWaitMS);
|
||||
}
|
||||
|
||||
void resize(MwWidget w, void* user, void* client){
|
||||
(void)w;
|
||||
(void)user;
|
||||
(void)client;
|
||||
|
||||
ww = MwGetInteger(w, MwNwidth);
|
||||
wh = MwGetInteger(w, MwNheight);
|
||||
}
|
||||
|
||||
int main(){
|
||||
MwWidget window = MwVaCreateWidget(MwWindowClass, "window", NULL, 0, 0, (ww = 500), (wh = 500),
|
||||
MwNtitle, "rotate",
|
||||
NULL);
|
||||
int i;
|
||||
|
||||
for(i = 0; i < (int)(sizeof(buttons) / sizeof(buttons[0])); i++){
|
||||
const char* color = "";
|
||||
char fgcolor[5];
|
||||
int j;
|
||||
|
||||
if(i == 0) color = "#f66";
|
||||
if(i == 1) color = "#6f6";
|
||||
if(i == 2) color = "#ff6";
|
||||
if(i == 3) color = "#66f";
|
||||
if(i == 4) color = "#f6f";
|
||||
if(i == 5) color = "#6ff";
|
||||
|
||||
fgcolor[0] = '#';
|
||||
fgcolor[4] = 0;
|
||||
for(j = 0; j < 3; j++){
|
||||
fgcolor[j + 1] = color[j + 1] == 'f' ? '6' : 'f';
|
||||
}
|
||||
|
||||
buttons[i] = MwVaCreateWidget(MwButtonClass, "button", window, 0, 0, SIZE, SIZE,
|
||||
MwNbackground, color,
|
||||
MwNforeground, fgcolor,
|
||||
MwNtext, "fancy",
|
||||
NULL);
|
||||
}
|
||||
|
||||
MwAddUserHandler(window, MwNtickHandler, handler, NULL);
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
#define MwDispatch(x, y) \
|
||||
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
|
||||
|
||||
#define MwWaitMS 5
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -14,5 +14,6 @@
|
||||
|
||||
#define MwNactivateHandler "Cactivate"
|
||||
#define MwNresizeHandler "Cresize"
|
||||
#define MwNtickHandler "Ctick"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -135,7 +135,9 @@ int MwPending(MwWidget handle) {
|
||||
void MwLoop(MwWidget handle) {
|
||||
while(1) {
|
||||
MwStep(handle);
|
||||
MwLLSleep(5);
|
||||
|
||||
MwDispatchUserHandler(handle, MwNtickHandler, NULL);
|
||||
MwLLSleep(MwWaitMS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
src/gdi.c
22
src/gdi.c
@@ -13,9 +13,27 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
|
||||
if(msg == WM_PAINT) {
|
||||
PAINTSTRUCT ps;
|
||||
u->ll->hDC = BeginPaint(hWnd, &ps);
|
||||
RECT rc;
|
||||
HBITMAP hbmp;
|
||||
HDC dc, hbdc;
|
||||
|
||||
GetClientRect(hWnd, &rc);
|
||||
|
||||
dc = GetDC(hWnd);
|
||||
hbmp = CreateCompatibleBitmap(dc, rc.right - rc.left, rc.bottom - rc.top);
|
||||
hbdc = CreateCompatibleDC(dc);
|
||||
SelectObject(hbdc, hbmp);
|
||||
ReleaseDC(hWnd, dc);
|
||||
|
||||
u->ll->hDC = hbdc;
|
||||
MwLLDispatch(u->ll, draw);
|
||||
|
||||
dc = BeginPaint(hWnd, &ps);
|
||||
StretchBlt(dc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hbdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SRCCOPY);
|
||||
EndPaint(hWnd, &ps);
|
||||
|
||||
DeleteDC(hbdc);
|
||||
DeleteObject(hbmp);
|
||||
} else if(msg == WM_LBUTTONDOWN) {
|
||||
SetCapture(hWnd);
|
||||
MwLLDispatch(u->ll, down);
|
||||
@@ -127,7 +145,7 @@ MwLLColor MwLLAllocColor(MwLL handle, int r, int g, int b) {
|
||||
c->green = g;
|
||||
c->blue = b;
|
||||
|
||||
DeleteDC(dc);
|
||||
ReleaseDC(handle->hWnd, dc);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user