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
This commit is contained in:
@@ -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 ;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ;
|
||||
|
||||
@@ -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.
|
||||
@@ -0,0 +1,137 @@
|
||||
// main.cpp
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
../../../../../distro/x86.R1/beos/system/servers/app_server &
|
||||
sleep 1s
|
||||
../../../../../tests/servers/app/scrolling/Scrolling
|
||||
Reference in New Issue
Block a user