The current playground. Eventually, this will transform into the demo program.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12696 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0b6fe6d3a9
commit
53bb64e469
@ -5,8 +5,16 @@ UseHeaders [ FDirName os interface ] ;
|
|||||||
|
|
||||||
SimpleTest Window :
|
SimpleTest Window :
|
||||||
main.cpp
|
main.cpp
|
||||||
# for running in the Haiku app_server under R5:
|
;
|
||||||
: <boot!home!config!lib>libopenbeos.so ;
|
|
||||||
# for running natively under R5 or Haiku:
|
if ( $(TARGET_PLATFORM) = haiku ) {
|
||||||
# : libbe.so ;
|
# for running natively under R5 or Haiku:
|
||||||
|
LinkSharedOSLibs Window :
|
||||||
|
libbe.so ;
|
||||||
|
} else {
|
||||||
|
# for running in the Haiku app_server under R5:
|
||||||
|
LinkSharedOSLibs Window :
|
||||||
|
<boot!home!config!lib>libopenbeos.so ;
|
||||||
|
# be ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <RadioButton.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
@ -18,97 +19,162 @@
|
|||||||
class HelloView : public BView {
|
class HelloView : public BView {
|
||||||
public:
|
public:
|
||||||
HelloView(BRect frame, const char* name,
|
HelloView(BRect frame, const char* name,
|
||||||
uint32 resizeFlags, uint32 flags)
|
uint32 resizeFlags, uint32 flags);
|
||||||
: BView(frame, name, resizeFlags, flags),
|
|
||||||
fTracking(false),
|
|
||||||
fTrackingStart(-1.0, -1.0),
|
|
||||||
fLastMousePos(-1.0, -1.0)
|
|
||||||
{
|
|
||||||
// TODO: Find bug: this influences StringWidth(), but the font is not used
|
|
||||||
// SetFontSize(9);
|
|
||||||
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
SetViewColor(bg);
|
|
||||||
SetLowColor(bg);
|
|
||||||
|
|
||||||
BFont font;
|
virtual void AttachedToWindow();
|
||||||
GetFont(&font);
|
|
||||||
BString string("ß amM öo\t");
|
|
||||||
int32 charCount = string.CountChars();
|
|
||||||
float* escapements = new float[charCount];
|
|
||||||
font.GetEscapements(string.String(), charCount, NULL, escapements);
|
|
||||||
for (int32 i = 0; i < charCount; i++)
|
|
||||||
printf("escapement: %.3f\n", escapements[i]);
|
|
||||||
delete[] escapements;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect)
|
virtual void Draw(BRect updateRect);
|
||||||
{
|
|
||||||
rgb_color shadow = tint_color(LowColor(), B_DARKEN_2_TINT);
|
|
||||||
rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT);
|
|
||||||
|
|
||||||
BRect r(Bounds());
|
virtual void FrameMoved(BPoint were);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
|
||||||
BeginLineArray(4);
|
virtual void MouseDown(BPoint where);
|
||||||
AddLine(BPoint(r.left, r.top),
|
virtual void MouseUp(BPoint where);
|
||||||
BPoint(r.right, r.top), shadow);
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||||
AddLine(BPoint(r.right, r.top + 1),
|
const BMessage* dragMessage);
|
||||||
BPoint(r.right, r.bottom), light);
|
|
||||||
AddLine(BPoint(r.right - 1, r.bottom),
|
|
||||||
BPoint(r.left, r.bottom), light);
|
|
||||||
AddLine(BPoint(r.left, r.bottom - 1),
|
|
||||||
BPoint(r.left, r.top + 1), shadow);
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
SetHighColor(255, 0, 0, 128);
|
|
||||||
|
|
||||||
const char* message = "Click and drag";
|
|
||||||
float 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 a line!";
|
|
||||||
width = StringWidth(message);
|
|
||||||
p.x = r.left + r.Width() / 2.0 - width / 2.0;
|
|
||||||
p.y += 20;
|
|
||||||
|
|
||||||
DrawString(message, p);
|
|
||||||
|
|
||||||
// SetDrawingMode(B_OP_OVER);
|
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
|
||||||
SetPenSize(10.0);
|
|
||||||
SetHighColor(0, 80, 255, 100);
|
|
||||||
StrokeLine(fTrackingStart, fLastMousePos);
|
|
||||||
// TODO: this should not be necessary with proper state stack
|
|
||||||
// (a new state is pushed before Draw() is called)
|
|
||||||
SetDrawingMode(B_OP_COPY);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MouseDown(BPoint where)
|
|
||||||
{
|
|
||||||
fTracking = true;
|
|
||||||
fTrackingStart = fLastMousePos = where;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MouseUp(BPoint where)
|
|
||||||
{
|
|
||||||
fTracking = false;
|
|
||||||
}
|
|
||||||
virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|
||||||
{
|
|
||||||
if (fTracking) {
|
|
||||||
fLastMousePos = where;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
bool fTracking;
|
bool fTracking;
|
||||||
BPoint fTrackingStart;
|
BPoint fTrackingStart;
|
||||||
BPoint fLastMousePos;
|
BPoint fLastMousePos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
HelloView::HelloView(BRect frame, const char* name,
|
||||||
|
uint32 resizeFlags, uint32 flags)
|
||||||
|
: BView(frame, name, resizeFlags, flags | B_FRAME_EVENTS),
|
||||||
|
fTracking(false),
|
||||||
|
fTrackingStart(-1.0, -1.0),
|
||||||
|
fLastMousePos(-1.0, -1.0)
|
||||||
|
{
|
||||||
|
// TODO: Find bug: this influences StringWidth(), but the font is not used
|
||||||
|
// SetFontSize(9);
|
||||||
|
rgb_color bg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT);
|
||||||
|
SetViewColor(bg);
|
||||||
|
SetLowColor(bg);
|
||||||
|
|
||||||
|
BFont font;
|
||||||
|
GetFont(&font);
|
||||||
|
BString string("ß amM öo\t");
|
||||||
|
int32 charCount = string.CountChars();
|
||||||
|
float* escapements = new float[charCount];
|
||||||
|
escapement_delta dummy;
|
||||||
|
dummy.space = 0.0;
|
||||||
|
dummy.nonspace = 0.0;
|
||||||
|
font.GetEscapements(string.String(), charCount, &dummy, escapements);
|
||||||
|
for (int32 i = 0; i < charCount; i++)
|
||||||
|
printf("escapement: %.3f\n", escapements[i]);
|
||||||
|
delete[] escapements;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AttachedToWindow
|
||||||
|
void
|
||||||
|
HelloView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
void
|
||||||
|
HelloView::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
rgb_color shadow = tint_color(noTint, B_DARKEN_2_TINT);
|
||||||
|
rgb_color light = tint_color(noTint, B_LIGHTEN_MAX_TINT);
|
||||||
|
|
||||||
|
BRect r(Bounds());
|
||||||
|
|
||||||
|
BeginLineArray(4);
|
||||||
|
AddLine(BPoint(r.left, r.top),
|
||||||
|
BPoint(r.right, r.top), shadow);
|
||||||
|
AddLine(BPoint(r.right, r.top + 1),
|
||||||
|
BPoint(r.right, r.bottom), light);
|
||||||
|
AddLine(BPoint(r.right - 1, r.bottom),
|
||||||
|
BPoint(r.left, r.bottom), light);
|
||||||
|
AddLine(BPoint(r.left, r.bottom - 1),
|
||||||
|
BPoint(r.left, r.top + 1), shadow);
|
||||||
|
EndLineArray();
|
||||||
|
|
||||||
|
SetHighColor(255, 0, 0, 128);
|
||||||
|
|
||||||
|
const char* message = "Click and drag";
|
||||||
|
float 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 a line!";
|
||||||
|
width = StringWidth(message);
|
||||||
|
p.x = r.left + r.Width() / 2.0 - width / 2.0;
|
||||||
|
p.y += 20;
|
||||||
|
|
||||||
|
DrawString(message, p);
|
||||||
|
|
||||||
|
// SetDrawingMode(B_OP_OVER);
|
||||||
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
SetPenSize(10.0);
|
||||||
|
SetHighColor(0, 80, 255, 100);
|
||||||
|
StrokeLine(fTrackingStart, fLastMousePos);
|
||||||
|
// TODO: this should not be necessary with proper state stack
|
||||||
|
// (a new state is pushed before Draw() is called)
|
||||||
|
SetDrawingMode(B_OP_COPY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FrameMoved
|
||||||
|
void
|
||||||
|
HelloView::FrameMoved(BPoint were)
|
||||||
|
{
|
||||||
|
printf("HelloView::FrameMoved()\n");
|
||||||
|
if (Window()) {
|
||||||
|
Window()->CurrentMessage()->PrintToStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FrameResized
|
||||||
|
void
|
||||||
|
HelloView::FrameResized(float width, float height)
|
||||||
|
{
|
||||||
|
printf("HelloView::FrameResized()\n");
|
||||||
|
if (Window()) {
|
||||||
|
Window()->CurrentMessage()->PrintToStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MouseDown
|
||||||
|
void
|
||||||
|
HelloView::MouseDown(BPoint where)
|
||||||
|
{
|
||||||
|
fTracking = true;
|
||||||
|
fTrackingStart = fLastMousePos = where;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// MouseUp
|
||||||
|
void
|
||||||
|
HelloView::MouseUp(BPoint where)
|
||||||
|
{
|
||||||
|
fTracking = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MouseMoved
|
||||||
|
void
|
||||||
|
HelloView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
||||||
|
{
|
||||||
|
if (fTracking) {
|
||||||
|
BRect invalidBefore(min_c(fTrackingStart.x, fLastMousePos.x),
|
||||||
|
min_c(fTrackingStart.y, fLastMousePos.y),
|
||||||
|
max_c(fTrackingStart.x, fLastMousePos.x),
|
||||||
|
max_c(fTrackingStart.y, fLastMousePos.y));
|
||||||
|
fLastMousePos = where;
|
||||||
|
BRect invalidAfter(min_c(fTrackingStart.x, fLastMousePos.x),
|
||||||
|
min_c(fTrackingStart.y, fLastMousePos.y),
|
||||||
|
max_c(fTrackingStart.x, fLastMousePos.x),
|
||||||
|
max_c(fTrackingStart.y, fLastMousePos.y));
|
||||||
|
BRect invalid(invalidBefore | invalidAfter);
|
||||||
|
invalid.InsetBy(-10.0, -10.0);
|
||||||
|
Invalidate(invalid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// show_window
|
// show_window
|
||||||
void
|
void
|
||||||
@ -143,28 +209,50 @@ show_window(BRect frame, const char* name)
|
|||||||
window->AddChild(bg);
|
window->AddChild(bg);
|
||||||
|
|
||||||
b = bg->Bounds();
|
b = bg->Bounds();
|
||||||
b.InsetBy(5.0, 5.0);
|
// occupy the right side of the window
|
||||||
|
b.Set((b.left + b.right) / 2.0 + 3.0, b.top + 5.0, b.right - 5.0, b.bottom - 5.0);
|
||||||
BView* view = new HelloView(b, "hello view", B_FOLLOW_ALL,
|
BView* view = new HelloView(b, "hello view", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
||||||
|
|
||||||
bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
bg->AddChild(view);
|
bg->AddChild(view);
|
||||||
|
|
||||||
|
b = bg->Bounds();
|
||||||
|
// occupy the left side of the window
|
||||||
|
b.Set(b.left + 5.0, b.top + 5.0, (b.left + b.right) / 2.0 - 2.0, b.bottom - 5.0);
|
||||||
|
BBox* controlGroup = new BBox(b, "controls box", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
|
||||||
|
B_WILL_DRAW, B_FANCY_BORDER);
|
||||||
|
|
||||||
|
controlGroup->SetLabel("Controls");
|
||||||
|
bg->AddChild(controlGroup);
|
||||||
|
|
||||||
|
b = controlGroup->Bounds();
|
||||||
|
b.top += 15.0;
|
||||||
|
b.bottom = b.top + 25.0;
|
||||||
|
b.InsetBy(5.0, 5.0);
|
||||||
|
BRadioButton* radioButton1 = new BRadioButton(b, "radio 1", "Choice One", NULL);
|
||||||
|
controlGroup->AddChild(radioButton1);
|
||||||
|
|
||||||
|
b.OffsetBy(0, radioButton1->Bounds().Height() + 5.0);
|
||||||
|
BRadioButton* radioButton2 = new BRadioButton(b, "radio 2", "Choice Two", NULL);
|
||||||
|
controlGroup->AddChild(radioButton2);
|
||||||
|
|
||||||
|
b.OffsetBy(0, radioButton2->Bounds().Height() + 5.0);
|
||||||
|
BRadioButton* radioButton3 = new BRadioButton(b, "radio 3", "Choice Three", NULL);
|
||||||
|
controlGroup->AddChild(radioButton3);
|
||||||
|
|
||||||
|
radioButton1->SetValue(B_CONTROL_ON);
|
||||||
|
|
||||||
// button
|
// button
|
||||||
b.Set(0.0, 0.0, 80.0, 13.0);
|
b.OffsetBy(0, radioButton3->Bounds().Height() + 5.0);
|
||||||
b.OffsetTo(5.0, 5.0);
|
|
||||||
BButton* button = new BButton(b, "button", "Button", NULL);
|
BButton* button = new BButton(b, "button", "Button", NULL);
|
||||||
view->AddChild(button);
|
controlGroup->AddChild(button);
|
||||||
//button->MoveTo(5.0, 5.0);
|
|
||||||
|
|
||||||
// text control
|
// text control
|
||||||
b.left = button->Frame().left;
|
b.OffsetBy(0, button->Bounds().Height() + 5.0);
|
||||||
b.top = button->Frame().bottom + 5.0;
|
|
||||||
b.bottom = b.top + 35.0;
|
|
||||||
b.right += 50.0;
|
|
||||||
BTextControl* textControl = new BTextControl(b, "text control", "Text", "<enter text here>", NULL);
|
BTextControl* textControl = new BTextControl(b, "text control", "Text", "<enter text here>", NULL);
|
||||||
textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 10.0);
|
textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 10.0);
|
||||||
view->AddChild(textControl);
|
controlGroup->AddChild(textControl);
|
||||||
|
|
||||||
/* BRect textRect(b);
|
/* BRect textRect(b);
|
||||||
textRect.OffsetTo(0.0, 0.0);
|
textRect.OffsetTo(0.0, 0.0);
|
||||||
@ -175,10 +263,9 @@ show_window(BRect frame, const char* name)
|
|||||||
textView->MakeFocus(true);*/
|
textView->MakeFocus(true);*/
|
||||||
|
|
||||||
// check box
|
// check box
|
||||||
// b.OffsetTo(5.0, view->Bounds().bottom - (b.Height() + 5.0));
|
b.OffsetBy(0, textControl->Bounds().Height() + 5.0);
|
||||||
BCheckBox* checkBox = new BCheckBox(b, "check box", "CheckBox", NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
BCheckBox* checkBox = new BCheckBox(b, "check box", "CheckBox", NULL);
|
||||||
view->AddChild(checkBox);
|
controlGroup->AddChild(checkBox);
|
||||||
checkBox->MoveTo(5.0, view->Bounds().bottom - (b.Height() + 10.0));
|
|
||||||
|
|
||||||
// window->MoveTo(frame.left, frame.top);
|
// window->MoveTo(frame.left, frame.top);
|
||||||
window->Show();
|
window->Show();
|
||||||
@ -190,10 +277,10 @@ main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
BApplication* app = new BApplication("application/x.vnd-Haiku.windows_test");
|
BApplication* app = new BApplication("application/x.vnd-Haiku.windows_test");
|
||||||
|
|
||||||
BRect frame(50.0, 50.0, 200.0, 250.0);
|
BRect frame(80.0, 100.0, 450.0, 400.0);
|
||||||
show_window(frame, "Window #1");
|
show_window(frame, "Playground");
|
||||||
|
|
||||||
// frame.Set(80.0, 100.0, 350.0, 300.0);
|
// frame.Set(50.0, 50.0, 200.0, 250.0);
|
||||||
// show_window(frame, "Window #2");
|
// show_window(frame, "Window #2");
|
||||||
|
|
||||||
app->Run();
|
app->Run();
|
||||||
|
Loading…
Reference in New Issue
Block a user