Starting to transfer everything to Tool

This commit is contained in:
andreja6
2020-03-11 23:10:49 -07:00
parent 72c6d19d7f
commit 0ec896e2fd
15 changed files with 212 additions and 58 deletions

View File

@@ -32,11 +32,9 @@
#include "RotateButtonListener.h" #include "RotateButtonListener.h"
#define LEGACY_LOAD_G3DFUN_LEVEL #define LEGACY_LOAD_G3DFUN_LEVEL
Ray testRay; Ray testRay;
static int cursorid = 0; //static int cursorid = 0;
static int cursorOvrid = 0; //static int cursorOvrid = 0;
static int currentcursorid = 0; //static int currentcursorid = 0;
static G3D::TextureRef cursor = NULL;
static G3D::TextureRef cursorOvr = NULL;
static bool mouseMovedBeginMotion = false; static bool mouseMovedBeginMotion = false;
static POINT oldGlobalMouse; static POINT oldGlobalMouse;
Vector2 oldMouse = Vector2(0,0); Vector2 oldMouse = Vector2(0,0);
@@ -181,7 +179,7 @@ void Application::deleteInstance()
void Application::onInit() { void Application::onInit() {
tool = new Tool();
// Called before Application::run() beings // Called before Application::run() beings
cameraController.setFrame(Vector3(0,2,10)); cameraController.setFrame(Vector3(0,2,10));
_dataModel = new DataModelInstance(); _dataModel = new DataModelInstance();
@@ -440,14 +438,14 @@ void Application::onUserInput(UserInput* ui) {
//_dataModel->mousex = ui->getMouseX(); //_dataModel->mousex = ui->getMouseX();
//_dataModel->mousey = ui->getMouseY(); //_dataModel->mousey = ui->getMouseY();
_dataModel->mouseButton1Down = (GetKeyState(VK_LBUTTON) & 0x100) != 0; mouse.setMouseDown((GetKeyState(VK_LBUTTON) & 0x100) != 0);
if (GetHoldKeyState(VK_LBUTTON)) { if (GetHoldKeyState(VK_LBUTTON)) {
if (_dragging) { if (_dragging) {
PartInstance* part = NULL; PartInstance* part = NULL;
if(g_selectedInstances.size() > 0) if(g_selectedInstances.size() > 0)
part = (PartInstance*) g_selectedInstances.at(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<Instance*> instances = _dataModel->getWorkspace()->getAllChildren(); std::vector<Instance*> instances = _dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances.size(); i++) 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 ); glBegin( GL_QUADS );
@@ -767,10 +765,11 @@ void Application::onKeyPressed(int key)
{ {
_dataModel->getOpen(); _dataModel->getOpen();
} }
tool->onKeyDown(key);
} }
void Application::onKeyUp(int key) void Application::onKeyUp(int key)
{ {
tool->onKeyUp(key);
} }
void Application::onMouseLeftPressed(HWND hwnd,int x,int y) 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; //std::cout << "Click: " << x << "," << y << std::endl;
bool onGUI = _dataModel->getGuiRoot()->mouseInGUI(renderDevice, x, y); bool onGUI = _dataModel->getGuiRoot()->mouseInGUI(renderDevice, x, y);
if(!onGUI) if(!onGUI)
{ {
tool->onButton1MouseDown(mouse);
Instance * selectedInstance = NULL; 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<float>::infinity(); float nearest=std::numeric_limits<float>::infinity();
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
std::vector<Instance*> instances = _dataModel->getWorkspace()->getAllChildren(); std::vector<Instance*> 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; //std::cout << "Release: " << x << "," << y << std::endl;
_dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y); _dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y);
_dragging = false; _dragging = false;
tool->onButton1MouseUp(mouse);
//_message = "Dragging = false."; //_message = "Dragging = false.";
//_messageTime = System::time(); //_messageTime = System::time();
@@ -875,15 +877,20 @@ void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y)
void Application::onMouseRightPressed(int x,int y) void Application::onMouseRightPressed(int x,int y)
{ {
tool->onButton2MouseDown(mouse);
} }
void Application::onMouseRightUp(int x,int y) void Application::onMouseRightUp(int x,int y)
{ {
tool->onButton2MouseUp(mouse);
} }
void Application::onMouseMoved(int x,int y) void Application::onMouseMoved(int x,int y)
{ {
oldMouse = _dataModel->getMousePos(); oldMouse = Vector2(mouse.x, mouse.y);
_dataModel->mousex = x; mouse.x = x;
_dataModel->mousey = y; mouse.y = y;
tool->onMouseMoved(mouse);
//_dataModel->mousex = x;
//_dataModel->mousey = y;
} }
void Application::onMouseWheel(int x,int y,short delta) 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); AudioPlayer::playSound(cameraSound);
} }
tool->onMouseScroll(mouse);
} }
void Application::run() { void Application::run() {
@@ -916,17 +924,13 @@ void Application::run() {
UpdateWindow(_hWndMain); UpdateWindow(_hWndMain);
// Load objects here= // 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::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png"));
Globals::surfaceId = Globals::surface->getOpenGLID(); Globals::surfaceId = Globals::surface->getOpenGLID();
cameraSound = GetFileInPath("/content/sounds/SWITCH3.wav"); cameraSound = GetFileInPath("/content/sounds/SWITCH3.wav");
clickSound = GetFileInPath("/content/sounds/switch.wav"); clickSound = GetFileInPath("/content/sounds/switch.wav");
dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav"); dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav");
sky = Sky::create(NULL, ExePath() + "/content/sky/"); sky = Sky::create(NULL, ExePath() + "/content/sky/");
cursorid = cursor->openGLID();
currentcursorid = cursorid;
cursorOvrid = cursorOvr->openGLID();
RealTime now=0, lastTime=0; RealTime now=0, lastTime=0;
double simTimeRate = 1.0f; double simTimeRate = 1.0f;
float fps=30.0f; float fps=30.0f;

View File

@@ -5,6 +5,8 @@
#include "ImageButtonInstance.h" #include "ImageButtonInstance.h"
#include "CameraController.h" #include "CameraController.h"
#include "IEBrowser.h" #include "IEBrowser.h"
#include "Mouse.h"
#include "Tool.h"
//#include "GuiRoot.h" //#include "GuiRoot.h"
class TextButtonInstance; class TextButtonInstance;
@@ -54,6 +56,8 @@ class Application { // : public GApp {
RenderDevice* getRenderDevice(); RenderDevice* getRenderDevice();
void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow);
void setMode(int mode); void setMode(int mode);
Mouse mouse;
Tool * tool;
private: private:
RenderDevice* renderDevice; RenderDevice* renderDevice;
//void initGUI(); //void initGUI();

View File

@@ -1,5 +1,6 @@
#include "BaseButtonInstance.h" #include "BaseButtonInstance.h"
#include "Globals.h" #include "Globals.h"
#include "Application.h"
ButtonListener* listener = NULL; ButtonListener* listener = NULL;
@@ -13,8 +14,8 @@ BaseButtonInstance::BaseButtonInstance(void)
void BaseButtonInstance::render(RenderDevice* rd) void BaseButtonInstance::render(RenderDevice* rd)
{ {
DataModelInstance* dataModel = g_dataModel; DataModelInstance* dataModel = g_dataModel;
Vector2 pos = Vector2(dataModel->mousex,dataModel->mousey); Vector2 pos = Vector2(g_usableApp->mouse.x,g_usableApp->mouse.y);
drawObj(rd, pos, dataModel->mouseButton1Down); drawObj(rd, pos, g_usableApp->mouse.isMouseDown());
Instance::render(rd); Instance::render(rd);
} }

View File

@@ -20,9 +20,9 @@ DataModelInstance::DataModelInstance(void)
//children.push_back(workspace); //children.push_back(workspace);
//children.push_back(level); //children.push_back(level);
className = "dataModel"; className = "dataModel";
mousex = 0; //mousex = 0;
mousey = 0; //mousey = 0;
mouseButton1Down = false; //mouseButton1Down = false;
showMessage = false; showMessage = false;
canDelete = false; canDelete = false;
_modY=0; _modY=0;
@@ -586,7 +586,7 @@ WorkspaceInstance* DataModelInstance::getWorkspace()
{ {
return workspace; return workspace;
} }
Vector2 DataModelInstance::getMousePos() /*Vector2 DataModelInstance::getMousePos()
{ {
return Vector2(mousex,mousey); return Vector2(mousex,mousey);
} }
@@ -599,7 +599,7 @@ void DataModelInstance::setMousePos(Vector2 pos)
{ {
mousex=pos.x; mousex=pos.x;
mousey=pos.y; mousey=pos.y;
} }*/
GuiRoot* DataModelInstance::getGuiRoot() GuiRoot* DataModelInstance::getGuiRoot()
{ {
return guiRoot; return guiRoot;

View File

@@ -28,12 +28,12 @@ public:
bool showMessage; bool showMessage;
G3D::GFontRef font; G3D::GFontRef font;
GuiRoot* getGuiRoot(); GuiRoot* getGuiRoot();
float mousex; //float mousex;
float mousey; //float mousey;
Vector2 getMousePos(); //Vector2 getMousePos();
void setMousePos(int x,int y); //void setMousePos(int x,int y);
void setMousePos(Vector2 pos); //void setMousePos(Vector2 pos);
bool mouseButton1Down; //bool mouseButton1Down;
PartInstance* makePart(); PartInstance* makePart();
void clearLevel(); void clearLevel();
void toggleRun(); void toggleRun();

View File

@@ -290,6 +290,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\Mouse.cpp"
>
</File>
<File <File
RelativePath=".\propertyGrid.cpp" RelativePath=".\propertyGrid.cpp"
> >
@@ -302,10 +306,6 @@
RelativePath=".\StringFunctions.cpp" RelativePath=".\StringFunctions.cpp"
> >
</File> </File>
<File
RelativePath=".\Tool.cpp"
>
</File>
<File <File
RelativePath=".\WindowFunctions.cpp" RelativePath=".\WindowFunctions.cpp"
> >
@@ -398,6 +398,14 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="Tools"
>
<File
RelativePath=".\Tool.cpp"
>
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
@@ -455,6 +463,10 @@
RelativePath=".\LevelInstance.h" RelativePath=".\LevelInstance.h"
> >
</File> </File>
<File
RelativePath=".\Mouse.h"
>
</File>
<File <File
RelativePath=".\propertyGrid.h" RelativePath=".\propertyGrid.h"
> >
@@ -495,10 +507,6 @@
RelativePath=".\ToggleImageButtonInstance.h" RelativePath=".\ToggleImageButtonInstance.h"
> >
</File> </File>
<File
RelativePath=".\Tool.h"
>
</File>
<File <File
RelativePath=".\win32Defines.h" RelativePath=".\win32Defines.h"
> >
@@ -583,6 +591,14 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="Tools"
>
<File
RelativePath=".\Tool.h"
>
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"

View File

@@ -28,4 +28,6 @@ std::string cameraSound="";
std::string clickSound=""; std::string clickSound="";
std::string dingSound=""; std::string dingSound="";
Application *g_usableApp = NULL; Application *g_usableApp = NULL;
COLORREF g_acrCustClr[16] = {RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255)};

View File

@@ -20,6 +20,7 @@ public:
static G3D::TextureRef surface; static G3D::TextureRef surface;
static int surfaceId; static int surfaceId;
static const std::string g_PlaceholderName; static const std::string g_PlaceholderName;
static COLORREF g_acrCustClr[16]; //Will be dynamic later
}; };
extern std::vector<Instance*> postRenderStack; extern std::vector<Instance*> postRenderStack;
@@ -31,7 +32,8 @@ extern Application* g_usableApp;
extern GFontRef g_fntdominant; extern GFontRef g_fntdominant;
extern GFontRef g_fntlighttrek; extern GFontRef g_fntlighttrek;
extern COLORREF g_acrCustClr[16]; //Will be dynamic later
extern std::string cameraSound; extern std::string cameraSound;
extern std::string clickSound; extern std::string clickSound;
extern std::string dingSound; extern std::string dingSound;
const std::string g_PlaceholderName = "HyperCube"; const std::string g_PlaceholderName = "Dygysphere";

View File

@@ -4,7 +4,7 @@
#include <windows.h> #include <windows.h>
#include <Commdlg.h>
#include "IEBrowser.h" #include "IEBrowser.h"
#include "Globals.h" #include "Globals.h"
#pragma once #pragma once
@@ -28,7 +28,9 @@ HRESULT IEBrowser::doExternal(std::wstring funcName,
} }
else if (funcName==L"ToggleHopperBin") 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") else if (funcName==L"SetController")
{ {
@@ -51,10 +53,41 @@ HRESULT IEBrowser::doExternal(std::wstring funcName,
AudioPlayer::playSound(dingSound); AudioPlayer::playSound(dingSound);
return S_OK; 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) { IEBrowser::IEBrowser(HWND attachHWnd) {

31
Mouse.cpp Normal file
View File

@@ -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;
}

18
Mouse.h Normal file
View File

@@ -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;
};

View File

@@ -2,8 +2,34 @@
Tool::Tool(void) Tool::Tool(void)
{ {
cursorRef = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png"));
cursorId = cursorRef->openGLID();
} }
Tool::~Tool(void) 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;
}

37
Tool.h
View File

@@ -1,17 +1,34 @@
#pragma once #pragma once
#include <G3DAll.h>
#pragma once
#include "Mouse.h"
#pragma once
#include "Globals.h"
#pragma once
#include "StringFunctions.h"
#pragma once
class Tool class Tool
{ {
public: public:
Tool(void); Tool(void);
~Tool(void); ~Tool(void);
void OnButton1MouseDown(); void onButton1MouseDown(Mouse); //yes
void OnButton2MouseDown(); void onButton2MouseDown(Mouse); //yes
void OnButton3MouseDown(); void onButton3MouseDown(Mouse);
void OnButton1MouseUp(); void onButton1MouseUp(Mouse);//yes
void OnButton2MouseUp(); void onButton2MouseUp(Mouse);//yes
void OnButton3MouseUp(); void onButton3MouseUp(Mouse);
void OnMouseScroll(); void onMouseMoved(Mouse);//yes
void OnKeyDown(); void onSelect(Mouse);//For later
void OnKeyUp(); 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;
}; };

Binary file not shown.

View File

@@ -22,7 +22,7 @@
} }
</style> </style>
<body style="background-color: ButtonFace; margin: 0; padding: 5px; overflow: hidden; border:0;"> <body style="background-color: ButtonFace; margin: 0; padding: 5px; overflow: hidden; border:0;">
<span class="container" onmousedown="toolOvr(this)" onmouseup="toolOut(this)" onmouseout="toolOut(this)" onclick="window.external.ToggleHopperBin(0)"> <span class="container" onmousedown="toolOvr(this)" onmouseup="toolOut(this)" onmouseout="toolOut(this)" onclick="alert(window.external.ToggleHopperBin(0))">
<img src="../images/GameTool.png" /> <img src="../images/GameTool.png" />
</span> </span>
<span class="container" onmousedown="toolOvr(this)" onmouseup="toolOut(this)" onmouseout="toolOut(this)" onclick="window.external.ToggleHopperBin(1)"> <span class="container" onmousedown="toolOvr(this)" onmouseup="toolOut(this)" onmouseout="toolOut(this)" onclick="window.external.ToggleHopperBin(1)">