Added base class for button listening
Fixed a few memory leaks
This commit is contained in:
14
ButtonListener.cpp
Normal file
14
ButtonListener.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "ButtonListener.h"
|
||||
|
||||
ButtonListener::ButtonListener(void)
|
||||
{
|
||||
}
|
||||
|
||||
ButtonListener::~ButtonListener(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ButtonListener::onButton1MouseClick(TextButtonInstance* button)
|
||||
{
|
||||
}
|
||||
|
||||
18
ButtonListener.h
Normal file
18
ButtonListener.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "TextButtonInstance.h"
|
||||
class TextButtonInstance;
|
||||
class ButtonListener
|
||||
{
|
||||
public:
|
||||
ButtonListener(void);
|
||||
~ButtonListener(void);
|
||||
virtual void onButton1MouseClick(TextButtonInstance*);
|
||||
//virtual void onMouseOver(); //TODO
|
||||
//virtual void onMouseOut(); //TODO
|
||||
//virtual void onButton1MouseDown(); //TODO
|
||||
//virtual void onButton1MouseUp(); //TODO
|
||||
//virtual void onButton2MouseClick(); //TODO
|
||||
//virtual void onButton2MouseDown(); //TODO
|
||||
//virtual void onButton2MouseUp(); //TODO
|
||||
//What to do now...
|
||||
};
|
||||
@@ -230,6 +230,10 @@
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\ButtonListener.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Dialogs.rc"
|
||||
>
|
||||
@@ -279,6 +283,10 @@
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\ButtonListener.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ImageButtonInstance.h"
|
||||
>
|
||||
|
||||
@@ -22,6 +22,7 @@ bool floatBottom;
|
||||
bool floatRight;
|
||||
bool floatCenter;
|
||||
bool visible;
|
||||
ButtonListener* buttonListener;
|
||||
|
||||
TextButtonInstance::TextButtonInstance(void)
|
||||
{
|
||||
@@ -40,11 +41,24 @@ TextButtonInstance::TextButtonInstance(void)
|
||||
floatCenter = false;
|
||||
visible = true;
|
||||
className = "TextButton";
|
||||
|
||||
}
|
||||
|
||||
TextButtonInstance::~TextButtonInstance(void)
|
||||
{
|
||||
delete buttonListener;
|
||||
}
|
||||
|
||||
void TextButtonInstance::setButtonListener(ButtonListener* listener)
|
||||
{
|
||||
buttonListener = listener;
|
||||
}
|
||||
|
||||
void TextButtonInstance::onClick()
|
||||
{
|
||||
if(buttonListener != NULL)
|
||||
{
|
||||
buttonListener->onButton1MouseClick(this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextButtonInstance::drawObj(RenderDevice* rd)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "instance.h"
|
||||
|
||||
#pragma once
|
||||
#include "ButtonListener.h"
|
||||
class ButtonListener;
|
||||
class TextButtonInstance :
|
||||
public Instance
|
||||
{
|
||||
@@ -30,5 +32,6 @@ public:
|
||||
bool visible;
|
||||
int textSize;
|
||||
void drawObj(G3D::RenderDevice*);
|
||||
|
||||
void setButtonListener(ButtonListener*);
|
||||
void onClick();
|
||||
};
|
||||
11
main.cpp
11
main.cpp
@@ -340,7 +340,9 @@ void Demo::onInit() {
|
||||
void clearInstances()
|
||||
{
|
||||
for(size_t i = 0; i < instances.size(); i++)
|
||||
{
|
||||
delete instances.at(i);
|
||||
}
|
||||
delete dataModel;
|
||||
}
|
||||
void OnError(int err, std::string msg = "")
|
||||
@@ -354,10 +356,15 @@ void OnError(int err, std::string msg = "")
|
||||
|
||||
void Demo::onCleanup() {
|
||||
clearInstances();
|
||||
go->~Texture();
|
||||
go_ovr->~Texture();
|
||||
go_dn->~Texture();
|
||||
app->sky->~Sky();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Demo::onLogic() {
|
||||
// Add non-simulation game logic and AI code here
|
||||
}
|
||||
@@ -704,8 +711,6 @@ int main(int argc, char** argv) {
|
||||
settings.window.defaultIconFilename = GetFileInPath("/content/images/rico256c.png");
|
||||
settings.window.resizable = true;
|
||||
settings.writeLicenseFile = false;
|
||||
App app = App(settings);
|
||||
//app.window()->setIcon(ExePath() + "/content/images/rico.png");
|
||||
app.run();
|
||||
App(settings).run();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user