From d662f7f4517d87934a3792535022086588ca4781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 1 Jul 2003 15:42:44 +0000 Subject: [PATCH] Implemented a very simple default media theme. You can't do anything yet, but you should already see most of the options. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3783 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/media/DefaultMediaTheme.cpp | 145 ++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/src/kits/media/DefaultMediaTheme.cpp b/src/kits/media/DefaultMediaTheme.cpp index b79f6aec9b..d11c16b047 100644 --- a/src/kits/media/DefaultMediaTheme.cpp +++ b/src/kits/media/DefaultMediaTheme.cpp @@ -9,6 +9,14 @@ #include +#include +#include +#include +#include +#include +#include +#include + using namespace BPrivate; @@ -24,6 +32,9 @@ BControl * DefaultMediaTheme::MakeControlFor(BParameter *parameter) { CALLED(); + + BRect rect(0, 0, 150, 100); + return MakeViewFor(parameter, &rect); } @@ -31,6 +42,41 @@ BView * DefaultMediaTheme::MakeViewFor(BParameterWeb *web, const BRect *hintRect) { CALLED(); + + if (web == NULL) + return NULL; + + BRect rect; + if (hintRect) + rect = *hintRect; + else + rect.Set(0, 0, 150, 100); + + BView *view = new BView(rect, "web", B_FOLLOW_ALL, B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + rect.OffsetTo(B_ORIGIN); + + for (int32 i = 0; i < web->CountGroups(); i++) { + BParameterGroup *group = web->GroupAt(i); + if (group == NULL) + continue; + + BView *groupView = MakeViewFor(group, &rect); + if (groupView == NULL) + continue; + + view->AddChild(groupView); + + rect.OffsetBy(0, groupView->Bounds().Height() + 5); + + if (groupView->Bounds().Width() + 5 > rect.Width()) + rect.right = groupView->Bounds().Width() - 1; + } + + view->ResizeTo(rect.right + 10, rect.top + 5); + + return view; } @@ -38,22 +84,117 @@ BView * DefaultMediaTheme::MakeViewFor(BParameterGroup *group, const BRect *hintRect) { CALLED(); + + BRect rect(*hintRect); + rect.InsetBySelf(5, 5); + + BBox *view = new BBox(rect, group->Name()); + view->SetLabel(group->Name()); + + // Add the sub-group views + + rect.OffsetTo(B_ORIGIN); + rect.InsetBySelf(5, 5); + rect.top += 10; // ToDo: font height + rect.right = rect.left + 100; + + for (int32 i = 0; i < group->CountGroups(); i++) { + BParameterGroup *subGroup = group->GroupAt(i); + if (subGroup == NULL) + continue; + + BView *groupView = MakeViewFor(subGroup, &rect); + if (groupView == NULL) + continue; + + view->AddChild(groupView); + + rect.OffsetBy(groupView->Bounds().Width() + 5, 0); + + if (groupView->Bounds().Height() > rect.Height()) + rect.bottom = groupView->Bounds().Height() - 1; + } + + view->ResizeTo(rect.left + 10, rect.bottom + 25); + rect.left = 5; + + // add the parameter views part of the group + + if (view->CountChildren() > 0) + rect.OffsetBy(0, rect.Height() + 5); + + for (int32 i = 0; i < group->CountParameters(); i++) { + BParameter *parameter = group->ParameterAt(i); + if (parameter == NULL) + continue; + + BControl *control = MakeViewFor(parameter, &rect); + if (control == NULL) + continue; + + view->AddChild(control); + + rect.OffsetBy(0, control->Bounds().Height() + 5); + + if (control->Bounds().Width() + 5 > rect.Width()) + rect.right = control->Bounds().Width() - 1; + } + + if (group->CountParameters() > 0) + view->ResizeTo(rect.right + 10, rect.top + 5); + + return view; } BControl * DefaultMediaTheme::MakeViewFor(BParameter *parameter, const BRect *hintRect) { + BRect rect; + if (hintRect) + rect = *hintRect; + else + rect.Set(0, 0, 150, 100); + switch (parameter->Type()) { case BParameter::B_NULL_PARAMETER: // there is no default view for a null parameter return NULL; case BParameter::B_DISCRETE_PARAMETER: - break; + { + BDiscreteParameter &discrete = static_cast(*parameter); + + if (discrete.CountItems() > 0) { + // create a pop up menu field + + BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(), discrete.Name(), NULL); + + for (int32 i = 0; i < discrete.CountItems(); i++) { + popUp->AddOption(discrete.ItemNameAt(i), discrete.ItemValueAt(i)); + } + + popUp->ResizeToPreferred(); + + return popUp; + } else { + // create a checkbox item + + BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(), discrete.Name(), NULL); + checkBox->ResizeToPreferred(); + + return checkBox; + } + } case BParameter::B_CONTINUOUS_PARAMETER: - break; + { + BSlider *slider = new BSlider(rect, parameter->Name(), parameter->Name(), + NULL, 0, 100); + slider->ResizeToPreferred(); + + return slider; + } default: ERROR("BMediaTheme: Don't know parameter type: 0x%lx\n", parameter->Type());