From: MandhelingFreak Date: Sun, 9 Mar 2014 08:33:57 +0000 (+0900) Subject: 整理。 X-Git-Tag: release/ver1.3~4 X-Git-Url: http://git.osdn.net/view?p=gvonavish%2FGVONavish.git;a=commitdiff_plain;h=34f4dfccf8eb034f7dddbf13257ac47cf8b997fe 整理。 --- diff --git a/GVONavish/GVONavish/GVONavish.cpp b/GVONavish/GVONavish/GVONavish.cpp index 489403a..a6c185f 100644 --- a/GVONavish/GVONavish/GVONavish.cpp +++ b/GVONavish/GVONavish/GVONavish.cpp @@ -71,8 +71,8 @@ static void s_closeShipRoute(); // ƒ[ƒJƒ‹•Ï” -static LPCWSTR const k_appName = L"GVONavii‚Á‚Û‚¢‰½‚©j"; // ƒAƒvƒŠƒP[ƒVƒ‡ƒ“–¼ -static LPCWSTR const k_version = L"ver 1.2"; // ƒo[ƒWƒ‡ƒ“”ԍ† +static LPCWSTR const k_appName = L"GVONavish"; // ƒAƒvƒŠƒP[ƒVƒ‡ƒ“–¼ +static LPCWSTR const k_version = L"ver 1.2"; // ƒo[ƒWƒ‡ƒ“”ԍ† static LPCWSTR const k_copyright = L"copyright(c) @MandhelingFreak"; // ’˜ìŒ •\Ž¦i‚¢‚¿‚¨[j static LPCWSTR const k_windowClassName = L"GVONavish"; // ƒƒCƒ“ ƒEƒBƒ“ƒhƒE ƒNƒ‰ƒX–¼ diff --git a/GVONavish/GVONavish/GVORenderer.cpp b/GVONavish/GVONavish/GVORenderer.cpp index c8f24dd..bc4a3e3 100644 --- a/GVONavish/GVONavish/GVORenderer.cpp +++ b/GVONavish/GVONavish/GVORenderer.cpp @@ -343,7 +343,7 @@ void GVORenderer::renderShipRouteList( int width, int height, const GVOShipRoute ::glColor4f( 1.0f, 1.0f, 1.0f, 0.5f ); } - for ( const GVOShipRoute *route : shipRouteList->getList() ) { + for ( const GVOShipRoutePtr route : shipRouteList->getList() ) { // ÅVq˜H‚¾‚¯‚ð•s“§–¾‚Å•`‰æ if ( shipRouteList->getList().back() == route ) { ::glLineWidth( lineWidth ); diff --git a/GVONavish/GVONavish/GVOShipRoute.cpp b/GVONavish/GVONavish/GVOShipRoute.cpp index 6e934cf..5431d1b 100644 --- a/GVONavish/GVONavish/GVOShipRoute.cpp +++ b/GVONavish/GVONavish/GVOShipRoute.cpp @@ -19,6 +19,8 @@ GVOShipRoute::~GVOShipRoute() void GVOShipRoute::addRoutePoint( const GVONormalizedPoint & point ) { + _ASSERT( !isFixed() ); + if ( m_lines.empty() ) { m_lines.push_back( Line() ); } diff --git a/GVONavish/GVONavish/GVOShipRoute.h b/GVONavish/GVONavish/GVOShipRoute.h index 6998b0e..84a1943 100644 --- a/GVONavish/GVONavish/GVOShipRoute.h +++ b/GVONavish/GVONavish/GVOShipRoute.h @@ -11,11 +11,13 @@ private: Lines m_lines; bool m_favorite = false; bool m_hilight = false; + bool m_fixed = false; //!<@brief q˜HŒÅ’èƒtƒ‰ƒO public: GVOShipRoute(); ~GVOShipRoute(); + //!@attention ŒÅ’肳‚ꂽq˜H‚ɍÀ•W‚ð’ljÁ‚µ‚Ä‚Í‚È‚ç‚È‚¢BƒƒWƒbƒNƒGƒ‰[‚È‚Ì‚ÅDebugŽž‚̂݃Gƒ‰[‚Æ‚µ‚Ä‚¢‚éB void addRoutePoint( const GVONormalizedPoint & point ); const Lines & getLines() const @@ -60,5 +62,18 @@ public: } return true; } + + bool isFixed() const + { + return m_fixed; + } + + void setFix( bool isFixed) + { + m_fixed = isFixed; + } private: }; + +typedef std::shared_ptr GVOShipRoutePtr; +typedef std::weak_ptr GVOShipRouteWeakPtr; diff --git a/GVONavish/GVONavish/GVOShipRouteList.cpp b/GVONavish/GVONavish/GVOShipRouteList.cpp index 70c88d0..32b0300 100644 --- a/GVONavish/GVONavish/GVOShipRouteList.cpp +++ b/GVONavish/GVONavish/GVOShipRouteList.cpp @@ -1,52 +1,40 @@ -#include "stdafx.h" +#include "stdafx.h" #include "GVOShipRouteList.h" -GVOShipRouteList::~GVOShipRouteList() -{ - for ( GVOShipRoute *route : m_shipRouteList ) { - delete route; - } - m_shipRouteList.clear(); -} - void GVOShipRouteList::closeRoute() { - addRoute(); + if ( !m_shipRouteList.empty() ) { + m_shipRouteList.back()->setFix( true ); + } } void GVOShipRouteList::addRoutePoint( const GVONormalizedPoint point ) { - if ( m_shipRouteList.empty() ) { + if ( m_shipRouteList.empty() || m_shipRouteList.back()->isFixed() ) { addRoute(); } m_shipRouteList.back()->addRoutePoint( point ); if ( m_observer ) { - m_observer->onShipRouteListUpdateRoute( *m_shipRouteList.back() ); + m_observer->onShipRouteListUpdateRoute( m_shipRouteList.back() ); } } -void GVOShipRouteList::removeShipRouteAtReverseIndex( int reverseIndex ) +void GVOShipRouteList::removeShipRoute( GVOShipRoutePtr shipRoute ) { - _ASSERT( 0 <= reverseIndex ); - _ASSERT( reverseIndex < (int)m_shipRouteList.size() ); - - std::unique_ptr route; - RouteList::iterator it; - it = m_shipRouteList.begin(); - std::advance( it, indexFromReverseIndex( reverseIndex ) ); - route.reset( std::move( *it ) ); + _ASSERT( shipRoute != nullptr ); + auto it = std::find( m_shipRouteList.begin(), m_shipRouteList.end(), shipRoute ); + if ( it == m_shipRouteList.end() ) { + return; + } + GVOShipRoutePtr removeTarget = shipRoute; m_shipRouteList.erase( it ); if ( m_observer ) { - m_observer->onShipRouteListRemoveItem( *route ); - } - if ( reverseIndex == 0 ) { - // ÅVXV’†q˜H‚ð’Pƒíœ‚·‚é‚Æ’¼‘O‚̍q˜H‚ªXV‚³‚ꑱ‚¯‚éˆ×AV‹Kq˜H‚ðì¬‚·‚éB - addRoute(); + m_observer->onShipRouteListRemoveItem( removeTarget ); } } @@ -63,9 +51,9 @@ void GVOShipRouteList::clearAllItems() void GVOShipRouteList::addRoute() { // ’ljÁ‚Æ’Ê’m - m_shipRouteList.push_back( new GVOShipRoute() ); + m_shipRouteList.push_back( GVOShipRoutePtr( new GVOShipRoute() ) ); if ( m_observer ) { - m_observer->onShipRouteListAddRoute( *m_shipRouteList.back() ); + m_observer->onShipRouteListAddRoute( m_shipRouteList.back() ); } // ˆì‚ꂽ•ª‚ðíœ @@ -81,13 +69,11 @@ void GVOShipRouteList::addRoute() int removeCount = 0; auto it = m_shipRouteList.begin(); while ( it != m_shipRouteList.end() && removeCount < overCount) { - auto route = *it; - if ( route->isFavorite() ) { + if ( (*it)->isFavorite() ) { ++it; continue; } auto itNext = std::next( it, 1 ); - delete route; m_shipRouteList.erase( it ); ++removeCount; it = itNext; @@ -106,18 +92,18 @@ void GVOShipRouteList::joinPreviousRouteAtReverseIndex( int reverseIndex ) std::advance( itBase, indexFromReverseIndex( reverseIndex ) ); RouteList::iterator itPrev = std::prev( itBase ); _ASSERT( itPrev != m_shipRouteList.end() ); - GVOShipRoute *baseRoute = *itBase; - std::unique_ptr prevRoute( std::move( *itPrev ) ); + GVOShipRoutePtr baseRoute = *itBase; + GVOShipRoutePtr prevRoute = *itPrev; m_shipRouteList.erase( itPrev ); if ( m_observer ) { - m_observer->onShipRouteListRemoveItem( *prevRoute ); + m_observer->onShipRouteListRemoveItem( prevRoute ); } baseRoute->jointPreviousLinesWithRoute( *prevRoute ); // ’Ê’m if ( m_observer ) { - m_observer->onShipRouteListUpdateRoute( *baseRoute ); + m_observer->onShipRouteListUpdateRoute( baseRoute ); } } diff --git a/GVONavish/GVONavish/GVOShipRouteList.h b/GVONavish/GVONavish/GVOShipRouteList.h index e075cac..436277d 100644 --- a/GVONavish/GVONavish/GVOShipRouteList.h +++ b/GVONavish/GVONavish/GVOShipRouteList.h @@ -10,14 +10,14 @@ class IGVOShipRouteListObserver; //!@brief q˜HƒŠƒXƒgŠÇ—ƒNƒ‰ƒX class GVOShipRouteList { private: - typedef std::list RouteList; + typedef std::list RouteList; RouteList m_shipRouteList; IGVOShipRouteListObserver * m_observer = nullptr; size_t m_maxRouteCountWithoutFavorits = 30; //!<@brief ‚¨‹C‚É“ü‚è‚ðœŠO‚µ‚½q˜H•Û‘¶” public: GVOShipRouteList() = default; - ~GVOShipRouteList(); + ~GVOShipRouteList() = default; void setObserver( IGVOShipRouteListObserver * observer ) { @@ -33,18 +33,7 @@ public: return m_shipRouteList; } - //GVOShipRoute * getRouteAtIndex( int index ) - //{ - // if ( m_shipRouteList.size() <= (size_t)index ) { - // return NULL; - // } - // RouteList::iterator it; - // it = m_shipRouteList.begin(); - // std::advance( it, index ); - // return *it; - //} - - GVOShipRoute * getRouteAtReverseIndex( int reverseIndex ) + GVOShipRoutePtr getRouteAtReverseIndex( int reverseIndex ) { if ( m_shipRouteList.size() <= (size_t)reverseIndex ) { return nullptr; @@ -56,17 +45,19 @@ public: return *it; } - int indexFromShipRoute( GVOShipRoute & shipRoute ) + int reverseIndexFromShipRoute( GVOShipRoutePtr shipRoute ) const { - RouteList::iterator it; - it = std::find( m_shipRouteList.begin(), m_shipRouteList.end(), &shipRoute ); - if ( it == m_shipRouteList.end() ) { + auto it = std::find( m_shipRouteList.crbegin(), m_shipRouteList.crend(), shipRoute ); + if ( it == m_shipRouteList.crend() ) { return -1; } - return std::distance( m_shipRouteList.begin(), it ); + const int reverseIndex = std::distance( m_shipRouteList.crbegin(), it ); + return reverseIndex; } - void removeShipRouteAtReverseIndex( int reverseIndex ); + //void removeShipRouteAtReverseIndex( int reverseIndex ); + + void removeShipRoute( GVOShipRoutePtr shipRoute ); void clearAllItems(); @@ -86,8 +77,8 @@ public: IGVOShipRouteListObserver() = default; virtual ~IGVOShipRouteListObserver() = default; - virtual void onShipRouteListAddRoute( GVOShipRoute & shipRoute ) = 0; - virtual void onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) = 0; - virtual void onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) = 0; + virtual void onShipRouteListAddRoute( GVOShipRoutePtr shipRoute ) = 0; + virtual void onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute ) = 0; + virtual void onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute ) = 0; virtual void onShipRouteListRemoveAllItems() = 0; }; diff --git a/GVONavish/GVONavish/GVOShipRouteManageView.cpp b/GVONavish/GVONavish/GVOShipRouteManageView.cpp index ab240e3..12228cb 100644 --- a/GVONavish/GVONavish/GVOShipRouteManageView.cpp +++ b/GVONavish/GVONavish/GVOShipRouteManageView.cpp @@ -51,32 +51,31 @@ void GVOShipRouteManageView::teardown() } -void GVOShipRouteManageView::onShipRouteListAddRoute( GVOShipRoute & shipRoute ) +void GVOShipRouteManageView::onShipRouteListAddRoute( GVOShipRoutePtr shipRoute ) { updateVisibleListItemCount(); - if ( m_selectedRoute ) { - const int prevLineIndex = m_selectionIndex; - const int nextLineIndex = m_selectionIndex + 1; - ListView_SetItemState( m_listViewCtrl, prevLineIndex, 0, LVIS_SELECTED ); - ListView_SetItemState( m_listViewCtrl, nextLineIndex, LVIS_SELECTED, LVIS_SELECTED ); + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { + const int reverseIndex = m_routeList->reverseIndexFromShipRoute( selectedRoute ); + selectRow( m_selectionIndex, false ); + selectRow( reverseIndex, true ); } } -void GVOShipRouteManageView::onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) +void GVOShipRouteManageView::onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute ) { - int index = ((int)m_routeList->getList().size() - 1) - m_routeList->indexFromShipRoute( shipRoute ); - ListView_RedrawItems( m_listViewCtrl, index, index ); + int reverseIndex = m_routeList->reverseIndexFromShipRoute( shipRoute ); + if ( 0 <= reverseIndex ) { + ListView_RedrawItems( m_listViewCtrl, reverseIndex, reverseIndex ); + } } -void GVOShipRouteManageView::onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) +void GVOShipRouteManageView::onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute ) { - if ( m_selectedRoute == &shipRoute ) { - const int selectionIndex = m_selectionIndex; - if ( shipRoute.isHilight() ) { - ListView_SetItemState( m_listViewCtrl, selectionIndex, 0, LVIS_SELECTED ); - ListView_RedrawItems( m_listViewCtrl, selectionIndex, selectionIndex ); + if ( m_selectedRoute.lock() == shipRoute ) { + if ( 0 <= m_selectionIndex ) { + selectRow( m_selectionIndex, false ); } } updateVisibleListItemCount(); @@ -149,25 +148,24 @@ void GVOShipRouteManageView::onCommand( WORD eventCode, WORD cmdId, HANDLE ctrl ::ShowWindow( m_hwnd, SW_HIDE ); break; case IDM_DESELECT_ROUTE: - if ( m_selectedRoute ) { - ListView_SetItemState( m_listViewCtrl, m_selectionIndex, 0, LVIS_SELECTED ); + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { + selectRow( m_selectionIndex, false ); } break; case IDM_DELETE_SHIP_ROUTE: - if ( m_selectedRoute ) { - const int index = m_selectionIndex; - ListView_SetItemState( m_listViewCtrl, index, 0, LVIS_SELECTED ); - m_routeList->removeShipRouteAtReverseIndex( index ); + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { + selectRow( m_selectionIndex, false ); + m_routeList->removeShipRoute( selectedRoute ); } break; case IDM_JOINT_SHIP_ROUTE: - if ( m_selectedRoute ) { + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { m_routeList->joinPreviousRouteAtReverseIndex( m_selectionIndex ); } break; case IDM_TOGGLE_FAVORITE: - if ( m_selectedRoute ) { - m_selectedRoute->setFavorite( !m_selectedRoute->isFavorite() ); + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { + selectedRoute->setFavorite( !selectedRoute->isFavorite() ); ListView_RedrawItems( m_listViewCtrl, m_selectionIndex, m_selectionIndex ); } break; @@ -187,7 +185,7 @@ void GVOShipRouteManageView::onNotify( LPNMHDR nmh ) LV_DISPINFO * dispInfo = reinterpret_cast(nmh); LVITEM & item = dispInfo->item; dispInfo->hdr.idFrom; - GVOShipRoute *route = m_routeList->getRouteAtReverseIndex( item.iItem ); + GVOShipRoutePtr route = m_routeList->getRouteAtReverseIndex( item.iItem ); // íœˆ—‚Æ•`‰æˆ—‚̃^ƒCƒ~ƒ“ƒO‚ŊԂɍ‡‚í‚È‚¢‚±‚Æ‚ª‚ ‚éH if ( !route ) { updateVisibleListItemCount(); @@ -234,7 +232,7 @@ void GVOShipRouteManageView::onNotify( LPNMHDR nmh ) } break; case NM_RCLICK: - if ( m_selectedRoute ) { + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { POINT point = { 0 }; ::GetCursorPos( &point ); HMENU menu = ::LoadMenu( g_hinst, MAKEINTRESOURCE( IDR_SHIPROUTEMANAGEPOPUPMENU ) ); @@ -244,7 +242,7 @@ void GVOShipRouteManageView::onNotify( LPNMHDR nmh ) if ( count == (m_selectionIndex + 1) ) { ::EnableMenuItem( menu, IDM_JOINT_SHIP_ROUTE, MF_BYCOMMAND | MF_DISABLED ); } - if ( m_selectedRoute->isFavorite() ) { + if ( selectedRoute->isFavorite() ) { ::CheckMenuItem( menu, IDM_TOGGLE_FAVORITE, MF_BYCOMMAND | MF_CHECKED ); } ::TrackPopupMenu( menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NOANIMATION, @@ -256,13 +254,16 @@ void GVOShipRouteManageView::onNotify( LPNMHDR nmh ) LPNMLISTVIEW nmlv = reinterpret_cast(nmh); if ( ((nmlv->uOldState & LVIS_SELECTED) == 0) && (nmlv->uNewState & LVIS_SELECTED) ) { m_selectionIndex = nmlv->iItem; - m_selectedRoute = m_routeList->getRouteAtReverseIndex( m_selectionIndex ); - m_selectedRoute->setHilight( true ); + GVOShipRoutePtr selectedRoute = m_routeList->getRouteAtReverseIndex( m_selectionIndex ); + selectedRoute->setHilight( true ); + m_selectedRoute = selectedRoute; ::InvalidateRect( g_hwndMain, NULL, FALSE ); } else if ( (nmlv->uOldState & LVIS_SELECTED) && ((nmlv->uNewState & LVIS_SELECTED) == 0) ) { - m_selectedRoute->setHilight( false ); - m_selectedRoute = nullptr; + if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) { + selectedRoute->setHilight( false ); + m_selectedRoute.reset(); + } m_selectionIndex = -1; ::InvalidateRect( g_hwndMain, NULL, FALSE ); } @@ -317,3 +318,9 @@ void GVOShipRouteManageView::updateVisibleListItemCount() { ListView_SetItemCountEx( m_listViewCtrl, m_routeList->getList().size(), LVSICF_NOSCROLL ); } + + +void GVOShipRouteManageView::selectRow( int index, bool isSelection ) +{ + ListView_SetItemState( m_listViewCtrl, index, isSelection ? LVIS_SELECTED : 0, LVIS_SELECTED ); +} diff --git a/GVONavish/GVONavish/GVOShipRouteManageView.h b/GVONavish/GVONavish/GVOShipRouteManageView.h index 41b345a..c6d94bf 100644 --- a/GVONavish/GVONavish/GVOShipRouteManageView.h +++ b/GVONavish/GVONavish/GVOShipRouteManageView.h @@ -19,8 +19,8 @@ private: GVOShipRouteList * m_routeList = nullptr; HWND m_listViewCtrl = nullptr; - int m_selectionIndex = -1; - GVOShipRoute * m_selectedRoute = nullptr; + int m_selectionIndex = -1; //!<@brief ‰¼‘zƒŠƒXƒgƒrƒ…[‚È‚Ì‚Å‘I‘ðs‚ðŽ©‘OŠÇ— + GVOShipRouteWeakPtr m_selectedRoute; size_t m_visibleCount = 50; @@ -37,9 +37,9 @@ public: ::SetForegroundWindow( m_hwnd ); } - virtual void onShipRouteListAddRoute( GVOShipRoute & shipRoute ) override; - virtual void onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) override; - virtual void onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) override; + virtual void onShipRouteListAddRoute( GVOShipRoutePtr shipRoute ) override; + virtual void onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute ) override; + virtual void onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute ) override; virtual void onShipRouteListRemoveAllItems() override; private: static BOOL CALLBACK dlgProcThunk( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp ); @@ -48,5 +48,6 @@ private: void onNotify( LPNMHDR nmh ); void setupRouteList(); void updateVisibleListItemCount(); + void selectRow( int index, bool isSelection ); };