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 |
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 |
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);
}
|
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 10:15:19 CEST 2024
Total time taken to generate the page: 0.03719 seconds
|