#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->setHighlightedObject(NULL); editManager->setSelectedObject(NULL); } void ToolAddPolygon::deactivate() { editManager->addRoom(newRoom); } void ToolAddPolygon::render(const Level &level, const Rectangle &rect, float scale) { if(editManager->polygonOk(newRoom.getPolygon())) glColor4f(0.0f, 0.7f, 1.0f, 0.2f); else glColor4f(1.0f, 0.3f, 0.3f, 0.2f); fillPolygon(newRoom.getPolygon()); glLineWidth(2.0f); glColor4f(0.0f, 0.7f, 1.0f, 0.7f); drawPolygon(newRoom.getPolygon(), false); if(!newRoom.getPolygon().empty() && editManager->getHoveredVertex()) { if(!editManager->vertexOk(*editManager->getHoveredVertex(), &newRoom)) glColor4f(1.0f, 0.3f, 0.3f, 0.7f); glBegin(GL_LINES); glVertex2f(newRoom.getPolygon().back().getX(), newRoom.getPolygon().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(*editManager->getHoveredVertex(), &newRoom)) return false; newRoom.addVertex(*editManager->getHoveredVertex()); editManager->redraw(); sidebar.update(); return true; }