diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2003-07-07 13:17:41 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2003-07-07 13:17:41 +0000 |
commit | c2f25eba38e238fcd46d4054cf9895c4c78cf94a (patch) | |
tree | e961a35f91285b5345a1aaa0dd9fe6a281936495 | |
parent | ef110660c174e12431180117c0bdda20aa70f0fe (diff) |
Suite nettoyage. Amelioration gestion evenements (PR#1735)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5665 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | otherlibs/win32graph/draw.c | 15 | ||||
-rw-r--r-- | otherlibs/win32graph/libgraph.h | 2 | ||||
-rw-r--r-- | otherlibs/win32graph/open.c | 8 |
3 files changed, 13 insertions, 12 deletions
diff --git a/otherlibs/win32graph/draw.c b/otherlibs/win32graph/draw.c index 3b67db12c..31166d813 100644 --- a/otherlibs/win32graph/draw.c +++ b/otherlibs/win32graph/draw.c @@ -478,7 +478,7 @@ CAMLprim value gr_wait_event(value eventlist) } else { // Not polled. Block for a message InspectMessages = &msg; - while (1) { + do { WaitForSingleObject(EventHandle,INFINITE); stop = 0; switch (msg.message) { @@ -501,17 +501,18 @@ CAMLprim value gr_wait_event(value eventlist) key = msg.wParam & 0xFF; if (mask&Key_pressed) stop = 1; break; + case WM_CLOSE: + stop = 1; + break; } if (stop) { pt = msg.pt; MapWindowPoints(HWND_DESKTOP,grwindow.hwnd,&pt,1); mouse_x = pt.x; mouse_y = grwindow.height- 1 - pt.y; - break; } - if (msg.message == WM_CLOSE) - break; - } + SetEvent(EventProcessedHandle); + } while (! stop); InspectMessages = NULL; } res = alloc_small(5, 0); @@ -602,7 +603,7 @@ CAMLprim value gr_create_image(value vw, value vh) if (w < 0 || h < 0) gr_fail("create_image: width and height must be positive",0); - cbm = CreateCompatibleBitmap(grwindow.tempDC, w, h); + cbm = CreateCompatibleBitmap(grwindow.gc, w, h); res = alloc_custom(&image_ops, sizeof(struct image), w * h, Max_image_mem); if (res) { @@ -619,8 +620,6 @@ CAMLprim value gr_blit_image (value i, value x, value y) HBITMAP oldBmp = SelectObject(grwindow.tempDC,Data(i)); int xsrc = Int_val(x); int ysrc = Wcvt(Int_val(y) + Height(i) - 1); - printf("blitting from (%d, %d) size (%d, %d)\n", - xsrc, ysrc, Width(i), Height(i)); BitBlt(grwindow.tempDC,0, 0, Width(i), Height(i), grwindow.gcBitmap, xsrc, ysrc, SRCCOPY); SelectObject(grwindow.tempDC,oldBmp); diff --git a/otherlibs/win32graph/libgraph.h b/otherlibs/win32graph/libgraph.h index 833a52693..305270a41 100644 --- a/otherlibs/win32graph/libgraph.h +++ b/otherlibs/win32graph/libgraph.h @@ -78,7 +78,7 @@ typedef struct tagWindow { extern GR_WINDOW grwindow; HFONT CreationFont(char *name); extern int MouseLbuttonDown,MouseMbuttonDown,MouseRbuttonDown; -extern HANDLE EventHandle; +extern HANDLE EventHandle, EventProcessedHandle; extern MSG * InspectMessages; extern int MouseLbuttonDown,MouseMbuttonDown,MouseRbuttonDown; extern int MouseLastX, MouseLastY; diff --git a/otherlibs/win32graph/open.c b/otherlibs/win32graph/open.c index 9457129b6..b40086231 100644 --- a/otherlibs/win32graph/open.c +++ b/otherlibs/win32graph/open.c @@ -36,7 +36,7 @@ int grcolor; extern HFONT * grfont; MSG msg; -HANDLE EventHandle; +HANDLE EventHandle, EventProcessedHandle; static char *szOcamlWindowClass = "OcamlWindowClass"; static BOOL gr_initialized = 0; CAMLprim value gr_clear_graph(void); @@ -166,7 +166,6 @@ static value gr_reset(void) grwindow.width = rc.right; grwindow.height = rc.bottom; if (grwindow.gcBitmap == (HDC)0) { -// grwindow.hBitmap = CreateCompatibleBitmap(grwindow.gc,grwindow.width,grwindow.height); grwindow.hBitmap = CreateCompatibleBitmap(grwindow.gc,screenx,screeny); grwindow.gcBitmap = CreateCompatibleDC(grwindow.gc); grwindow.tempDC = CreateCompatibleDC(grwindow.gc); @@ -268,6 +267,7 @@ static DWORD WINAPI gr_open_graph_internal(value arg) grwindow.gry = 0; EventHandle = CreateEvent(NULL,0,0,NULL); + EventProcessedHandle = CreateEvent(NULL,0,0,NULL); /* The global data structures are now correctly initialized. Restart the Caml main thread. */ @@ -279,12 +279,14 @@ static DWORD WINAPI gr_open_graph_internal(value arg) if (InspectMessages != NULL) { *InspectMessages = msg; SetEvent(EventHandle); - Sleep(10); } TranslateMessage(&msg); // Translates virtual key codes DispatchMessage(&msg); // Dispatches message to window if (!IsWindow(grwindow.hwnd)) break; + if (InspectMessages != NULL) { + WaitForSingleObject(EventProcessedHandle,INFINITE); + } } return 0; } |