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 » How to resize an ImageCtrl to fit the Image?
How to resize an ImageCtrl to fit the Image? [message #5549] Mon, 02 October 2006 16:17 Go to next message
James Thomas is currently offline  James Thomas
Messages: 26
Registered: June 2006
Promising Member
I'd like to be able to load an arbitary image into an ImageCtrl and set the size of control (inc. frames) to match the size of the image. I'd really like to do this while preserving the auto-layout set with the designer, so that if it's position was set with HLeftPos or HRightPos it keeps this behaviour.

Setting the Image is easy but I've tried resizing it using all of the obvious functions accessible in Ctrl but without any success. Is this possible? Am I missing something obvious?

Thanks in advance.

[Updated on: Mon, 02 October 2006 16:19]

Report message to a moderator

Re: How to resize an ImageCtrl to fit the Image? [message #5550 is a reply to message #5549] Mon, 02 October 2006 17:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Have you tried SetRect?

Actually, the situation is a little bit complicated, because Ctrls have "logical" coordinates. However, SetRect sets logical coordinates equivalent to simply placing Ctrl to the specified Rect.

Another possible trouble is that this Rect is "outer", while to fit the Image you are more interested about the size of view rectangle. You can get required "outer" rect size using AddFrameSize.

Mirek
Re: How to resize an ImageCtrl to fit the Image? [message #5625 is a reply to message #5550] Fri, 06 October 2006 11:07 Go to previous messageGo to next message
James Thomas is currently offline  James Thomas
Messages: 26
Registered: June 2006
Promising Member
Sorry it's taken a while to reply, I've been away all week.

SetRect was the first thing I tried, but using it causes strange behaviour in my app which I assumed was normal until I read your post.

The problem is that if I run the following two lines in the constructor (after CtrlLayout of course)
Rect r = _imgLogo.GetRect();
_imgLogo.SetRect(r);

the control moves to a different place in the window. If you then call GetRect again the returned rectangle is exactly as you would expect (ie no change). Perhaps something else has changed?

Unfortunately I have been unable to reproduce this in a simple example, but clearly this is the wrong behaviour. If you have any suggestions as to how I might fix/trace this they would be greatly appreciated, though I understand this is difficult until I can reproduce it.

Cheers.

EDIT: This happens with both 605 and dev-2 versions.

[Updated on: Fri, 06 October 2006 11:18]

Report message to a moderator

Re: How to resize an ImageCtrl to fit the Image? [message #5630 is a reply to message #5625] Fri, 06 October 2006 16:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am not sure whether this is the cause, but GetRect and SetRect are not always "equivalent".

SetRect in fact is helper function that calls LeftPos(x, cx).TopPos(y, cy).

Meanwhile, GetRect returns actual "physical" coordinates.

Maybe that is the cause? (It would be if your widget has other placement than LeftPos / TopPos).
Re: How to resize an ImageCtrl to fit the Image? [message #5672 is a reply to message #5630] Mon, 09 October 2006 11:11 Go to previous messageGo to next message
James Thomas is currently offline  James Thomas
Messages: 26
Registered: June 2006
Promising Member
Thanks, that is definitely the problem as it's positioned using CenterPos and BottomPos.

So is there any way to modify the size of a control without affecting it's logical position?
Re: How to resize an ImageCtrl to fit the Image? [message #5691 is a reply to message #5672] Tue, 10 October 2006 09:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, logical position defines the size. Therefore you cannot change the size without modifying the position.

Perhaps you should rather try to describe what your are really trying to achieve.
Re: How to resize an ImageCtrl to fit the Image? [message #5695 is a reply to message #5691] Tue, 10 October 2006 12:41 Go to previous messageGo to next message
James Thomas is currently offline  James Thomas
Messages: 26
Registered: June 2006
Promising Member
Ah ha! I don't think I'd quite understood how logical positions worked. LogC members a & b are similar to position and size but relative to the anchor, except when SizePos is used, correct?

Basically the code I was looking for is this:
		Size sz = ctrl.AddFrameSize(img->GetSize());
		
		// Resize ctrl
		Ctrl::LogPos p = ctrl.GetPos();
		p.x.SetB(sz.cx);
		p.y.SetB(sz.cy);
		ctrl.SetPos(p);	

I realise this won't work for all cases, but it's good enough for now.

I really should have seen this straight away but I haven't written a GUI in anything that does layouts like this before so it took a while for me to clock it. It's always the simple things in U++ that get me stuck.

Thanks for your patience Smile

[Updated on: Tue, 10 October 2006 13:53]

Report message to a moderator

Re: How to resize an ImageCtrl to fit the Image? [message #5697 is a reply to message #5695] Tue, 10 October 2006 14:49 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Actually, it is not always that simple: for "size" type, A is distance from left/top parent side, B is distance from right/bottom parent size....
Previous Topic: Exception,how to find where?
Next Topic: Problem with ColumnList (with example) [BUG/FIXED]
Goto Forum:
  


Current Time: Sun Apr 28 00:51:29 CEST 2024

Total time taken to generate the page: 0.04312 seconds