Changed how buttons render
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include "BaseButtonInstance.h"
|
#include "BaseButtonInstance.h"
|
||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
bool floatBottom = false;
|
bool floatBottom = false;
|
||||||
bool floatRight = false;
|
bool floatRight = false;
|
||||||
@@ -12,6 +13,14 @@ BaseButtonInstance::BaseButtonInstance(void)
|
|||||||
listener = NULL;
|
listener = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseButtonInstance::render(RenderDevice* rd)
|
||||||
|
{
|
||||||
|
DataModelInstance* dataModel = Globals::dataModel;
|
||||||
|
Vector2 pos = Vector2(dataModel->mousex,dataModel->mousey);
|
||||||
|
drawObj(rd, pos, dataModel->mouseButton1Down);
|
||||||
|
Instance::render(rd);
|
||||||
|
}
|
||||||
|
|
||||||
BaseButtonInstance::~BaseButtonInstance(void)
|
BaseButtonInstance::~BaseButtonInstance(void)
|
||||||
{
|
{
|
||||||
delete listener;
|
delete listener;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class BaseButtonInstance : public Instance
|
|||||||
public:
|
public:
|
||||||
BaseButtonInstance(void);
|
BaseButtonInstance(void);
|
||||||
virtual ~BaseButtonInstance(void);
|
virtual ~BaseButtonInstance(void);
|
||||||
|
virtual void render(RenderDevice* rd);
|
||||||
virtual void drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown);
|
virtual void drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown);
|
||||||
virtual bool mouseInButton(float, float, RenderDevice* rd);
|
virtual bool mouseInButton(float, float, RenderDevice* rd);
|
||||||
virtual void onMouseClick();
|
virtual void onMouseClick();
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
WorkspaceInstance* workspace;
|
WorkspaceInstance* workspace;
|
||||||
Instance* guiRoot;
|
Instance* guiRoot;
|
||||||
|
float mousex;
|
||||||
|
float mousey;
|
||||||
|
bool mouseButton1Down;
|
||||||
|
|
||||||
|
|
||||||
DataModelInstance::DataModelInstance(void)
|
DataModelInstance::DataModelInstance(void)
|
||||||
{
|
{
|
||||||
@@ -10,6 +14,9 @@ DataModelInstance::DataModelInstance(void)
|
|||||||
guiRoot = new Instance();
|
guiRoot = new Instance();
|
||||||
children.push_back(workspace);
|
children.push_back(workspace);
|
||||||
className = "dataModel";
|
className = "dataModel";
|
||||||
|
mousex = 0;
|
||||||
|
mousey = 0;
|
||||||
|
mouseButton1Down = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataModelInstance::~DataModelInstance(void)
|
DataModelInstance::~DataModelInstance(void)
|
||||||
|
|||||||
@@ -10,4 +10,7 @@ public:
|
|||||||
~DataModelInstance(void);
|
~DataModelInstance(void);
|
||||||
WorkspaceInstance* getWorkspace();
|
WorkspaceInstance* getWorkspace();
|
||||||
Instance* getGuiRoot();
|
Instance* getGuiRoot();
|
||||||
|
float mousex;
|
||||||
|
float mousey;
|
||||||
|
bool mouseButton1Down;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -242,6 +242,10 @@
|
|||||||
RelativePath=".\Dialogs.rc"
|
RelativePath=".\Dialogs.rc"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Globals.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="main.cpp"
|
RelativePath="main.cpp"
|
||||||
>
|
>
|
||||||
@@ -307,6 +311,10 @@
|
|||||||
RelativePath=".\ButtonListener.h"
|
RelativePath=".\ButtonListener.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Globals.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\resource.h"
|
RelativePath=".\resource.h"
|
||||||
>
|
>
|
||||||
|
|||||||
12
Globals.cpp
Normal file
12
Globals.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
|
DataModelInstance* Globals::dataModel = NULL;
|
||||||
|
|
||||||
|
Globals::Globals(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Globals::~Globals(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
10
Globals.h
Normal file
10
Globals.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DataModelInstance.h"
|
||||||
|
|
||||||
|
class Globals
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Globals(void);
|
||||||
|
~Globals(void);
|
||||||
|
static DataModelInstance* dataModel;
|
||||||
|
};
|
||||||
37
main.cpp
37
main.cpp
@@ -19,6 +19,7 @@
|
|||||||
#include "ImageButtonInstance.h"
|
#include "ImageButtonInstance.h"
|
||||||
#include "DataModelInstance.h"
|
#include "DataModelInstance.h"
|
||||||
#include "AudioPlayer.h"
|
#include "AudioPlayer.h"
|
||||||
|
#include "Globals.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#if G3D_VER < 61000
|
#if G3D_VER < 61000
|
||||||
@@ -45,11 +46,11 @@ static G3D::TextureRef go = NULL;
|
|||||||
static G3D::TextureRef go_ovr = NULL;
|
static G3D::TextureRef go_ovr = NULL;
|
||||||
static G3D::TextureRef go_dn = NULL;
|
static G3D::TextureRef go_dn = NULL;
|
||||||
VARAreaRef varStatic = NULL;
|
VARAreaRef varStatic = NULL;
|
||||||
static float mousex = 0;
|
//static float dataModel->mousex = 0;
|
||||||
static float mousey = 0;
|
//static float dataModel->mousey = 0;
|
||||||
static int cursorid = 0;
|
static int cursorid = 0;
|
||||||
static G3D::TextureRef cursor = NULL;
|
static G3D::TextureRef cursor = NULL;
|
||||||
static bool mouseButton1Down = false;
|
//static bool dataModel->mouseButton1Down = false;
|
||||||
static bool running = true;
|
static bool running = true;
|
||||||
static bool mouseMovedBeginMotion = false;
|
static bool mouseMovedBeginMotion = false;
|
||||||
static bool showMouse = true;
|
static bool showMouse = true;
|
||||||
@@ -71,10 +72,7 @@ Vector3 cameraPos = Vector3(0,2,10);
|
|||||||
Vector2 oldMouse = Vector2(0,0);
|
Vector2 oldMouse = Vector2(0,0);
|
||||||
float moveRate = 0.5;
|
float moveRate = 0.5;
|
||||||
Instance* selectedInstance = NULL;
|
Instance* selectedInstance = NULL;
|
||||||
/**
|
|
||||||
This simple demo applet uses the debug mode as the regular
|
|
||||||
rendering mode so you can fly around the scene.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -703,6 +701,8 @@ void Demo::onInit() {
|
|||||||
dataModel = new DataModelInstance();
|
dataModel = new DataModelInstance();
|
||||||
dataModel->setParent(NULL);
|
dataModel->setParent(NULL);
|
||||||
dataModel->name = "undefined";
|
dataModel->name = "undefined";
|
||||||
|
|
||||||
|
Globals::dataModel = dataModel;
|
||||||
|
|
||||||
initGUI();
|
initGUI();
|
||||||
|
|
||||||
@@ -1085,9 +1085,9 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
message = "FPS has been locked at " + Convert(FPSVal[index]);
|
message = "FPS has been locked at " + Convert(FPSVal[index]);
|
||||||
//setDesiredFrameRate(FPSVal[index]);
|
//setDesiredFrameRate(FPSVal[index]);
|
||||||
}
|
}
|
||||||
mousex = ui->getMouseX();
|
dataModel->mousex = ui->getMouseX();
|
||||||
mousey = ui->getMouseY();
|
dataModel->mousey = ui->getMouseY();
|
||||||
mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY);
|
dataModel->mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY);
|
||||||
if(ui->keyDown(SDLK_UP))
|
if(ui->keyDown(SDLK_UP))
|
||||||
{
|
{
|
||||||
forwards = true;
|
forwards = true;
|
||||||
@@ -1125,7 +1125,7 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
if(!onGUI)
|
if(!onGUI)
|
||||||
{
|
{
|
||||||
selectedInstance = NULL;
|
selectedInstance = NULL;
|
||||||
testRay = app->debugCamera.worldRay(mousex, mousey, app->renderDevice->getViewport());
|
testRay = app->debugCamera.worldRay(dataModel->mousex, dataModel->mousey, app->renderDevice->getViewport());
|
||||||
float nearest=std::numeric_limits<float>::infinity();
|
float nearest=std::numeric_limits<float>::infinity();
|
||||||
Vector3 camPos = app->debugCamera.getCoordinateFrame().translation;
|
Vector3 camPos = app->debugCamera.getCoordinateFrame().translation;
|
||||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||||
@@ -1143,7 +1143,7 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
selectedInstance = test;
|
selectedInstance = test;
|
||||||
//message = "Dragging = true.";
|
//message = "Dragging = true.";
|
||||||
//messageTime = System::time();
|
//messageTime = System::time();
|
||||||
dragging = true;
|
//dragging = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1179,7 +1179,7 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
if (ui->keyDown(SDL_LEFT_MOUSE_KEY)) {
|
if (ui->keyDown(SDL_LEFT_MOUSE_KEY)) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
PhysicalInstance* part = (PhysicalInstance*) selectedInstance;
|
PhysicalInstance* part = (PhysicalInstance*) selectedInstance;
|
||||||
Ray dragRay = app->debugCamera.worldRay(mousex, mousey, app->renderDevice->getViewport());
|
Ray dragRay = app->debugCamera.worldRay(dataModel->mousex, dataModel->mousey, app->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++)
|
||||||
{
|
{
|
||||||
@@ -1246,9 +1246,9 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if(mousex >= point1x && mousey >= point1y)
|
if(dataModel->mousex >= point1x && dataModel->mousey >= point1y)
|
||||||
{
|
{
|
||||||
if(mousex < point2x && mousey < point2y)
|
if(dataModel->mousex < point2x && dataModel->mousey < point2y)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1259,16 +1259,17 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
|
|||||||
|
|
||||||
void drawButtons(RenderDevice* rd)
|
void drawButtons(RenderDevice* rd)
|
||||||
{
|
{
|
||||||
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getChildren();
|
dataModel->getGuiRoot()->render(rd);
|
||||||
|
/*std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getChildren();
|
||||||
for(size_t i = 0; i < instances_2D.size(); i++)
|
for(size_t i = 0; i < instances_2D.size(); i++)
|
||||||
{
|
{
|
||||||
Instance* instance = instances_2D.at(i);
|
Instance* instance = instances_2D.at(i);
|
||||||
if(instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton")
|
if(instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton")
|
||||||
{
|
{
|
||||||
BaseButtonInstance* tbi = (BaseButtonInstance*)instance;
|
BaseButtonInstance* tbi = (BaseButtonInstance*)instance;
|
||||||
tbi->drawObj(rd, Vector2(mousex, mousey), mouseButton1Down);
|
tbi->drawObj(rd, Vector2(dataModel->mousex, dataModel->mousey), dataModel->mouseButton1Down);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters lighting, Vector3 size, Vector3 pos, CoordinateFrame c)
|
void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters lighting, Vector3 size, Vector3 pos, CoordinateFrame c)
|
||||||
|
|||||||
Reference in New Issue
Block a user