diff --git a/Application.cpp b/Application.cpp index 379b817..de15824 100644 --- a/Application.cpp +++ b/Application.cpp @@ -30,13 +30,11 @@ #include "DeleteListener.h" #include "CameraButtonListener.h" #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; +//#define LEGACY_LOAD_G3DFUN_LEVEL +//Ray testRay; +//static int cursorid = 0; +//static int cursorOvrid = 0; +//static int currentcursorid = 0; static bool mouseMovedBeginMotion = false; static POINT oldGlobalMouse; Vector2 oldMouse = Vector2(0,0); @@ -163,8 +161,7 @@ void Application::deleteInstance() { AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); Instance* selectedInstance = g_selectedInstances.at(0); - if(selectedInstance->getParent() != NULL) - selectedInstance->getParent()->removeChild(selectedInstance); + selectedInstance->setParent(NULL); delete selectedInstance; selectedInstance = NULL; g_selectedInstances.erase(g_selectedInstances.begin()); @@ -181,7 +178,7 @@ void Application::deleteInstance() void Application::onInit() { - + tool = new Tool(); // Called before Application::run() beings cameraController.setFrame(Vector3(0,2,10)); _dataModel = new DataModelInstance(); @@ -417,7 +414,11 @@ bool IsHolding(int button) */ void Application::onUserInput(UserInput* ui) { - + if(mouseMoveState) + { + mouseMoveState = false; + tool->onMouseMoved(mouse); + } /* if(GetHoldKeyState(VK_LCONTROL)) { @@ -440,14 +441,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) { + /* 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++) { @@ -468,7 +469,7 @@ void Application::onUserInput(UserInput* ui) { } } Sleep(10); - } + }*/ } // Camera KB Handling { if (GetKPBool(VK_OEM_COMMA)) //Left @@ -485,6 +486,18 @@ void Application::onUserInput(UserInput* ui) { // Add other key handling here } +void Application::changeTool(Tool * newTool) +{ + tool->onDeselect(mouse); + delete tool; + if(newTool != NULL) + tool = newTool; + else + tool = new Tool(); //Nulltool + tool->onSelect(mouse); + +} + void Application::makeFlag(Vector3 &vec, RenderDevice* &rd) { @@ -662,6 +675,11 @@ void Application::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor, true, true)); renderDevice->setAmbientLightColor(lighting.ambient); + + //renderDevice->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE); + + + renderDevice->setShininess(70); renderDevice->setSpecularCoefficient(Color3(0.1F, 0.1F, 0.1F)); @@ -674,6 +692,7 @@ void Application::onGraphics(RenderDevice* rd) { //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, lightSpecular); //glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 70); + rd->beforePrimitive(); CoordinateFrame forDraw = rd->getObjectToWorldMatrix(); glEnableClientState(GL_VERTEX_ARRAY); @@ -689,6 +708,10 @@ void Application::onGraphics(RenderDevice* rd) { rd->setObjectToWorldMatrix(forDraw); rd->afterPrimitive(); + + + + Draw::sphere(G3D::Sphere(mouse.getPosition(), 1), rd, Color3::cyan(), Color4::clear()); if(g_selectedInstances.size() > 0) { for(size_t i = 0; i < g_selectedInstances.size(); i++) @@ -747,7 +770,7 @@ void Application::onGraphics(RenderDevice* rd) { } } */ - glBindTexture( GL_TEXTURE_2D, currentcursorid); + glBindTexture( GL_TEXTURE_2D, tool->getCursorId()); glBegin( GL_QUADS ); @@ -779,10 +802,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) @@ -791,69 +815,14 @@ 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) { - Instance * selectedInstance = NULL; - testRay = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()); - float nearest=std::numeric_limits::infinity(); - Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; - std::vector instances = _dataModel->getWorkspace()->getAllChildren(); - bool objFound = false; - for(size_t i = 0; i < instances.size(); i++) - { - if(PartInstance* test = dynamic_cast(instances.at(i))) - { - float time = testRay.intersectionTime(test->getBox()); - - if (time != inf()) - { - objFound = true; - if (nearest>time) - { - nearest=time; - //bool found = false; - selectedInstance = test; - /*for(size_t i = 0; i < g_selectedInstances.size(); i++) - { - if(g_selectedInstances.at(i) == test) - { - found = true; - //ShowWindow(_propWindow->_hwndProp, SW_SHOW); - //SetActiveWindow(_propWindow->_hwndProp); - //SetForegroundWindow(_propWindow->_hwndProp); - break; - } - } - if(!found) - { - selectedInstance = test; - //if(!GetHoldKeyState(VK_RCONTROL) && !GetHoldKeyState(VK_LCONTROL)) - //g_selectedInstances.clear(); - //if(std::find(g_selectedInstances.begin(), g_selectedInstances.end(),test)==g_selectedInstances.end()) - //g_selectedInstances.push_back(test); - } - //selectInstance(test, _propWindow); - //_message = "Dragging = true."; - //_messageTime = System::time(); - //_dragging = true;*/ - } - } - } - } - if(!objFound) - selectInstance(_dataModel,_propWindow); - else - { - while(selectedInstance->getParent() != g_dataModel->getWorkspace()) - { - selectedInstance = selectedInstance->getParent(); - } - selectInstance(selectedInstance, _propWindow); - } + tool->onButton1MouseDown(mouse); } } @@ -880,6 +849,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(); @@ -887,15 +857,23 @@ 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.oldx = mouse.x; + mouse.oldy = mouse.y; + mouse.x = x; + mouse.y = y; + //tool->onMouseMoved(mouse); + mouseMoveState = true; + //_dataModel->mousex = x; + //_dataModel->mousey = y; } void Application::onMouseWheel(int x,int y,short delta) @@ -905,6 +883,7 @@ void Application::onMouseWheel(int x,int y,short delta) { AudioPlayer::playSound(cameraSound); } + tool->onMouseScroll(mouse); } void Application::run() { @@ -928,17 +907,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..c33f121 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,7 +56,12 @@ class Application { // : public GApp { RenderDevice* getRenderDevice(); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void setMode(int mode); + + Tool * tool; + void changeTool(Tool *); + Mouse mouse; private: + bool mouseMoveState; RenderDevice* renderDevice; //void initGUI(); HWND _hWndMain; diff --git a/ArrowTool.cpp b/ArrowTool.cpp new file mode 100644 index 0000000..ad58279 --- /dev/null +++ b/ArrowTool.cpp @@ -0,0 +1,82 @@ +#include "ArrowTool.h" +#include "Application.h" + +ArrowTool::ArrowTool(void) +{ + lctrlDown = false; + rctrlDown = false; + dragging = false; + mouseDown = false; +} + +ArrowTool::~ArrowTool(void) +{ +} + +void ArrowTool::onButton1MouseDown(Mouse mouse) +{ + mouseDownStartx = mouse.x; + mouseDownStarty = mouse.y; + mouseDown = true; + if(!lctrlDown && !rctrlDown) + g_selectedInstances.clear(); + PartInstance * target = mouse.getTarget(); + if(target != NULL && std::find(g_selectedInstances.begin(), g_selectedInstances.end(), target) == g_selectedInstances.end()) + g_selectedInstances.push_back(target); + if(g_selectedInstances.size() == 0) + g_selectedInstances.push_back(g_dataModel); + g_usableApp->_propWindow->UpdateSelected(g_selectedInstances[0]); +} +void ArrowTool::onButton1MouseUp(Mouse mouse) +{ + if(dragging) + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); + mouseDown = false; + dragging = false; +} + +void ArrowTool::onMouseMoved(Mouse mouse) +{ + if(mouseDown) + { + if(!dragging) + { + if(abs(mouse.x-mouseDownStartx) > 5 || abs(mouse.y-mouseDownStarty) > 5) + { + this->setCursor(GetFileInPath("/content/images/GrabRotateCursor.png")); + dragging = true; + } + else return; + } + for(size_t i = 0; i < g_selectedInstances.size(); i++) //This will later decide primary and move all parts according to primary + { + if(PartInstance * part = dynamic_cast(g_selectedInstances[i])) + { + part->setPosition(mouse.getPosition(g_selectedInstances)); + } + } + return; + } + PartInstance * target = mouse.getTarget(); + if(target == NULL) + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); + else this->setCursor(GetFileInPath("/content/images/DragCursor.png")); +} +void ArrowTool::onSelect(Mouse mouse) +{ + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); +} + +void ArrowTool::onKeyDown(int key) +{ + if(key == VK_CONTROL) + { + lctrlDown = true; + } +} + +void ArrowTool::onKeyUp(int key) +{ + if(key == VK_CONTROL) + lctrlDown = false; +} \ No newline at end of file diff --git a/ArrowTool.h b/ArrowTool.h new file mode 100644 index 0000000..0da873d --- /dev/null +++ b/ArrowTool.h @@ -0,0 +1,23 @@ +#pragma once +#include "tool.h" + +class ArrowTool : + public Tool +{ +public: + ArrowTool(void); //OnSelect? + ~ArrowTool(void); //OnDeselect? + virtual void onButton1MouseDown(Mouse); + virtual void onButton1MouseUp(Mouse); + virtual void onMouseMoved(Mouse mouse); + virtual void onSelect(Mouse mouse); + virtual void onKeyDown(int key); + virtual void onKeyUp(int key); +private: + bool lctrlDown; + bool rctrlDown; + int mouseDownStartx; + int mouseDownStarty; + bool dragging; + bool mouseDown; +}; diff --git a/BaseButtonInstance.cpp b/BaseButtonInstance.cpp index b1fb23f..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,14 +14,18 @@ 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); } BaseButtonInstance::~BaseButtonInstance(void) { - delete listener; + if(listener != NULL && listener->doDelete) + { + delete listener; + listener = NULL; + } } void BaseButtonInstance::setButtonListener(ButtonListener* buttonListener) diff --git a/ButtonListener.cpp b/ButtonListener.cpp index 8d6c5d0..7d1f9e9 100644 --- a/ButtonListener.cpp +++ b/ButtonListener.cpp @@ -4,6 +4,7 @@ ButtonListener::ButtonListener() { + doDelete = true; } ButtonListener::~ButtonListener(void) diff --git a/ButtonListener.h b/ButtonListener.h index bbf2e40..b334c63 100644 --- a/ButtonListener.h +++ b/ButtonListener.h @@ -1,6 +1,6 @@ #pragma once //#include "Application.h" -//#include "BaseButtonInstance.h" +#include "BaseButtonInstance.h" class BaseButtonInstance; @@ -10,6 +10,7 @@ class ButtonListener ButtonListener(); ~ButtonListener(void); virtual void onButton1MouseClick(BaseButtonInstance*); + bool doDelete; //virtual void onMouseOver(); //TODO //virtual void onMouseOut(); //TODO //virtual void onButton1MouseDown(); //TODO diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 2c9fca2..c3a4b25 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; @@ -452,6 +452,7 @@ bool DataModelInstance::load(const char* filename, bool clearObjects) std::stringstream msg; msg << "Failed to load file:" << std::endl << filename << std::endl << strerror(errno); MessageBoxStr(msg.str()); + return false; } } @@ -586,7 +587,7 @@ WorkspaceInstance* DataModelInstance::getWorkspace() { return workspace; } -Vector2 DataModelInstance::getMousePos() +/*Vector2 DataModelInstance::getMousePos() { return Vector2(mousex,mousey); } @@ -599,7 +600,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 bc40e81..036c122 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -170,7 +170,7 @@ /> + + @@ -303,7 +307,7 @@ > + + @@ -389,6 +397,22 @@ RelativePath=".\RotateButtonListener.cpp" > + + + + + + + + + + @@ -483,6 +511,10 @@ RelativePath=".\StringFunctions.h" > + + @@ -566,6 +598,22 @@ RelativePath=".\ModeSelectionListener.h" > + + + + + + + + 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/GuiRoot.cpp b/GuiRoot.cpp index 7e1fe2a..4bef3a1 100644 --- a/GuiRoot.cpp +++ b/GuiRoot.cpp @@ -15,6 +15,7 @@ #include "RotateButtonListener.h" #include "CameraButtonListener.h" #include "DeleteListener.h" +#include "ToolbarListener.h" #include "ImageButtonInstance.h" @@ -31,9 +32,11 @@ TextButtonInstance* GuiRoot::makeTextButton() TextButtonInstance* part = new TextButtonInstance(); return part; } - +ToolbarListener * toolbar; GuiRoot::GuiRoot() : _message(""), _messageTime(0) { + toolbar = new ToolbarListener(); + toolbar->doDelete = false; g_fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); g_fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); @@ -51,6 +54,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); @@ -66,7 +71,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); - + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -72); @@ -81,6 +87,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -96); @@ -95,6 +103,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -120); @@ -109,6 +119,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); //Top bar button = makeTextButton(); @@ -503,6 +515,11 @@ void GuiRoot::update() } } +GuiRoot::~GuiRoot() +{ + delete toolbar; +} + void GuiRoot::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x,int y) { std::vector instances_2D = this->getAllChildren(); diff --git a/GuiRoot.h b/GuiRoot.h index 546c5b5..a19339f 100644 --- a/GuiRoot.h +++ b/GuiRoot.h @@ -9,6 +9,7 @@ class GuiRoot : public Instance { public: GuiRoot(); + GuiRoot::~GuiRoot(); TextButtonInstance* makeTextButton(); void drawButtons(RenderDevice* rd); ImageButtonInstance* makeImageButton(G3D::TextureRef newImage, G3D::TextureRef overImage, G3D::TextureRef downImage, G3D::TextureRef disableImage); 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/ModeSelectionListener.cpp b/ModeSelectionListener.cpp index 653cd8e..9356155 100644 --- a/ModeSelectionListener.cpp +++ b/ModeSelectionListener.cpp @@ -2,6 +2,7 @@ #include "Instance.h" #include "ModeSelectionListener.h" #include "Application.h" +#include "ArrowTool.h" void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button) { @@ -20,7 +21,7 @@ void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button) button->selected = true; if(button->name == "Cursor") - g_usableApp->setMode(CURSOR); + g_usableApp->changeTool(new ArrowTool()); else if(button->name == "Resize") g_usableApp->setMode(RESIZE); else if(button->name == "Arrows") diff --git a/Mouse.cpp b/Mouse.cpp new file mode 100644 index 0000000..3ead8d0 --- /dev/null +++ b/Mouse.cpp @@ -0,0 +1,116 @@ +#include "Mouse.h" +#include "Application.h" +#include "Globals.h" +#include + +Mouse::Mouse(){ + x = y = 0; +} +Mouse::~Mouse(){} + +PartInstance * selectedInstance = NULL; +Ray testRay; +float nearest=std::numeric_limits::infinity(); +void eprt(PartInstance * instance) +{ + float time = testRay.intersectionTime(instance->getBox()); + if (time != inf()) + { + if (nearest>time) + { + nearest=time; + selectedInstance = instance; + //This is where dead code below was + } + } +} + +PartInstance * Mouse::getTarget() +{ + selectedInstance = NULL; + testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); + nearest=std::numeric_limits::infinity(); + //Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation; + for_each (g_dataModel->getWorkspace()->partObjects.begin(), g_dataModel->getWorkspace()->partObjects.end(), eprt); + return selectedInstance; +} + + +double getVectorDistance(Vector3 vector1, Vector3 vector2) +{ + return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5); +} + +MousePoint Mouse::getPositionAndPart(std::vector ignore) +{ + testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); + PartInstance * currPart = NULL; + Vector3 pos = testRay.closestPoint(Vector3(0,0,0)); + nearest=std::numeric_limits::infinity(); + for(size_t i = 0; i < g_dataModel->getWorkspace()->partObjects.size(); i++) + { + PartInstance * p = g_dataModel->getWorkspace()->partObjects[i]; + if(std::find(ignore.begin(), ignore.end(), p) != ignore.end()) + continue; + float newdistance = testRay.intersectionTime(p->getBox()); //testRay.distance(inter); + if(G3D::isFinite(newdistance)) + { + if(nearest > abs(newdistance)) + { + nearest = newdistance; + pos = testRay.origin+(testRay.direction*nearest); + currPart = p; + } + } + } + return MousePoint(pos, currPart); +} + +Vector3 Mouse::getPosition(std::vector ignore) +{ + return getPositionAndPart(ignore).position; +} + +bool Mouse::isMouseOnScreen() +{ + //hm + return true; +} + +bool Mouse::isMouseDown() +{ + return mouseDown; +} + +void Mouse::setMouseDown(bool bval) +{ + mouseDown = bval; +} + + + + //bool found = false; + /*for(size_t i = 0; i < g_selectedInstances.size(); i++) + { + if(g_selectedInstances.at(i) == test) + { + found = true; + //ShowWindow(_propWindow->_hwndProp, SW_SHOW); + //SetActiveWindow(_propWindow->_hwndProp); + //SetForegroundWindow(_propWindow->_hwndProp); + break; + } + } + if(!found) + { + selectedInstance = test; + //if(!GetHoldKeyState(VK_RCONTROL) && !GetHoldKeyState(VK_LCONTROL)) + //g_selectedInstances.clear(); + //if(std::find(g_selectedInstances.begin(), g_selectedInstances.end(),test)==g_selectedInstances.end()) + //g_selectedInstances.push_back(test); + } + //selectInstance(test, _propWindow); + //_message = "Dragging = true."; + //_messageTime = System::time(); + //_dragging = true;*/ + diff --git a/Mouse.h b/Mouse.h new file mode 100644 index 0000000..929fbf6 --- /dev/null +++ b/Mouse.h @@ -0,0 +1,32 @@ +#pragma once +#include "PartInstance.h" +#pragma once +#include "WorkspaceInstance.h" + +struct MousePoint{ + Vector3 position; + PartInstance * target; + MousePoint(Vector3 pos, PartInstance * targ) + { + position = pos; + target = targ; + } +}; + +#pragma once +class Mouse +{ +public: + Mouse(); + ~Mouse(void); + int x, y; + int oldx, oldy; + PartInstance * getTarget(); + MousePoint getPositionAndPart(std::vector ignore = std::vector()); + Vector3 getPosition(std::vector ignore = std::vector()); + bool isMouseOnScreen(); + bool isMouseDown(); + void setMouseDown(bool mouseDown); +private: + bool mouseDown; +}; diff --git a/PartInstance.cpp b/PartInstance.cpp index e869799..bf84982 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -76,19 +76,20 @@ void PartInstance::postRender(RenderDevice *rd) } } -void PartInstance::setParent(Instance* parent) +void PartInstance::setParent(Instance* prnt) { - Instance * cparent = this->parent; + Instance * cparent = getParent(); while(cparent != NULL) { - if(WorkspaceInstance* workspace = dynamic_cast(parent)) + if(WorkspaceInstance* workspace = dynamic_cast(cparent)) { + std::cout << "Removed from partarray " << std::endl; workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end()); break; } cparent = cparent->getParent(); } - Instance::setParent(parent); + Instance::setParent(prnt); while(parent != NULL) { if(WorkspaceInstance* workspace = dynamic_cast(parent)) @@ -205,8 +206,27 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame) // Can probably be deleted CoordinateFrame PartInstance::getCFrameRenderBased() { - return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); + return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); } + +bool PartInstance::collides(PartInstance * part) +{ + if(shape == Enum::Shape::Block) + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(part->getSphere(), getBox()); + } + else + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(getSphere(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere(getSphere(), part->getSphere()); + } +} + #ifdef NEW_BOX_RENDER Box PartInstance::getBox() { @@ -215,6 +235,13 @@ Box PartInstance::getBox() itemBox = c.toWorldSpace(box); return itemBox; } +Sphere PartInstance::getSphere() +{ + Sphere sphere = Sphere(Vector3(0,0,0), size.y/2); + CoordinateFrame c = getCFrameRenderBased(); + //itemBox = c.toWorldSpace(Sphere); + return sphere;//itemBox; +} #else Box PartInstance::getBox() { @@ -966,6 +993,7 @@ static TCHAR* enumStr(int shape) case Enum::Shape::Cylinder: return "Cylinder"; } + return "Block"; } void PartInstance::PropUpdate(LPPROPGRIDITEM &item) diff --git a/PartInstance.h b/PartInstance.h index b47e22b..6df56b7 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -31,10 +31,12 @@ public: void setParent(Instance* parent); void setPosition(Vector3); void setVelocity(Vector3); + bool collides(PartInstance * part); void setRotVelocity(Vector3); CoordinateFrame getCFrame(); void setCFrame(CoordinateFrame); Box getBox(); + Sphere getSphere(); Box getScaledBox(); CoordinateFrame getCFrameRenderBased(); Vector3 getSize(); diff --git a/TextureHandler.cpp b/TextureHandler.cpp new file mode 100644 index 0000000..9e3a578 --- /dev/null +++ b/TextureHandler.cpp @@ -0,0 +1,12 @@ +#include "TextureHandler.h" + +TextureHandler::TextureHandler(void) +{ +} + +TextureHandler::~TextureHandler(void) +{ +} +std::map TextureHandler::volTex = std::map(); +std::map TextureHandler::volExp = std::map(); +std::map TextureHandler::permTex = std::map(); \ No newline at end of file diff --git a/TextureHandler.h b/TextureHandler.h new file mode 100644 index 0000000..0c0abf9 --- /dev/null +++ b/TextureHandler.h @@ -0,0 +1,87 @@ +#pragma once +#include +#include +class TextureHandler +{ +public: + TextureHandler(void); + ~TextureHandler(void); + static int getTextureVolatile(std::string str) + { + if(!volTex[str].isNull()) + { + volExp[str] = G3D::System::time(); + return volTex[str]->openGLID(); + } + else + { + G3D::TextureRef tex = G3D::Texture::fromFile(str); + volExp[str] = G3D::System::time(); + volTex[str] = tex; + return tex->openGLID(); + } + } + static int getTexturePermanent(std::string str) + { + if(!permTex[str].isNull()) + { + return permTex[str]->openGLID(); + } + else + { + G3D::TextureRef tex = G3D::Texture::fromFile(str); + permTex[str] = tex; + return tex->openGLID(); + } + } + static void flushVolatile() + { + std::map::iterator it; + for (it=volExp.begin(); it!=volExp.end(); ++it) + { + if(it->second < G3D::System::time() - 3) + { + volTex[it->first]->~Texture(); + volTex.erase(it->first); + volExp.erase(it->first); + //it->second->~ReferenceCountedPointer(); + } + } + } + static void dispose() + { + std::map::iterator it; + for (it=volTex.begin(); it!=volTex.end(); ++it) + { + it->second->~Texture(); + //it->second->~ReferenceCountedPointer(); + } + for (it=permTex.begin(); it!=permTex.end(); ++it) + { + it->second->~Texture(); + //it->second->~ReferenceCountedPointer(); + } + permTex.clear(); + volTex.clear(); + } + + static void remove(std::string str) + { + if(!volTex[str].isNull()) + { + volTex[str]->~Texture(); + //volTex[str]->~ReferenceCountedPointer(); + volTex.erase(str); + } + if(!permTex[str].isNull()) + { + permTex[str]->~Texture(); + //permTex[str]->~ReferenceCountedPointer(); + permTex.erase(str); + } + } +private: + static std::map volTex; + static std::map volExp; + static std::map permTex; +}; \ No newline at end of file diff --git a/Tool.cpp b/Tool.cpp new file mode 100644 index 0000000..25f8f93 --- /dev/null +++ b/Tool.cpp @@ -0,0 +1,32 @@ +#include "Tool.h" + +Tool::Tool(void) +{ + cursorString = GetFileInPath("/content/images/ArrowFarCursor.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(int key){} +void Tool::onKeyUp(int key){} +void Tool::setCursor(std::string str) +{ + cursorString = str; +} +int Tool::getCursorId() +{ + return TextureHandler::getTexturePermanent(cursorString); +} \ No newline at end of file diff --git a/Tool.h b/Tool.h new file mode 100644 index 0000000..292db3f --- /dev/null +++ b/Tool.h @@ -0,0 +1,34 @@ +#pragma once +#include "TextureHandler.h" +#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); + virtual void onButton1MouseDown(Mouse); //yes + virtual void onButton2MouseDown(Mouse); //yes + virtual void onButton3MouseDown(Mouse); //no + virtual void onButton1MouseUp(Mouse);//yes + virtual void onButton2MouseUp(Mouse);//yes + virtual void onButton3MouseUp(Mouse); //no + virtual void onMouseMoved(Mouse);//yes + virtual void onSelect(Mouse);//yes + virtual void onDeselect(Mouse);//yes + virtual void onMouseScroll(Mouse);//Kinda + virtual void onKeyDown(int);//yes + virtual void onKeyUp(int);//yes + virtual int getCursorId();//yes +protected: + virtual void setCursor(std::string); +private: + std::string cursorString; +}; diff --git a/ToolbarListener.cpp b/ToolbarListener.cpp new file mode 100644 index 0000000..f551275 --- /dev/null +++ b/ToolbarListener.cpp @@ -0,0 +1,23 @@ +#include "ToolbarListener.h" +#include "Globals.h" +#include "StringFunctions.h" +#include "Application.h" + +void ToolbarListener::onButton1MouseClick(BaseButtonInstance* btn) +{ + if(TextButtonInstance* button = dynamic_cast(btn)) + { + for(size_t i = 0; i < btns.size(); i++) + btns[i]->selected = false; + button->selected = true; + if(button->title == "Model") g_usableApp->navigateToolbox("http://androdome.com/res/ClientToolbox.php"); + else if(button->title == "Surface") g_usableApp->navigateToolbox(GetFileInPath("/content/page/surface.html")); + else if(button->title == "Color") g_usableApp->navigateToolbox(GetFileInPath("/content/page/color.html")); + else if(button->title == "Controller") g_usableApp->navigateToolbox(GetFileInPath("/content/page/controller.html")); + else if(button->title == "Hopper") g_usableApp->navigateToolbox(GetFileInPath("/content/page/hopper.html")); + } +} +void ToolbarListener::addButtonRef(BaseButtonInstance* button) +{ + btns.push_back(button); +} \ No newline at end of file diff --git a/ToolbarListener.h b/ToolbarListener.h new file mode 100644 index 0000000..21079a4 --- /dev/null +++ b/ToolbarListener.h @@ -0,0 +1,13 @@ +#pragma once +#include "buttonlistener.h" +#pragma once +#include + +class ToolbarListener : public ButtonListener +{ +public: + void onButton1MouseClick(BaseButtonInstance* button); + void addButtonRef(BaseButtonInstance* button); +private: + std::vector btns; +}; diff --git a/content/images/ArrowFarCursor.png b/content/images/ArrowFarCursor.png new file mode 100644 index 0000000..9a1954a Binary files /dev/null and b/content/images/ArrowFarCursor.png differ diff --git a/content/page/color.html b/content/page/color.html index 8858292..acdb23f 100644 Binary files a/content/page/color.html and b/content/page/color.html differ diff --git a/content/page/hopper.html b/content/page/hopper.html index d1e1ea2..f20c4a0 100644 --- a/content/page/hopper.html +++ b/content/page/hopper.html @@ -22,25 +22,25 @@ } - + - + - + - + - + - + - + diff --git a/content/page/surface.html b/content/page/surface.html index f1652d1..a165e6a 100644 --- a/content/page/surface.html +++ b/content/page/surface.html @@ -12,12 +12,12 @@ } - - - - - - - + + + + + + + \ No newline at end of file