From dd55678524633bf2adb7a89274748ae9f2e2931e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 27 Apr 2005 17:30:18 +0000 Subject: [PATCH] test app for scrolling, link for running on R5 to see how it should behave git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12482 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/servers/app/Jamfile | 1 + src/tests/servers/app/copy_bits/main.cpp | 57 +++++++--- src/tests/servers/app/scrolling/Jamfile | 14 +++ src/tests/servers/app/scrolling/NOTES | 3 + src/tests/servers/app/scrolling/main.cpp | 137 +++++++++++++++++++++++ src/tests/servers/app/scrolling/run | 5 + 6 files changed, 200 insertions(+), 17 deletions(-) create mode 100644 src/tests/servers/app/scrolling/Jamfile create mode 100644 src/tests/servers/app/scrolling/NOTES create mode 100644 src/tests/servers/app/scrolling/main.cpp create mode 100755 src/tests/servers/app/scrolling/run diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 86ad3ecec0..62c8e80897 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -2,4 +2,5 @@ SubDir OBOS_TOP src tests servers app ; SubInclude OBOS_TOP src tests servers app copy_bits ; SubInclude OBOS_TOP src tests servers app painter ; +SubInclude OBOS_TOP src tests servers app scrolling ; SubInclude OBOS_TOP src tests servers app windows ; diff --git a/src/tests/servers/app/copy_bits/main.cpp b/src/tests/servers/app/copy_bits/main.cpp index 4100b6f97f..f33948f749 100644 --- a/src/tests/servers/app/copy_bits/main.cpp +++ b/src/tests/servers/app/copy_bits/main.cpp @@ -33,6 +33,8 @@ class TestView : public BView { frame.right, frame.bottom); fSourceRect.InsetBy(10.0, 10.0); fDestRect.InsetBy(10.0, 10.0); + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } virtual void MessageReceived(BMessage* message); @@ -79,8 +81,9 @@ TestView::Draw(BRect updateRect) fCopyBitsJustCalled = false; } - SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - FillRect(updateRect); + // background +// SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +// FillRect(updateRect); BRect r(Bounds()); @@ -88,6 +91,7 @@ TestView::Draw(BRect updateRect) float width = r.Width(); float height = r.Height(); int32 lineCount = 20; + SetPenSize(2.0); for (int32 i = 0; i < lineCount; i++) { SetHighColor(255, (255 / lineCount) * i, 255 - (255 / lineCount) * i); StrokeLine(BPoint(r.left + (width / lineCount) * i, r.top), @@ -95,28 +99,47 @@ TestView::Draw(BRect updateRect) StrokeLine(BPoint(r.right - (width / lineCount) * i, r.bottom), BPoint(r.right, r.bottom - (height / lineCount) * i)); } + StrokeLine(BPoint(r.left, r.bottom), BPoint(r.right, r.top)); - SetHighColor(255, 0, 0, 128); - - const char* message = "Left-Click and drag"; - width = StringWidth(message); - BPoint p(r.left + r.Width() / 2.0 - width / 2.0, - r.top + r.Height() / 2.0); - - DrawString(message, p); - - message = "to draw source rect!"; - width = StringWidth(message); - p.x = r.left + r.Width() / 2.0 - width / 2.0; - p.y += 20; - - DrawString(message, p); + // source and dest rect + SetPenSize(1.0); SetHighColor(0, 255, 0, 255); StrokeRect(fSourceRect); SetHighColor(0, 0, 255, 255); StrokeRect(fDestRect); + + // text + SetHighColor(128, 0, 50, 255); + + const char* message = "Left-Click and drag"; + width = StringWidth(message); + BPoint p(r.left + r.Width() / 2.0 - width / 2.0, + r.top + r.Height() / 2.0 - 50.0); + + DrawString(message, p); + + message = "to set source rect!"; + width = StringWidth(message); + p.x = r.left + r.Width() / 2.0 - width / 2.0; + p.y += 20; + + DrawString(message, p); + + message = "Right-Click and drag"; + width = StringWidth(message); + p.x = r.left + r.Width() / 2.0 - width / 2.0; + p.y += 30.0; + + DrawString(message, p); + + message = "to set destination rect!"; + width = StringWidth(message); + p.x = r.left + r.Width() / 2.0 - width / 2.0; + p.y += 20; + + DrawString(message, p); } // MouseDown diff --git a/src/tests/servers/app/scrolling/Jamfile b/src/tests/servers/app/scrolling/Jamfile new file mode 100644 index 0000000000..b1457ce685 --- /dev/null +++ b/src/tests/servers/app/scrolling/Jamfile @@ -0,0 +1,14 @@ +SubDir OBOS_TOP src tests servers app scrolling ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +SimpleTest Scrolling : + main.cpp +# for running natively under R5: +# : be ; +# for running in the Haiku app_server under R5: + : libopenbeos.so ; +# for running on Haiku: +# : libbe.so ; + diff --git a/src/tests/servers/app/scrolling/NOTES b/src/tests/servers/app/scrolling/NOTES new file mode 100644 index 0000000000..1b144f5a46 --- /dev/null +++ b/src/tests/servers/app/scrolling/NOTES @@ -0,0 +1,3 @@ +For the test to run properly on BeOS, you need to make links to some Haiku libs in your ~/config/lib folder. The test itself links to libopenbeos.so, app_server additionally links to libappserver.so, libz.so, libpng.so and libfreetype.so. + +The script "run" launches the Haiku app_server and a second later the test app which connects to it. diff --git a/src/tests/servers/app/scrolling/main.cpp b/src/tests/servers/app/scrolling/main.cpp new file mode 100644 index 0000000000..ba6fbaae61 --- /dev/null +++ b/src/tests/servers/app/scrolling/main.cpp @@ -0,0 +1,137 @@ +// main.cpp + +#include + +#include "Application.h" +#include "Message.h" +#include "Button.h" +#include "View.h" +#include "Window.h" + +enum { + MSG_RESET = 'rset' +}; + +class TestView : public BView { + + public: + TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags) + : BView(frame, name, resizeFlags, flags), + fTracking(false), + fLastMousePos(0.0, 0.0) + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } + + virtual void MessageReceived(BMessage* message); + + virtual void Draw(BRect updateRect); + + virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); + + private: + bool fTracking; + + BPoint fLastMousePos; +}; + +// MessageReceived +void +TestView::MessageReceived(BMessage* message) +{ + if (message->what == MSG_RESET) + ScrollTo(0.0, 0.0); + else + BView::MessageReceived(message); +} + +// Draw +void +TestView::Draw(BRect updateRect) +{ + // ellipses + SetHighColor(200, 90, 0, 255); + StrokeEllipse(BPoint(80.0, 50.0), 70.0, 40.0); + + SetPenSize(2.0); + SetHighColor(20, 40, 180, 255); + StrokeEllipse(BPoint(230.0, 90.0), 14.0, 60.0); + + SetPenSize(5.0); + SetHighColor(60, 20, 110, 255); + StrokeEllipse(BPoint(100.0, 180.0), 35.0, 25.0); + + // text + SetHighColor(0, 0, 0, 255); + const char* message = "Click and drag to scroll this view!"; + DrawString(message, BPoint(0.0, 30.0)); +} + +// MouseDown +void +TestView::MouseDown(BPoint where) +{ + fTracking = true; + fLastMousePos = where; +} + +// MouseUp +void +TestView::MouseUp(BPoint where) +{ + fTracking = false; +} + +// MouseMoved +void +TestView::MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage) +{ + if (fTracking) { + BPoint offset = fLastMousePos - where; + ScrollBy(offset.x, offset.y); + fLastMousePos = where + offset; + } +} + + + +// show_window +void +show_window(BRect frame, const char* name) +{ + BWindow* window = new BWindow(frame, name, + B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE); + + BView* view = new TestView(window->Bounds(), "test", B_FOLLOW_ALL, + B_WILL_DRAW/* | B_FULL_UPDATE_ON_RESIZE*/); + + window->AddChild(view); + BRect b(0.0, 0.0, 60.0, 15.0); + b.OffsetTo(5.0, view->Bounds().bottom - (b.Height() + 15.0)); + BButton* control = new BButton(b, "button", "Reset", new BMessage(MSG_RESET)); + view->AddChild(control); + control->SetTarget(view); + + window->Show(); +} + +// main +int +main(int argc, char** argv) +{ + BApplication* app = new BApplication("application/x.vnd-Haiku.Scrolling"); + + BRect frame(50.0, 50.0, 300.0, 250.0); + show_window(frame, "Scrolling Test"); + + app->Run(); + + delete app; + return 0; +} diff --git a/src/tests/servers/app/scrolling/run b/src/tests/servers/app/scrolling/run new file mode 100755 index 0000000000..12d62d0c28 --- /dev/null +++ b/src/tests/servers/app/scrolling/run @@ -0,0 +1,5 @@ +#!/bin/sh + +../../../../../distro/x86.R1/beos/system/servers/app_server & +sleep 1s +../../../../../tests/servers/app/scrolling/Scrolling