Merge pull request #12 from andreja6/buttons

Added button listeners, added some buttons, Made window use HWND rather than SDL
This commit is contained in:
andreja6
2018-04-25 14:36:03 -07:00
committed by GitHub
41 changed files with 1056 additions and 182 deletions

51
BaseButtonInstance.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include "BaseButtonInstance.h"
bool floatBottom = false;
bool floatRight = false;
bool floatCenter = false;
bool disabled = false;
bool selected = false;
ButtonListener* listener = NULL;
BaseButtonInstance::BaseButtonInstance(void)
{
listener = NULL;
}
BaseButtonInstance::~BaseButtonInstance(void)
{
delete listener;
}
void BaseButtonInstance::setButtonListener(ButtonListener* buttonListener)
{
listener = buttonListener;
}
void BaseButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown){}
bool BaseButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd){return false;}
void BaseButtonInstance::onMouseClick()
{
if(listener != NULL)
{
listener->onButton1MouseClick(this);
}
}
bool BaseButtonInstance::mouseInArea(float point1x, float point1y, float point2x, float point2y, float mousex, float mousey)
{
if(mousex >= point1x && mousey >= point1y)
{
if(mousex < point2x && mousey < point2y)
{
return true;
}
}
return false;
}

23
BaseButtonInstance.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include "instance.h"
#pragma once
#include "ButtonListener.h"
class ButtonListener;
class BaseButtonInstance : public Instance
{
public:
BaseButtonInstance(void);
virtual ~BaseButtonInstance(void);
virtual void drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown);
virtual bool mouseInButton(float, float, RenderDevice* rd);
virtual void onMouseClick();
void setButtonListener(ButtonListener*);
bool floatBottom;
bool floatRight;
bool floatCenter;
bool disabled;
bool selected;
protected:
bool mouseInArea(float, float, float, float, float, float);
class ButtonListener* listener;
};

View File

@@ -1,5 +1,6 @@
#include "ButtonListener.h"
ButtonListener::ButtonListener(void)
{
}
@@ -8,7 +9,7 @@ ButtonListener::~ButtonListener(void)
{
}
void ButtonListener::onButton1MouseClick(TextButtonInstance* button)
void ButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{
}

View File

