button is draw by menu
This commit is contained in:
+7
-5
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
-2
@@ -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();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <GL\freeglut.h>
|
||||
#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();
|
||||
|
||||
|
||||
+2
-2
@@ -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) {};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user