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
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 previous 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);
}
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Hide Mouse Cursor?
Next Topic: Stripping an executable doesn't reduces it's size
Goto Forum:
  


Current Time: Fri Jun 06 11:07:24 CEST 2025

Total time taken to generate the page: 0.04253 seconds