#include "globals.h"
#include <math.h>
-
+#include "mathconstants.h"
//
// Class MapEdge:
{
}
-
MapEdge::MapEdge(RoomNum r1, RoomNum r2, EdgeType t1, EdgeType t2, RoomCorner e1, RoomCorner e2): room1(r1), room2(r2), end1(e1), end2(e2), type1(t1), type2(t2)
{
}
+void MapEdge::Clear(void)
+{
+ room1 = room2 = 0;
+ end1 = end2 = rcNone;
+ type1 = type2 = 0;
+}
//
// Actually swap the rooms for this edge
end2 = tc;
}
-
bool MapEdge::HasRoom(RoomNum r)
{
if ((room1 != r) && (room2 != r))
return true;
}
-
//
// Return the MapEdge but with the RoomNums, EdgeTypes, & RoomCorners swapped
//
return MapEdge(room2, room1, type2 | (type1 & etObstructed), type1 & ~etObstructed, end2, end1);
}
-
//
// Class MapRoom:
//
{
}
-
MapRoom::MapRoom(const MapRoom & o)
{
*this = o;
}
-
MapRoom & MapRoom::operator=(const MapRoom & source)
{
pos = source.pos;
return *this;
}
-
QRect MapRoom::getRect(void)
{
return QRect(pos,
(flags & rfCorner ? QSize(gridX, gridY) : QSize(roomWidth, roomHeight)));
}
-
QRect MapRoom::getTranslatedRect(QPoint t)
{
return QRect(pos + t,
(flags & rfCorner ? QSize(gridX, gridY) : QSize(roomWidth, roomHeight)));
}
-
QPoint MapRoom::GetCenter(void)
{
return QPoint(pos +
: QPoint(roomWidth / 2, roomHeight / 2)));
}
-
RoomFlags MapRoom::isCorner() const
{
return (flags & rfCorner);
}
-
bool MapRoom::operator!=(const MapRoom & mr) const
{
if (pos != mr.pos)
return true;
}
-
//
// Miscellaneous functions:
//--------------------------------------------------------------------
s.erase(0, p);
}
-
//
// Trim whitespace from right of string:
//
s.erase(p + 1);
}
-
//
// Consolidates action creation from a multi-step process to a single-step one.
//
return action;
}
-
//
// This is essentially the same as the previous function, but this allows more
// than one key sequence to be added as key shortcuts.
return action;
}
-
//
// Miscellaneous geometrical helper functions
//
return sqrt((p.x() * p.x()) + (p.y() * p.y()));
}
-
QPointF UnitVector(QPointF p)
{
double magnitude = Magnitude(p);
return QPointF(p.x() / magnitude, p.y() / magnitude);
}
-
double Angle(QPointF p)
{
- return atan2(p.y(), p.x());
-}
+ double angle = atan2(p.y(), p.x());
+ if (angle < 0)
+ angle += TAU;
+
+ return angle;
+}
double Angle(QPoint p)
{
- return atan2((double)p.y(), (double)p.x());
-}
+ double angle = atan2((double)p.y(), (double)p.x());
+
+ if (angle < 0)
+ angle += TAU;
+ return angle;
+}
double Dot(QPointF a, QPointF b)
{
return (a.x() * b.x()) + (a.y() * b.y());
}
-
double Determinant(QPointF a, QPointF b)
{
return (a.x() * b.y()) - (b.x() * a.y());
}
-
// Returns the parameter of a point in space to this vector. If the parameter
// is between 0 and 1, the normal of the vector to the point is on the vector.
double ParameterOfLineAndPoint(QPointF tail, QPointF head, QPointF point)
double magnitude = Magnitude(lineSegment);
QPointF pointSegment = point - tail;
double t = Dot(lineSegment, pointSegment) / (magnitude * magnitude);
+
return t;
}
-
#include "roomdialog.h"
#include "undo.h"
-
const int
penEdgeWidth = 9,
penPageWidth = 20,
static const char a2z[] = "abcdefghijklmnopqrstuvwxyz";
-
//
// Parse a direction word:
//
return rcNone;
}
-
#if 0
/////////////////////////////////////////////////////////////////////////////
// CRepaginateDlg dialog
};
#endif
-
-
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CMapView
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;
painter->drawPolygon(arrow);
}
-
void MapView::DrawNoExit(QPainter * painter, QPointF head, QPointF tail)
{
const double angle = Angle(tail - head);
painter->drawLine(p2, p3);
}
-
//
// MapView drawing
//
QPoint ex = QPoint(0, 0);
double angle = Angle(end - start);
- if (angle < 0)
- angle += TAU;
-
// 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))
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);
- if (angle < 0)
- angle += TAU;
-
// 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))
}
}
-
void MapView::keyPressEvent(QKeyEvent * event)
{
bool oldShift = shiftDown;
#endif
}
-
void MapView::keyReleaseEvent(QKeyEvent * event)
{
bool oldShift = shiftDown;
}
}
-
#if 0
/////////////////////////////////////////////////////////////////////////////
// CMapView printing
printingPage = 0;
}
-
bool MapView::OnPreparePrinting(CPrintInfo * pInfo)
{
// Require registration before printing map with more than 10 rooms:
return DoPreparePrinting(pInfo);
}
-
void MapView::OnBeginPrinting(QPainter * /*pDC*/, CPrintInfo * /*pInfo*/)
{
// Don't show selection or corners while printing:
showCorners = false;
}
-
void MapView::OnEndPrinting(QPainter* /*pDC*/, CPrintInfo* /*pInfo*/)
{
if (GetDocument()->locked)
}
#endif
-
//
// CMapView miscellaneous
//
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)
editProperties(epuAddRoom, wasModified);
}
-
//
// Make sure we aren't dragging a room off the edge:
//
p.ry() = size.height() - rTmp.bottom();
}
-
//
// Deselect all rooms:
//
deselectPages(update);
}
-
//
// Compute a rectangle enclosing all selected rooms:
//
}
}
-
//
// Deselect a page:
//
}
}
-
//
// Deselect all pages:
//
selectedOne = -1;
}
-
//
// Deselect a room:
//
}
}
-
//
// Update the room comments dialog after the selection changes:
//
// static_cast<CMapApp *>(AfxGetApp())->setComment(this, (selectedOne >= 0 ? &(GetDocument()->getRoom(selectedOne)) : NULL));
}
-
//
// Select a page:
//
}
}
-
//
// Select a room:
//
}
}
-
void MapView::selectOnlyRoom(RoomNum n)
{
if (selectedOne != n)
}
}
-
//
// Make sure that a room is visible:
//
#endif
}
-
//
// Paste a string to the clipboard:
//
return true;
}
-
//
// Update the selected room's comment from the floating dialog:
//
}
}
-
int MapView::FindHoveredEdge(void)
{
for(int i=0; i<doc->edge.size(); i++)
return -1;
}
-
//
// Set the step size of the scroll bars:
//
#endif
}
-
//
// Zoom the display:
//
}
}
-
//
// Navigation:
//---------------------------------------------------------------------------
}
}
-
//
// Fill in the edge type from the navigation box:
//
}
}
-
//
// Start typing in the navigation bar:
//
#endif
}
-
#if 0
void MapView::OnChar(unsigned int c, unsigned int nRepCnt, unsigned int nFlags)
{
}
#endif
-
//
// Parse the text in the navigation bar:
//
#endif
}
-
#if 0
//
// Handle the Go button in the navigation bar:
}
}
-
//
// Handle the direction keys on the numeric keypad:
//
MessageBeep(MB_ICONASTERISK);
}
-
//
// CMapView message handlers
//---------------------------------------------------------------------------
}
#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)
update();
}
-
void MapView::HandleAddUnexplored(void)
{
EdgeVec deletedEdges;
update();
}
-
void MapView::HandleAddLoopBack(void)
{
EdgeVec deletedEdges;
update();
}
-
void MapView::HandleAddNoExit(void)
{
EdgeVec deletedEdges;
update();
}
-
void MapView::SetEdgeDirection(EdgeType et)
{
MapEdge e;
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)
{
/*
}
}
-
void MapView::ClearEdges(int room, int edgeNum, EdgeType eType)
{
// Go thru from current room to all connected "corner" rooms
}
}
-
void MapView::HandleAddOneWay(void)
{
MapEdge e;
update();
}
-
void MapView::HandleClearOneWay(void)
{
MapEdge e;
update();
}
-
void MapView::HandleAddRestricted(void)
{
MapEdge e;
update();
}
-
void MapView::HandleClearRestricted(void)
{
MapEdge e;
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)
{
update();
}
-
//void MapView::OnEditClear()
void MapView::HandleDelete(void)
{
update();
}
-
#if 0
//--------------------------------------------------------------------
void MapView::OnEditAddPage()
}
#endif
-
//
// Input:
// removeCorner: (default true)
}
}
-
#if 0
//--------------------------------------------------------------------
// Cut, Copy & Paste:
}
}
-
void MapView::OnEditCut()
{
OnEditCopy();
deleteSelection();
}
-
void MapView::OnEditPaste()
{
const RoomScrap * scrap = static_cast<CMapApp *>(AfxGetApp())->getClipboard();
}
}
-
void MapView::OnEditPaginate()
{
showPages = true;
}
#endif
-
//
// Handle Edit Properties:
//
editProperties(epuRoomInfo);
}
-
//
// Bring up the Properties dialog:
//
delete undoRoom;
}
-
#if 0
//
// Select all rooms:
selectDone();
}
-
//---------------------------------------------------------------------------
// Select connected rooms:
selectDone();
}
-
void MapView::OnInitialUpdate()
{
const MapDoc * doc = GetDocument();
setScrollBars(); // Now fix the scroll bars
}
-
void MapView::OnKeyDown(unsigned int c, unsigned int nRepCnt, unsigned int nFlags)
{
bool ctrl = (GetKeyState(VK_CONTROL) < 0);
}
#endif
-
void MapView::mouseDoubleClickEvent(QMouseEvent * event)
//void MapView::OnLButtonDblClk(unsigned int nFlags, QPoint point)
{
addRoom(point);
}
-
/* N.B.: Handles RButton & MButton too */
void MapView::mousePressEvent(QMouseEvent * event)
//void MapView::OnLButtonDown(unsigned int nFlags, QPoint point)
{
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;
update();
}
-
//void MapView::OnLButtonUp(unsigned int nFlags, QPoint point)
void MapView::mouseReleaseEvent(QMouseEvent * event)
{
update();
}
-
#if 0
int MapView::OnMouseActivate(CWnd * wnd, unsigned int hitTest, unsigned int message)
{
return result;
}
-
bool MapView::OnMouseWheel(unsigned int nFlags, short zDelta, QPoint pt)
{
if (nFlags == MK_CONTROL)
return CScrollZoomView::OnMouseWheel(nFlags, zDelta, pt);
}
-
void MapView::OnSize(unsigned int nType, int cx, int cy)
{
CScrollZoomView::OnSize(nType, cx, cy);
setScrollBars();
}
-
void MapView::OnTimer(unsigned int idEvent)
{
if (idEvent == menuTimer)
CScrollZoomView::OnTimer(idEvent);
}
-
//
// Update the view after the document changes:
//
Invalidate();
}
-
void MapView::OnUpdateEditAddCorner(CCmdUI* pCmdUI)
{
pCmdUI->Enable(opInProgress == gmoAddCorner);
}
-
void MapView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
pCmdUI->Enable((static_cast<CMapApp*>(AfxGetApp())->getClipboard() != NULL)
&& !GetDocument()->locked);
}
-
//
// Commands which require selected rooms and unlocked document:
//
pCmdUI->Enable(selected && !doc->locked);
}
-
//
// Commands which require the document to be unlocked:
//
pCmdUI->Enable(!GetDocument()->locked);
}
-
//
// Toggle the grid on and off:
//
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));
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:
//
InvalidateRect(NULL);
}
-
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CRepaginateDlg dialog
/////////////////////////////////////////////////////////////////////////////
// CRepaginateDlg message handlers
-
bool CRepaginateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return true; // return TRUE unless you set the focus to a control
}
-
void CRepaginateDlg::OnYes()
{
EndDialog(IDYES);
}
#endif
-