From 6cf94376207578bc73fb2ffb52e72246b4442ad5 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 20 Jun 2016 12:11:24 +0200 Subject: [PATCH] button is draw by menu --- Button.cpp | 12 +++++++----- Button.h | 2 +- CrystalPoint.cpp | 6 ++++-- Menu.cpp | 3 ++- MenuElement.h | 4 ++-- Util.h | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Button.cpp b/Button.cpp index 81d60a7..65e1506 100644 --- a/Button.cpp +++ b/Button.cpp @@ -3,7 +3,7 @@ #include "Util.h" #include "Vector.h" -Button::Button(std::string & text, Vec2f position, float width, float height) : MenuElement(position) +Button::Button(const std::string & text, Vec2f position, float width, float height) : MenuElement(position) { this->width = width; this->height = height; @@ -19,17 +19,19 @@ Button::~Button() void Button::draw(void) { - glColor4f(background.x, background.y, background.z, 1.0f); + + glColor4f(background.x/255.0f, background.y / 255.0f, background.z / 255.0f, 1.0f); glBegin(GL_QUADS); glVertex2f(position.x, position.y); glVertex2f(position.x, position.y + height); glVertex2f(position.x + width, position.y + height); glVertex2f(position.x + width, position.y); - glEnd(); + glEnd(); + + glColor4f(foreground.x / 255.0f, foreground.y / 255.0f, foreground.z / 255.0f, 1.0f); + Util::glutBitmapString(text, position.x, position.y+height/2+18/2); - glColor4f(foreground.x, foreground.y, foreground.z, 1.0f); - Util::glutBitmapString(text, position.x + (width / 2), position.y + (height / 2)); } void Button::update(int x, int y) diff --git a/Button.h b/Button.h index 7b7883b..fe7e0f7 100644 --- a/Button.h +++ b/Button.h @@ -9,7 +9,7 @@ private: Vec3f foreground; Vec3f background; public: - Button(std::string &text, Vec2f position, float width, float height); + Button(const std::string &text, Vec2f position, float width, float height); ~Button(); void draw(void); diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 05296be..02617f4 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -9,6 +9,7 @@ #include "Menu.h" #include "Text.h" #include "Vector.h" +#include "Button.h" int CrystalPoint::width = 0; int CrystalPoint::height = 0; @@ -22,7 +23,8 @@ void CrystalPoint::init() cursor = Cursor::getInstance(); menu = new Menu(); - menu->AddMenuElement(new Text("Hello", Vec2f(10, 10))); + menu->AddMenuElement(new Text("Hello", Vec2f(10, 18))); + menu->AddMenuElement(new Button("Start", Vec2f(1920 / 2, 1080 / 2), 100, 50)); lastFrameTime = 0; @@ -44,7 +46,7 @@ void CrystalPoint::draw() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - worldhandler->draw(); + //worldhandler->draw(); menu->draw(); glutSwapBuffers(); diff --git a/Menu.cpp b/Menu.cpp index 0419336..c9a2f99 100644 --- a/Menu.cpp +++ b/Menu.cpp @@ -1,5 +1,6 @@ #include #include "Menu.h" +#include "CrystalPoint.h" Menu::Menu() { @@ -16,7 +17,7 @@ void Menu::draw(void) //Switch view to Ortho glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, 1000, 1000, 0, -10, 10); + glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); diff --git a/MenuElement.h b/MenuElement.h index efd263d..4f09c21 100644 --- a/MenuElement.h +++ b/MenuElement.h @@ -11,7 +11,7 @@ public: MenuElement(Vec2f position); ~MenuElement(); - virtual void draw(void) = 0; - virtual void update(int x, int y) = 0; + virtual void draw(void) {}; + virtual void update(int x, int y) {}; }; diff --git a/Util.h b/Util.h index 7719eed..63bd840 100644 --- a/Util.h +++ b/Util.h @@ -9,6 +9,6 @@ private: ~Util(); public: static GLuint loadTexture(const std::string &filename); - static inline void glutBitmapString(const std::string str, int x, int y); + static void glutBitmapString(std::string str, int x, int y); };