Files
haiku-beta6/src/tests/servers/app/newClipping/MyView.cpp
T

100 lines
2.0 KiB
C++
Raw Normal View History

2005-05-16 18:31:01 +00:00
#include <Message.h>
#include <Messenger.h>
#include <Window.h>
2005-05-16 18:31:01 +00:00
#include <stdio.h>
#include "MyView.h"
#include "Layer.h"
extern BWindow *wind;
2005-05-16 18:31:01 +00:00
MyView::MyView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags)
{
SetViewColor(B_TRANSPARENT_COLOR);
rgb_color col;
col.red = 49;
col.green = 101;
col.blue = 156;
2005-05-24 14:39:16 +00:00
topLayer = new Layer(Bounds(), "topLayer", B_FOLLOW_ALL, 0, col);
2005-05-16 18:31:01 +00:00
topLayer->SetRootLayer(this);
topLayer->rebuild_visible_regions(BRegion(Bounds()), BRegion(Bounds()), NULL);
2005-05-18 20:47:13 +00:00
fRedrawReg.Set(Bounds());
2005-05-16 18:31:01 +00:00
}
MyView::~MyView()
{
delete topLayer;
}
Layer* MyView::FindLayer(Layer *lay, const char *bytes) const
{
if (strcmp(lay->Name(), bytes) == 0)
return lay;
else
{
Layer *ret = NULL;
Layer *cursor = lay->VirtualBottomChild();
while(cursor)
{
ret = FindLayer(cursor, bytes);
if (ret)
return ret;
cursor = cursor->VirtualUpperSibling();
}
}
return NULL;
}
2005-05-18 20:47:13 +00:00
void MyView::CopyRegion(BRegion *reg, float dx, float dy)
{
wind->Lock();
// ConstrainClippingRegion(&r);
// CopyBits(Bounds(), Bounds().OffsetByCopy(dx, dy));
// TODO: properly do that!
// LAME, I know!
CopyBits(reg->Frame(), reg->Frame().OffsetByCopy(dx, dy));
// ConstrainClippingRegion(NULL);
wind->Unlock();
}
void MyView::RequestRedraw()
{
wind->Lock();
Invalidate();
wind->Unlock();
}
2005-05-16 18:31:01 +00:00
void MyView::Draw(BRect area)
{
2005-05-18 20:47:13 +00:00
ConstrainClippingRegion(&fRedrawReg);
2005-05-24 14:39:16 +00:00
FillRect(Bounds());
Flush();
snooze(1000000);
2005-05-18 20:47:13 +00:00
PushState();
2005-05-16 18:31:01 +00:00
DrawSubTree(topLayer);
2005-05-18 20:47:13 +00:00
PopState();
ConstrainClippingRegion(NULL);
fRedrawReg.MakeEmpty();
2005-05-16 18:31:01 +00:00
}
void MyView::DrawSubTree(Layer* lay)
{
2005-05-18 20:47:13 +00:00
//printf("======== %s =======\n", lay->Name());
// lay->Visible()->PrintToStream();
// lay->FullVisible()->PrintToStream();
2005-05-16 18:31:01 +00:00
Layer *child = lay->VirtualBottomChild();
while(child)
{
DrawSubTree(child);
child = child->VirtualUpperSibling();
}
ConstrainClippingRegion(lay->Visible());
SetHighColor(lay->HighColor());
BRect temp = lay->Bounds();
lay->ConvertToScreen2(&temp);
FillRect(temp);
ConstrainClippingRegion(NULL);
}