Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » keeping fixed x/y ratio in a control
keeping fixed x/y ratio in a control [message #8142] Mon, 12 February 2007 19:20 Go to next message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
Hi,

I'm using a Ctrl as a container for drawing. However, when I resize the window, drawings in the 'pane' become stretched and no longer on a 1:1 (or whatever i:j initial constant) x:y aspect.

This is especially obvious because I'm drawing text into the Ctrl as well, in a Drawing object. I suppose either I can forcibly scale the Drawing object to a sensible ratio before painting it, or I could find a way to dynamically resize the parent Ctrl to match the ratio of the minimum x/y value.

Is there an easy way to do this? I couldn't find a function to override in Ctrl that will allow me to adjust things when resizing - I've tried overriding SetRect and SetFrameRect in their various incarnations, but they don't seem to be called.
Re: keeping fixed x/y ratio in a control [message #8143 is a reply to message #8142] Mon, 12 February 2007 19:50 Go to previous messageGo to next message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
Well, this seems to work, but (as almost always with my GUI code) it seems a bit unnecessarily dirty.

Does anyone know a nicer, simpler way of achieving this?

The code sets cx = cy = min(cx, cy), then centres the drawing (graph) in the Ctrl.

virtual void Paint(Draw& w) {
    Ctrl::Paint(w);

    // scale/clip drawing to fit control on a x/y = 1 ratio
    Size paneSize = GetSize();
    int cx = paneSize.cx;
    int cy = paneSize.cy;
    if(cx < cy)
        cy = cx;
    else
        cx = cy;

    w.DrawRect(GetSize(), WhiteGray());
    w.DrawDrawing((paneSize.cx - cx)/2, (paneSize.cy - cy)/2, cx, cy, graph);
}
Re: keeping fixed x/y ratio in a control [message #8145 is a reply to message #8143] Mon, 12 February 2007 21:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Forcing the size ratio of window is tricky business on both platform we support now. Therefore I think your solution is not dirty at all.

Mirek
Re: keeping fixed x/y ratio in a control [message #8154 is a reply to message #8142] Tue, 13 February 2007 02:25 Go to previous message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
Thanks Mirek. I guess the other solution would be to embed a Ctrl in a Ctrl and scale the inner one in the same way, although that's just moving the problem up one level.
Previous Topic: Hide Mouse Cursor?
Next Topic: Stripping an executable doesn't reduces it's size
Goto Forum:
  


Current Time: Fri Apr 19 17:42:38 CEST 2024

Total time taken to generate the page: 0.03481 seconds