diff options
Diffstat (limited to 'edit.cpp')
-rw-r--r-- | edit.cpp | 169 |
1 files changed, 0 insertions, 169 deletions
diff --git a/edit.cpp b/edit.cpp deleted file mode 100644 index 487cf4f..0000000 --- a/edit.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "edit.h" - - -static int editMode = EDIT_MODE_VIEW; - -static Level *level = NULL; - -static Room *activeRoom = NULL; -static Room *hoveredRoom = NULL; - -static Room addRoom; - -static Vertex hoveredVertex; -static int hasHoveredVertex = 0; - -static IdManager idManager; - -int getEditMode() { - return editMode; -} - -Level *getLevel() { - return level; -} - -void setLevel(Level *l) { - level = l; -} - -Room *getActiveRoom() { - return activeRoom; -} - -void setActiveRoom(Room *room) { - activeRoom = room; - - if(room == NULL) { - editMode = EDIT_MODE_VIEW; - } - else if(editMode == EDIT_MODE_VIEW) { - editMode = EDIT_MODE_SELECTED; - } -} - -Vertex *getHoveredVertex() { - if(hasHoveredVertex) return &hoveredVertex; - else return NULL; -} - -void setHoveredVertex(Vertex *v) { - if(v) { - hasHoveredVertex = 1; - hoveredVertex = *v; - - hoveredRoom = NULL; - - for(Level::iterator room = level->begin(); room != level->end(); room++) { - if(room->contains(*v)) { - hoveredRoom = &*room; - break; - } - } - } - else { - hasHoveredVertex = 0; - hoveredRoom = NULL; - } -} - -void startAddMode() { - addRoom = Room(idManager.generate("room")); - activeRoom = &addRoom; - - editMode = EDIT_MODE_ADD; -} - -void endAddMode() { - editMode = activeRoom ? EDIT_MODE_SELECTED : EDIT_MODE_VIEW; -} - -Room *getHoveredRoom() { - return hoveredRoom; -} - -IdManager *getIdManager() { - return &idManager; -} - -static bool isLineOk(Line *l) { - Line l2; - - - if(activeRoom) { - for(size_t i = 0; i+2 < activeRoom->size(); i++) { - l2.setVertex1(activeRoom->at(i)); - l2.setVertex2(activeRoom->at(i+1)); - - if(l->intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false; - } - - if(activeRoom->size() > 1) { - l2.setVertex1(activeRoom->at(activeRoom->size()-2)); - l2.setVertex2(activeRoom->back()); - if(l2.contains(l->getVertex2())) return false; - } - } - - for(Level::iterator room = level->begin(); room != level->end(); room++) { - if(room->intersects(*l)) - return false; - } - - return true; -} - -bool isVertexOk(Vertex *v) { - Line l; - - for(Level::iterator room = level->begin(); room != level->end(); room++) { - if(room->contains(*v)) return false; - } - - if(!(getActiveRoom() && !getActiveRoom()->empty())) - return true; - - l.setVertex1(getActiveRoom()->back()); - l.setVertex2(*v); - - return isLineOk(&l); -} - - - -bool isPolygonOk(Polygon *polygon) { - Line l, l2; - - if(polygon->empty()) return false; - - for(Level::iterator room = level->begin(); room != level->end(); room++) { - if(room->empty()) continue; - - if(room->contains(polygon->front())) - return false; - - if(polygon->contains(room->front())) - return false; - } - - if(polygon->size() == 1) - return true; - - if(!polygon->isSimple()) - return false; - - for(Polygon::const_iterator it = polygon->begin(); it != polygon->end(); it++) { - Polygon::const_iterator it2 = it+1; - if(it2 == polygon->end()) it2 = polygon->begin(); - - l.setVertex1(*it); - l.setVertex2(*it2); - - for(Level::iterator room = level->begin(); room != level->end(); room++) { - if(room->intersects(l)) - return false; - } - } - - return true; -} |