From 05da8e22702c2b5bde8db037021ae38c4dab9b66 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Mon, 23 Apr 2018 23:40:58 -0700 Subject: [PATCH] Added "disabled" bool to button Changed null check --- BaseButtonInstance.cpp | 1 + BaseButtonInstance.h | 1 + ImageButtonInstance.cpp | 24 ++++++++++++++++++------ TextButtonInstance.cpp | 1 + main.cpp | 4 ++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/BaseButtonInstance.cpp b/BaseButtonInstance.cpp index 33251e8..cd30ca4 100644 --- a/BaseButtonInstance.cpp +++ b/BaseButtonInstance.cpp @@ -3,6 +3,7 @@ bool floatBottom; bool floatRight; bool floatCenter; +bool disabled; BaseButtonInstance::BaseButtonInstance(void) { diff --git a/BaseButtonInstance.h b/BaseButtonInstance.h index 3459b9a..aade340 100644 --- a/BaseButtonInstance.h +++ b/BaseButtonInstance.h @@ -10,6 +10,7 @@ public: bool floatBottom; bool floatRight; bool floatCenter; + bool disabled; protected: bool mouseInArea(float, float, float, float, float, float); }; diff --git a/ImageButtonInstance.cpp b/ImageButtonInstance.cpp index bbda5d0..3f91a43 100644 --- a/ImageButtonInstance.cpp +++ b/ImageButtonInstance.cpp @@ -5,23 +5,30 @@ G3D::TextureRef image_ovr = NULL; int openGLID_ovr = 0; G3D::TextureRef image_dn = NULL; int openGLID_dn = 0; +G3D::TextureRef image_ds = NULL; +int openGLID_ds = 0; Vector2 size; Vector2 position; -ImageButtonInstance::ImageButtonInstance(G3D::TextureRef newImage = NULL, G3D::TextureRef overImage = NULL, G3D::TextureRef downImage = NULL, G3D::TextureRef disableImage = NULL) +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"; } @@ -45,13 +52,18 @@ void ImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouse positionRelative = Vector2(rd->getWidth() + position.x, position.y); } int renderimage = openGLID; - if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y)) + if(disabled) { - if(mouseDown && openGLID_dn != 0) + if(openGLID_ds != 0) + renderimage = openGLID; + } + 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(openGLID_ovr != 0) + else if(!image_ovr.isNull()) { renderimage = openGLID_ovr; } diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index f9e0c13..ac92225 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -40,6 +40,7 @@ TextButtonInstance::TextButtonInstance(void) floatCenter = false; visible = true; className = "TextButton"; + disabled = false; } void TextButtonInstance::setAllColorsSame() diff --git a/main.cpp b/main.cpp index f31e65b..b3e3bf8 100644 --- a/main.cpp +++ b/main.cpp @@ -351,7 +351,7 @@ void initGUI() instance = makeImageButton( Texture::fromFile(GetFileInPath("/content/images/SelectionRotate.png")), Texture::fromFile(GetFileInPath("/content/images/SelectionRotate_ovr.png")), - Texture::fromFile(GetFileInPath("/content/images/SelectionRotate_ovr.png")), + NULL, Texture::fromFile(GetFileInPath("/content/images/SelectionRotate_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(10, 175); @@ -360,7 +360,7 @@ void initGUI() instance = makeImageButton( Texture::fromFile(GetFileInPath("/content/images/SelectionTilt.png")), Texture::fromFile(GetFileInPath("/content/images/SelectionTilt_ovr.png")), - Texture::fromFile(GetFileInPath("/content/images/SelectionTilt_ovr.png")), + NULL, Texture::fromFile(GetFileInPath("/content/images/SelectionTilt_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(40, 175);