[Gcblue-commits] gcb_wx/src/graphics tcMapObject.cpp, 1.11, 1.12 tcMapOverlay.cpp, 1.4, 1.5 tcMapVi
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-12-11 01:20:46
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv32130/src/graphics Modified Files: tcMapObject.cpp tcMapOverlay.cpp tcMapView.cpp Log Message: Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** tcMapView.cpp 6 Dec 2006 01:20:42 -0000 1.52 --- tcMapView.cpp 11 Dec 2006 01:20:42 -0000 1.53 *************** *** 2656,2659 **** --- 2656,2665 ---- CheckForNavPointEdit(buttonDownPoint); + if (hookedId.size() == 0) + { + overlay->OnLButtonDown(event); + if (overlay->IsInteracting()) return; + } + isLButtonDown = true; *************** *** 2730,2733 **** --- 2736,2745 ---- tcDragStatus::Get()->StopDrag(); + if (overlay->IsInteracting()) + { + overlay->OnLButtonUp(event); + return; + } + if (!isLButtonDown) return; *************** *** 2829,2832 **** --- 2841,2849 ---- UpdateEdgeScroll(point); } + + if (overlay->IsInteracting()) + { + overlay->OnMouseMove(event); + } } Index: tcMapOverlay.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapOverlay.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcMapOverlay.cpp 17 Aug 2006 01:28:04 -0000 1.4 --- tcMapOverlay.cpp 11 Dec 2006 01:20:42 -0000 1.5 *************** *** 105,108 **** --- 105,121 ---- } + void tcMapOverlay::ClearInteraction() + { + if (hookedIdx < overlayObjects.size()) + { + overlayObjects[hookedIdx]->SetIsHooked(false); + } + + isInteracting = false; + hookedIdx = 99999; + + Redraw(); + } + void tcMapOverlay::ClearMapObjects() { *************** *** 130,133 **** --- 143,218 ---- } + void tcMapOverlay::HookObject(size_t idx) + { + if (isInteracting && (hookedIdx == idx)) return; // already hooked + + if (hookedIdx < overlayObjects.size()) + { + overlayObjects[hookedIdx]->SetIsHooked(false); // clear previous hook + } + + if (idx >= overlayObjects.size()) // clear hook + { + ClearInteraction(); + return; + } + + overlayObjects[idx]->SetIsHooked(true); + hookedIdx = idx; + isInteracting = true; + } + + + /** + * @return true if player is interacting with overlay + */ + bool tcMapOverlay::IsInteracting() const + { + return isInteracting; + } + + void tcMapOverlay::OnLButtonDown(wxMouseEvent& event) + { + wxPoint pos = event.GetPosition(); + + for (size_t n=0; n < overlayObjects.size(); n++) + { + tcMapObject* obj = overlayObjects[n]; + + if (true || obj->IsInteractive()) + { + float dist = overlayObjects[n]->GetScreenDistanceFrom(pos); + if (dist < 5.0f) + { + HookObject(n); + Redraw(); + return; + } + } + } + + ClearInteraction(); + + } + + void tcMapOverlay::OnLButtonUp(wxMouseEvent& event) + { + ClearInteraction(); + } + + void tcMapOverlay::OnMouseMove(wxMouseEvent& event) + { + if (!isInteracting) return; + + if (hookedIdx >= overlayObjects.size()) + { + wxASSERT(false); + return; + } + + overlayObjects[hookedIdx]->MoveToScreenPoint(event.GetPosition()); + Redraw(); + } + void tcMapOverlay::OnSize(wxSizeEvent& event) *************** *** 156,160 **** const wxString& name) : tc3DWindow(parent, pos, size, name, 0), ! redraw(false) { --- 241,247 ---- const wxString& name) : tc3DWindow(parent, pos, size, name, 0), ! redraw(false), ! isInteracting(false), ! hookedIdx(0) { Index: tcMapObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapObject.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcMapObject.cpp 17 Aug 2006 01:28:04 -0000 1.11 --- tcMapObject.cpp 11 Dec 2006 01:20:42 -0000 1.12 *************** *** 155,158 **** --- 155,179 ---- host->DrawLineR(x+8, y-8, x-8, y+8, color); } + + if (isHooked) + { + host->DrawLineR(x-8, y-10, x+8, y-10, color); + } + } + + /** + * @return screen distance from screen point pos + */ + float tcMapObject::GetScreenDistanceFrom(const wxPoint& pos) + { + tcPoint screenPoint = GetScreenPoint(); + tcPoint refPoint((float)pos.x, (float)pos.y); + + return screenPoint.DistanceTo(refPoint); + } + + bool tcMapObject::IsInteractive() const + { + return isInteractive; } *************** *** 174,177 **** --- 195,225 ---- } + void tcMapObject::MoveToScreenPoint(const wxPoint& pos) + { + wxASSERT(mapView); + if (!useRelativeCoords) + { + tcPoint p = mapView->ScreenToGeo((float)pos.x, (float)pos.y); + _x = p.x; + _y = p.y; + } + else + { + _x = (double)pos.x; + _y = (double)pos.y; + } + } + + + void tcMapObject::SetIsHooked(bool state) + { + isHooked = state; + } + + void tcMapObject::SetInteractive(bool state) + { + isInteractive = state; + } + /** * mapView is used to translate lat/lon coords into screen coords. *************** *** 189,193 **** tcMapObject::tcMapObject(double x, double y, bool useRel) ! : useRelativeCoords(useRel) { if (useRel) --- 237,243 ---- tcMapObject::tcMapObject(double x, double y, bool useRel) ! : useRelativeCoords(useRel), ! isInteractive(false), ! isHooked(false) { if (useRel) *************** *** 259,262 **** --- 309,323 ---- } + if (isHooked) + { + const osg::Vec4 hookColor(1, 1, 1, 1); + const float a = 10.0f; + + host->DrawLineR(x-a, y-a, x+a, y-a, hookColor); + host->DrawLineR(x-a, y+a, x+a, y+a, hookColor); + host->DrawLineR(x-a, y-a, x-a, y+a, hookColor); + host->DrawLineR(x+a, y-a, x+a, y+a, hookColor); + } + } |