* Wrote application to test the invalidation area on window changes.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32468 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -194,5 +194,6 @@ SubInclude HAIKU_TOP src tests servers app textview ;
|
||||
SubInclude HAIKU_TOP src tests servers app view_state ;
|
||||
SubInclude HAIKU_TOP src tests servers app view_transit ;
|
||||
SubInclude HAIKU_TOP src tests servers app window_creation ;
|
||||
SubInclude HAIKU_TOP src tests servers app window_invalidation ;
|
||||
SubInclude HAIKU_TOP src tests servers app workspace_activated ;
|
||||
SubInclude HAIKU_TOP src tests servers app workspace_switcher ;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
SubDir HAIKU_TOP src tests servers app window_invalidation ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
UseHeaders [ FDirName os app ] ;
|
||||
UseHeaders [ FDirName os interface ] ;
|
||||
|
||||
Application WindowInvalidation :
|
||||
WindowInvalidation.cpp
|
||||
: be $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
||||
if $(TARGET_PLATFORM) = libbe_test {
|
||||
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : WindowInvalidation
|
||||
: tests!apps ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
class ShowInvalidationView : public BView {
|
||||
public:
|
||||
ShowInvalidationView(BRect rect);
|
||||
virtual ~ShowInvalidationView();
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
};
|
||||
|
||||
|
||||
class ShowingWindow : public BWindow {
|
||||
public:
|
||||
ShowingWindow();
|
||||
};
|
||||
|
||||
|
||||
class ChangingWindow : public BWindow {
|
||||
public:
|
||||
ChangingWindow();
|
||||
virtual ~ChangingWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
BMessageRunner* fRunner;
|
||||
};
|
||||
|
||||
|
||||
class Application : public BApplication {
|
||||
public:
|
||||
Application();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
};
|
||||
|
||||
|
||||
ShowInvalidationView::ShowInvalidationView(BRect rect)
|
||||
:
|
||||
BView(rect, "show invalidation", B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
}
|
||||
|
||||
|
||||
ShowInvalidationView::~ShowInvalidationView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ShowInvalidationView::Draw(BRect updateRect)
|
||||
{
|
||||
SetHighColor(rand() % 256, rand() % 256, rand() % 256);
|
||||
FillRect(updateRect);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ShowingWindow::ShowingWindow()
|
||||
:
|
||||
BWindow(BRect(150, 150, 450, 450), "WindowInvalidation-Test",
|
||||
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
BView* view = new ShowInvalidationView(Bounds());
|
||||
AddChild(view);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ChangingWindow::ChangingWindow()
|
||||
:
|
||||
BWindow(BRect(150, 150, 400, 400), "WindowInvalidation-Test",
|
||||
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
BMessage message('actn');
|
||||
fRunner = new BMessageRunner(this, &message, 25000);
|
||||
}
|
||||
|
||||
|
||||
ChangingWindow::~ChangingWindow()
|
||||
{
|
||||
delete fRunner;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ChangingWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
if (message->what == 'actn') {
|
||||
switch (rand() % 3) {
|
||||
case 0:
|
||||
{
|
||||
// resize window
|
||||
BRect bounds;
|
||||
do {
|
||||
bounds = Bounds();
|
||||
bounds.right += rand() % 21 - 10;
|
||||
bounds.bottom += rand() % 21 - 10;
|
||||
} while (bounds.Width() > 400 || bounds.Height() > 400
|
||||
|| bounds.Width() < 50 || bounds.Height() < 50);
|
||||
|
||||
ResizeTo(bounds.Width() + 1, bounds.Height() + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
// move window
|
||||
BPoint leftTop;
|
||||
do {
|
||||
leftTop = Frame().LeftTop();
|
||||
leftTop.x += rand() % 21 - 10;
|
||||
leftTop.y += rand() % 21 - 10;
|
||||
} while (!BRect(100, 100, 200, 200).Contains(leftTop));
|
||||
|
||||
MoveTo(leftTop);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
// set title
|
||||
static const char* kChoices[]
|
||||
= {"Window", "Invalidation", "Test", "Hooray"};
|
||||
|
||||
SetTitle(kChoices[rand() % (sizeof(kChoices) / sizeof(char*))]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Application::Application()
|
||||
:
|
||||
BApplication("application/x-vnd.haiku-view_state")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Application::ReadyToRun()
|
||||
{
|
||||
BWindow* window = new ChangingWindow();
|
||||
window->Show();
|
||||
|
||||
window = new ShowingWindow();
|
||||
window->Show();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
Application app;
|
||||
app.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user