@@ -1,12 +1,12 @@
#pragma once
#include "TextButtonInstance.h"
class TextButtonInstance;
#include "BaseButtonInstance.h"
class BaseButtonInstance;
class ButtonListener
{
public:
ButtonListener(void);
~ButtonListener(void);
virtual void onButton1MouseClick(TextButtonInstance*);
virtual void onButton1MouseClick(BaseButtonInstance*);
//virtual void onMouseOver(); //TODO
//virtual void onMouseOut(); //TODO
//virtual void onButton1MouseDown(); //TODO

Binary file not shown.

View File

@@ -46,6 +46,37 @@ END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_TOOLBOX DIALOGEX 0, 0, 398, 64
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
CONTROL "",IDC_TOOLBOX_BROWSER,
"{A8F8E829-06DA-11D2-8D70-00A0C98B28E2}",WS_TABSTOP,0,0,398,64
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog Info
//
IDD_TOOLBOX DLGINIT
BEGIN
IDC_TOOLBOX_BROWSER, 0x376, 76, 0
0x0000, 0x0000, 0xb293, 0x0000, 0x0048, 0x0000, 0x0003, 0x0008, 0xf20b,
0x4757, 0x0020, 0x0000, 0x005f, 0x0065, 0x0078, 0x0074, 0x0065, 0x006e,
0x0074, 0x0078, 0x3db4, 0x0000, 0x0003, 0x0008, 0xf20a, 0x4757, 0xffe0,
0xffff, 0x005f, 0x0065, 0x0078, 0x0074, 0x0065, 0x006e, 0x0074, 0x0079,
0x0ac0, 0x0000,
0
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
@@ -92,6 +123,15 @@ BEGIN
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "icon1.ico"
#endif // English (Canada) resources
/////////////////////////////////////////////////////////////////////////////

View File

@@ -230,6 +230,10 @@
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\BaseButtonInstance.cpp"
>
</File>
<File
RelativePath=".\ButtonListener.cpp"
>
@@ -279,6 +283,10 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\BaseButtonInstance.h"
>
</File>
<File
RelativePath=".\ButtonListener.h"
>
@@ -308,6 +316,10 @@
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
<File
RelativePath=".\icon1.ico"
>
</File>
</Filter>
</Files>
<Globals>

View File

@@ -5,17 +5,140 @@ G3D::TextureRef image_ovr = NULL;
int openGLID_ovr = 0;
G3D::TextureRef image_dn = NULL;
int openGLID_dn = 0;
ImageButtonInstance::ImageButtonInstance(G3D::TextureRef newImage = NULL, G3D::TextureRef overImage = NULL, G3D::TextureRef downImage = NULL)
G3D::TextureRef image_ds = NULL;
int openGLID_ds = 0;
Vector2 size;
Vector2 position;
ImageButtonInstance::ImageButtonInstance(G3D::TextureRef newImage, G3D::TextureRef overImage = NULL, G3D::TextureRef downImage = NULL, G3D::TextureRef disableImage = NULL)
{
image = newImage;
openGLID = image->getOpenGLID();
image_ovr = overImage;
if(!image_ovr.isNull())
openGLID_ovr = image_ovr->getOpenGLID();
image_dn = downImage;
openGLID_dn = image_dn->getOpenGLID();
if(!image_dn.isNull())
openGLID_dn = image_dn->getOpenGLID();
image_ds = disableImage;
if(!image_ds.isNull())
openGLID_ds = image_ds->getOpenGLID();
Vector2 size = Vector2(0,0);
Vector2 position = Vector2(0,0);
floatCenter = false;
floatBottom = false;
floatRight = false;
disabled = false;
className = "ImageButton";
}
ImageButtonInstance::~ImageButtonInstance(void)
{
//Delete everything on destruction
image.~ReferenceCountedPointer();
delete image.getPointer();
image_ovr.~ReferenceCountedPointer();
delete image_ovr.getPointer();
image_ds.~ReferenceCountedPointer();
delete image_ds.getPointer();
image_dn.~ReferenceCountedPointer();
delete image_dn.getPointer();
image = NULL;
image_ovr = NULL;
image_ds = NULL;
image_dn = NULL;
delete listener;
listener = NULL;
selected = false;
}
bool ImageButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd)
{
Vector2 positionRelative = position;
if(floatRight && floatBottom)
{
positionRelative = Vector2(rd->getWidth() + position.x, rd->getHeight() + position.y);
}
else if(floatBottom)
{
positionRelative = Vector2(position.x, rd->getHeight() + position.y);
}
else if(floatRight)
{
positionRelative = Vector2(rd->getWidth() + position.x, position.y);
}
if(mousex >= positionRelative.x && mousey >= positionRelative.y)
{
if(mousex < positionRelative.x + size.x && mousey < positionRelative.y + size.y)
{
return true;
}
}
return false;
}
void ImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown)
{
bool drawDisabledBox = false;
Vector2 positionRelative = position;
if(floatRight && floatBottom)
{
positionRelative = Vector2(rd->getWidth() + position.x, rd->getHeight() + position.y);
}
else if(floatBottom)
{
positionRelative = Vector2(position.x, rd->getHeight() + position.y);
}
else if(floatRight)
{
positionRelative = Vector2(rd->getWidth() + position.x, position.y);
}
int renderimage = openGLID;
if(selected == true && !image_dn.isNull())
{
renderimage = openGLID_dn;
}
else if(disabled)
{
if(!image_ds.isNull())
renderimage = openGLID_ds;
else
drawDisabledBox = true;
}
else if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y))
{
if(mouseDown && !image_dn.isNull())
{
renderimage = openGLID_dn;
}
else if(!image_ovr.isNull())
{
renderimage = openGLID_ovr;
}
}
rd->pushState();
rd->beforePrimitive();
glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture( GL_TEXTURE_2D, renderimage);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( positionRelative.x, positionRelative.y );
glTexCoord2d( 1.0,0.0 );
glVertex2f( positionRelative.x + size.x, positionRelative.y );
glTexCoord2d( 1.0,1.0 );
glVertex2f( positionRelative.x + size.x, positionRelative.y + size.y );
glTexCoord2d( 0.0,1.0 );
glVertex2f( positionRelative.x, positionRelative.y + size.y );
glEnd();
glDisable( GL_TEXTURE_2D );
rd->afterPrimitive();
rd->popState();
if(drawDisabledBox)
{
Draw::box(Box(Vector3(positionRelative.x, positionRelative.y, 0), Vector3(positionRelative.x+size.x, positionRelative.y+size.y, 0)), rd, Color4(0.7F,0.7F,0.7F,0.3F), Color4::clear());
}
}

