Untitled
unknown
plain_text
2 years ago
2.8 kB
11
Indexable
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <GL/freeglut.h>
#include "Color.h"
struct Rectangle {
float x;
float y;
float w;
float h;
Color color;
bool selected;
bool erase;
public:
Rectangle() {
x = 0.0f;
y = 0.0f;
w = 0.4f;
h = 0.2f;
selected = false;
erase = false;
}
Rectangle(float x, float y, float w, float h) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
color = Color(0, 0, 0);
selected = false;
erase = false;
}
Rectangle(float x, float y, float w, float h, Color color) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->color = color;
selected = false;
erase = false;
}
void draw() {
if (!erase){
glColor3f(color.getR(), color.getG(), color.getB());
glBegin(GL_POLYGON);
glVertex2f(x, y);
glVertex2f(x + w, y);
glVertex2f(x + w, y - h);
glVertex2f(x, y - h);
glEnd();
if (selected){
glColor3f(1,0.8431,0);
glBegin(GL_POLYGON);
glVertex2f(x, y);
glVertex2f(x+w, y);
glVertex2f(x+w, y-h);
glVertex2f(x, y-h);
glEnd();
glColor3f(color.getR(), color.getG(), color.getB());
glBegin(GL_POLYGON);
glVertex2f(x+0.01, y-0.01);
glVertex2f(x+w-0.01, y-0.01);
glVertex2f(x+w-0.01, y-h+0.01);
glVertex2f(x+0.01, y-h+0.01);
glEnd();
}
}
}
// getter functions
float getX(){
return x;
}
float getY(){
return y;
}
float getWidth(){
return w;
}
float getHeight(){
return h;
}
// setter functions
void setColor(Color color) {
this->color = color;
}
void setX(float mx){
x = mx;
}
void setY(float my){
y = my;
}
void setWidth(float mw){
w = mw;
}
void setHeight(float mh){
h = mh;
}
void setErase(){
erase = true;
}
// selecting functions
void select() {
selected = true;
}
void deselect() {
selected = false;
}
bool isSelected(){
return selected;
}
// contains function
bool contains(float mx, float my) {
if (mx >= x && mx <= x + w && my <= y && my >= y - h) {
return true;
} else {
return false;
}
}
};
#endifEditor is loading...
Leave a Comment