Sitrep panel icon / text size adjustment

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Sitrep panel icon / text size adjustment

#1 Post by The Silent One »

As mentioned in this thread viewtopic.php?f=10&p=78809#p78809, I am trying to make both the icon and the text size of the sitrep items editable; and kinda succeded ;). But with this, another problem came up: if the icon is larger than the text, it will get cut off by the panel border (see below). I would fix this by checking if the text or the icon is larger, and using the larger figure to render the panel border.
However, I have several problems:

- not sure where exactly in the code the panel border is rendered. is it here?
class SitrepDataPanel: [...]

Code: Select all

virtual void        SizeMove(const GG::Pt& ul, const GG::Pt& lr) {
            Init();
            const GG::Pt old_size = Size();
            GG::Control::SizeMove(ul, lr);
            if (old_size != Size()) {
                DoLayout();
            }
            if (m_link_text) {
                // Use the height of the text as our height.
                // DoLayout reflowed the text.
                GG::Pt text_size = m_link_text->TextLowerRight() - m_link_text->TextUpperLeft();
                text_size.y += ITEM_VERTICAL_PADDING*2; // Text centers, so this puts padding on both above and below
                text_size.x = lr.x - ul.x; // Ignore the width of the text, use whatever was requested.
                GG::Control::SizeMove(ul, ul + text_size );
                DoLayout();
            }
        }
- I intend to do something like

Code: Select all

if (GetIconSize() > text_size.y) {
    text_size.y = GetIconSize() }
... which isn't working because GetIconSize() returns the type GG:X while GetIconSize returns a GG:Y... while both are essentially integers. (How) is it possible to do a typecast?
Attachments
sitrep.jpg
sitrep.jpg (134.89 KiB) Viewed 2582 times
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Sitrep panel icon / text size adjustment

#2 Post by Dilvish »

I'm not understanding what problem you are trying to solve here (overall, not about the situation with the icon being too much larger than the text)-- I don't get what you mean by "At large icon sizes, the text will get too large in relation to the icon."

As for the comparison, I kind of had it in my head that GG had some more direct way to manage something like this, but I'm not finding it now (maybe I'm just thinking of something from Font). X and Y are essentially just renamed ints-- if it won't let you directly cast from Y to X, then perhaps you can try

Code: Select all

GG::X(int(some_ggY_value))
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Sitrep panel icon / text size adjustment

#3 Post by MatGB »

Dilvish wrote:I'm not understanding what problem you are trying to solve here (overall, not about the situation with the icon being too much larger than the text)-- I don't get what you mean by "At large icon sizes, the text will get too large in relation to the icon."
Go into config.xml and change the icon size to 32 (ie twice the current size). Do nothing else.

Boot the game up and look at the sitrep panel

Say hello to my little friends
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#4 Post by The Silent One »

MatGB wrote:Go into config.xml and change the icon size to 32 (ie twice the current size). Do nothing else.

Boot the game up and look at the sitrep panel
... see here:
Attachments
sitrep2.jpg
sitrep2.jpg (137.74 KiB) Viewed 2576 times
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Sitrep panel icon / text size adjustment

#5 Post by MatGB »

Exactly, I'd love to have the icons that size, but I can't stand havign the text that size.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#6 Post by The Silent One »

Dilvish wrote:As for the comparison, I kind of had it in my head that GG had some more direct way to manage something like this, but I'm not finding it now (maybe I'm just thinking of something from Font). X and Y are essentially just renamed ints-- if it won't let you directly cast from Y to X, then perhaps you can try

Code: Select all

GG::X(int(some_ggY_value))
Figured it out:

Code: Select all

if (Value(GetIconSize()) > Value(text_size.y)) {
					text_size.y = GG::Y(Value(GetIconSize()));
				}
Result (icons 32/ text 14) below. Ok to commit?
Attachments
sitrep3.jpg
sitrep3.jpg (134.9 KiB) Viewed 2572 times
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Sitrep panel icon / text size adjustment

#7 Post by Dilvish »

The Silent One wrote:Ok to commit?
The feature itself certainly looks fine, if that's what you're asking. As for the code changes, it's not clear to me if you are saying that the 3 lines quoted above were all it took, but even if that's the case, since you don't have any recent history making c++ code changes in FO you should probably just start out submitting PRs so that Geoff might comment. For example, even just for the 3 lines you quoted above, I expect that Geoff might comment that the braces are unnecessary (so it can be just 2 lines), and that the second line is (or at least in this representation appears) over-indented (indentation and similar formatting issues are something we try to be consistent with).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#8 Post by The Silent One »

The feature itself certainly looks fine, if that's what you're asking. As for the code changes, it's not clear to me if you are saying that the 3 lines quoted above were all it took, but even if that's the case, since you don't have any recent history making c++ code changes in FO you should probably just start out submitting PRs so that Geoff might comment. For example, even just for the 3 lines you quoted above, I expect that Geoff might comment that the braces are unnecessary (so it can be just 2 lines), and that the second line is (or at least in this representation appears) over-indented (indentation and similar formatting issues are something we try to be consistent with).
Sure, I can do a PR. It took a little more code changes than above, and I would find it helpful to have someone experienced look over my code.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Sitrep panel icon / text size adjustment

#9 Post by Geoff the Medio »

Dilvish wrote:...the second line is (or at least in this representation appears) over-indented...
I'd assume that's due to not-careful use of copy+paste into code tags.

In addition to Dilvish's points, I think changing text_size is misleading. Instead it should use the max of text_size and icon_size when making the call to SizeMove. Possibly an additional temp variable would be used to implement this.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#10 Post by The Silent One »

Is this what you had in mind:

Code: Select all

GG::Pt panel_size = m_link_text->TextLowerRight() - m_link_text->TextUpperLeft();

// use icon or text size, whichever is larger
int maxPanelSize = Value(GetIconSize());
if (maxPanelSize < Value(panel_size.y))
maxPanelSize = Value(panel_size.y);

maxPanelSize += Value(ITEM_VERTICAL_PADDING);
panel_size.y = GG::Y(maxPanelSize); // Text centers, so this puts padding on both above and below
panel_size.x = lr.x - ul.x; // Ignore the width of the text, use whatever was requested.
GG::Control::SizeMove(ul, ul + panel_size );
DoLayout();
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Sitrep panel icon / text size adjustment

#11 Post by Dilvish »

Geoff the Medio wrote:I'd assume that's due to not-careful use of copy+paste into code tags.
No point in assuming when one can simply explicitly note the uncertainty. :)
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#12 Post by The Silent One »

Edited post above.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
vincele
Space Dragon
Posts: 341
Joined: Sun Mar 23, 2014 6:10 pm

Re: Sitrep panel icon / text size adjustment

#13 Post by vincele »

Or that kind of things:

Code: Select all

int maxPanelSize = std::max(Value(GetIconSize()), Value(panel_size.y));
All the patches I'll provide for freeorion will be released under the GPL v2 or later license.
Let's unleash the dyson forest powa!

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#14 Post by The Silent One »

Ooooh me likes! Thanks. I've changed the relevant lines.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Sitrep panel icon / text size adjustment

#15 Post by The Silent One »

I've done a little code grooming, compiles and works as intended.
Pull request is on GitHub:
https://github.com/freeorion/freeorion/pull/181
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

Post Reply