X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmapview.cpp;h=f745caf9cd36f238f976b73afaaf3189e9b0ccb4;hb=075de16b7430454597f1cde039405b18232f0058;hp=7a915eda1f554f6ed752b1a5fd3c920178463935;hpb=c2745adcb9e3ac580efa825e653c5758857bde73;p=guemap diff --git a/src/mapview.cpp b/src/mapview.cpp index 7a915ed..f745caf 100644 --- a/src/mapview.cpp +++ b/src/mapview.cpp @@ -20,7 +20,6 @@ #include "roomdialog.h" #include "undo.h" - const int penEdgeWidth = 9, penPageWidth = 20, @@ -53,7 +52,6 @@ static const DirectionName directions[] = { static const char a2z[] = "abcdefghijklmnopqrstuvwxyz"; - // // Parse a direction word: // @@ -89,7 +87,6 @@ RoomCorner parseDirection(string & text) return rcNone; } - #if 0 ///////////////////////////////////////////////////////////////////////////// // CRepaginateDlg dialog @@ -122,8 +119,6 @@ class CRepaginateDlg : public CDialog }; #endif - - ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // CMapView @@ -360,14 +355,12 @@ MapView::MapView(QWidget * parent/*= NULL*/): QWidget(parent), mapContextMenu->addAction(deleteRoomAct); } - MapView::~MapView() { delete doc; // gueApp()->closingView(this); // Remove any comment for this view } - void MapView::DrawArrowhead(QPainter * painter, QPointF head, QPointF tail) { QPolygonF arrow; @@ -387,7 +380,6 @@ void MapView::DrawArrowhead(QPainter * painter, QPointF head, QPointF tail) painter->drawPolygon(arrow); } - void MapView::DrawNoExit(QPainter * painter, QPointF head, QPointF tail) { const double angle = Angle(tail - head); @@ -403,7 +395,6 @@ void MapView::DrawNoExit(QPainter * painter, QPointF head, QPointF tail) painter->drawLine(p2, p3); } - // // MapView drawing // @@ -424,6 +415,16 @@ void MapView::paintEvent(QPaintEvent * /*event*/) { roomWidth / 4 - 48, roomHeight + 52 } }; + // Offsets used when the label collides with the line... + const QPoint edgLblOffsetEx[] = { + // N, S, E, W + { -48, 0 }, { 48, 0 }, { 0, -76 }, { 0, 76 }, + // NE, NW, SE, SW + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + // NNE, NNW, SSE, SSW + { -48, 0 }, { -48, 0 }, { 48, 0 }, { 48, 0 } + }; + const int cantGoSide = 19, cantGoAngleX = gridY / 6, @@ -723,18 +724,41 @@ printf(" clip = %i, %i, %i, %i; docSize = %i, %i\n", clip.left(), clip.right( if (edge->type1 & etDirection) { + QPoint ex = QPoint(0, 0); + double angle = Angle(end - start); + + // Adjust text position if it runs into an edge + if (((edge->end1 == rcNNW || edge->end1 == rcN || edge->end1 == rcNNE) && (angle > THREE_QTR_TAU && angle < TAU)) + || ((edge->end1 == rcSSW || edge->end1 == rcS || edge->end1 == rcSSE) && (angle > QTR_TAU && angle < HALF_TAU)) + || ((edge->end1 == rcE) && (angle > 0 && angle < QTR_TAU)) + || ((edge->end1 == rcW) && (angle > HALF_TAU && angle < THREE_QTR_TAU))) + { + ex = edgLblOffsetEx[edge->end1]; + } + const QPoint & p = room[edge->room1]->pos; -// dc->TextOut(p.x + edgLblXOffset[edge->end1], p.y + edgLblYOffset[edge->end1], &edgeLabel[(edge->type1 & etDirection) - 1], 1); elBuf[0] = edgeLabel[(edge->type1 & etDirection) - 1]; - dc->drawText(p + edgLblOffset[edge->end1], elBuf); + dc->drawText(p + edgLblOffset[edge->end1] + ex, elBuf); } - if (edge->type2 & etDirection) + // Make sure there's an actual room #2 for this edge... + if (!(edge->type1 & etNoRoom2) && (edge->type2 & etDirection)) { + QPoint ex = QPoint(0, 0); + double angle = Angle(start - end); + + // Adjust text position if it runs into an edge + if (((edge->end2 == rcNNW || edge->end2 == rcN || edge->end2 == rcNNE) && (angle > THREE_QTR_TAU && angle < TAU)) + || ((edge->end2 == rcSSW || edge->end2 == rcS || edge->end2 == rcSSE) && (angle > QTR_TAU && angle < HALF_TAU)) + || ((edge->end2 == rcE) && (angle > 0 && angle < QTR_TAU)) + || ((edge->end2 == rcW) && (angle > HALF_TAU && angle < THREE_QTR_TAU))) + { + ex = edgLblOffsetEx[edge->end2]; + } + const QPoint & p = room[edge->room2]->pos; -// dc->TextOut(p.x + edgLblXOffset[edge->end2], p.y + edgLblYOffset[edge->end2], &edgeLabel[(edge->type2 & etDirection) - 1], 1); elBuf[0] = edgeLabel[(edge->type2 & etDirection) - 1]; - dc->drawText(p + edgLblOffset[edge->end2], elBuf); + dc->drawText(p + edgLblOffset[edge->end2] + ex, elBuf); } edge--; @@ -853,7 +877,6 @@ printf(" clip = %i, %i, %i, %i; docSize = %i, %i\n", clip.left(), clip.right( } } - void MapView::keyPressEvent(QKeyEvent * event) { bool oldShift = shiftDown; @@ -937,7 +960,6 @@ void MapView::keyPressEvent(QKeyEvent * event) #endif } - void MapView::keyReleaseEvent(QKeyEvent * event) { bool oldShift = shiftDown; @@ -968,7 +990,6 @@ void MapView::keyReleaseEvent(QKeyEvent * event) } } - #if 0 ///////////////////////////////////////////////////////////////////////////// // CMapView printing @@ -988,7 +1009,6 @@ void MapView::OnPrepareDC(QPainter * dc, CPrintInfo * pInfo) printingPage = 0; } - bool MapView::OnPreparePrinting(CPrintInfo * pInfo) { // Require registration before printing map with more than 10 rooms: @@ -1013,7 +1033,6 @@ bool MapView::OnPreparePrinting(CPrintInfo * pInfo) return DoPreparePrinting(pInfo); } - void MapView::OnBeginPrinting(QPainter * /*pDC*/, CPrintInfo * /*pInfo*/) { // Don't show selection or corners while printing: @@ -1024,7 +1043,6 @@ void MapView::OnBeginPrinting(QPainter * /*pDC*/, CPrintInfo * /*pInfo*/) showCorners = false; } - void MapView::OnEndPrinting(QPainter* /*pDC*/, CPrintInfo* /*pInfo*/) { if (GetDocument()->locked) @@ -1032,7 +1050,6 @@ void MapView::OnEndPrinting(QPainter* /*pDC*/, CPrintInfo* /*pInfo*/) } #endif - // // CMapView miscellaneous // @@ -1051,9 +1068,7 @@ void MapView::addRoom(QPoint & point) return; } - point.rx() -= roomWidth / 2 - gridX / 2; point.rx() -= point.x() % gridX; - point.ry() -= roomHeight / 2 - gridY / 2; point.ry() -= point.y() % gridY; if (point.x() < 0) @@ -1077,7 +1092,6 @@ void MapView::addRoom(QPoint & point) editProperties(epuAddRoom, wasModified); } - // // Make sure we aren't dragging a room off the edge: // @@ -1107,7 +1121,6 @@ void MapView::adjustOffset(QPoint & p) const p.ry() = size.height() - rTmp.bottom(); } - // // Deselect all rooms: // @@ -1149,7 +1162,6 @@ void MapView::clearSelection(bool update/* = true*/) deselectPages(update); } - // // Compute a rectangle enclosing all selected rooms: // @@ -1188,7 +1200,6 @@ void MapView::computeSelectedRect(QRect & r) const } } - // // Deselect a page: // @@ -1232,7 +1243,6 @@ void MapView::deselectPage(int n, bool update/* = true*/) } } - // // Deselect all pages: // @@ -1289,7 +1299,6 @@ void MapView::deselectPages(bool update/* = true*/) selectedOne = -1; } - // // Deselect a room: // @@ -1336,7 +1345,6 @@ void MapView::deselectRoom(RoomNum n, bool update/* = true*/) } } - // // Update the room comments dialog after the selection changes: // @@ -1345,7 +1353,6 @@ void MapView::selectDone() // static_cast(AfxGetApp())->setComment(this, (selectedOne >= 0 ? &(GetDocument()->getRoom(selectedOne)) : NULL)); } - // // Select a page: // @@ -1381,7 +1388,6 @@ void MapView::selectPage(int n, bool update/* = true*/) } } - // // Select a room: // @@ -1423,7 +1429,6 @@ void MapView::selectRoom(RoomNum n, bool update/*= true*/) } } - void MapView::selectOnlyRoom(RoomNum n) { if (selectedOne != n) @@ -1434,7 +1439,6 @@ void MapView::selectOnlyRoom(RoomNum n) } } - // // Make sure that a room is visible: // @@ -1504,7 +1508,6 @@ void MapView::makeRoomVisible(RoomNum n) #endif } - // // Paste a string to the clipboard: // @@ -1544,7 +1547,6 @@ bool MapView::pasteClipboard(const string & text) return true; } - // // Update the selected room's comment from the floating dialog: // @@ -1562,7 +1564,6 @@ void MapView::setRoomNote(const char * comment) } } - int MapView::FindHoveredEdge(void) { for(int i=0; iedge.size(); i++) @@ -1594,7 +1595,6 @@ int MapView::FindHoveredEdge(void) return -1; } - // // Set the step size of the scroll bars: // @@ -1621,7 +1621,6 @@ void MapView::setScrollBars() #endif } - // // Zoom the display: // @@ -1650,7 +1649,6 @@ void MapView::zoomTo(short newZoom) } } - // // Navigation: //--------------------------------------------------------------------------- @@ -1865,7 +1863,6 @@ void MapView::navigate(RoomCorner corner, bool toggleStubs/* = true*/) } } - // // Fill in the edge type from the navigation box: // @@ -1946,7 +1943,6 @@ void MapView::setEdgeType(MapEdge & e) } } - // // Start typing in the navigation bar: // @@ -1969,7 +1965,6 @@ void MapView::setNavText(char c) #endif } - #if 0 void MapView::OnChar(unsigned int c, unsigned int nRepCnt, unsigned int nFlags) { @@ -1982,7 +1977,6 @@ void MapView::OnChar(unsigned int c, unsigned int nRepCnt, unsigned int nFlags) } #endif - // // Parse the text in the navigation bar: // @@ -2057,7 +2051,6 @@ void MapView::getNavText(char & initial, RoomCorner & dir1, char & separator, Ro #endif } - #if 0 // // Handle the Go button in the navigation bar: @@ -2099,7 +2092,6 @@ void MapView::OnNavGo() } } - // // Handle the direction keys on the numeric keypad: // @@ -2140,7 +2132,6 @@ void MapView::OnNavGoDir(unsigned int cmd) MessageBeep(MB_ICONASTERISK); } - // // CMapView message handlers //--------------------------------------------------------------------------- @@ -2155,7 +2146,6 @@ void MapView::OnActivateView(bool bActivate, CView * pActivateView, CView * pDea } #endif - // N.B.: If you click on a corner with no edge coming out of it, it will crash here... !!! FIX !!! [MOSTLY DONE--there's still a way to make it crash with "Add Corner", but I can't remember the specifics...] //void MapView::OnEditAddCorner() void MapView::HandleAddCorner(void) @@ -2175,7 +2165,6 @@ void MapView::HandleAddCorner(void) update(); } - void MapView::HandleAddUnexplored(void) { EdgeVec deletedEdges; @@ -2211,7 +2200,6 @@ void MapView::HandleAddUnexplored(void) update(); } - void MapView::HandleAddLoopBack(void) { EdgeVec deletedEdges; @@ -2247,7 +2235,6 @@ void MapView::HandleAddLoopBack(void) update(); } - void MapView::HandleAddNoExit(void) { EdgeVec deletedEdges; @@ -2283,7 +2270,6 @@ void MapView::HandleAddNoExit(void) update(); } - void MapView::SetEdgeDirection(EdgeType et) { MapEdge e; @@ -2310,31 +2296,26 @@ void MapView::SetEdgeDirection(EdgeType et) update(); } - void MapView::HandleAddUp(void) { SetEdgeDirection(etUp); } - void MapView::HandleAddDown(void) { SetEdgeDirection(etDown); } - void MapView::HandleAddIn(void) { SetEdgeDirection(etIn); } - void MapView::HandleAddOut(void) { SetEdgeDirection(etOut); } - void MapView::SetEdges(int room, int edgeNum, EdgeType eType) { /* @@ -2388,7 +2369,6 @@ One way to make that less awful is to overload the RoomCorner (which, for some r } } - void MapView::ClearEdges(int room, int edgeNum, EdgeType eType) { // Go thru from current room to all connected "corner" rooms @@ -2424,7 +2404,6 @@ void MapView::ClearEdges(int room, int edgeNum, EdgeType eType) } } - void MapView::HandleAddOneWay(void) { MapEdge e; @@ -2439,7 +2418,6 @@ void MapView::HandleAddOneWay(void) update(); } - void MapView::HandleClearOneWay(void) { MapEdge e; @@ -2454,7 +2432,6 @@ void MapView::HandleClearOneWay(void) update(); } - void MapView::HandleAddRestricted(void) { MapEdge e; @@ -2469,7 +2446,6 @@ void MapView::HandleAddRestricted(void) update(); } - void MapView::HandleClearRestricted(void) { MapEdge e; @@ -2484,13 +2460,32 @@ void MapView::HandleClearRestricted(void) update(); } - //void MapView::OnEditAddRoom() void MapView::HandleAddRoom(void) { - addRoom(scrollDragStart); -} +#if 0 + MapDoc * const doc = GetDocument(); + ASSERT_VALID(doc); + const int p = doc->page.size(); + + if (p < maxPages) + { + MapPage page; + page.pos = scrollDragStart; + page.pos.x -= page.pos.x % gridX; + page.pos.y -= page.pos.y % gridY; + doc->setUndoData(new UndoAdd(doc->isDirty, p)); + showPages = true; + doc->addPage(p, page); + clearSelection(); + selectPage(p); + } +#else + QPoint roomPt(scrollDragStart - offset); + addRoom(roomPt); +#endif +} void MapView::HandleMapProperties(void) { @@ -2519,7 +2514,6 @@ void MapView::HandleMapProperties(void) update(); } - //void MapView::OnEditClear() void MapView::HandleDelete(void) { @@ -2527,7 +2521,6 @@ void MapView::HandleDelete(void) update(); } - #if 0 //-------------------------------------------------------------------- void MapView::OnEditAddPage() @@ -2552,7 +2545,6 @@ void MapView::OnEditAddPage() } #endif - // // Input: // removeCorner: (default true) @@ -2623,7 +2615,6 @@ void MapView::deleteSelection(bool removeCorner/* = true*/) } } - #if 0 //-------------------------------------------------------------------- // Cut, Copy & Paste: @@ -2678,14 +2669,12 @@ void MapView::OnEditCopy() } } - void MapView::OnEditCut() { OnEditCopy(); deleteSelection(); } - void MapView::OnEditPaste() { const RoomScrap * scrap = static_cast(AfxGetApp())->getClipboard(); @@ -2712,7 +2701,6 @@ void MapView::OnEditPaste() } } - void MapView::OnEditPaginate() { showPages = true; @@ -2720,7 +2708,6 @@ void MapView::OnEditPaginate() } #endif - // // Handle Edit Properties: // @@ -2730,7 +2717,6 @@ void MapView::HandleRoomProperties(void) editProperties(epuRoomInfo); } - // // Bring up the Properties dialog: // @@ -2895,7 +2881,6 @@ void MapView::editProperties(EditPropUndo undoType, bool wasModified/*= false*/, delete undoRoom; } - #if 0 // // Select all rooms: @@ -2908,7 +2893,6 @@ void MapView::OnEditSelectAll() selectDone(); } - //--------------------------------------------------------------------------- // Select connected rooms: @@ -2941,7 +2925,6 @@ void MapView::OnEditSelectConnected() selectDone(); } - void MapView::OnInitialUpdate() { const MapDoc * doc = GetDocument(); @@ -2967,7 +2950,6 @@ void MapView::OnInitialUpdate() setScrollBars(); // Now fix the scroll bars } - void MapView::OnKeyDown(unsigned int c, unsigned int nRepCnt, unsigned int nFlags) { bool ctrl = (GetKeyState(VK_CONTROL) < 0); @@ -2997,7 +2979,6 @@ void MapView::OnKeyDown(unsigned int c, unsigned int nRepCnt, unsigned int nFlag } #endif - void MapView::mouseDoubleClickEvent(QMouseEvent * event) //void MapView::OnLButtonDblClk(unsigned int nFlags, QPoint point) { @@ -3034,7 +3015,6 @@ void MapView::mouseDoubleClickEvent(QMouseEvent * event) addRoom(point); } - /* N.B.: Handles RButton & MButton too */ void MapView::mousePressEvent(QMouseEvent * event) //void MapView::OnLButtonDown(unsigned int nFlags, QPoint point) @@ -3235,7 +3215,8 @@ Qt::NoModifier, Qt::ShiftModifier, Qt::ControlModifier, Qt::AltModifier, etc. { edgeTmp.room1 = room; edgeTmp.end1 = corner; - setEdgeType(edgeTmp); +// This is setting edge types when it shouldn't... So we're commenting this out for now. +// setEdgeType(edgeTmp); } edgeTmp.room2 = 0; @@ -3706,7 +3687,6 @@ void MapView::mouseMoveEvent(QMouseEvent * event) update(); } - //void MapView::OnLButtonUp(unsigned int nFlags, QPoint point) void MapView::mouseReleaseEvent(QMouseEvent * event) { @@ -3947,7 +3927,6 @@ void MapView::mouseReleaseEvent(QMouseEvent * event) update(); } - #if 0 int MapView::OnMouseActivate(CWnd * wnd, unsigned int hitTest, unsigned int message) { @@ -3959,7 +3938,6 @@ int MapView::OnMouseActivate(CWnd * wnd, unsigned int hitTest, unsigned int mess return result; } - bool MapView::OnMouseWheel(unsigned int nFlags, short zDelta, QPoint pt) { if (nFlags == MK_CONTROL) @@ -3971,7 +3949,6 @@ bool MapView::OnMouseWheel(unsigned int nFlags, short zDelta, QPoint pt) return CScrollZoomView::OnMouseWheel(nFlags, zDelta, pt); } - void MapView::OnSize(unsigned int nType, int cx, int cy) { CScrollZoomView::OnSize(nType, cx, cy); @@ -3980,7 +3957,6 @@ void MapView::OnSize(unsigned int nType, int cx, int cy) setScrollBars(); } - void MapView::OnTimer(unsigned int idEvent) { if (idEvent == menuTimer) @@ -3996,7 +3972,6 @@ void MapView::OnTimer(unsigned int idEvent) CScrollZoomView::OnTimer(idEvent); } - // // Update the view after the document changes: // @@ -4069,20 +4044,17 @@ void MapView::OnUpdate(CView * pSender, LPARAM lHint, CObject * pHint) Invalidate(); } - void MapView::OnUpdateEditAddCorner(CCmdUI* pCmdUI) { pCmdUI->Enable(opInProgress == gmoAddCorner); } - void MapView::OnUpdateEditPaste(CCmdUI* pCmdUI) { pCmdUI->Enable((static_cast(AfxGetApp())->getClipboard() != NULL) && !GetDocument()->locked); } - // // Commands which require selected rooms and unlocked document: // @@ -4110,7 +4082,6 @@ void MapView::OnUpdateSelectedUnlocked(CCmdUI * pCmdUI) pCmdUI->Enable(selected && !doc->locked); } - // // Commands which require the document to be unlocked: // @@ -4121,7 +4092,6 @@ void MapView::OnUpdateUnlocked(CCmdUI* pCmdUI) pCmdUI->Enable(!GetDocument()->locked); } - // // Toggle the grid on and off: // @@ -4131,13 +4101,11 @@ void MapView::OnViewGrid() InvalidateRect(NULL); } - void MapView::OnUpdateViewGrid(CCmdUI * pCmdUI) { pCmdUI->SetCheck(showGrid); } - void MapView::OnViewZoom(unsigned int cmd) { ASSERT((cmd == ID_VIEW_ZOOM_IN) || (cmd == ID_VIEW_ZOOM_OUT)); @@ -4148,14 +4116,12 @@ void MapView::OnViewZoom(unsigned int cmd) zoomTo(zoom + 10 - zoom % 10); } - void MapView::OnUpdateViewZoom(CCmdUI * pCmdUI) { pCmdUI->Enable((pCmdUI->m_nID == ID_VIEW_ZOOM_IN) ? (zoom < maxZoom) : (zoom > minZoom)); } - // // Redraw the window: // @@ -4164,7 +4130,6 @@ void MapView::OnWindowRefresh() InvalidateRect(NULL); } - ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // CRepaginateDlg dialog @@ -4184,7 +4149,6 @@ END_MESSAGE_MAP(); ///////////////////////////////////////////////////////////////////////////// // CRepaginateDlg message handlers - bool CRepaginateDlg::OnInitDialog() { CDialog::OnInitDialog(); @@ -4195,10 +4159,8 @@ bool CRepaginateDlg::OnInitDialog() return true; // return TRUE unless you set the focus to a control } - void CRepaginateDlg::OnYes() { EndDialog(IDYES); } #endif -