From: <tz...@us...> - 2008-06-28 01:48:11
|
Revision: 2611 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2611&view=rev Author: tzlaine Date: 2008-06-27 18:48:16 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Added two new files accidentally omitted from previous commit. Added Paths: ----------- trunk/FreeOrion/UI/QueueListBox.cpp trunk/FreeOrion/UI/QueueListBox.h Added: trunk/FreeOrion/UI/QueueListBox.cpp =================================================================== --- trunk/FreeOrion/UI/QueueListBox.cpp (rev 0) +++ trunk/FreeOrion/UI/QueueListBox.cpp 2008-06-28 01:48:16 UTC (rev 2611) @@ -0,0 +1,76 @@ +#include "QueueListBox.h" + +#include <GG/DrawUtil.h> +#include <GG/WndEvent.h> + +#include <boost/cast.hpp> + + +//////////////////////////////////////////////////////////// +// QueueListBox +//////////////////////////////////////////////////////////// +QueueListBox::QueueListBox(int x, int y, int w, int h, const std::string& drop_type_str) : + CUIListBox(x, y, w, h), + m_drop_point(end()), + m_show_drop_point(false) +{ AllowDropType(drop_type_str); } + +void QueueListBox::DropsAcceptable(DropsAcceptableIter first, + DropsAcceptableIter last, + const GG::Pt& pt) const +{ + assert(std::distance(first, last) == 1); + for (DropsAcceptableIter it = first; it != last; ++it) { + it->second = + AllowedDropTypes().find(it->first->DragDropDataType()) != AllowedDropTypes().end(); + } +} + +void QueueListBox::AcceptDrops(const std::vector<GG::Wnd*>& wnds, const GG::Pt& pt) +{ + assert(wnds.size() == 1); + assert(AllowedDropTypes().find((*wnds.begin())->DragDropDataType()) != AllowedDropTypes().end()); + GG::ListBox::Row* row = boost::polymorphic_downcast<GG::ListBox::Row*>(*wnds.begin()); + assert(std::find(begin(), end(), row) != end()); + iterator it = RowUnderPt(pt); + QueueItemMoved(row, std::distance(begin(), it)); +} + +void QueueListBox::Render() +{ + ListBox::Render(); + if (m_show_drop_point) { + GG::ListBox::Row& row = **(m_drop_point == end() ? --end() : m_drop_point); + GG::Control* panel = row[0]; + GG::Pt ul = row.UpperLeft(), lr = row.LowerRight(); + if (m_drop_point == end()) + ul.y = lr.y; + ul.x = panel->UpperLeft().x; + lr.x = panel->LowerRight().x; + GG::FlatRectangle(ul.x, ul.y - 1, lr.x, ul.y, GG::CLR_ZERO, GG::CLR_WHITE, 1); + } +} + +void QueueListBox::DragDropEnter(const GG::Pt& pt, const std::map<GG::Wnd*, GG::Pt>& drag_drop_wnds, + GG::Flags<GG::ModKey> mod_keys) +{ DragDropHere(pt, drag_drop_wnds, mod_keys); } + +void QueueListBox::DragDropHere(const GG::Pt& pt, const std::map<GG::Wnd*, GG::Pt>& drag_drop_wnds, + GG::Flags<GG::ModKey> mod_keys) +{ + if (drag_drop_wnds.size() == 1 && + AllowedDropTypes().find(drag_drop_wnds.begin()->first->DragDropDataType()) != + AllowedDropTypes().end()) { + m_drop_point = RowUnderPt(pt); + m_show_drop_point = true; + } else { + m_drop_point = end(); + m_show_drop_point = false; + } +} + +void QueueListBox::DragDropLeave() +{ + m_drop_point = end(); + m_show_drop_point = false; +} Added: trunk/FreeOrion/UI/QueueListBox.h =================================================================== --- trunk/FreeOrion/UI/QueueListBox.h (rev 0) +++ trunk/FreeOrion/UI/QueueListBox.h 2008-06-28 01:48:16 UTC (rev 2611) @@ -0,0 +1,33 @@ +// -*- C++ -*- +#ifndef _QueueListBox_h_ +#define _QueueListBox_h_ + +#include "CUIControls.h" + + +/** A list box type for representing queues (eg the research and production queues). */ +class QueueListBox : + public CUIListBox +{ +public: + QueueListBox(int x, int y, int w, int h, const std::string& drop_type_str); + + virtual void DropsAcceptable(DropsAcceptableIter first, + DropsAcceptableIter last, + const GG::Pt& pt) const; + virtual void AcceptDrops(const std::vector<GG::Wnd*>& wnds, const GG::Pt& pt); + virtual void Render(); + virtual void DragDropEnter(const GG::Pt& pt, const std::map<GG::Wnd*, GG::Pt>& drag_drop_wnds, + GG::Flags<GG::ModKey> mod_keys); + virtual void DragDropHere(const GG::Pt& pt, const std::map<GG::Wnd*, GG::Pt>& drag_drop_wnds, + GG::Flags<GG::ModKey> mod_keys); + virtual void DragDropLeave(); + + boost::signal<void (GG::ListBox::Row*, std::size_t)> QueueItemMoved; + +private: + iterator m_drop_point; + bool m_show_drop_point; +}; + +#endif |
From: <tz...@us...> - 2008-06-28 19:22:09
|
Revision: 2613 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2613&view=rev Author: tzlaine Date: 2008-06-28 12:22:18 -0700 (Sat, 28 Jun 2008) Log Message: ----------- Fixed a crash bug due to an invalid decrement of and end() iterator to an empty container in ProductionWnd and ResearchWnd. Modified Paths: -------------- trunk/FreeOrion/UI/ProductionWnd.cpp trunk/FreeOrion/UI/ResearchWnd.cpp Modified: trunk/FreeOrion/UI/ProductionWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ProductionWnd.cpp 2008-06-28 18:06:25 UTC (rev 2612) +++ trunk/FreeOrion/UI/ProductionWnd.cpp 2008-06-28 19:22:18 UTC (rev 2613) @@ -358,7 +358,8 @@ m_queue_lb->Insert(new QueueRow(QUEUE_WIDTH, *it, i)); } - m_queue_lb->BringRowIntoView(--m_queue_lb->end()); + if (!m_queue_lb->Empty()) + m_queue_lb->BringRowIntoView(--m_queue_lb->end()); if (m_queue_lb->NumRows() <= original_queue_length) m_queue_lb->BringRowIntoView(boost::next(m_queue_lb->begin(), first_visible_queue_row)); } Modified: trunk/FreeOrion/UI/ResearchWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.cpp 2008-06-28 18:06:25 UTC (rev 2612) +++ trunk/FreeOrion/UI/ResearchWnd.cpp 2008-06-28 19:22:18 UTC (rev 2613) @@ -281,7 +281,8 @@ m_queue_lb->Insert(new QueueRow(QUEUE_WIDTH, it->tech, it->spending, it->turns_left)); } - m_queue_lb->BringRowIntoView(--m_queue_lb->end()); + if (!m_queue_lb->Empty()) + m_queue_lb->BringRowIntoView(--m_queue_lb->end()); if (m_queue_lb->NumRows() <= original_queue_length) m_queue_lb->BringRowIntoView(boost::next(m_queue_lb->begin(), first_visible_queue_row)); } |
From: <geo...@us...> - 2008-07-12 05:23:10
|
Revision: 2640 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2640&view=rev Author: geoffthemedio Date: 2008-07-11 22:23:19 -0700 (Fri, 11 Jul 2008) Log Message: ----------- -Added tooltips to PartControls. Not sure how useful they are, but the lack of mouseover feedback seemed bad. -Tweaked IconTextBrowseWnd to accept user-readable strings, rather than string names to look up in the stringtable, which makes them more flexible -Moved IconTextBrowseWnd definition into InfoPanels.h so it can be used outside InfoPanels.cpp Modified Paths: -------------- trunk/FreeOrion/UI/DesignWnd.cpp trunk/FreeOrion/UI/InfoPanels.cpp trunk/FreeOrion/UI/InfoPanels.h Modified: trunk/FreeOrion/UI/DesignWnd.cpp =================================================================== --- trunk/FreeOrion/UI/DesignWnd.cpp 2008-07-11 03:58:51 UTC (rev 2639) +++ trunk/FreeOrion/UI/DesignWnd.cpp 2008-07-12 05:23:19 UTC (rev 2640) @@ -1,6 +1,8 @@ #include "DesignWnd.h" #include "../util/AppInterface.h" +#include "../util/OptionsDB.h" +#include "../util/MultiplayerCommon.h" #include "ClientUI.h" #include "CUIWnd.h" #include "CUIControls.h" @@ -8,7 +10,6 @@ #include "EncyclopediaDetailPanel.h" #include "../Empire/Empire.h" #include "../client/human/HumanClientApp.h" -#include "../util/MultiplayerCommon.h" #include "../universe/ShipDesign.h" #include <GG/DrawUtil.h> @@ -69,7 +70,16 @@ m_icon = new GG::StaticGraphic(0, 0, SIZE, SIZE, ClientUI::PartTexture(m_part->Name()), GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); m_icon->Show(); AttachChild(m_icon); + SetDragDropDataType(PART_CONTROL_DROP_TYPE_STRING); + + if (m_part) { + Logger().debugStream() << "PartControl::PartControl part name: " << m_part->Name(); + SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); + SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(ClientUI::PartTexture(m_part->Name()), + UserString(m_part->Name()), + UserString(m_part->Description())))); + } } void PartControl::Render() {} Modified: trunk/FreeOrion/UI/InfoPanels.cpp =================================================================== --- trunk/FreeOrion/UI/InfoPanels.cpp 2008-07-11 03:58:51 UTC (rev 2639) +++ trunk/FreeOrion/UI/InfoPanels.cpp 2008-07-12 05:23:19 UTC (rev 2640) @@ -19,7 +19,6 @@ #include <GG/DrawUtil.h> #include <GG/GUI.h> #include <GG/StaticGraphic.h> -#include <GG/BrowseInfoWnd.h> #include <GG/StyleFactory.h> #include <GG/WndEvent.h> @@ -276,54 +275,7 @@ bool initialized; }; - class IconTextBrowseWnd : public GG::BrowseInfoWnd { - public: - IconTextBrowseWnd(const boost::shared_ptr<GG::Texture> texture, const std::string& title_text, const std::string& main_text) : - GG::BrowseInfoWnd(0, 0, TEXT_WIDTH + ICON_WIDTH, 1), - ROW_HEIGHT(ClientUI::Pts()*3/2) - { - m_icon = new GG::StaticGraphic(0, 0, ICON_WIDTH, ICON_WIDTH, texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE, GG::CLICKABLE); - AttachChild(m_icon); - const boost::shared_ptr<GG::Font>& font = GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()); - const boost::shared_ptr<GG::Font>& font_bold = GG::GUI::GetGUI()->GetFont(ClientUI::FontBold(), ClientUI::Pts()); - - m_title_text = new GG::TextControl(m_icon->Width() + TEXT_PAD, 0, TEXT_WIDTH, ROW_HEIGHT, UserString(title_text), - font_bold, ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); - AttachChild(m_title_text); - - m_main_text = new GG::TextControl(m_icon->Width() + TEXT_PAD, ROW_HEIGHT, TEXT_WIDTH, ICON_WIDTH, UserString(main_text), - font, ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_TOP | GG::FORMAT_WORDBREAK); - AttachChild(m_main_text); - - m_main_text->SetMinSize(true); - m_main_text->Resize(m_main_text->MinSize()); - Resize(GG::Pt(TEXT_WIDTH + ICON_WIDTH, std::max(m_icon->Height(), ROW_HEIGHT + m_main_text->Height()))); - } - virtual bool WndHasBrowseInfo(const Wnd* wnd, int mode) const { - const std::vector<Wnd::BrowseInfoMode>& browse_modes = wnd->BrowseModes(); - assert(0 <= mode && mode <= static_cast<int>(browse_modes.size())); - return true; - } - - virtual void Render() { - GG::Pt ul = UpperLeft(); - GG::Pt lr = LowerRight(); - GG::FlatRectangle(ul.x, ul.y, lr.x, lr.y, ClientUI::WndColor(), ClientUI::WndOuterBorderColor(), 1); // main background - GG::FlatRectangle(ul.x + ICON_WIDTH, ul.y, lr.x, ul.y + ROW_HEIGHT, ClientUI::WndOuterBorderColor(), ClientUI::WndOuterBorderColor(), 0); // top title filled background - } - - private: - GG::StaticGraphic* m_icon; - GG::TextControl* m_title_text; - GG::TextControl* m_main_text; - - static const int TEXT_WIDTH = 400; - static const int TEXT_PAD = 3; - static const int ICON_WIDTH = 64; - const int ROW_HEIGHT; - }; - GG::Clr MeterColor(MeterType meter_type) { switch (meter_type) { @@ -1978,8 +1930,8 @@ boost::shared_ptr<GG::Texture> texture = ClientUI::BuildingTexture(type.Name()); SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); - SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(texture, type.Name(), type.Description()))); - + SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(texture, UserString(type.Name()), UserString(type.Description())))); + m_graphic = new GG::StaticGraphic(0, 0, w, w, texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_graphic); } @@ -1994,7 +1946,7 @@ boost::shared_ptr<GG::Texture> texture = ClientUI::BuildingTexture(type.Name()); SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); - SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(texture, type.Name(), type.Description()))); + SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(texture, UserString(type.Name()), UserString(type.Description())))); m_graphic = new GG::StaticGraphic(0, 0, w, w, texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_graphic); @@ -2116,9 +2068,12 @@ // get specials and use them to create specials icons for (std::set<std::string>::const_iterator it = specials.begin(); it != specials.end(); ++it) { const Special* special = GetSpecial(*it); - GG::StaticGraphic* graphic = new GG::StaticGraphic(0, 0, icon_size, icon_size, ClientUI::SpecialTexture(special->Name()), GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE, GG::CLICKABLE); + GG::StaticGraphic* graphic = new GG::StaticGraphic(0, 0, icon_size, icon_size, ClientUI::SpecialTexture(special->Name()), + GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE, GG::CLICKABLE); graphic->SetBrowseModeTime(tooltip_time); - graphic->SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(ClientUI::SpecialTexture(special->Name()), special->Name(), special->Description()))); + graphic->SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(new IconTextBrowseWnd(ClientUI::SpecialTexture(special->Name()), + UserString(special->Name()), + UserString(special->Description())))); m_icons.push_back(graphic); } @@ -2200,3 +2155,42 @@ const ShipDesign* ShipDesignPanel::GetDesign() { return GetShipDesign(m_design_id); } + +///////////////////////////////////// +// IconTextBrowseWnd // +///////////////////////////////////// +IconTextBrowseWnd::IconTextBrowseWnd(const boost::shared_ptr<GG::Texture> texture, const std::string& title_text, const std::string& main_text) : + GG::BrowseInfoWnd(0, 0, TEXT_WIDTH + ICON_WIDTH, 1), + ROW_HEIGHT(ClientUI::Pts()*3/2) +{ + m_icon = new GG::StaticGraphic(0, 0, ICON_WIDTH, ICON_WIDTH, texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE, GG::CLICKABLE); + AttachChild(m_icon); + + const boost::shared_ptr<GG::Font>& font = GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()); + const boost::shared_ptr<GG::Font>& font_bold = GG::GUI::GetGUI()->GetFont(ClientUI::FontBold(), ClientUI::Pts()); + + m_title_text = new GG::TextControl(m_icon->Width() + TEXT_PAD, 0, TEXT_WIDTH, ROW_HEIGHT, title_text, + font_bold, ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); + AttachChild(m_title_text); + + m_main_text = new GG::TextControl(m_icon->Width() + TEXT_PAD, ROW_HEIGHT, TEXT_WIDTH, ICON_WIDTH, main_text, + font, ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_TOP | GG::FORMAT_WORDBREAK); + AttachChild(m_main_text); + + m_main_text->SetMinSize(true); + m_main_text->Resize(m_main_text->MinSize()); + Resize(GG::Pt(TEXT_WIDTH + ICON_WIDTH, std::max(m_icon->Height(), ROW_HEIGHT + m_main_text->Height()))); +} + +bool IconTextBrowseWnd::WndHasBrowseInfo(const Wnd* wnd, int mode) const { + const std::vector<Wnd::BrowseInfoMode>& browse_modes = wnd->BrowseModes(); + assert(0 <= mode && mode <= static_cast<int>(browse_modes.size())); + return true; +} + +void IconTextBrowseWnd::Render() { + GG::Pt ul = UpperLeft(); + GG::Pt lr = LowerRight(); + GG::FlatRectangle(ul.x, ul.y, lr.x, lr.y, ClientUI::WndColor(), ClientUI::WndOuterBorderColor(), 1); // main background + GG::FlatRectangle(ul.x + ICON_WIDTH, ul.y, lr.x, ul.y + ROW_HEIGHT, ClientUI::WndOuterBorderColor(), ClientUI::WndOuterBorderColor(), 0); // top title filled background +} Modified: trunk/FreeOrion/UI/InfoPanels.h =================================================================== --- trunk/FreeOrion/UI/InfoPanels.h 2008-07-11 03:58:51 UTC (rev 2639) +++ trunk/FreeOrion/UI/InfoPanels.h 2008-07-12 05:23:19 UTC (rev 2640) @@ -6,6 +6,7 @@ #include <GG/Button.h> #include <GG/DropDownList.h> +#include <GG/BrowseInfoWnd.h> class PopulationPanel; class ResourcePanel; @@ -362,4 +363,23 @@ std::vector<GG::Clr> m_bar_colours; }; +/** A popup tooltop for display when mousing over in-game icons. Has an icon and title and some detail text.*/ +class IconTextBrowseWnd : public GG::BrowseInfoWnd { +public: + IconTextBrowseWnd(const boost::shared_ptr<GG::Texture> texture, const std::string& title_text, + const std::string& main_text); + virtual bool WndHasBrowseInfo(const Wnd* wnd, int mode) const; + virtual void Render(); + +private: + GG::StaticGraphic* m_icon; + GG::TextControl* m_title_text; + GG::TextControl* m_main_text; + + static const int TEXT_WIDTH = 400; + static const int TEXT_PAD = 3; + static const int ICON_WIDTH = 64; + const int ROW_HEIGHT; +}; + #endif |