From 0ec896e2fd13dc3c7ecae7fbfb55cf6c439dfc50 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 11 Mar 2020 23:10:49 -0700 Subject: [PATCH] Starting to transfer everything to Tool --- Application.cpp | 44 +++++++++++++++++++++------------------ Application.h | 4 ++++ BaseButtonInstance.cpp | 5 +++-- DataModelInstance.cpp | 10 ++++----- DataModelInstance.h | 12 +++++------ G3DTest.vcproj | 32 +++++++++++++++++++++------- Globals.cpp | 4 +++- Globals.h | 4 +++- IEBrowser.cpp | 41 ++++++++++++++++++++++++++++++++---- Mouse.cpp | 31 +++++++++++++++++++++++++++ Mouse.h | 18 ++++++++++++++++ Tool.cpp | 26 +++++++++++++++++++++++ Tool.h | 37 +++++++++++++++++++++++--------- content/page/color.html | Bin 2088 -> 4371 bytes content/page/hopper.html | 2 +- 15 files changed, 212 insertions(+), 58 deletions(-) create mode 100644 Mouse.cpp create mode 100644 Mouse.h diff --git a/Application.cpp b/Application.cpp index 4c90e99..a1e1de4 100644 --- a/Application.cpp +++ b/Application.cpp @@ -32,11 +32,9 @@ #include "RotateButtonListener.h" #define LEGACY_LOAD_G3DFUN_LEVEL Ray testRay; -static int cursorid = 0; -static int cursorOvrid = 0; -static int currentcursorid = 0; -static G3D::TextureRef cursor = NULL; -static G3D::TextureRef cursorOvr = NULL; +//static int cursorid = 0; +//static int cursorOvrid = 0; +//static int currentcursorid = 0; static bool mouseMovedBeginMotion = false; static POINT oldGlobalMouse; Vector2 oldMouse = Vector2(0,0); @@ -181,7 +179,7 @@ void Application::deleteInstance() void Application::onInit() { - + tool = new Tool(); // Called before Application::run() beings cameraController.setFrame(Vector3(0,2,10)); _dataModel = new DataModelInstance(); @@ -440,14 +438,14 @@ void Application::onUserInput(UserInput* ui) { //_dataModel->mousex = ui->getMouseX(); //_dataModel->mousey = ui->getMouseY(); - _dataModel->mouseButton1Down = (GetKeyState(VK_LBUTTON) & 0x100) != 0; + mouse.setMouseDown((GetKeyState(VK_LBUTTON) & 0x100) != 0); if (GetHoldKeyState(VK_LBUTTON)) { if (_dragging) { PartInstance* part = NULL; if(g_selectedInstances.size() > 0) part = (PartInstance*) g_selectedInstances.at(0); - Ray dragRay = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()); + Ray dragRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); std::vector instances = _dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { @@ -735,7 +733,7 @@ void Application::onGraphics(RenderDevice* rd) { } } */ - glBindTexture( GL_TEXTURE_2D, currentcursorid); + glBindTexture( GL_TEXTURE_2D, tool->getCursorId()); glBegin( GL_QUADS ); @@ -767,10 +765,11 @@ void Application::onKeyPressed(int key) { _dataModel->getOpen(); } + tool->onKeyDown(key); } void Application::onKeyUp(int key) { - + tool->onKeyUp(key); } void Application::onMouseLeftPressed(HWND hwnd,int x,int y) @@ -779,14 +778,16 @@ void Application::onMouseLeftPressed(HWND hwnd,int x,int y) //std::cout << "Click: " << x << "," << y << std::endl; - + + bool onGUI = _dataModel->getGuiRoot()->mouseInGUI(renderDevice, x, y); if(!onGUI) { + tool->onButton1MouseDown(mouse); Instance * selectedInstance = NULL; - testRay = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()); + testRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); float nearest=std::numeric_limits::infinity(); Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; std::vector instances = _dataModel->getWorkspace()->getAllChildren(); @@ -868,6 +869,7 @@ void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y) //std::cout << "Release: " << x << "," << y << std::endl; _dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y); _dragging = false; + tool->onButton1MouseUp(mouse); //_message = "Dragging = false."; //_messageTime = System::time(); @@ -875,15 +877,20 @@ void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y) void Application::onMouseRightPressed(int x,int y) { + tool->onButton2MouseDown(mouse); } void Application::onMouseRightUp(int x,int y) { + tool->onButton2MouseUp(mouse); } void Application::onMouseMoved(int x,int y) { - oldMouse = _dataModel->getMousePos(); - _dataModel->mousex = x; - _dataModel->mousey = y; + oldMouse = Vector2(mouse.x, mouse.y); + mouse.x = x; + mouse.y = y; + tool->onMouseMoved(mouse); + //_dataModel->mousex = x; + //_dataModel->mousey = y; } void Application::onMouseWheel(int x,int y,short delta) @@ -893,6 +900,7 @@ void Application::onMouseWheel(int x,int y,short delta) { AudioPlayer::playSound(cameraSound); } + tool->onMouseScroll(mouse); } void Application::run() { @@ -916,17 +924,13 @@ void Application::run() { UpdateWindow(_hWndMain); // Load objects here= - cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); - cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png")); + Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png")); Globals::surfaceId = Globals::surface->getOpenGLID(); cameraSound = GetFileInPath("/content/sounds/SWITCH3.wav"); clickSound = GetFileInPath("/content/sounds/switch.wav"); dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav"); sky = Sky::create(NULL, ExePath() + "/content/sky/"); - cursorid = cursor->openGLID(); - currentcursorid = cursorid; - cursorOvrid = cursorOvr->openGLID(); RealTime now=0, lastTime=0; double simTimeRate = 1.0f; float fps=30.0f; diff --git a/Application.h b/Application.h index 2584550..3e08059 100644 --- a/Application.h +++ b/Application.h @@ -5,6 +5,8 @@ #include "ImageButtonInstance.h" #include "CameraController.h" #include "IEBrowser.h" +#include "Mouse.h" +#include "Tool.h" //#include "GuiRoot.h" class TextButtonInstance; @@ -54,6 +56,8 @@ class Application { // : public GApp { RenderDevice* getRenderDevice(); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void setMode(int mode); + Mouse mouse; + Tool * tool; private: RenderDevice* renderDevice; //void initGUI(); diff --git a/BaseButtonInstance.cpp b/BaseButtonInstance.cpp index 8c92859..2df06ef 100644 --- a/BaseButtonInstance.cpp +++ b/BaseButtonInstance.cpp @@ -1,5 +1,6 @@ #include "BaseButtonInstance.h" #include "Globals.h" +#include "Application.h" ButtonListener* listener = NULL; @@ -13,8 +14,8 @@ BaseButtonInstance::BaseButtonInstance(void) void BaseButtonInstance::render(RenderDevice* rd) { DataModelInstance* dataModel = g_dataModel; - Vector2 pos = Vector2(dataModel->mousex,dataModel->mousey); - drawObj(rd, pos, dataModel->mouseButton1Down); + Vector2 pos = Vector2(g_usableApp->mouse.x,g_usableApp->mouse.y); + drawObj(rd, pos, g_usableApp->mouse.isMouseDown()); Instance::render(rd); } diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 2c9fca2..5364ff6 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -20,9 +20,9 @@ DataModelInstance::DataModelInstance(void) //children.push_back(workspace); //children.push_back(level); className = "dataModel"; - mousex = 0; - mousey = 0; - mouseButton1Down = false; + //mousex = 0; + //mousey = 0; + //mouseButton1Down = false; showMessage = false; canDelete = false; _modY=0; @@ -586,7 +586,7 @@ WorkspaceInstance* DataModelInstance::getWorkspace() { return workspace; } -Vector2 DataModelInstance::getMousePos() +/*Vector2 DataModelInstance::getMousePos() { return Vector2(mousex,mousey); } @@ -599,7 +599,7 @@ void DataModelInstance::setMousePos(Vector2 pos) { mousex=pos.x; mousey=pos.y; -} +}*/ GuiRoot* DataModelInstance::getGuiRoot() { return guiRoot; diff --git a/DataModelInstance.h b/DataModelInstance.h index 7afa538..c143a05 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -28,12 +28,12 @@ public: bool showMessage; G3D::GFontRef font; GuiRoot* getGuiRoot(); - float mousex; - float mousey; - Vector2 getMousePos(); - void setMousePos(int x,int y); - void setMousePos(Vector2 pos); - bool mouseButton1Down; + //float mousex; + //float mousey; + //Vector2 getMousePos(); + //void setMousePos(int x,int y); + //void setMousePos(Vector2 pos); + //bool mouseButton1Down; PartInstance* makePart(); void clearLevel(); void toggleRun(); diff --git a/G3DTest.vcproj b/G3DTest.vcproj index cd1ef4d..dbc0833 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -290,6 +290,10 @@ /> + + @@ -302,10 +306,6 @@ RelativePath=".\StringFunctions.cpp" > - - @@ -398,6 +398,14 @@ > + + + + + + @@ -495,10 +507,6 @@ RelativePath=".\ToggleImageButtonInstance.h" > - - @@ -583,6 +591,14 @@ > + + + + postRenderStack; @@ -31,7 +32,8 @@ extern Application* g_usableApp; extern GFontRef g_fntdominant; extern GFontRef g_fntlighttrek; +extern COLORREF g_acrCustClr[16]; //Will be dynamic later extern std::string cameraSound; extern std::string clickSound; extern std::string dingSound; -const std::string g_PlaceholderName = "HyperCube"; \ No newline at end of file +const std::string g_PlaceholderName = "Dygysphere"; \ No newline at end of file diff --git a/IEBrowser.cpp b/IEBrowser.cpp index b560aea..5bf843c 100644 --- a/IEBrowser.cpp +++ b/IEBrowser.cpp @@ -4,7 +4,7 @@ #include - +#include #include "IEBrowser.h" #include "Globals.h" #pragma once @@ -28,7 +28,9 @@ HRESULT IEBrowser::doExternal(std::wstring funcName, } else if (funcName==L"ToggleHopperBin") { - MessageBox(NULL, "BOOP", "Boopity boop",MB_OK); + pVarResult->vt = VT_INT; + pVarResult->intVal = 5; + //MessageBox(NULL, "BOOP", "Boopity boop",MB_OK); } else if (funcName==L"SetController") { @@ -51,10 +53,41 @@ HRESULT IEBrowser::doExternal(std::wstring funcName, AudioPlayer::playSound(dingSound); return S_OK; } - else + else if(funcName==L"SetColor") { - return E_NOTIMPL; + + return S_OK; } + else if(funcName==L"ChooseColor") + { + CHOOSECOLOR color; + + DWORD rgbCurrent; //Will be dynamic later + ZeroMemory(&color, sizeof(CHOOSECOLOR)); + color.lStructSize = sizeof(color); + color.hwndOwner = hwnd; + color.lpCustColors = (LPDWORD) g_acrCustClr; + color.rgbResult = rgbCurrent; + color.Flags = CC_FULLOPEN | CC_RGBINIT; + if(ChooseColorA((LPCHOOSECOLOR)&color)) + { + //DWORD dwR = GetRValue(color.rgbResult); + //DWORD dwG = GetGValue(color.rgbResult); + //DWORD dwB = GetBValue(color.rgbResult); + //wchar_t * str = L"Test"; + //swprintf_s(str, 16, L"#%02X%02X%02X", dwR, dwG, dwB); + pVarResult->vt = VT_UI4; + pVarResult->ulVal = color.rgbResult; + } + else + { + DWORD error = CommDlgExtendedError(); + std::cout << error; + pVarResult->vt = VT_NULL; + } + return S_OK; + } + return E_NOTIMPL; } IEBrowser::IEBrowser(HWND attachHWnd) { diff --git a/Mouse.cpp b/Mouse.cpp new file mode 100644 index 0000000..4b9cd8a --- /dev/null +++ b/Mouse.cpp @@ -0,0 +1,31 @@ +#include "Mouse.h" +Mouse::Mouse(){ + x = y = 0; +} +Mouse::~Mouse(){} + + +Instance * Mouse::getTarget() +{ + return NULL; +} +Vector3 Mouse::getPosition() +{ + return Vector3(); + //Not implemented +} +bool Mouse::isMouseOnScreen() +{ + //hm + return true; +} + +bool Mouse::isMouseDown() +{ + return mouseDown; +} + +void Mouse::setMouseDown(bool bval) +{ + mouseDown = bval; +} \ No newline at end of file diff --git a/Mouse.h b/Mouse.h new file mode 100644 index 0000000..83a1c4c --- /dev/null +++ b/Mouse.h @@ -0,0 +1,18 @@ +#pragma once +#include "PartInstance.h" +#pragma once + +class Mouse +{ +public: + Mouse(void); + ~Mouse(void); + int x, y; + Instance * getTarget(); + Vector3 getPosition(); + bool isMouseOnScreen(); + bool isMouseDown(); + void setMouseDown(bool mouseDown); +private: + bool mouseDown; +}; diff --git a/Tool.cpp b/Tool.cpp index 7459701..169b92b 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -2,8 +2,34 @@ Tool::Tool(void) { + cursorRef = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); + cursorId = cursorRef->openGLID(); } Tool::~Tool(void) { } + +void Tool::onButton1MouseDown(Mouse mouse){} +void Tool::onButton2MouseDown(Mouse mouse){} +void Tool::onButton3MouseDown(Mouse mouse){} +void Tool::onButton1MouseUp(Mouse mouse){} +void Tool::onButton2MouseUp(Mouse mouse){} +void Tool::onButton3MouseUp(Mouse mouse){} +void Tool::onMouseMoved(Mouse mouse){} +void Tool::onSelect(Mouse mouse){} +void Tool::onDeselect(Mouse mouse){} +void Tool::onMouseScroll(Mouse mouse){} +void Tool::onKeyDown(char key){} +void Tool::onKeyUp(char key){} +void Tool::setCursor(std::string) +{ +} +int Tool::getCursorId() +{ + return cursorId; +} +void Tool::setCursorId(int id) +{ + cursorId = id; +} \ No newline at end of file diff --git a/Tool.h b/Tool.h index 2336dbe..bd1868b 100644 --- a/Tool.h +++ b/Tool.h @@ -1,17 +1,34 @@ #pragma once - +#include +#pragma once +#include "Mouse.h" +#pragma once +#include "Globals.h" +#pragma once +#include "StringFunctions.h" +#pragma once class Tool { public: Tool(void); ~Tool(void); - void OnButton1MouseDown(); - void OnButton2MouseDown(); - void OnButton3MouseDown(); - void OnButton1MouseUp(); - void OnButton2MouseUp(); - void OnButton3MouseUp(); - void OnMouseScroll(); - void OnKeyDown(); - void OnKeyUp(); + void onButton1MouseDown(Mouse); //yes + void onButton2MouseDown(Mouse); //yes + void onButton3MouseDown(Mouse); + void onButton1MouseUp(Mouse);//yes + void onButton2MouseUp(Mouse);//yes + void onButton3MouseUp(Mouse); + void onMouseMoved(Mouse);//yes + void onSelect(Mouse);//For later + void onDeselect(Mouse);//For later + void onMouseScroll(Mouse);//Kinda + void onKeyDown(char);//yes + void onKeyUp(char);//yes + void setCursor(std::string); + void setCursorId(int);//yes + int getCursorId();//yes +private: + int cursorId; + G3D::TextureRef cursorRef; + std::string cursorString; }; diff --git a/content/page/color.html b/content/page/color.html index 88582929609379f5ff75e75564ae44f5675b222e..acdb23f15b44331e78e63db1cd78cc058968d26d 100644 GIT binary patch literal 4371 zcmcIoZExE)5dJLx3QoZmdy8J&cCI1I{?MRC19ZTE<`3wFwzyEFM^UleHvfHhq@*ZC z^I?E#1r}e9&)q$|JJ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(5)jV9Ii zZ~}Ihz!{fr65X;Wg~-y54z5Nno~L^+C$mRhf;?ngONxCyLoVQ``xTa>Ygfv=sX;x( z8SJ&5z;G2xHgodv=wUJFnp{LR>P4o-SX`v>VouFdnzZ!H-k&4yKe}(u8HgGI1%WnI zG=LE5h5H_N4CTURTgS5h*`K&}Ps6vz)XeQ9HoMz3-7C#5U)8hTvV=93r01Sj7@|*C z?^q2}uQpY{3bxyPfL)Ou;6enB-bR}YL_%LZtmu!U_)kyDJDRCE&xkSoADtl>hY;G1 zQk)c`tkZ9DmjXGeyq)^^z^7h0@{ez8>5a=mrw-fd>fF`EFYN`Ze2S2Q*_>k?Igfe~ zfqx_&lKcgI=2oF{wfq7S3RVubhd=a1zlpDlp(uc5Dkd*G zbsJc%7+6q7>n{?uPanXy8^q2yDY(;X*(r BU>yJe diff --git a/content/page/hopper.html b/content/page/hopper.html index 1abc863..f20c4a0 100644 --- a/content/page/hopper.html +++ b/content/page/hopper.html @@ -22,7 +22,7 @@ } - +