Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » RectTracker filled with black
Re: RectTracker filled with black [message #14216 is a reply to message #14210] |
Wed, 20 February 2008 10:55   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
This would be my suggested version:
void RectTracker::MouseMove(Point, dword)
{
Point p = GetMousePos();
rect = org;
if(tx == ALIGN_CENTER && ty == ALIGN_CENTER) {
int x = org.left - op.x + p.x;
int y = org.top - op.y + p.y;
if(x + org.Width() > maxrect.right)
x = maxrect.right - org.Width();
if(x < maxrect.left)
x = maxrect.left;
if(y + org.Height() > maxrect.bottom)
y = maxrect.bottom - org.Height();
if(y < maxrect.top)
y = maxrect.top;
rect = RectC(x, y, org.Width(), org.Height());
}
else {
if(tx == ALIGN_LEFT) {
rect.left = max(org.left - op.x + p.x, maxrect.left);
rect.left = minmax(rect.left, rect.right - maxsize.cx, rect.right - minsize.cx);
}
if(tx == ALIGN_RIGHT) {
rect.right = min(org.right - op.x + p.x, maxrect.right);
rect.right = minmax(rect.right, rect.left + minsize.cx, rect.left + maxsize.cx);
}
if(ty == ALIGN_TOP) {
rect.top = max(org.top - op.y + p.y, maxrect.top);
rect.top = minmax(rect.top, rect.bottom - maxsize.cy, rect.bottom - minsize.cy);
}
if(ty == ALIGN_BOTTOM) {
rect.bottom = min(org.bottom - op.y + p.y, maxrect.bottom);
rect.bottom = minmax(rect.bottom, rect.top + minsize.cy, rect.top + maxsize.cy);
}
if(tx == ALIGN_NULL) {
rect.right = min(org.right - op.x + p.x, maxrect.right);
if (rect.right < rect.left) {
Swap(rect.right, rect.left);
rect.InflateHorz(1);
}
}
if(ty == ALIGN_NULL) {
rect.bottom = min(org.bottom - op.y + p.y, maxrect.bottom);
if (rect.bottom < rect.top) {
Swap(rect.bottom, rect.top);
rect.InflateVert(1);
}
}
if(keepratio) {
int cy = org.Width() ? rect.Width() * org.Height() / org.Width() : 0;
int cx = org.Height() ? rect.Height() * org.Width() / org.Height() : 0;
if(tx == ALIGN_BOTTOM && ty == ALIGN_RIGHT) {
Size sz = rect.Size();
if(cx > sz.cx)
rect.right = rect.left + cx;
else
rect.bottom = rect.top + cy;
}
else
if(tx == ALIGN_RIGHT)
rect.bottom = rect.top + cy;
else
if(ty == ALIGN_BOTTOM)
rect.right = rect.left + cx;
}
}
if(rect != o) {
rect = Round(rect);
if(rect != o) {
DrawRect(o, rect);
sync(rect);
o = rect;
}
}
}
It fixes the cursor alignment problem. I also believe that this is the correct place to modify the coordinates, as doing so before drawing means that the final rectangle is inaccurate.
IMO if you really need to have the final rectangle backwards I think you should compare and switch it after getting the final rect back.
[Updated on: Wed, 20 February 2008 11:13] Report message to a moderator
|
|
|
 |
|
RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mirek on Wed, 13 February 2008 08:44
|
 |
|
Re: RectTracker filled with black
By: mrjt on Wed, 13 February 2008 12:13
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mrjt on Wed, 20 February 2008 10:55
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mrjt on Wed, 20 February 2008 14:13
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mrjt on Wed, 20 February 2008 14:52
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mirek on Tue, 26 February 2008 21:13
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mrjt on Fri, 29 February 2008 15:20
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mirek on Mon, 03 March 2008 20:48
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
|
 |
|
Re: RectTracker filled with black
By: mirek on Sat, 22 March 2008 20:33
|
 |
|
Re: RectTracker filled with black
By: mirek on Wed, 20 February 2008 13:57
|
Goto Forum:
Current Time: Fri Sep 05 21:03:04 CEST 2025
Total time taken to generate the page: 0.09518 seconds
|