View File

@@ -1,10 +1,24 @@
#pragma once
#include "instance.h"
class ImageButtonInstance :
public Instance
#include "BaseButtonInstance.h"
class ImageButtonInstance : public BaseButtonInstance
{
public:
ImageButtonInstance(G3D::TextureRef,G3D::TextureRef,G3D::TextureRef);
//ImageButtonInstance(G3D::TextureRef);
//ImageButtonInstance(G3D::TextureRef,G3D::TextureRef);
//ImageButtonInstance(G3D::TextureRef,G3D::TextureRef,G3D::TextureRef);
ImageButtonInstance(G3D::TextureRef,G3D::TextureRef,G3D::TextureRef,G3D::TextureRef);
~ImageButtonInstance(void);
void drawObj(RenderDevice*, Vector2, bool);
Vector2 size;
Vector2 position;
G3D::TextureRef image;
int openGLID;
G3D::TextureRef image_ovr;
int openGLID_ovr;
G3D::TextureRef image_dn;
int openGLID_dn;
G3D::TextureRef image_ds;
int openGLID_ds;
bool mouseInButton(float, float, RenderDevice*);
};

View File

@@ -4,12 +4,12 @@
std::string name;
Instance* parent;
static std::string className = "Instance";
static std::string className = "DataModel";
Instance::Instance(void)
{
name = "Default Game Instance";
className = "Part";
className = "DataModel";
}
Instance::~Instance(void)

View File

@@ -5,7 +5,7 @@ class Instance
{
public:
Instance(void);
~Instance(void);
virtual ~Instance(void);
std::string name;
Instance* parent; // Another pointer.
std::string className;

View File

@@ -6,6 +6,7 @@ Vector3 size;
Vector3 position;
Vector3 velocity;
Vector3 rotVelocity;
CoordinateFrame cFrame;
Color3 color;
PhysicalInstance::PhysicalInstance(void)
@@ -16,11 +17,32 @@ PhysicalInstance::PhysicalInstance(void)
anchored = true;
size = Vector3(2,1,4);
position = Vector3(0,0,0);
cFrame = CoordinateFrame(position);
color = Color3::gray();
velocity = Vector3(0,0,0);
rotVelocity = Vector3(0,0,0);
}
Vector3 PhysicalInstance::getPosition()
{
return position;
}
void PhysicalInstance::setPosition(Vector3 pos)
{
position = pos;
cFrame = CoordinateFrame(pos);
}
CoordinateFrame PhysicalInstance::getCFrame()
{
return cFrame;
}
void PhysicalInstance::setCFrame(CoordinateFrame coordinateFrame)
{
cFrame = coordinateFrame;
position = coordinateFrame.translation;
}
PhysicalInstance::~PhysicalInstance(void)
{
}

View File

@@ -8,8 +8,14 @@ public:
PhysicalInstance(void);
~PhysicalInstance(void);
Vector3 size;
Vector3 position;
Vector3 velocity;
Vector3 rotvelocity;
CoordinateFrame cFrame;
Color3 color;
Vector3 getPosition();
void setPosition(Vector3);
CoordinateFrame getCFrame();
void setCFrame(CoordinateFrame);
private:
Vector3 position;
};

