- moving and resizing is new performed only with the primary mouse button
- by holding the secondary mouse button pressed one can draw random lines so you can see what regions are invalidated durring a move, resize or scroll operation - clicking the third mouse button issues a redraw, WITHOUT a region rebuild action (this is to force a redraw because the window does not redraw itself, I've been lazy :-) - playing with the mouse wheel results in the layer under mouse cursor being scrolled on the y-axis. - fixed redraw and copyRegion of this sandbox app. They work correctly now. - TODO: fix a clipping bug which appears when moving a layer arround. --This line, and those below, will be ignored-- M newClipping/MyView.cpp M newClipping/main.cpp M newClipping/MyView.h M newClipping/Layer.cpp M newClipping/Clipping.proj git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12895 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
38b2e6ccbe
commit
a332730df7
Binary file not shown.
@ -355,11 +355,14 @@ void Layer::ResizeBy(float dx, float dy)
|
||||
|
||||
void Layer::MoveBy(float dx, float dy)
|
||||
{
|
||||
fFrame.Set(fFrame.left+dx, fFrame.top+dy, fFrame.right+dx, fFrame.bottom+dy);
|
||||
if (dx == 0.0f && dy == 0.0f)
|
||||
return;
|
||||
|
||||
// fFrame.Set(fFrame.left+dx, fFrame.top+dy, fFrame.right+dx, fFrame.bottom+dy);
|
||||
fFrame.OffsetBy(dx, dy);
|
||||
|
||||
// call hook function
|
||||
if (dx != 0.0f || dy != 0.0f)
|
||||
MovedByHook(dx, dy);
|
||||
MovedByHook(dx, dy);
|
||||
|
||||
if (!IsVisuallyHidden() && GetRootLayer())
|
||||
{
|
||||
|
@ -15,6 +15,7 @@ MyView::MyView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
fTracking = false;
|
||||
fIsResize = false;
|
||||
fIs2ndButton= false;
|
||||
fMovingLayer = NULL;
|
||||
|
||||
rgb_color col;
|
||||
@ -49,27 +50,41 @@ Layer* MyView::FindLayer(Layer *lay, BPoint &where) const
|
||||
|
||||
void MyView::MouseDown(BPoint where)
|
||||
{
|
||||
fTracking = true;
|
||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||
int32 buttons;
|
||||
Looper()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||
fLastPos = where;
|
||||
fMovingLayer = FindLayer(topLayer, where);
|
||||
if (fMovingLayer == topLayer)
|
||||
fMovingLayer = NULL;
|
||||
if (fMovingLayer)
|
||||
if (buttons == B_PRIMARY_MOUSE_BUTTON)
|
||||
{
|
||||
BRect bounds(fMovingLayer->Bounds());
|
||||
fMovingLayer->ConvertToScreen2(&bounds);
|
||||
BRect resizeRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom);
|
||||
if (resizeRect.Contains(where))
|
||||
fIsResize = true;
|
||||
else
|
||||
fIsResize = false;
|
||||
fTracking = true;
|
||||
fMovingLayer = FindLayer(topLayer, where);
|
||||
if (fMovingLayer == topLayer)
|
||||
fMovingLayer = NULL;
|
||||
if (fMovingLayer)
|
||||
{
|
||||
BRect bounds(fMovingLayer->Bounds());
|
||||
fMovingLayer->ConvertToScreen2(&bounds);
|
||||
BRect resizeRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom);
|
||||
if (resizeRect.Contains(where))
|
||||
fIsResize = true;
|
||||
else
|
||||
fIsResize = false;
|
||||
}
|
||||
}
|
||||
else if (buttons == B_SECONDARY_MOUSE_BUTTON)
|
||||
{
|
||||
fIs2ndButton = true;
|
||||
}
|
||||
else if (buttons == B_TERTIARY_MOUSE_BUTTON)
|
||||
{
|
||||
DrawSubTree(topLayer);
|
||||
}
|
||||
}
|
||||
|
||||
void MyView::MouseUp(BPoint where)
|
||||
{
|
||||
fTracking = false;
|
||||
fIs2ndButton = false;
|
||||
fMovingLayer = NULL;
|
||||
}
|
||||
|
||||
@ -93,27 +108,67 @@ void MyView::MouseMoved(BPoint where, uint32 code, const BMessage *a_message)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fIs2ndButton)
|
||||
{
|
||||
SetHighColor(0,0,0);
|
||||
StrokeLine(fLastPos, where);
|
||||
Flush();
|
||||
fLastPos = where;
|
||||
}
|
||||
}
|
||||
|
||||
void MyView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what)
|
||||
{
|
||||
case B_MOUSE_WHEEL_CHANGED:
|
||||
{
|
||||
float dy;
|
||||
msg->FindFloat("be:wheel_delta_y", &dy);
|
||||
|
||||
BPoint pt;
|
||||
uint32 buttons;
|
||||
Layer *lay;
|
||||
GetMouse(&pt, &buttons, false);
|
||||
if ((lay = FindLayer(topLayer, pt)))
|
||||
lay->ScrollBy(0, dy*5);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void MyView::CopyRegion(BRegion *reg, float dx, float dy)
|
||||
{
|
||||
// Yes... in this sandbox app, do a redraw.
|
||||
reg->OffsetBy(dx, dy);
|
||||
wind->Lock();
|
||||
ConstrainClippingRegion(reg);
|
||||
PushState();
|
||||
DrawSubTree(topLayer);
|
||||
Flush();
|
||||
PopState();
|
||||
ConstrainClippingRegion(NULL);
|
||||
wind->Unlock();
|
||||
}
|
||||
|
||||
void MyView::RequestRedraw()
|
||||
{
|
||||
wind->Lock();
|
||||
Invalidate();
|
||||
ConstrainClippingRegion(&fRedrawReg);
|
||||
PushState();
|
||||
DrawSubTree(topLayer);
|
||||
PopState();
|
||||
ConstrainClippingRegion(NULL);
|
||||
|
||||
fRedrawReg.MakeEmpty();
|
||||
|
||||
wind->Unlock();
|
||||
}
|
||||
|
||||
void MyView::Draw(BRect area)
|
||||
{
|
||||
/*
|
||||
ConstrainClippingRegion(&fRedrawReg);
|
||||
//FillRect(Bounds());
|
||||
//Flush();
|
||||
@ -123,6 +178,7 @@ void MyView::Draw(BRect area)
|
||||
PopState();
|
||||
ConstrainClippingRegion(NULL);
|
||||
fRedrawReg.MakeEmpty();
|
||||
*/
|
||||
}
|
||||
|
||||
void MyView::DrawSubTree(Layer* lay)
|
||||
|
@ -14,6 +14,7 @@ public:
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseUp(BPoint where);
|
||||
virtual void MouseMoved(BPoint where, uint32 code, const BMessage *a_message);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
|
||||
void CopyRegion(BRegion *reg, float dx, float dy);
|
||||
void RequestRedraw();
|
||||
@ -29,4 +30,5 @@ private:
|
||||
BPoint fLastPos;
|
||||
Layer *fMovingLayer;
|
||||
bool fIsResize;
|
||||
bool fIs2ndButton;
|
||||
};
|
@ -66,6 +66,7 @@ clsMainWindow::clsMainWindow(const char *uWindowTitle)
|
||||
wind = this;
|
||||
fView = new MyView(Bounds(), "emu", B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
AddChild(fView);
|
||||
fView->MakeFocus(true);
|
||||
}
|
||||
|
||||
clsMainWindow::~clsMainWindow()
|
||||
@ -157,15 +158,13 @@ void clsMainWindow::test1()
|
||||
wb2->GetWantedRegion(temp);
|
||||
topLayer->RebuildVisibleRegions(temp, wb2);
|
||||
|
||||
wind->Lock();
|
||||
fView->Invalidate();
|
||||
wind->Unlock();
|
||||
fView->RequestRedraw();
|
||||
|
||||
snooze(2000000);
|
||||
snooze(1000000);
|
||||
|
||||
wb1->Hide();
|
||||
|
||||
snooze(2000000);
|
||||
snooze(1000000);
|
||||
|
||||
wb1->Show();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user