[Plib-users] R: Problem with a PUI-Win32-Native
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2008-02-29 13:47:10
|
I'm not a PUI user so I don't know if this could be useful, yet in your code I reported below: case WM_LBUTTONDOWN: oldMousePos.x = currentMousePos.x = LOWORD (lParam); oldMousePos.y = currentMousePos.y = HIWORD (lParam); if( puMouse ( 1, PU_DOWN, currentMousePos.x, currentMousePos.y )) ==>> //{ }//MessageBox(NULL,"DOWN","down",MB_OK); } isMouseActive = true; break; case WM_LBUTTONUP: currentMousePos.x = LOWORD (lParam); currentMousePos.y = HIWORD (lParam); if( puMouse ( 1, PU_UP, currentMousePos.x, currentMousePos.y )) {}// MessageBox(NULL,"UP","UP",MB_OK); } isMouseActive = false; break; Looking at the pointed line, are you sure you want to set isMouseActive = true when the call to puMouse returns 1? This is what actually happens since the subject line is commented out. Which is different, I see, from the similar code line for the button up case. Paolo > -----Messaggio originale----- > Da: pli...@li... > [mailto:pli...@li...] Per conto > di pos...@ca... > Inviato: venerdì 29 febbraio 2008 0.58 > A: pli...@li... > Oggetto: [Plib-users] Problem with a PUI-Win32-Native > > Hi all, > > I integrated plib into my GLUT-based application. It works > GREAT. I'm one more happy user in my sandbox. > > Now, problem arises when integrating inside a WIN32 > application, whose windows does (and will, probably) not be > wrapped with GLUT. > > The following code below, using basis example, illustrates > the problem : > a device context gets created, some opengl is painted inside, > and the gui (a button and a menu) gets called. > > Running the application : the gui shows up. > when I check if a gui's element is hit by a mouse clic, the > puMouse(..) returns correct, identifying wether an element > was clicked or not. > But no objects callbacks occurs and the submenu stays > invisible. The menu is hilighted when the mouse points over > and the buttonbox can be checked. > > What am I doing wrong ? > > > /* PUI - WIN32 - NO GLUT */ > > #pragma comment ( lib, "fnt.lib" ) > #pragma comment ( lib, "pui.lib" ) > #pragma comment ( lib, "sg.lib" ) > #pragma comment ( lib, "ul.lib" ) > > #define PU_USE_NATIVE > #include <plib/pu.h> > #include<windows.h> > #include<gl/gl.h> > #include<gl/glu.h> > > void Render(); > bool InitializeGL(); > > HDC g_HDC; > > float xRotation = 0.0f; > float yRotation = 0.0f; > > int gWidth = 0; > int gHeight = 0; > > > void button_cb(puObject *) {MessageBox(NULL,"ok","ok",MB_OK);} > void foo_cb (puObject *) {MessageBox(NULL,"foo","foo",MB_OK);} > void bar_cb (puObject *) {MessageBox(NULL,"bar","bar",MB_OK);} > void exit_cb (puObject *) {exit(0);} > > char *file_submenu [] = { "Exit","foo","bar", NULL } ; > puCallback file_submenu_cb[] = { exit_cb, foo_cb, bar_cb, > NULL } ; char * PUIlabels[5] = { "Label1", "Label2", "This is > Label3", "Four", NULL } ; > > > puMenuBar * menu; > puOneShot *b; > puButtonBox * checkList; > > void SetupPixelFormat(HDC hDC) > { > int nPixelFormat; > > static PIXELFORMATDESCRIPTOR pfd = { > sizeof(PIXELFORMATDESCRIPTOR), // size of structure. > 1, // always 1. > PFD_DRAW_TO_WINDOW | // > support window > PFD_SUPPORT_OPENGL | // > support OpenGl > PFD_DOUBLEBUFFER, // > support double buffering > PFD_TYPE_RGBA, // support RGBA > 16, // bit > color mode > 0, 0, 0, 0, 0, 0, // > ignore color bits > 0, // no > alpha buffer > 0, // > ignore shift bit > 0, // no > accumulation buffer > 0, 0, 0, 0, // > ignore accumulation bits. > 16, // > number of depth buffer bits. > 0, // > number of stencil buffer bits. > 0, // 0 > means no auxiliary buffer > PFD_MAIN_PLANE, // The > main drawing plane > 0, // > this is reserved > 0, 0, 0 }; // > layer masks ignored. > > // this chooses the best pixel format and returns index. > nPixelFormat = ChoosePixelFormat(hDC, &pfd); > > // This set pixel format to device context. > SetPixelFormat(hDC, nPixelFormat, &pfd); } > > > LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM > wParam, LPARAM lParam) { > static HGLRC hRC; // Rendering context. > static HDC hDC; // Device context. > int width, height; // The window > width and height. > static POINT oldMousePos; // Last mouse position. > static POINT currentMousePos; // Current mouse > position. > static bool isMouseActive; // Is the left > mouse button down. > > switch(message) > { > case WM_CREATE: // Windows creation. > hDC = GetDC(hwnd); // This gets the > device context for our window. > g_HDC = hDC; // Assigns the > global device context to this > one. > SetupPixelFormat(hDC); // Call the pixel > format function. > > hRC = wglCreateContext(hDC); // Creates the > rendering context. > wglMakeCurrent(hDC, hRC); // Makes the > rendering context. > return 0; > break; > > case WM_CLOSE: // Close message. > case WM_DESTROY: > wglMakeCurrent(hDC, NULL); > wglDeleteContext(hRC); // Deletes the > rendering context. > > PostQuitMessage(0); // Says close the program. > return 0; > break; > > case WM_SIZE: // re-size message. > height = HIWORD(lParam); // This gets the > height of the window. > width = LOWORD(lParam); // This gets the > width of the window. > > if(height == 0) // we don't want > it to be possible for a > { // height of 0. If > it is 0 me make it 1. > height = 1; > } > > gHeight = height; > gWidth = width; > puSetWindowSize ( width, height ) ; > glViewport(0, 0, width, height);// resets the > viewport to new dimensions. > glMatrixMode(GL_PROJECTION); // Sets the > projection matrix. > glLoadIdentity(); // Reset the > modelview matrix. > > // calculate the aspect ratio of the window. > gluPerspective(45.0f, > (GLfloat)width/(GLfloat)height, 0.1f, 1000.0f); > > glMatrixMode(GL_MODELVIEW); > glLoadIdentity(); > > return 0; > break; > > case WM_KEYDOWN: > switch(wParam) > { > case VK_ESCAPE: > PostQuitMessage(0); > break; > } > break; > > case WM_LBUTTONDOWN: > oldMousePos.x = currentMousePos.x = LOWORD (lParam); > oldMousePos.y = currentMousePos.y = HIWORD (lParam); > if( puMouse ( 1, PU_DOWN, currentMousePos.x, > currentMousePos.y )) > //{ }//MessageBox(NULL,"DOWN","down",MB_OK); } > isMouseActive = true; > break; > > case WM_LBUTTONUP: > currentMousePos.x = LOWORD (lParam); > currentMousePos.y = HIWORD (lParam); > if( puMouse ( 1, PU_UP, currentMousePos.x, > currentMousePos.y )) > {}// MessageBox(NULL,"UP","UP",MB_OK); } > isMouseActive = false; > break; > > case WM_MOUSEMOVE: > currentMousePos.x = LOWORD (lParam); > currentMousePos.y = HIWORD (lParam); > if(isMouseActive) > { > xRotation -= (currentMousePos.x - > oldMousePos.x); > yRotation -= (currentMousePos.y - > oldMousePos.y); > } > oldMousePos.x = currentMousePos.x; > oldMousePos.y = currentMousePos.y; > puMouse(currentMousePos.x,currentMousePos.y); > break; > > default: break; > } > > // What this does is pass all of the unhandled messages > to DefWindowProc > return (DefWindowProc(hwnd, message, wParam, lParam)); } > > int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE > hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { > MSG msg; // A > message variable. > WNDCLASSEX windowClass; // Your > Window class. > HWND hwnd; // The > Window handle. > bool isFinished; // True > then exit. > > windowClass.cbSize = sizeof(WNDCLASSEX); // size > of the WNDCLASSEX > structure. > windowClass.style = CS_HREDRAW | CS_VREDRAW; // > style of the window. > windowClass.lpfnWndProc = WndProc; // > Address to the windows > procedure. > windowClass.cbClsExtra = 0; // > Extra class information. > windowClass.cbWndExtra = 0; // > Extra window information. > windowClass.hInstance = hInstance; // > Handle of application > Instance. > windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);// > Handle of application Icon. > windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);// > mouse cursor > windowClass.hbrBackground = NULL; // > background color. > windowClass.lpszMenuName = NULL; // name > of the main menu. > windowClass.lpszClassName = "puitest";// window class name. > windowClass.hIconSm = LoadIcon(NULL, > IDI_APPLICATION);// icon when minimized. > > if(!RegisterClassEx(&windowClass)) return 0; > > // Create the window. > hwnd = CreateWindowEx(NULL,// The extended window style. > "puitest",// window Class name. > "a problem",// window name. > WS_OVERLAPPEDWINDOW | WS_VISIBLE |// The window style. > WS_SYSMENU | WS_CLIPCHILDREN |// window style. > WS_CLIPSIBLINGS,// window style. > 100, 100,// window x, y coordinate. > 640, 480,// window width and height. > NULL,// handle to parent window. > NULL,// menu. > hInstance,// handle to app instance. > NULL); // pointer to window creation data. > > if(!hwnd) return 0; > > ShowWindow(hwnd, SW_SHOW); > UpdateWindow(hwnd); > > isFinished = false; > > if(!InitializeGL()) isFinished = true; > > while(!isFinished) > { > if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) > { > if(msg.message == WM_QUIT) > { > isFinished = true; > } > TranslateMessage(&msg); > DispatchMessage(&msg); > } > else Render(); > } > return (int)msg.wParam; > } > > > bool InitializeGL() > { > puInit (); > menu = new puMenuBar(-1); > menu->add_submenu ( "File", file_submenu, file_submenu_cb ) ; > menu->close(); > b = new puOneShot ( 0, 0, "say hello") ; > b -> setCallback ( button_cb ) ; > > checkList = new puButtonBox ( 50, 50, 200, 200, > PUIlabels, 0 ) ; > > glClearColor(0.6f, 0.6f, 0.8f, 0.0f); // Clear the > screen to black. > glShadeModel(GL_SMOOTH); > glEnable(GL_DEPTH_TEST); > return true; > } > > > void Render() > { > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); > glLoadIdentity(); > > glTranslatef(0.0f, 0.0f, -5.0f); > glRotatef(-yRotation, 1.0f, 0.0f, 0.0f); > glRotatef(-xRotation, 0.0f, 1.0f, 0.0f); > > glBegin(GL_TRIANGLES); > glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); > glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.0f); > glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 0.0f); > glEnd(); > > puDisplay () ; > > SwapBuffers(g_HDC); > } > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by: Microsoft Defy all > challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > plib-users mailing list > pli...@li... > https://lists.sourceforge.net/lists/listinfo/plib-users > |