Child windows added.

This commit is contained in:
MusicalProgrammer
2018-06-04 22:58:20 -04:00
parent 22e018e138
commit 90c609d06d
3 changed files with 175 additions and 67 deletions

10
Demo.h
View File

@@ -4,7 +4,7 @@
class Demo { // : public GApp { class Demo { // : public GApp {
public: public:
Demo(const GAppSettings& settings,Win32Window* wind); Demo(const GAppSettings& settings,HWND parentWindow);
virtual ~Demo() {} virtual ~Demo() {}
virtual void exitApplication(); virtual void exitApplication();
virtual void onInit(); virtual void onInit();
@@ -18,6 +18,8 @@ class Demo { // : public GApp {
Instance* getSelection(); Instance* getSelection();
void run(); void run();
void QuitApp(); void QuitApp();
void resizeWithParent(HWND parentWindow);
void onCreate(HWND parentWindow);
void onKeyPressed(int key); void onKeyPressed(int key);
void onKeyUp(int key); void onKeyUp(int key);
void onMouseLeftPressed(int x, int y); void onMouseLeftPressed(int x, int y);
@@ -31,12 +33,16 @@ class Demo { // : public GApp {
UserInput* userInput; UserInput* userInput;
private: private:
void initGUI(); void initGUI();
HWND hWndMain; HWND _hWndMain;
SkyRef sky; SkyRef sky;
bool quit; bool quit;
bool mouseOnScreen;
bool rightButtonHolding; bool rightButtonHolding;
void main(); void main();
GWindow* _window; GWindow* _window;
HWND _hwndToolbox;
HWND _buttonTest;
HWND _hwndRenderer;
protected: protected:
Stopwatch m_graphicsWatch; Stopwatch m_graphicsWatch;
Stopwatch m_logicWatch; Stopwatch m_logicWatch;

View File

@@ -1,5 +1,9 @@
#include "WindowFunctions.h" #include "WindowFunctions.h"
#include <sstream>
#include <string>
using namespace std;
bool createWindowClass(const char* name,WNDPROC proc,HMODULE hInstance) bool createWindowClass(const char* name,WNDPROC proc,HMODULE hInstance)
{ {
@@ -17,7 +21,12 @@ bool createWindowClass(const char* name,WNDPROC proc,HMODULE hInstance)
wc.lpszClassName = name; wc.lpszClassName = name;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx (&wc)) if (!RegisterClassEx (&wc))
{
stringstream errMsg;
errMsg<<"Failed to register " << name;
MessageBox(NULL, errMsg.str().c_str(),"Dynamica Crash", MB_OK);
return false; return false;
}
return true; return true;
} }

207
main.cpp
View File

@@ -11,6 +11,8 @@
@author Morgan McGuire, matrix@graphics3d.com @author Morgan McGuire, matrix@graphics3d.com
*/ */
// TODO: Move toolbar buttons with resized window.
#define _WIN32_WINNT 0x0400 #define _WIN32_WINNT 0x0400
#include <G3DAll.h> #include <G3DAll.h>
@@ -63,14 +65,68 @@ Instance* selectedInstance = NULL;
Demo *usableApp = NULL; Demo *usableApp = NULL;
Demo::Demo(const GAppSettings& settings,Win32Window* window) { //: GApp(settings,window) { Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,window) {
hWndMain = window->hwnd(); _hWndMain = parentWindow;
HMODULE hThisInstance = GetModuleHandle(NULL);
_hwndToolbox = CreateWindowEx(
WS_EX_ACCEPTFILES,
"toolboxHWND",
"Main test",
WS_CHILD | WS_VISIBLE,
0,
560,
800,
50,
_hWndMain, // parent
NULL, // menu
hThisInstance,
NULL
);
_buttonTest = CreateWindow(
"COMBOBOX",
"",
CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
20,
10,
80,
120,
_hwndToolbox, // parent
NULL, // menu
hThisInstance,
NULL
);
SendMessage(_buttonTest,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) "TEST");
SendMessage(_buttonTest,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) "TEST2");
SendMessage(_buttonTest, CB_SETCURSEL, (WPARAM)1, (LPARAM)0);
_hwndRenderer = CreateWindowEx(
WS_EX_ACCEPTFILES,
"G3DWindow",
"3D",
WS_CHILD,
CW_USEDEFAULT,
CW_USEDEFAULT,
1,
1,
_hWndMain, // parent
NULL, // menu
hThisInstance,
NULL
);
Win32Window* window = Win32Window::create(settings.window,_hwndRenderer);
ShowWindow(_hwndRenderer, SW_SHOW);
SetWindowLongPtr(_hWndMain,GWL_USERDATA,(LONG)this);
SetWindowLongPtr(_hwndRenderer,GWL_USERDATA,(LONG)this);
SetWindowLongPtr(_hwndToolbox,GWL_USERDATA,(LONG)this);
ShowWindow(_hWndMain, SW_SHOW);
quit=false; quit=false;
rightButtonHolding=false; rightButtonHolding=false;
mouseOnScreen=false;
// GApp replacement // GApp replacement
renderDevice = new RenderDevice(); renderDevice = new RenderDevice();
if (window != NULL) { if (window != NULL) {
renderDevice->init(window, NULL); renderDevice->init(window, NULL);
} }
@@ -81,6 +137,7 @@ Demo::Demo(const GAppSettings& settings,Win32Window* window) { //: GApp(settings
} }
_window = renderDevice->window(); _window = renderDevice->window();
_window->makeCurrent(); _window->makeCurrent();
} }
void clearInstances() void clearInstances()
@@ -755,7 +812,7 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
{ {
title = dataModel->name; title = dataModel->name;
std::string text = "Game \"" + title + "\""; std::string text = "Game \"" + title + "\"";
SetWindowText(hWndMain, text.c_str()); SetWindowText(_hWndMain, text.c_str());
} }
@@ -991,10 +1048,10 @@ void Demo::onGraphics(RenderDevice* rd) {
G3D::uint8 num = 0; G3D::uint8 num = 0;
POINT mousepos; POINT mousepos;
bool mouseOnScreen = true; mouseOnScreen = true;
if (GetCursorPos(&mousepos)) if (GetCursorPos(&mousepos))
{ {
if (ScreenToClient(hWndMain, &mousepos)) if (ScreenToClient(_hWndMain, &mousepos))
{ {
//mouseOnScreen = true; //mouseOnScreen = true;
@@ -1019,7 +1076,7 @@ void Demo::onGraphics(RenderDevice* rd) {
if(Globals::useMousePoint) if(Globals::useMousePoint)
{ {
mousepos = Globals::mousepoint; mousepos = Globals::mousepoint;
ScreenToClient(hWndMain, &mousepos); ScreenToClient(_hWndMain, &mousepos);
} }
LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM));
@@ -1225,6 +1282,7 @@ void Demo::onMouseMoved(int x,int y)
} }
void Demo::onMouseWheel(int x,int y,short delta) void Demo::onMouseWheel(int x,int y,short delta)
{ {
if (mouseOnScreen==true)
if (cameraController.onMouseWheel(x, y, delta)) if (cameraController.onMouseWheel(x, y, delta))
{ {
AudioPlayer::playSound(cameraSound); AudioPlayer::playSound(cameraSound);
@@ -1262,12 +1320,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
switch(msg) switch(msg)
{ {
case WM_QUIT:
app->QuitApp();
break;
case WM_DESTROY:
app->QuitApp();
break;
case WM_KEYDOWN: case WM_KEYDOWN:
if ((HIWORD(lParam)&0x4000)==0) // single key press if ((HIWORD(lParam)&0x4000)==0) // single key press
{ {
@@ -1279,46 +1331,27 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
app->onKeyUp(wParam); app->onKeyUp(wParam);
} }
break; break;
case WM_LBUTTONDOWN:
app->onMouseLeftPressed(LOWORD(lParam),HIWORD(lParam));
break;
case WM_MOUSEMOVE:
app->onMouseMoved(LOWORD(lParam),HIWORD(lParam));
break;
case WM_LBUTTONUP:
app->onMouseLeftUp(LOWORD(lParam),HIWORD(lParam));
break;
case WM_RBUTTONDOWN:
app->onMouseRightPressed(LOWORD(lParam),HIWORD(lParam));
break;
case WM_RBUTTONUP:
app->onMouseRightUp(LOWORD(lParam),HIWORD(lParam));
break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
app->onMouseWheel(LOWORD(lParam),HIWORD(lParam),HIWORD(wParam)); app->onMouseWheel(LOWORD(lParam),HIWORD(lParam),HIWORD(wParam));
break; break;
case WM_SIZE: case WM_SIZE:
{ app->resizeWithParent(hwnd);
int viewWidth = LOWORD(lParam);
int viewHeight = HIWORD(lParam);
app->renderDevice->notifyResize(viewWidth,viewHeight);
Rect2D viewportRect = Rect2D::xywh(0,0,viewWidth,viewHeight);
app->renderDevice->setViewport(viewportRect);
app->onGraphics(app->renderDevice);
}
break; break;
default: default:
{ {
return DefWindowProc(hwnd, msg, wParam, lParam); return DefWindowProc(hwnd, msg, wParam, lParam);
} }
} }
return 0; return 0;
} }
LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK ToolboxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
//Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA); Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
if (app==NULL)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
switch(msg) switch(msg)
{ {
case WM_SIZE: case WM_SIZE:
@@ -1330,7 +1363,49 @@ LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
return 0; return 0;
} }
LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
if (app==NULL)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
switch(msg)
{
case WM_QUIT:
app->QuitApp();
break;
case WM_DESTROY:
app->QuitApp();
break;
case WM_LBUTTONDOWN:
app->onMouseLeftPressed(LOWORD(lParam),HIWORD(lParam));
break;
case WM_LBUTTONUP:
app->onMouseLeftUp(LOWORD(lParam),HIWORD(lParam));
break;
case WM_RBUTTONDOWN:
app->onMouseRightPressed(LOWORD(lParam),HIWORD(lParam));
break;
case WM_RBUTTONUP:
app->onMouseRightUp(LOWORD(lParam),HIWORD(lParam));
break;
case WM_MOUSEMOVE:
app->onMouseMoved(LOWORD(lParam),HIWORD(lParam));
break;
case WM_SIZE:
{
app->onGraphics(app->renderDevice);
}
break;
default:
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
return 0;
}
void Demo::run() { void Demo::run() {
usableApp = this; usableApp = this;
//setDebugMode(false); //setDebugMode(false);
@@ -1349,7 +1424,7 @@ void Demo::run() {
ShowWindow(propertyHWnd,SW_SHOW); ShowWindow(propertyHWnd,SW_SHOW);
*/ */
UpdateWindow(hWndMain); UpdateWindow(_hWndMain);
// Load objects here= // Load objects here=
cursor = Texture::fromFile(GetFileInPath("/content/cursor2.png")); cursor = Texture::fromFile(GetFileInPath("/content/cursor2.png"));
@@ -1370,13 +1445,13 @@ void Demo::run() {
RealTime lastWaitTime=0; RealTime lastWaitTime=0;
MSG messages; MSG messages;
RECT cRect; //RECT cRect;
GetClientRect(hWndMain,&cRect); //GetClientRect(_hWndMain,&cRect);
//renderDevice->notifyResize(cRect.right,cRect.bottom);
renderDevice->notifyResize(cRect.right,cRect.bottom); //Rect2D viewportRect = Rect2D::xywh(0,0,cRect.right,cRect.bottom);
Rect2D viewportRect = Rect2D::xywh(0,0,cRect.right,cRect.bottom); //renderDevice->setViewport(viewportRect);
renderDevice->setViewport(viewportRect);
//window()->setInputCaptureCount(1); //window()->setInputCaptureCount(1);
resizeWithParent(_hWndMain);
while (!quit) while (!quit)
{ {
@@ -1424,7 +1499,7 @@ void Demo::run() {
while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE)) while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE))
{ {
if (IsDialogMessage(hWndMain, &messages) == 0) if (IsDialogMessage(_hWndMain, &messages) == 0)
{ {
TranslateMessage(&messages); TranslateMessage(&messages);
DispatchMessage(&messages); DispatchMessage(&messages);
@@ -1433,12 +1508,32 @@ void Demo::run() {
} }
onCleanup(); onCleanup();
} }
void Demo::resizeWithParent(HWND parentWindow)
{
RECT rect;
GetClientRect(parentWindow,&rect);
SetWindowPos(_hwndRenderer,NULL,0,0,rect.right,rect.bottom-50,SWP_NOMOVE);
SetWindowPos(_hwndToolbox,NULL,0,rect.bottom-50,rect.right,50,SWP_NOACTIVATE | SWP_SHOWWINDOW);
GetClientRect(_hwndRenderer,&rect);
int viewWidth=rect.right;
int viewHeight=rect.bottom;
renderDevice->notifyResize(viewWidth,viewHeight);
Rect2D viewportRect = Rect2D::xywh(0,0,viewWidth,viewHeight);
renderDevice->setViewport(viewportRect);
}
void Demo::QuitApp() void Demo::QuitApp()
{ {
PostQuitMessage(0); PostQuitMessage(0);
quit=true; quit=true;
} }
void Demo::onCreate(HWND parentWindow)
{
//SetWindowLongPtr(hwndRenderer,GWL_USERDATA,(LONG)this);
//SetWindowLongPtr(hwndToolbox,GWL_USERDATA,(LONG)this);
//SetWindowLongPtr(hwndMain,GWL_USERDATA,(LONG)&demo);
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
try{ try{
@@ -1456,11 +1551,11 @@ int main(int argc, char** argv) {
HMODULE hThisInstance = GetModuleHandle(NULL); HMODULE hThisInstance = GetModuleHandle(NULL);
if (!createWindowClass("mainHWND",WndProc,hThisInstance)) if (!createWindowClass("mainHWND",WndProc,hThisInstance))
{
MessageBox(NULL, "Failed to register mainHWND","Dynamica Crash", MB_OK);
return false; return false;
} if (!createWindowClass("toolboxHWND",ToolboxProc,hThisInstance))
return false;
if (!createWindowClass("G3DWindow",G3DProc,hThisInstance))
return false;
HWND hwndMain = CreateWindowEx( HWND hwndMain = CreateWindowEx(
WS_EX_ACCEPTFILES, WS_EX_ACCEPTFILES,
@@ -1470,7 +1565,7 @@ int main(int argc, char** argv) {
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 800,
600, 660,
NULL, // parent NULL, // parent
NULL, // menu NULL, // menu
hThisInstance, hThisInstance,
@@ -1483,11 +1578,9 @@ int main(int argc, char** argv) {
return 0; return 0;
} }
SendMessage(hwndMain, WM_SETICON, ICON_BIG,(LPARAM)LoadImage(GetModuleHandle(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE)); SendMessage(hwndMain, WM_SETICON, ICON_BIG,(LPARAM)LoadImage(GetModuleHandle(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE));
ShowWindow(hwndMain, SW_SHOW);
Win32Window* win32Window = Win32Window::create(settings.window,hwndMain);
Demo demo = Demo(settings,win32Window); Demo demo = Demo(settings,hwndMain);
SetWindowLongPtr(hwndMain,GWL_USERDATA,(LONG)&demo);
demo.run(); demo.run();
} }
catch(...) catch(...)