stuff
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@400 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
7a531de084
commit
599b1ee0c8
11 changed files with 214 additions and 3 deletions
|
|
@ -91,7 +91,29 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
|||
p.x = LOWORD(lp);
|
||||
p.y = HIWORD(lp);
|
||||
|
||||
if(u->ll->grabbed){
|
||||
RECT rc;
|
||||
|
||||
GetClientRect(hWnd, &rc);
|
||||
p.x -= (rc.right - rc.left) / 2;
|
||||
p.y -= (rc.bottom - rc.top) / 2;
|
||||
}
|
||||
|
||||
MwLLDispatch(u->ll, move, &p);
|
||||
|
||||
if(u->ll->grabbed && (p.x != 0 || p.y != 0)){
|
||||
RECT rc;
|
||||
POINT p;
|
||||
|
||||
GetClientRect(hWnd, &rc);
|
||||
|
||||
p.x = (rc.right - rc.left) / 2;
|
||||
p.y = (rc.bottom - rc.top) / 2;
|
||||
|
||||
MapWindowPoints(hWnd, HWND_DESKTOP, &p, 1);
|
||||
|
||||
SetCursorPos(p.x, p.y);
|
||||
}
|
||||
} else if(msg == WM_SIZE) {
|
||||
MwLLDispatch(u->ll, resize, NULL);
|
||||
} else if(msg == WM_ERASEBKGND) {
|
||||
|
|
@ -108,12 +130,19 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
|||
int n = wp;
|
||||
|
||||
MwLLDispatch(u->ll, key, &n);
|
||||
}else if(msg == WM_SETFOCUS){
|
||||
MwLLDispatch(u->ll, focus_in, NULL);
|
||||
}else if(msg == WM_KILLFOCUS){
|
||||
MwLLDispatch(u->ll, focus_out, NULL);
|
||||
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP) {
|
||||
int n = -1;
|
||||
if(wp == VK_LEFT) n = MwLLKeyLeft;
|
||||
if(wp == VK_RIGHT) n = MwLLKeyRight;
|
||||
if(wp == VK_UP) n = MwLLKeyUp;
|
||||
if(wp == VK_DOWN) n = MwLLKeyDown;
|
||||
if(wp == VK_RETURN) n = MwLLKeyEnter;
|
||||
if(wp == VK_BACK) n = MwLLKeyBackSpace;
|
||||
if(wp == VK_ESCAPE) n = MwLLKeyEscape;
|
||||
if(n != -1) {
|
||||
if(msg == WM_KEYDOWN) {
|
||||
MwLLDispatch(u->ll, key, &n);
|
||||
|
|
@ -181,6 +210,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
|||
|
||||
RegisterClassEx(&wc);
|
||||
|
||||
r->grabbed = 0;
|
||||
r->copy_buffer = 1;
|
||||
r->hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
|
||||
r->hInstance = wc.hInstance;
|
||||
|
|
@ -556,3 +586,36 @@ void MwLLMakeBorderless(MwLL handle, int toggle) {
|
|||
long MwLLGetTick(void) {
|
||||
return GetTickCount();
|
||||
}
|
||||
|
||||
void MwLLFocus(MwLL handle){
|
||||
SetFocus(handle->hWnd);
|
||||
}
|
||||
|
||||
void MwLLGrabPointer(MwLL handle, int toggle){
|
||||
if(toggle){
|
||||
POINT p;
|
||||
RECT rc;
|
||||
|
||||
GetClientRect(handle->hWnd, &rc);
|
||||
|
||||
rc.right -= rc.left;
|
||||
rc.bottom -= rc.top;
|
||||
|
||||
p.x = (rc.right - rc.left) / 2;
|
||||
p.y = (rc.bottom - rc.top) / 2;
|
||||
|
||||
MapWindowPoints(handle->hWnd, HWND_DESKTOP, &p, 1);
|
||||
|
||||
handle->grabbed = 1;
|
||||
|
||||
SetFocus(handle->hWnd);
|
||||
|
||||
GetWindowRect(handle->hWnd, &rc);
|
||||
ClipCursor(&rc);
|
||||
|
||||
SetCursorPos(p.x, p.y);
|
||||
}else{
|
||||
handle->grabbed = 0;
|
||||
ClipCursor(NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ struct _MwLL {
|
|||
int copy_buffer;
|
||||
|
||||
MwLLHandler handler;
|
||||
|
||||
int grabbed;
|
||||
};
|
||||
|
||||
struct _MwLLColor {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ enum mwm_hints_enum {
|
|||
MWM_FUNC_CLOSE = (1L << 5)
|
||||
};
|
||||
|
||||
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | KeymapNotify;
|
||||
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | KeymapNotify | FocusChangeMask;
|
||||
|
||||
static void create_pixmap(MwLL handle) {
|
||||
XWindowAttributes attr;
|
||||
|
|
@ -110,6 +110,8 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
|||
r->width = width;
|
||||
r->height = height;
|
||||
|
||||
r->grabbed = 0;
|
||||
|
||||
r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display));
|
||||
r->wm_delete = XInternAtom(r->display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(r->display, r->window, &r->wm_delete, 1);
|
||||
|
|
@ -284,12 +286,28 @@ void MwLLNextEvent(MwLL handle) {
|
|||
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
|
||||
MwLLDispatch(handle, close, NULL);
|
||||
}
|
||||
} else if(ev.type == FocusIn){
|
||||
MwLLDispatch(handle, focus_in, NULL);
|
||||
} else if(ev.type == FocusOut){
|
||||
MwLLDispatch(handle, focus_out, NULL);
|
||||
} else if(ev.type == MotionNotify) {
|
||||
MwPoint p;
|
||||
XWindowAttributes attr;
|
||||
|
||||
XGetWindowAttributes(handle->display, handle->window, &attr);
|
||||
|
||||
p.x = ev.xmotion.x;
|
||||
p.y = ev.xmotion.y;
|
||||
|
||||
if(handle->grabbed){
|
||||
p.x -= attr.width / 2;
|
||||
p.y -= attr.height / 2;
|
||||
}
|
||||
|
||||
MwLLDispatch(handle, move, &p);
|
||||
if(handle->grabbed && (p.x != 0 || p.y != 0)){
|
||||
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
|
||||
}
|
||||
} else if(ev.type == KeyPress || ev.type == KeyRelease) {
|
||||
int n = -1;
|
||||
char str[512];
|
||||
|
|
@ -325,6 +343,10 @@ void MwLLNextEvent(MwLL handle) {
|
|||
n = MwLLKeyUp;
|
||||
} else if(strcmp(str, "Down") == 0) {
|
||||
n = MwLLKeyDown;
|
||||
} else if(strcmp(str, "Return") == 0){
|
||||
n = MwLLKeyEnter;
|
||||
} else if(strcmp(str, "Escape") == 0){
|
||||
n = MwLLKeyEscape;
|
||||
}
|
||||
|
||||
if(n != -1) {
|
||||
|
|
@ -663,3 +685,21 @@ long MwLLGetTick(void) {
|
|||
|
||||
return n;
|
||||
}
|
||||
|
||||
void MwLLFocus(MwLL handle){
|
||||
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
|
||||
}
|
||||
|
||||
void MwLLGrabPointer(MwLL handle, int toggle){
|
||||
XWindowAttributes attr;
|
||||
|
||||
XGetWindowAttributes(handle->display, handle->window, &attr);
|
||||
|
||||
if(toggle){
|
||||
handle->grabbed = 1;
|
||||
|
||||
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
|
||||
}else{
|
||||
handle->grabbed = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ struct _MwLL {
|
|||
unsigned int height;
|
||||
|
||||
MwLLHandler handler;
|
||||
|
||||
int grabbed;
|
||||
};
|
||||
|
||||
struct _MwLLColor {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue