From: <geo...@us...> - 2009-02-21 15:59:52
|
Revision: 2843 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2843&view=rev Author: geoffthemedio Date: 2009-02-21 15:59:39 +0000 (Sat, 21 Feb 2009) Log Message: ----------- -FleetButton stuff: Made them clickable again, added mouseover highlighting with temporary circle behind them, made them adjust in size properly -Adjusted system name position -Enlarged system mouseover indicator default size -Move optimized system rendering toggle to the system icon section of the galaxy map options page -Added a circle around system icons and changed SystemIcon::InWindow to check whether cursor is within that circle, rather than the default square-shaped active area that was previously used Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.cpp trunk/FreeOrion/UI/FleetButton.cpp trunk/FreeOrion/UI/FleetButton.h trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/MapWnd.h trunk/FreeOrion/UI/OptionsWnd.cpp trunk/FreeOrion/UI/SystemIcon.cpp trunk/FreeOrion/UI/SystemIcon.h Modified: trunk/FreeOrion/UI/ClientUI.cpp =================================================================== --- trunk/FreeOrion/UI/ClientUI.cpp 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/ClientUI.cpp 2009-02-21 15:59:39 UTC (rev 2843) @@ -467,7 +467,7 @@ // galaxy map db.Add("UI.system-icon-size", "OPTIONS_DB_UI_SYSTEM_ICON_SIZE", 14, RangedValidator<int>(8, 50)); db.Add("UI.system-name-unowned-color", "OPTIONS_DB_UI_SYSTEM_NAME_UNOWNED_COLOR", StreamableColor(GG::Clr(160, 160, 160, 255)), Validator<StreamableColor>()); - db.Add("UI.system-selection-indicator-size","OPTIONS_DB_UI_SYSTEM_SELECTION_INDICATOR_SIZE",2.0, RangedStepValidator<double>(0.1, 0.5, 5)); + db.Add("UI.system-selection-indicator-size","OPTIONS_DB_UI_SYSTEM_SELECTION_INDICATOR_SIZE",2.5, RangedStepValidator<double>(0.1, 0.5, 5)); db.Add("UI.large-fleet-button-size", "OPTIONS_DB_UI_LARGE_FLEET_BUTTON_SIZE", 24, RangedValidator<int>(8, 48)); db.Add("UI.small-fleet-button-size", "OPTIONS_DB_UI_SMALL_FLEET_BUTTON_SIZE", 16, RangedValidator<int>(8, 32)); db.Add("UI.tiny-fleet-button-size", "OPTIONS_DB_UI_TINY_FLEET_BUTTON_SIZE", 10, RangedValidator<int>(4, 24)); Modified: trunk/FreeOrion/UI/FleetButton.cpp =================================================================== --- trunk/FreeOrion/UI/FleetButton.cpp 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/FleetButton.cpp 2009-02-21 15:59:39 UTC (rev 2843) @@ -10,6 +10,7 @@ #include "../util/OptionsDB.h" #include "../universe/System.h" #include "../Empire/Empire.h" +#include "CUIDrawUtil.h" #include <GG/DrawUtil.h> @@ -25,7 +26,7 @@ // FleetButton /////////////////////////// FleetButton::FleetButton(const std::vector<int>& fleet_IDs, SizeType size) : - GG::Button(), + GG::Button(GG::X0, GG::Y0, GG::X1, GG::Y1, "", boost::shared_ptr<GG::Font>(), GG::CLR_ZERO), m_fleets(), m_head_icon(), m_size_icon() @@ -34,14 +35,14 @@ } FleetButton::FleetButton(int fleet_id, SizeType size) : - GG::Button(), + GG::Button(GG::X0, GG::Y0, GG::X1, GG::Y1, "", boost::shared_ptr<GG::Font>(), GG::CLR_ZERO), m_fleets(), m_head_icon(), m_size_icon() { - std::vector<int> fleet_ids; - fleet_ids.push_back(fleet_id); - Init(fleet_ids, size); + std::vector<int> fleet_IDs; + fleet_IDs.push_back(fleet_id); + Init(fleet_IDs, size); } void FleetButton::Init(const std::vector<int>& fleet_IDs, SizeType size) { @@ -95,11 +96,7 @@ // set button size - int button_size = ClientUI::TinyFleetButtonSize(); - if (size == FLEET_BUTTON_SMALL) - button_size = ClientUI::SmallFleetButtonSize(); - else if (size == FLEET_BUTTON_LARGE) - button_size = ClientUI::LargeFleetButtonSize(); + int button_size = SizeForSizeType(size); Resize(GG::Pt(GG::X(button_size), GG::Y(button_size))); @@ -137,6 +134,24 @@ } } +void FleetButton::LClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys) +{ + MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); + if (!Disabled() && (!map_wnd || !map_wnd->InProductionViewMode())) + PlayFleetButtonOpenSound(); + GG::Button::LClick(pt, mod_keys); +} + +int FleetButton::SizeForSizeType(SizeType size_type) { + if (size_type == FLEET_BUTTON_TINY) + return ClientUI::TinyFleetButtonSize(); + if (size_type == FLEET_BUTTON_SMALL) + return ClientUI::SmallFleetButtonSize(); + if (size_type == FLEET_BUTTON_LARGE) + return ClientUI::LargeFleetButtonSize(); + return 0; +} + void FleetButton::RenderUnpressed() { glColor(Color()); GG::Pt ul = UpperLeft(), lr = LowerRight(); @@ -147,9 +162,21 @@ } void FleetButton::RenderPressed() { + const double TWO_PI = 2.0*3.14159; + glDisable(GL_TEXTURE_2D); + glColor(Color()); + CircleArc(UpperLeft(), LowerRight(), 0.0, TWO_PI, true); + glEnable(GL_TEXTURE_2D); + RenderUnpressed(); // TODO: do something else } void FleetButton::RenderRollover() { + const double TWO_PI = 2.0*3.14159; + glDisable(GL_TEXTURE_2D); + glColor(GG::CLR_WHITE); + CircleArc(UpperLeft(), LowerRight(), 0.0, TWO_PI, true); + glEnable(GL_TEXTURE_2D); + RenderUnpressed(); // TODO: do something else } Modified: trunk/FreeOrion/UI/FleetButton.h =================================================================== --- trunk/FreeOrion/UI/FleetButton.h 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/FleetButton.h 2009-02-21 15:59:39 UTC (rev 2843) @@ -32,8 +32,11 @@ /** \name Mutators */ //@{ virtual void MouseHere(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); + virtual void FleetButton::LClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); //@} + static int SizeForSizeType(SizeType size_type); + protected: /** \name Mutators */ //@{ virtual void RenderUnpressed(); Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/MapWnd.cpp 2009-02-21 15:59:39 UTC (rev 2843) @@ -233,7 +233,7 @@ // MapWnd // static(s) double MapWnd::s_max_scale_factor = 8.0; -double MapWnd::s_min_scale_factor = MapWnd::s_max_scale_factor / pow(ZOOM_STEP_SIZE, 14.0); +double MapWnd::s_min_scale_factor = MapWnd::s_max_scale_factor / std::pow(ZOOM_STEP_SIZE, 14.0); MapWnd::MapWnd() : GG::Wnd(-GG::GUI::GetGUI()->AppWidth(), -GG::GUI::GetGUI()->AppHeight(), @@ -1415,7 +1415,8 @@ void MapWnd::DoFleetButtonsLayout() { - const int FLEET_BUTTON_SIZE = FleetButtonSizeType(); + FleetButton::SizeType FLEET_BUTTON_SIZE_TYPE = FleetButtonSizeType(); + const int FLEET_BUTTON_SIZE = FleetButton::SizeForSizeType(FLEET_BUTTON_SIZE_TYPE); // position and resize unattached (to system icons) fleet icons for (unsigned int i = 0; i < m_moving_fleet_buttons.size(); ++i) { Fleet* fleet = *m_moving_fleet_buttons[i]->Fleets().begin(); @@ -1431,6 +1432,11 @@ return static_cast<int>(ClientUI::SystemIconSize() * m_zoom_factor); } +double MapWnd::SystemHaloScaleFactor() const +{ + return 1.0 + log10(m_zoom_factor); +} + FleetButton::SizeType MapWnd::FleetButtonSizeType() const { if (m_zoom_factor > ClientUI::LargeFleetButtonZoomThreshold()) @@ -1582,7 +1588,7 @@ void MapWnd::RenderSystems() { - const double HALO_SCALE_FACTOR = 1.0 + log10(m_zoom_factor); + const double HALO_SCALE_FACTOR = SystemHaloScaleFactor(); if (GetOptionsDB().Get<bool>("UI.optimized-system-rendering")) { glColor4f(1.0, 1.0, 1.0, 1.0); Modified: trunk/FreeOrion/UI/MapWnd.h =================================================================== --- trunk/FreeOrion/UI/MapWnd.h 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/MapWnd.h 2009-02-21 15:59:39 UTC (rev 2843) @@ -61,6 +61,7 @@ double ZoomFactor() const; int SystemIconSize() const; + double SystemHaloScaleFactor() const; FleetButton::SizeType FleetButtonSizeType() const; //!< returns what size type (tiny, small, large) fleet buttons on this map are shown at SidePanel* GetSidePanel() const; Modified: trunk/FreeOrion/UI/OptionsWnd.cpp =================================================================== --- trunk/FreeOrion/UI/OptionsWnd.cpp 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/OptionsWnd.cpp 2009-02-21 15:59:39 UTC (rev 2843) @@ -722,6 +722,7 @@ BeginSection(UserString("OPTIONS_SYSTEM_ICONS")); IntOption("UI.system-icon-size", UserString("OPTIONS_UI_SYSTEM_ICON_SIZE")); DoubleOption("UI.system-selection-indicator-size", UserString("OPTIONS_UI_SYSTEM_SELECTION_INDICATOR_SIZE")); + BoolOption("UI.optimized-system-rendering", UserString("OPTIONS_OPTIMIZED_SYSTEM_RENDERING")); ColorOption("UI.system-name-unowned-color", UserString("OPTIONS_UI_SYSTEM_NAME_UNOWNED_COLOR")); EndSection(); BeginSection(UserString("OPTIONS_FLEET_ICONS")); @@ -735,7 +736,6 @@ BeginSection(UserString("OPTIONS_GALAXY_MAP_GENERAL")); BoolOption("UI.galaxy-gas-background", UserString("OPTIONS_GALAXY_MAP_GAS")); BoolOption("UI.galaxy-starfields", UserString("OPTIONS_GALAXY_MAP_STARFIELDS")); - BoolOption("UI.optimized-system-rendering", UserString("OPTIONS_OPTIMIZED_SYSTEM_RENDERING")); DoubleOption("UI.starlane-thickness", UserString("OPTIONS_STARLANE_THICKNESS")); BoolOption("UI.resource-starlane-colouring", UserString("OPTIONS_RESOURCE_STARLANE_COLOURING")); BoolOption("UI.fleet-supply-lines", UserString("OPTIONS_FLEET_SUPPLY_LINES")); Modified: trunk/FreeOrion/UI/SystemIcon.cpp =================================================================== --- trunk/FreeOrion/UI/SystemIcon.cpp 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/SystemIcon.cpp 2009-02-21 15:59:39 UTC (rev 2843) @@ -192,7 +192,8 @@ GG::Pt retval = GG::Pt(); const MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); - const int FLEETBUTTON_SIZE = map_wnd->FleetButtonSizeType(); + FleetButton::SizeType FLEETBUTTON_SIZE_TYPE = map_wnd->FleetButtonSizeType(); + const int FLEETBUTTON_SIZE = FleetButton::SizeForSizeType(FLEETBUTTON_SIZE_TYPE); /* Positions of buttons relative to star. Moving fleet * buttons at top left, stationary buttons at top right. @@ -214,6 +215,11 @@ } } +int SystemIcon::EnclosingCircleDiameter() const +{ + return static_cast<const int>(Value(Width())*1.5) + 1; +} + void SystemIcon::SizeMove(const GG::Pt& ul, const GG::Pt& lr) { Wnd::SizeMove(ul, lr); @@ -221,8 +227,8 @@ if (m_tiny_graphic && lr.x - ul.x < TINY_SIZE) { GG::Pt tiny_size = m_tiny_graphic->Size(); GG::Pt middle = GG::Pt(Width() / 2, Height() / 2); - GG::Pt tiny_ul(static_cast<GG::X>(middle.x - tiny_size.x / 2.0 + 0.5), - static_cast<GG::Y>(middle.y - tiny_size.y / 2.0 + 0.5)); + GG::Pt tiny_ul(static_cast<GG::X>(middle.x - tiny_size.x / 2.0), + static_cast<GG::Y>(middle.y - tiny_size.y / 2.0)); m_tiny_graphic->SizeMove(tiny_ul, tiny_ul + tiny_size); m_tiny_graphic->Show(); } else { @@ -241,9 +247,34 @@ PositionSystemName(); - DoFleetButtonLayout(); + RefreshFleetButtons(); } +void SystemIcon::Render() +{ + const int ARC_SIZE = EnclosingCircleDiameter(); + const double TWO_PI = 2.0*3.14159; + + GG::Pt ul = UpperLeft(), lr = LowerRight(); + GG::Pt size = lr - ul; + GG::Pt half_size = GG::Pt(size.x / 2, size.y / 2); + GG::Pt middle = ul + half_size; + + GG::Pt circle_size = GG::Pt(static_cast<GG::X>(ARC_SIZE), + static_cast<GG::Y>(ARC_SIZE)); + GG::Pt circle_half_size = GG::Pt(circle_size.x / 2, circle_size.y / 2); + GG::Pt circle_ul = middle - circle_half_size; + GG::Pt circle_lr = circle_ul + circle_size; + + glDisable(GL_TEXTURE_2D); + glLineWidth(1.0); + glColor(ClientUI::SystemNameTextColor()); + glBegin(GL_LINE_STRIP); + CircleArc(circle_ul, circle_lr, 0.0, TWO_PI, false); + glEnd(); + glEnable(GL_TEXTURE_2D); +} + void SystemIcon::ManualRender(double halo_scale_factor) { if (!Visible()) @@ -354,6 +385,7 @@ MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); FleetButton* fb = 0; + FleetButton::SizeType FLEETBUTTON_SIZE = map_wnd->FleetButtonSizeType(); // create new fleet buttons for (EmpireManager::const_iterator it = Empires().begin(); it != Empires().end(); ++it) { @@ -371,7 +403,7 @@ // Logger().debugStream() << "... " << *it1; if (!fleet_IDs.empty()) { - fb = new FleetButton(fleet_IDs); + fb = new FleetButton(fleet_IDs, FLEETBUTTON_SIZE); m_stationary_fleet_markers[empire_id] = fb; AttachChild(m_stationary_fleet_markers[empire_id]); GG::Connect(fb->ClickedSignal, FleetButtonClickedFunctor(*fb, *this, false)); @@ -379,7 +411,7 @@ fleet_IDs = m_system.FindObjectIDs(OrderedMovingFleetVisitor(it->first)); if (!fleet_IDs.empty()) { - fb = new FleetButton(fleet_IDs); + fb = new FleetButton(fleet_IDs, FLEETBUTTON_SIZE); m_moving_fleet_markers[empire_id] = fb; AttachChild(m_moving_fleet_markers[empire_id]); GG::Connect(fb->ClickedSignal, FleetButtonClickedFunctor(*fb, *this, true)); @@ -435,15 +467,12 @@ void SystemIcon::DoFleetButtonLayout() { - const int FLEETBUTTON_SIZE = ClientUI::SmallFleetButtonSize(); - const GG::Pt SIZE = GG::Pt(GG::X(FLEETBUTTON_SIZE), GG::Y(FLEETBUTTON_SIZE)); - // stationary fleet buttons int empire_num = 1; for (std::map<int, FleetButton*>::iterator it = m_stationary_fleet_markers.begin(); it != m_stationary_fleet_markers.end(); ++it) { GG::Pt ul = NthFleetButtonUpperLeft(empire_num, false); ++empire_num; - it->second->SizeMove(ul, ul + SIZE); + it->second->MoveTo(ul); } // departing fleet buttons @@ -451,14 +480,14 @@ for (std::map<int, FleetButton*>::iterator it = m_moving_fleet_markers.begin(); it != m_moving_fleet_markers.end(); ++it) { GG::Pt ul = NthFleetButtonUpperLeft(empire_num, true); ++empire_num; - it->second->SizeMove(ul, ul + SIZE); + it->second->MoveTo(ul); } } void SystemIcon::PositionSystemName() { if (m_colored_name) - m_colored_name->MoveTo(GG::Pt((Width() - m_colored_name->Width()) / 2, Height())); + m_colored_name->MoveTo(GG::Pt((Width() - m_colored_name->Width()) / 2, (Height() + GG::Y(EnclosingCircleDiameter() / 2) / 2))); } bool SystemIcon::InWindow(const GG::Pt& pt) const @@ -473,7 +502,21 @@ return true; } - return Wnd::InWindow(pt); + // find if cursor is within require distance of centre of icon + const int RADIUS = EnclosingCircleDiameter() / 2; + const int RADIUS2 = RADIUS*RADIUS; + + GG::Pt ul = UpperLeft(), lr = LowerRight(); + GG::Pt size = lr - ul; + GG::Pt half_size = GG::Pt(size.x / 2, size.y / 2); + GG::Pt middle = ul + half_size; + + GG::Pt delta = pt - middle; + + const int distx = Value(delta.x); + const int disty = Value(delta.y); + + return distx*distx + disty*disty <= RADIUS2; } void SystemIcon::FleetInserted(Fleet& fleet) Modified: trunk/FreeOrion/UI/SystemIcon.h =================================================================== --- trunk/FreeOrion/UI/SystemIcon.h 2009-02-21 14:27:56 UTC (rev 2842) +++ trunk/FreeOrion/UI/SystemIcon.h 2009-02-21 15:59:39 UTC (rev 2843) @@ -61,7 +61,7 @@ //! \name Mutators //!@{ virtual void SizeMove(const GG::Pt& ul, const GG::Pt& lr); - virtual void Render() {} + virtual void Render(); void ManualRender(double halo_scale_factor); //!< Draw disc and halo textures virtual void LClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); virtual void RClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); @@ -93,12 +93,14 @@ void Init(); //!< common constructor tasks GG::Pt NthFleetButtonUpperLeft(int button_number, bool moving) const; //!< returns upper left point of moving or stationary fleetbutton owned by empire \a n, where n is the position in order of fleetbuttons shown starting from 1(not empire id) + int EnclosingCircleDiameter() const; //!< returns diameter of circle enclosing icon around which other icons can be placed and within which the mouse is over the icon + void FleetInserted(Fleet& fleet); void FleetRemoved(Fleet& fleet); void FleetStateChanged(); - void PositionSystemName(); + void PositionSystemName(); const System& m_system; //!< the System object associated with this SystemIcon boost::shared_ptr<GG::Texture> m_disc_texture; //!< solid star disc texture |