Fix parent datamodel issues, update callbacks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <G3DAll.h>
|
||||
#include "../Instance.h"
|
||||
#include "../../MenuActions.h"
|
||||
|
||||
namespace B3D{
|
||||
class BaseButtonInstance : public Instance
|
||||
@@ -12,7 +13,7 @@ namespace B3D{
|
||||
virtual void drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown);
|
||||
virtual bool mouseInButton(float, float, RenderDevice* rd);
|
||||
virtual void onMouseClick();
|
||||
virtual void setCallback(void (*callback)(DataModelInstance * theDatamodel, BaseButtonInstance * theCaller, WPARAM wParam, LPARAM lParam));
|
||||
virtual void setCallback(void (*callback)(const ActionParam &actionParam));
|
||||
void setActionCode(int actionCode);
|
||||
bool floatBottom;
|
||||
bool floatRight;
|
||||
@@ -22,6 +23,6 @@ namespace B3D{
|
||||
protected:
|
||||
int actionCode;
|
||||
bool mouseInArea(float, float, float, float, float, float);
|
||||
void (*callback)(DataModelInstance * theDatamodel, BaseButtonInstance * theCaller, WPARAM wParam, LPARAM lParam);
|
||||
void (*callback)(const ActionParam &actionParam);
|
||||
};
|
||||
}
|
||||
@@ -23,6 +23,7 @@ namespace B3D
|
||||
virtual void renderName(RenderDevice*);
|
||||
virtual void update();
|
||||
virtual void setParent(Instance*);
|
||||
virtual void updateParentDatamodel();
|
||||
|
||||
//TODO implement
|
||||
virtual Instance* clone() const { return new Instance(*this); }
|
||||
|
||||
13
src/include/MenuActions.h
Executable file
13
src/include/MenuActions.h
Executable file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "DataModelV3/DataModelInstance.h"
|
||||
//TODO - Temporary location - Should be moved to different header once MFC gets involved
|
||||
struct ActionParam {
|
||||
DataModelInstance *dataModel;
|
||||
Instance *caller;
|
||||
int actionCode;
|
||||
};
|
||||
|
||||
#define MENUBTN_MENU 1
|
||||
#define MENUBTN_GO 2
|
||||
|
||||
void menuCallback(const ActionParam & actionParam);
|
||||
@@ -32,15 +32,16 @@ void BaseButtonInstance::onMouseClick()
|
||||
{
|
||||
if(callback != NULL)
|
||||
{
|
||||
callback(this->getParentDataModel(), this, NULL, NULL);
|
||||
ActionParam param = {
|
||||
this->getParentDataModel(),
|
||||
this,
|
||||
this->actionCode
|
||||
};
|
||||
callback(param);
|
||||
}
|
||||
// if(listener != NULL)
|
||||
// {
|
||||
// listener->onButton1MouseClick(this);
|
||||
// }
|
||||
}
|
||||
|
||||
void BaseButtonInstance::setCallback(void (*callback)(DataModelInstance * theDatamodel, BaseButtonInstance * theCaller, WPARAM wParam, LPARAM lParam))
|
||||
void BaseButtonInstance::setCallback(void (*callback)(const ActionParam &actionParam))
|
||||
{
|
||||
this->callback = callback;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ using namespace B3D;
|
||||
#define VS03_WORKAROUND
|
||||
#endif
|
||||
|
||||
void menuCallback(DataModelInstance * theDataModel, BaseButtonInstance * theCaller, WPARAM wParam, LPARAM lParam) {
|
||||
MessageBoxA(NULL, "Tomato", "Tomato", MB_OK);
|
||||
}
|
||||
|
||||
ImageButtonInstance* GuiRootInstance::makeImageButton(G3D::TextureRef newImage = NULL, G3D::TextureRef overImage = NULL, G3D::TextureRef downImage = NULL, G3D::TextureRef disableImage = NULL)
|
||||
{
|
||||
//Oh come on
|
||||
@@ -167,6 +163,7 @@ GuiRootInstance::GuiRootInstance() : Instance(), _message(""), _messageTime(0)
|
||||
);
|
||||
//TODO Define Action
|
||||
instance->setCallback(&menuCallback);
|
||||
instance->setActionCode(MENUBTN_GO);
|
||||
instance->name = "go";
|
||||
instance->size = Vector2(65,65);
|
||||
instance->position = Vector2(6.5, 25);
|
||||
|
||||
@@ -103,7 +103,15 @@ void Instance::setParent(Instance* newParent)
|
||||
if(newParent != NULL)
|
||||
{
|
||||
newParent->addChild(this);
|
||||
parentDataModel = newParent->getParentDataModel();
|
||||
updateParentDatamodel();
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::updateParentDatamodel() {
|
||||
parentDataModel = parent->getParentDataModel();
|
||||
for(size_t i = 0; i < children.size(); i++)
|
||||
{
|
||||
children.at(i)->updateParentDatamodel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +122,9 @@ Instance* Instance::getParent()
|
||||
|
||||
DataModelInstance* Instance::getParentDataModel()
|
||||
{
|
||||
if(parentDataModel == NULL && parent != NULL) {
|
||||
parentDataModel = parent->getParentDataModel();
|
||||
}
|
||||
return parentDataModel;
|
||||
}
|
||||
|
||||
|
||||
11
src/source/MenuActions.cpp
Executable file
11
src/source/MenuActions.cpp
Executable file
@@ -0,0 +1,11 @@
|
||||
#include "MenuActions.h"
|
||||
|
||||
|
||||
void menuCallback(const ActionParam &actionParam) {
|
||||
switch(actionParam.actionCode) {
|
||||
case MENUBTN_GO:
|
||||
actionParam.dataModel->toggleRun();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user