Changed how buttons render
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "BaseButtonInstance.h"
|
||||
#include "Globals.h"
|
||||
|
||||
bool floatBottom = false;
|
||||
bool floatRight = false;
|
||||
@@ -12,6 +13,14 @@ BaseButtonInstance::BaseButtonInstance(void)
|
||||
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)
|
||||
{
|
||||
delete listener;
|
||||
|
||||
@@ -8,6 +8,7 @@ class BaseButtonInstance : public Instance
|
||||
public:
|
||||
BaseButtonInstance(void);
|
||||
virtual ~BaseButtonInstance(void);
|
||||
virtual void render(RenderDevice* rd);
|
||||
virtual void drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown);
|
||||
virtual bool mouseInButton(float, float, RenderDevice* rd);
|
||||
virtual void onMouseClick();
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
WorkspaceInstance* workspace;
|
||||
Instance* guiRoot;
|
||||
float mousex;
|
||||
float mousey;
|
||||
bool mouseButton1Down;
|
||||
|
||||
|
||||
DataModelInstance::DataModelInstance(void)
|
||||
{
|
||||
@@ -10,6 +14,9 @@ DataModelInstance::DataModelInstance(void)
|
||||
guiRoot = new Instance();
|
||||
children.push_back(workspace);
|
||||
className = "dataModel";
|
||||
mousex = 0;
|
||||
mousey = 0;
|
||||
mouseButton1Down = false;
|
||||
}
|
||||
|
||||
DataModelInstance::~DataModelInstance(void)
|
||||
|
||||
@@ -10,4 +10,7 @@ public:
|
||||
~DataModelInstance(void);
|
||||
WorkspaceInstance* getWorkspace();
|
||||
Instance* getGuiRoot();
|
||||
float mousex;
|
||||
float mousey;
|
||||
bool mouseButton1Down;
|
||||
};
|
||||
|
||||
@@ -242,6 +242,10 @@
|
||||
RelativePath=".\Dialogs.rc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Globals.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="main.cpp"
|
||||
>
|
||||
@@ -307,6 +311,10 @@
|
||||
RelativePath=".\ButtonListener.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Globals.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
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 "DataModelInstance.h"
|
||||
#include "AudioPlayer.h"
|
||||
#include "Globals.h"
|
||||
#include <limits.h>
|
||||
|
||||
#if G3D_VER < 61000
|
||||
@@ -45,11 +46,11 @@ static G3D::TextureRef go = NULL;
|
||||
static G3D::TextureRef go_ovr = NULL;
|
||||
static G3D::TextureRef go_dn = NULL;
|
||||
VARAreaRef varStatic = NULL;
|
||||
static float mousex = 0;
|
||||
static float mousey = 0;
|
||||
//static float dataModel->mousex = 0;
|
||||
//static float dataModel->mousey = 0;
|
||||
static int cursorid = 0;
|
||||
static G3D::TextureRef cursor = NULL;
|
||||
static bool mouseButton1Down = false;
|
||||
//static bool dataModel->mouseButton1Down = false;
|
||||
static bool running = true;
|
||||
static bool mouseMovedBeginMotion = false;
|
||||
static bool showMouse = true;
|
||||
@@ -71,10 +72,7 @@ Vector3 cameraPos = Vector3(0,2,10);
|
||||
Vector2 oldMouse = Vector2(0,0);
|
||||
float moveRate = 0.5;
|
||||
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->setParent(NULL);
|
||||
dataModel->name = "undefined";
|
||||
|
||||
Globals::dataModel = dataModel;
|
||||
|
||||
initGUI();
|
||||
|
||||
@@ -1085,9 +1085,9 @@ void Demo::onUserInput(UserInput* ui) {
|
||||
message = "FPS has been locked at " + Convert(FPSVal[index]);
|
||||
//setDesiredFrameRate(FPSVal[index]);
|
||||
}
|
||||
mousex = ui->getMouseX();
|
||||
mousey = ui->getMouseY();
|
||||
mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY);
|
||||
dataModel->mousex = ui->getMouseX();
|
||||
dataModel->mousey = ui->getMouseY();
|
||||
dataModel->mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY);
|
||||
if(ui->keyDown(SDLK_UP))
|
||||
{
|
||||
forwards = true;
|
||||
@@ -1125,7 +1125,7 @@ void Demo::onUserInput(UserInput* ui) {
|
||||
if(!onGUI)
|
||||
{
|
||||
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();
|
||||
Vector3 camPos = app->debugCamera.getCoordinateFrame().translation;
|
||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||
@@ -1143,7 +1143,7 @@ void Demo::onUserInput(UserInput* ui) {
|
||||
selectedInstance = test;
|
||||
//message = "Dragging = true.";
|
||||
//messageTime = System::time();
|
||||
dragging = true;
|
||||
//dragging = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1179,7 +1179,7 @@ void Demo::onUserInput(UserInput* ui) {
|
||||
if (ui->keyDown(SDL_LEFT_MOUSE_KEY)) {
|
||||
if (dragging) {
|
||||
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();
|
||||
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;
|
||||
}
|
||||
@@ -1259,16 +1259,17 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
|
||||
|
||||
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++)
|
||||
{
|
||||
Instance* instance = instances_2D.at(i);
|
||||
if(instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton")
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user