View File

@@ -18,11 +18,8 @@ bool centeredWithinBox;
std::string title;
G3D::GFontRef* font;
int textSize;
bool floatBottom;
bool floatRight;
bool floatCenter;
bool visible;
ButtonListener* buttonListener;
TextButtonInstance::TextButtonInstance(void)
{
@@ -35,33 +32,17 @@ TextButtonInstance::TextButtonInstance(void)
textOutlineColor = Color4(0, 0, 0, 0);
boxColor = Color4(0.6F,0.6F,0.6F,0.4F);
boxOutlineColor = Color4(0, 0, 0, 0);
setAllColorsSame();
textSize = 12;
floatBottom = false;
floatRight = false;
floatCenter = false;
visible = true;
className = "TextButton";
disabled = false;
}
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)
bool TextButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd)
{
Vector3 point1;
Vector3 point2;
@@ -76,8 +57,65 @@ void TextButtonInstance::drawObj(RenderDevice* rd)
point1 = Vector3(boxBegin.x, boxBegin.y,0);
point2 = Vector3(boxEnd.x, boxEnd.y,0);
}
Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor);
Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y);
font->draw2D(rd, title, RelativeTo, textSize, textColor, textOutlineColor);
if(mousex >= point1.x && mousey >= point1.y)
{
if(mousex < point2.x && mousey < point2.y)
{
return true;
}
}
return false;
}
void TextButtonInstance::setAllColorsSame()
{
textColorOvr = textColor;
textOutlineColorOvr = textOutlineColor;
boxColorOvr = boxColor;
boxOutlineColorOvr = boxOutlineColor;
textColorDn = textColor;
textOutlineColorDn = textOutlineColor;
boxColorDn = boxColor;
boxOutlineColorDn = boxOutlineColor;
}
TextButtonInstance::~TextButtonInstance(void)
{
}
void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown)
{
Vector3 point1;
Vector3 point2;
if(floatBottom)
{
point1 = Vector3(boxBegin.x, rd->getHeight() + boxBegin.y,0);
point2 = Vector3(boxEnd.x, rd->getHeight() + boxEnd.y,0);
}
else
{
point1 = Vector3(boxBegin.x, boxBegin.y,0);
point2 = Vector3(boxEnd.x, boxEnd.y,0);
}
Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y);
if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown)
{
Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn);
font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn);
}
else if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y))
{
Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr);
font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr);
}
else
{
Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor);
font->draw2D(rd, title, RelativeTo, textSize, textColor, textOutlineColor);
}
}
void doNullCheck()
{
}

View File

@@ -1,14 +1,11 @@
#pragma once
#include "instance.h"
#pragma once
#include "ButtonListener.h"
class ButtonListener;
class TextButtonInstance :
public Instance
#include "BaseButtonInstance.h"
class TextButtonInstance : public BaseButtonInstance
{
public:
TextButtonInstance(void);
~TextButtonInstance(void);
void setAllColorsSame();
Vector2 boxBegin;
Vector2 boxEnd;
Vector2 fontLocationRelativeTo;
@@ -27,11 +24,8 @@ public:
bool centeredWithinBox;
std::string title;
G3D::GFontRef font;
bool floatBottom;
bool floatRight;
bool visible;
int textSize;
void drawObj(G3D::RenderDevice*);
void setButtonListener(ButtonListener*);
void onClick();
void drawObj(RenderDevice*, Vector2, bool);
bool mouseInButton(float, float, RenderDevice*);
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 599 B

After

Width:  |  Height:  |  Size: 576 B

BIN
content/cursor2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 792 B

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

799
main.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -3,14 +3,17 @@
// Used by Dialogs.rc
//
#define IDD_ABOUT_DIALOG 102
#define IDD_TOOLBOX 103
#define IDI_ICON1 106
#define IDC_TOOLBOX_BROWSER 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_RESOURCE_VALUE 107
#define _APS_NEXT_COMMAND_VALUE 40004
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif