Added tools and texture handler
This commit is contained in:
@@ -30,8 +30,8 @@
|
||||
#include "DeleteListener.h"
|
||||
#include "CameraButtonListener.h"
|
||||
#include "RotateButtonListener.h"
|
||||
#define LEGACY_LOAD_G3DFUN_LEVEL
|
||||
Ray testRay;
|
||||
//#define LEGACY_LOAD_G3DFUN_LEVEL
|
||||
//Ray testRay;
|
||||
//static int cursorid = 0;
|
||||
//static int cursorOvrid = 0;
|
||||
//static int currentcursorid = 0;
|
||||
@@ -161,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());
|
||||
@@ -415,7 +414,11 @@ bool IsHolding(int button)
|
||||
*/
|
||||
|
||||
void Application::onUserInput(UserInput* ui) {
|
||||
|
||||
if(mouseMoveState)
|
||||
{
|
||||
mouseMoveState = false;
|
||||
tool->onMouseMoved(mouse);
|
||||
}
|
||||
/*
|
||||
if(GetHoldKeyState(VK_LCONTROL))
|
||||
{
|
||||
@@ -441,7 +444,7 @@ void Application::onUserInput(UserInput* ui) {
|
||||
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);
|
||||
@@ -466,7 +469,7 @@ void Application::onUserInput(UserInput* ui) {
|
||||
}
|
||||
}
|
||||
Sleep(10);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
// Camera KB Handling {
|
||||
if (GetKPBool(VK_OEM_COMMA)) //Left
|
||||
@@ -485,11 +488,14 @@ void Application::onUserInput(UserInput* ui) {
|
||||
|
||||
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)
|
||||
@@ -795,63 +801,6 @@ void Application::onMouseLeftPressed(HWND hwnd,int x,int y)
|
||||
if(!onGUI)
|
||||
{
|
||||
tool->onButton1MouseDown(mouse);
|
||||
Instance * selectedInstance = NULL;
|
||||
testRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport());
|
||||
float nearest=std::numeric_limits<float>::infinity();
|
||||
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
|
||||
std::vector<Instance*> instances = _dataModel->getWorkspace()->getAllChildren();
|
||||
bool objFound = false;
|
||||
for(size_t i = 0; i < instances.size(); i++)
|
||||
{
|
||||
if(PartInstance* test = dynamic_cast<PartInstance*>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -895,9 +844,12 @@ void Application::onMouseRightUp(int x,int y)
|
||||
void Application::onMouseMoved(int x,int y)
|
||||
{
|
||||
oldMouse = Vector2(mouse.x, mouse.y);
|
||||
mouse.oldx = mouse.x;
|
||||
mouse.oldy = mouse.y;
|
||||
mouse.x = x;
|
||||
mouse.y = y;
|
||||
tool->onMouseMoved(mouse);
|
||||
//tool->onMouseMoved(mouse);
|
||||
mouseMoveState = true;
|
||||
//_dataModel->mousex = x;
|
||||
//_dataModel->mousey = y;
|
||||
|
||||
|
||||
@@ -56,10 +56,12 @@ class Application { // : public GApp {
|
||||
RenderDevice* getRenderDevice();
|
||||
void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow);
|
||||
void setMode(int mode);
|
||||
Mouse mouse;
|
||||
|
||||
Tool * tool;
|
||||
void changeTool(Tool *);
|
||||
Mouse mouse;
|
||||
private:
|
||||
bool mouseMoveState;
|
||||
RenderDevice* renderDevice;
|
||||
//void initGUI();
|
||||
HWND _hWndMain;
|
||||
|
||||
28
ArrowTool.cpp
Normal file
28
ArrowTool.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "ArrowTool.h"
|
||||
|
||||
ArrowTool::ArrowTool(void)
|
||||
{
|
||||
}
|
||||
|
||||
ArrowTool::~ArrowTool(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ArrowTool::onButton1MouseDown(Mouse mouse)
|
||||
{
|
||||
g_selectedInstances.clear();
|
||||
PartInstance * target = mouse.getTarget();
|
||||
if(target != NULL)
|
||||
g_selectedInstances.push_back(target);
|
||||
}
|
||||
void ArrowTool::onMouseMoved(Mouse mouse)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
13
ArrowTool.h
Normal file
13
ArrowTool.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "tool.h"
|
||||
|
||||
class ArrowTool :
|
||||
public Tool
|
||||
{
|
||||
public:
|
||||
ArrowTool(void); //OnSelect?
|
||||
~ArrowTool(void); //OnDeselect?
|
||||
virtual void onButton1MouseDown(Mouse);
|
||||
virtual void onMouseMoved(Mouse mouse);
|
||||
virtual void onSelect(Mouse mouse); //Why is this not being called
|
||||
};
|
||||
@@ -306,6 +306,10 @@
|
||||
RelativePath=".\StringFunctions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TextureHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\WindowFunctions.cpp"
|
||||
>
|
||||
@@ -401,6 +405,10 @@
|
||||
<Filter
|
||||
Name="Tools"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\ArrowTool.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tool.cpp"
|
||||
>
|
||||
@@ -503,6 +511,10 @@
|
||||
RelativePath=".\StringFunctions.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TextureHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ToggleImageButtonInstance.h"
|
||||
>
|
||||
@@ -594,6 +606,10 @@
|
||||
<Filter
|
||||
Name="Tools"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\ArrowTool.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tool.h"
|
||||
>
|
||||
|
||||
@@ -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")
|
||||
|
||||
65
Mouse.cpp
65
Mouse.cpp
@@ -1,14 +1,43 @@
|
||||
#include "Mouse.h"
|
||||
#include "Application.h"
|
||||
#include "Globals.h"
|
||||
Mouse::Mouse(){
|
||||
x = y = 0;
|
||||
}
|
||||
Mouse::~Mouse(){}
|
||||
|
||||
|
||||
Instance * Mouse::getTarget()
|
||||
PartInstance * selectedInstance = NULL;
|
||||
Ray testRay;
|
||||
float nearest=std::numeric_limits<float>::infinity();
|
||||
void eprt(PartInstance * instance)
|
||||
{
|
||||
return NULL;
|
||||
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<float>::infinity();
|
||||
//Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation;
|
||||
for_each (g_dataModel->getWorkspace()->partObjects.begin(), g_dataModel->getWorkspace()->partObjects.end(), eprt);
|
||||
return selectedInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vector3 Mouse::getPosition()
|
||||
{
|
||||
return Vector3();
|
||||
@@ -28,4 +57,32 @@ bool Mouse::isMouseDown()
|
||||
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;*/
|
||||
|
||||
|
||||
8
Mouse.h
8
Mouse.h
@@ -1,14 +1,18 @@
|
||||
#pragma once
|
||||
#include "PartInstance.h"
|
||||
#pragma once
|
||||
#include "WorkspaceInstance.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Mouse
|
||||
{
|
||||
public:
|
||||
Mouse(void);
|
||||
Mouse();
|
||||
~Mouse(void);
|
||||
int x, y;
|
||||
Instance * getTarget();
|
||||
int oldx, oldy;
|
||||
PartInstance * getTarget();
|
||||
Vector3 getPosition();
|
||||
bool isMouseOnScreen();
|
||||
bool isMouseDown();
|
||||
|
||||
12
TextureHandler.cpp
Normal file
12
TextureHandler.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "TextureHandler.h"
|
||||
|
||||
TextureHandler::TextureHandler(void)
|
||||
{
|
||||
}
|
||||
|
||||
TextureHandler::~TextureHandler(void)
|
||||
{
|
||||
}
|
||||
std::map<std::string, G3D::TextureRef> TextureHandler::volTex = std::map<std::string, G3D::TextureRef>();
|
||||
std::map<std::string, G3D::RealTime> TextureHandler::volExp = std::map<std::string, G3D::RealTime>();
|
||||
std::map<std::string, G3D::TextureRef> TextureHandler::permTex = std::map<std::string, G3D::TextureRef>();
|
||||
87
TextureHandler.h
Normal file
87
TextureHandler.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
#include <G3DAll.h>
|
||||
#include <map>
|
||||
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<std::string, G3D::RealTime>::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<std::string, G3D::TextureRef>::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<std::string, G3D::TextureRef> volTex;
|
||||
static std::map<std::string, G3D::RealTime> volExp;
|
||||
static std::map<std::string, G3D::TextureRef> permTex;
|
||||
};
|
||||
13
Tool.cpp
13
Tool.cpp
@@ -2,8 +2,8 @@
|
||||
|
||||
Tool::Tool(void)
|
||||
{
|
||||
cursorRef = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png"));
|
||||
cursorId = cursorRef->openGLID();
|
||||
cursorString = GetFileInPath("/content/images/ArrowFarCursor.png");
|
||||
//cursorId = cursorRef->openGLID();
|
||||
}
|
||||
|
||||
Tool::~Tool(void)
|
||||
@@ -22,14 +22,11 @@ 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)
|
||||
void Tool::setCursor(std::string str)
|
||||
{
|
||||
cursorString = str;
|
||||
}
|
||||
int Tool::getCursorId()
|
||||
{
|
||||
return cursorId;
|
||||
}
|
||||
void Tool::setCursorId(int id)
|
||||
{
|
||||
cursorId = id;
|
||||
return TextureHandler::getTexturePermanent(cursorString);
|
||||
}
|
||||
34
Tool.h
34
Tool.h
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include "TextureHandler.h"
|
||||
#pragma once
|
||||
#include <G3DAll.h>
|
||||
#pragma once
|
||||
#include "Mouse.h"
|
||||
@@ -12,23 +14,21 @@ class Tool
|
||||
public:
|
||||
Tool(void);
|
||||
~Tool(void);
|
||||
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
|
||||
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(char);//yes
|
||||
virtual void onKeyUp(char);//yes
|
||||
virtual int getCursorId();//yes
|
||||
protected:
|
||||
virtual void setCursor(std::string);
|
||||
private:
|
||||
int cursorId;
|
||||
G3D::TextureRef cursorRef;
|
||||
std::string cursorString;
|
||||
};
|
||||
|
||||
BIN
content/images/ArrowFarCursor.png
Normal file
BIN
content/images/ArrowFarCursor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user