A test I used for checking ConstrainClippingRegion() with regards to states,

scales and origins.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25148 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-04-25 10:49:30 +00:00
parent 0a6ef8179c
commit d88d001f35
3 changed files with 351 additions and 0 deletions

View File

@ -0,0 +1,17 @@
SubDir HAIKU_TOP src tests servers app constrain_clipping_region ;
SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
UseHeaders [ FDirName os app ] ;
UseHeaders [ FDirName os interface ] ;
SimpleTest ClippingRegion :
main.cpp
: be ;
if ( $(TARGET_PLATFORM) = libbe_test ) {
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : ClippingRegion
: tests!apps ;
}

View File

@ -0,0 +1,316 @@
// main.cpp
#include <stdio.h>
#include <Application.h>
#include <Region.h>
#include <View.h>
#include <Window.h>
class TestView1 : public BView {
public:
TestView1(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void Draw(BRect updateRect)
{
BRegion region;
region.Include(BRect(20, 20, 40, 40));
region.Include(BRect(30, 30, 80, 80));
ConstrainClippingRegion(&region);
SetHighColor(255, 0, 0, 255);
FillRect(BRect(0, 0, 100, 100));
ConstrainClippingRegion(NULL);
SetHighColor(0, 0, 0, 255);
StrokeLine(BPoint(2, 2), BPoint(80, 80));
}
};
class TestView2 : public BView {
public:
TestView2(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void AttachedToWindow()
{
SetOrigin(20, 20);
}
virtual void Draw(BRect updateRect)
{
// SetOrigin(20, 20);
BRegion region;
region.Include(BRect(20, 20, 40, 40));
region.Include(BRect(30, 30, 80, 80));
ConstrainClippingRegion(&region);
SetHighColor(255, 128, 0, 255);
FillRect(BRect(0, 0, 100, 100));
ConstrainClippingRegion(NULL);
SetHighColor(0, 0, 0, 255);
StrokeLine(BPoint(2, 2), BPoint(80, 80));
}
};
class TestView3 : public BView {
public:
TestView3(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void AttachedToWindow()
{
SetOrigin(20, 20);
}
virtual void Draw(BRect updateRect)
{
BRegion region;
region.Include(BRect(20, 20, 40, 40));
region.Include(BRect(30, 30, 80, 80));
ConstrainClippingRegion(&region);
SetHighColor(55, 255, 128, 255);
FillRect(BRect(0, 0, 100, 100));
PushState();
SetOrigin(15, 15);
ConstrainClippingRegion(&region);
SetHighColor(155, 255, 128, 255);
FillRect(BRect(0, 0, 100, 100));
// ConstrainClippingRegion(NULL);
SetHighColor(0, 0, 0, 255);
StrokeLine(BPoint(2, 2), BPoint(80, 80));
SetHighColor(255, 0, 0, 255);
StrokeLine(BPoint(2, 2), BPoint(4, 2));
PopState();
SetHighColor(0, 0, 0, 255);
StrokeLine(BPoint(4, 2), BPoint(82, 80));
}
};
class TestView4 : public BView {
public:
TestView4(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void AttachedToWindow()
{
SetOrigin(20, 20);
}
virtual void Draw(BRect updateRect)
{
BRegion region;
region.Include(BRect(20, 20, 40, 40));
region.Include(BRect(30, 30, 140, 140));
ConstrainClippingRegion(&region);
SetHighColor(55, 255, 128, 255);
FillRect(BRect(0, 0, 200, 200));
// NOTE: This exposes broken behavior of the ZETA
// (probably R5 too) app_server. The new origin
// is not taken into account
PushState();
ConstrainClippingRegion(&region);
SetOrigin(15, 15);
SetScale(1.5);
SetHighColor(155, 255, 128, 255);
FillRect(BRect(0, 0, 200, 200));
ConstrainClippingRegion(NULL);
SetHighColor(0, 0, 0, 255);
SetDrawingMode(B_OP_OVER);
DrawString("Text is scaled.", BPoint(20, 30));
SetScale(1.2);
DrawString("Text is scaled.", BPoint(20, 30));
StrokeLine(BPoint(2, 2), BPoint(80, 80));
PopState();
SetHighColor(0, 0, 0, 255);
StrokeLine(BPoint(4, 2), BPoint(82, 80));
}
};
class TestView5 : public BView {
public:
TestView5(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void AttachedToWindow()
{
}
virtual void Draw(BRect updateRect)
{
BRegion region;
region.Include(BRect(0, 0, 40, 40));
region.Include(BRect(30, 30, 140, 140));
ConstrainClippingRegion(&region);
SetHighColor(55, 255, 128, 255);
FillRect(BRect(0, 0, 200, 200));
PushState();
ConstrainClippingRegion(&region);
SetOrigin(50, 10);
SetHighColor(155, 55, 128, 255);
FillRect(BRect(0, 0, 200, 200));
PopState();
SetHighColor(255, 0, 0);
StrokeLine(Bounds().LeftTop(), Bounds().RightBottom());
}
};
class TestView6 : public BView {
public:
TestView6(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ViewColor());
}
virtual void AttachedToWindow()
{
}
virtual void Draw(BRect updateRect)
{
BRegion region;
region.Include(BRect(0, 0, 40, 40));
region.Include(BRect(30, 30, 140, 140));
ConstrainClippingRegion(&region);
SetHighColor(55, 255, 128, 255);
FillRect(BRect(0, 0, 200, 200));
PushState();
SetOrigin(50, 10);
ConstrainClippingRegion(&region);
SetHighColor(155, 55, 128, 255);
FillRect(BRect(0, 0, 200, 200));
PopState();
SetHighColor(255, 0, 0);
StrokeLine(Bounds().LeftTop(), Bounds().RightBottom());
}
};
// main
int
main(int argc, char** argv)
{
BApplication* app = new BApplication(
"application/x.vnd-Haiku.ClippingRegion");
BRect frame(50.0, 50.0, 300.0, 250.0);
BWindow* window;
BView* view;
// window = new BWindow(frame, "Test1", B_TITLED_WINDOW,
// B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
//
// view = new TestView1(window->Bounds(), "test1", B_FOLLOW_ALL,
// B_WILL_DRAW);
// window->AddChild(view);
// window->Show();
//
// frame.OffsetBy(20, 20);
// window = new BWindow(frame, "Test2", B_TITLED_WINDOW,
// B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
//
// view = new TestView2(window->Bounds(), "test2", B_FOLLOW_ALL,
// B_WILL_DRAW);
// window->AddChild(view);
// window->Show();
//
// frame.OffsetBy(20, 20);
// window = new BWindow(frame, "Test3", B_TITLED_WINDOW,
// B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
//
// view = new TestView3(window->Bounds(), "test3", B_FOLLOW_ALL,
// B_WILL_DRAW);
// window->AddChild(view);
// window->Show();
//
// frame.OffsetBy(20, 20);
// window = new BWindow(frame, "Test4", B_TITLED_WINDOW,
// B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
//
// view = new TestView4(window->Bounds(), "test4", B_FOLLOW_ALL,
// B_WILL_DRAW);
// window->AddChild(view);
// window->Show();
frame.OffsetBy(20, 20);
window = new BWindow(frame, "Test5", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
view = new TestView5(window->Bounds(), "test5", B_FOLLOW_ALL,
B_WILL_DRAW);
window->AddChild(view);
window->Show();
frame.OffsetBy(20, 20);
window = new BWindow(frame, "Test6", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
view = new TestView6(window->Bounds(), "test6", B_FOLLOW_ALL,
B_WILL_DRAW);
window->AddChild(view);
window->Show();
app->Run();
delete app;
return 0;
}

View File

@ -0,0 +1,18 @@
#!/bin/sh
../../../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit
if test -f ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then
../../../../../generated/tests/libbe_test/x86/apps//haiku_app_server &
else
echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first."
fi
sleep 1s
if test -f ../../../../../generated/tests/libbe_test/x86/apps/ClippingRegion; then
../../../../../generated/tests/libbe_test/x86/apps/ClippingRegion
else
echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first."
fi