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:
@@ -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,15 +19,36 @@
|
|||||||
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);
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
|
virtual void FrameMoved(BPoint were);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
|
||||||
|
virtual void MouseDown(BPoint where);
|
||||||
|
virtual void MouseUp(BPoint where);
|
||||||
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||||
|
const BMessage* dragMessage);
|
||||||
|
private:
|
||||||
|
bool fTracking;
|
||||||
|
BPoint fTrackingStart;
|
||||||
|
BPoint fLastMousePos;
|
||||||
|
};
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
HelloView::HelloView(BRect frame, const char* name,
|
||||||
uint32 resizeFlags, uint32 flags)
|
uint32 resizeFlags, uint32 flags)
|
||||||
: BView(frame, name, resizeFlags, flags),
|
: BView(frame, name, resizeFlags, flags | B_FRAME_EVENTS),
|
||||||
fTracking(false),
|
fTracking(false),
|
||||||
fTrackingStart(-1.0, -1.0),
|
fTrackingStart(-1.0, -1.0),
|
||||||
fLastMousePos(-1.0, -1.0)
|
fLastMousePos(-1.0, -1.0)
|
||||||
{
|
{
|
||||||
// TODO: Find bug: this influences StringWidth(), but the font is not used
|
// TODO: Find bug: this influences StringWidth(), but the font is not used
|
||||||
// SetFontSize(9);
|
// SetFontSize(9);
|
||||||
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
|
rgb_color bg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT);
|
||||||
SetViewColor(bg);
|
SetViewColor(bg);
|
||||||
SetLowColor(bg);
|
SetLowColor(bg);
|
||||||
|
|
||||||
@@ -35,16 +57,28 @@ class HelloView : public BView {
|
|||||||
BString string("ß amM öo\t");
|
BString string("ß amM öo\t");
|
||||||
int32 charCount = string.CountChars();
|
int32 charCount = string.CountChars();
|
||||||
float* escapements = new float[charCount];
|
float* escapements = new float[charCount];
|
||||||
font.GetEscapements(string.String(), charCount, NULL, escapements);
|
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++)
|
for (int32 i = 0; i < charCount; i++)
|
||||||
printf("escapement: %.3f\n", escapements[i]);
|
printf("escapement: %.3f\n", escapements[i]);
|
||||||
delete[] escapements;
|
delete[] escapements;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect)
|
// AttachedToWindow
|
||||||
{
|
void
|
||||||
rgb_color shadow = tint_color(LowColor(), B_DARKEN_2_TINT);
|
HelloView::AttachedToWindow()
|
||||||
rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT);
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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());
|
BRect r(Bounds());
|
||||||
|
|
||||||
@@ -83,31 +117,63 @@ SetPenSize(10.0);
|
|||||||
// TODO: this should not be necessary with proper state stack
|
// TODO: this should not be necessary with proper state stack
|
||||||
// (a new state is pushed before Draw() is called)
|
// (a new state is pushed before Draw() is called)
|
||||||
SetDrawingMode(B_OP_COPY);
|
SetDrawingMode(B_OP_COPY);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void MouseDown(BPoint where)
|
// 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;
|
fTracking = true;
|
||||||
fTrackingStart = fLastMousePos = where;
|
fTrackingStart = fLastMousePos = where;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void MouseUp(BPoint where)
|
// MouseUp
|
||||||
{
|
void
|
||||||
|
HelloView::MouseUp(BPoint where)
|
||||||
|
{
|
||||||
fTracking = false;
|
fTracking = false;
|
||||||
}
|
}
|
||||||
virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|
||||||
{
|
// MouseMoved
|
||||||
|
void
|
||||||
|
HelloView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
||||||
|
{
|
||||||
if (fTracking) {
|
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;
|
fLastMousePos = where;
|
||||||
Invalidate();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
bool fTracking;
|
|
||||||
BPoint fTrackingStart;
|
|
||||||
BPoint fLastMousePos;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// show_window
|
// show_window
|
||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user