From f6b301a836bb62cc7e4fe0d198230f3010927913 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 24 Apr 2018 12:44:24 -0700 Subject: [PATCH] Added click listener to TextButton --- TextButtonInstance.cpp | 25 +++++++++++++++++++++++++ TextButtonInstance.h | 1 + 2 files changed, 26 insertions(+) diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index 916fe73..523c918 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -42,6 +42,31 @@ TextButtonInstance::TextButtonInstance(void) disabled = false; } +bool TextButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd) +{ + 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); + } + if(mousex >= point1.x && mousey >= point1.y) + { + if(mousex < point2.x && mousey < point2.y) + { + return true; + } + } + return false; +} + void TextButtonInstance::setAllColorsSame() { textColorOvr = textColor; diff --git a/TextButtonInstance.h b/TextButtonInstance.h index fe1c4e2..2f8823c 100644 --- a/TextButtonInstance.h +++ b/TextButtonInstance.h @@ -27,4 +27,5 @@ public: bool visible; int textSize; void drawObj(RenderDevice*, Vector2, bool); + bool mouseInButton(float, float, RenderDevice*); }; \ No newline at end of file