#include "ToolAddPolygon.h" #include ToolAddPolygon::ToolAddPolygon(EditManager *editManager) : Renderer(editManager), sidebar(editManager) { this->editManager = editManager; image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON); g_object_ref_sink(G_OBJECT(image)); } ToolAddPolygon::~ToolAddPolygon() { g_object_unref(G_OBJECT(image)); } void ToolAddPolygon::activate() { newRoom = Room(); editManager->setSelectedObject(NULL); } void ToolAddPolygon::deactivate() { editManager->addRoom(newRoom); } void ToolAddPolygon::render(const Level &level, const Rectangle &rect, float scale) { if(editManager->polygonOk(newRoom)) glColor4f(0.0f, 0.7f, 1.0f, 0.2f); else glColor4f(1.0f, 0.3f, 0.3f, 0.2f); fillPolygon(newRoom); glLineWidth(2.0f); glColor4f(0.0f, 0.7f, 1.0f, 0.7f); drawPolygon(newRoom, false); if(!newRoom.empty() && editManager->getHoveredVertex()) { if(!editManager->vertexOk(newRoom, *editManager->getHoveredVertex())) glColor4f(1.0f, 0.3f, 0.3f, 0.7f); glBegin(GL_LINES); glVertex2f(newRoom.back().getX(), newRoom.back().getY()); glVertex2f(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY()); glEnd(); } } bool ToolAddPolygon::buttonPress(unsigned int button) { if(button != 1) return false; if(!editManager->getHoveredVertex()) return false; if(!editManager->vertexOk(newRoom, *editManager->getHoveredVertex())) return false; newRoom.push_back(*editManager->getHoveredVertex()); editManager->redraw(); sidebar.update(); return true; }