FontDemo: convert to layout code.

Fixes #9241.
This commit is contained in:
Adrien Destugues
2014-11-27 17:49:22 +01:00
parent f448e83bdd
commit 344180b745
3 changed files with 39 additions and 63 deletions
+29 -56
View File
@@ -18,6 +18,7 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Messenger.h> #include <Messenger.h>
#include <PopUpMenu.h>
#include <Slider.h> #include <Slider.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
@@ -28,8 +29,8 @@
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ControlView" #define B_TRANSLATION_CONTEXT "ControlView"
ControlView::ControlView(BRect rect) ControlView::ControlView()
: BView(rect, "ControlView", B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE_JUMP), : BGroupView("ControlView", B_VERTICAL),
fMessenger(NULL), fMessenger(NULL),
fMessageRunner(NULL), fMessageRunner(NULL),
fTextControl(NULL), fTextControl(NULL),
@@ -48,6 +49,7 @@ ControlView::ControlView(BRect rect)
fFontStyleindex(0) fFontStyleindex(0)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
GroupLayout()->SetInsets(B_USE_WINDOW_SPACING);
} }
@@ -61,77 +63,54 @@ ControlView::~ControlView()
void void
ControlView::AttachedToWindow() ControlView::AttachedToWindow()
{ {
BRect rect(Bounds()); fTextControl = new BTextControl("TextInput", B_TRANSLATE("Text:"),
rect.InsetBySelf(10, 0);
rect.bottom = rect.top + 18;
rect.OffsetBy(0, 11);
float offsetX = 0;
float offsetY = 0;
fTextControl = new BTextControl(rect, "TextInput", B_TRANSLATE("Text:"),
B_TRANSLATE("Haiku, Inc."), NULL); B_TRANSLATE("Haiku, Inc."), NULL);
fTextControl->SetDivider(36.0);
fTextControl->SetModificationMessage(new BMessage(TEXT_CHANGED_MSG)); fTextControl->SetModificationMessage(new BMessage(TEXT_CHANGED_MSG));
AddChild(fTextControl); AddChild(fTextControl);
rect.OffsetBy(0.0, 27.0); _AddFontMenu();
_AddFontMenu(rect);
rect.OffsetBy(0.0, 36.0); fFontsizeSlider = new BSlider("Fontsize", B_TRANSLATE("Size: 50"),
fFontsizeSlider = new BSlider(rect, "Fontsize", B_TRANSLATE("Size: 50"), NULL, 4, 360, B_HORIZONTAL);
NULL, 4, 360);
fFontsizeSlider->SetModificationMessage(new BMessage(FONTSIZE_MSG)); fFontsizeSlider->SetModificationMessage(new BMessage(FONTSIZE_MSG));
fFontsizeSlider->SetValue(50); fFontsizeSlider->SetValue(50);
AddChild(fFontsizeSlider); AddChild(fFontsizeSlider);
// Get the preferred size for the sliders fShearSlider = new BSlider("Shear", B_TRANSLATE("Shear: 90"), NULL,
fFontsizeSlider->GetPreferredSize(&offsetY, &offsetX); 45, 135, B_HORIZONTAL);
offsetX += 1;
rect.OffsetBy(0.0, offsetX);
fShearSlider = new BSlider(rect, "Shear", B_TRANSLATE("Shear: 90"), NULL,
45, 135);
fShearSlider->SetModificationMessage(new BMessage(FONTSHEAR_MSG)); fShearSlider->SetModificationMessage(new BMessage(FONTSHEAR_MSG));
fShearSlider->SetValue(90); fShearSlider->SetValue(90);
AddChild(fShearSlider); AddChild(fShearSlider);
rect.OffsetBy(0.0, offsetX); fRotationSlider = new BSlider("Rotation", B_TRANSLATE("Rotation: 0"),
fRotationSlider = new BSlider(rect, "Rotation", B_TRANSLATE("Rotation: 0"), NULL, 0, 360, B_HORIZONTAL);
NULL, 0, 360);
fRotationSlider->SetModificationMessage( new BMessage(ROTATION_MSG)); fRotationSlider->SetModificationMessage( new BMessage(ROTATION_MSG));
fRotationSlider->SetValue(0); fRotationSlider->SetValue(0);
AddChild(fRotationSlider); AddChild(fRotationSlider);
rect.OffsetBy(0.0, offsetX); fSpacingSlider = new BSlider("Spacing", B_TRANSLATE("Spacing: 0"),
fSpacingSlider = new BSlider(rect, "Spacing", B_TRANSLATE("Spacing: 0"), NULL, -5, 50, B_HORIZONTAL);
NULL, -5, 50);
fSpacingSlider->SetModificationMessage(new BMessage(SPACING_MSG)); fSpacingSlider->SetModificationMessage(new BMessage(SPACING_MSG));
fSpacingSlider->SetValue(0); fSpacingSlider->SetValue(0);
AddChild(fSpacingSlider); AddChild(fSpacingSlider);
rect.OffsetBy(0.0, offsetX); fOutlineSlider = new BSlider("Outline", B_TRANSLATE("Outline:"),
fOutlineSlider = new BSlider(rect, "Outline", B_TRANSLATE("Outline:"), NULL, 0, 20, B_HORIZONTAL);
NULL, 0, 20);
fOutlineSlider->SetModificationMessage(new BMessage(OUTLINE_MSG)); fOutlineSlider->SetModificationMessage(new BMessage(OUTLINE_MSG));
AddChild(fOutlineSlider); AddChild(fOutlineSlider);
rect.OffsetBy(0.0, offsetX); fAliasingCheckBox = new BCheckBox("Aliasing",
fAliasingCheckBox = new BCheckBox(rect, "Aliasing",
B_TRANSLATE("Antialiased text"), new BMessage(ALIASING_MSG)); B_TRANSLATE("Antialiased text"), new BMessage(ALIASING_MSG));
fAliasingCheckBox->SetValue(B_CONTROL_ON); fAliasingCheckBox->SetValue(B_CONTROL_ON);
AddChild(fAliasingCheckBox); AddChild(fAliasingCheckBox);
rect.OffsetBy(0.0, 30.0f); _AddDrawingModeMenu();
_AddDrawingModeMenu(rect);
rect.OffsetBy(0.0, 30.0f); fBoundingboxesCheckBox = new BCheckBox("BoundingBoxes",
fBoundingboxesCheckBox = new BCheckBox(rect, "BoundingBoxes",
B_TRANSLATE("Bounding boxes"), new BMessage(BOUNDING_BOX_MSG)); B_TRANSLATE("Bounding boxes"), new BMessage(BOUNDING_BOX_MSG));
AddChild(fBoundingboxesCheckBox); AddChild(fBoundingboxesCheckBox);
rect.OffsetBy(0.0, 30.0f); fCyclingFontButton = new BButton("Cyclefonts",
fCyclingFontButton = new BButton(rect, "Cyclefonts",
B_TRANSLATE("Cycle fonts"), new BMessage(CYCLING_FONTS_MSG)); B_TRANSLATE("Cycle fonts"), new BMessage(CYCLING_FONTS_MSG));
AddChild(fCyclingFontButton); AddChild(fCyclingFontButton);
@@ -378,7 +357,7 @@ ControlView::_UpdateFontmenus(bool setInitialfont)
for (int32 i = 0; i < fontfamilies; i++) { for (int32 i = 0; i < fontfamilies; i++) {
if (get_font_family(i, &fontFamilyName) == B_OK) { if (get_font_family(i, &fontFamilyName) == B_OK) {
stylemenu = new BMenu(fontFamilyName); stylemenu = new BPopUpMenu(fontFamilyName);
const int32 styles = count_font_styles(fontFamilyName); const int32 styles = count_font_styles(fontFamilyName);
BMessage* familyMsg = new BMessage(FONTFAMILY_CHANGED_MSG); BMessage* familyMsg = new BMessage(FONTFAMILY_CHANGED_MSG);
@@ -422,25 +401,22 @@ ControlView::_UpdateFontmenus(bool setInitialfont)
void void
ControlView::_AddFontMenu(BRect rect) ControlView::_AddFontMenu()
{ {
fFontFamilyMenu = new BMenu("fontfamlilymenu"); fFontFamilyMenu = new BPopUpMenu("fontfamlilymenu");
_UpdateFontmenus(true); _UpdateFontmenus(true);
rect.bottom += 4; fFontMenuField = new BMenuField("FontMenuField",
fFontMenuField = new BMenuField(rect, "FontMenuField", B_TRANSLATE("Font:"), fFontFamilyMenu);
B_TRANSLATE("Font:"), fFontFamilyMenu, true);
fFontMenuField->SetDivider(
fFontMenuField->StringWidth(B_TRANSLATE("Font:")) + 5);
AddChild(fFontMenuField); AddChild(fFontMenuField);
} }
void void
ControlView::_AddDrawingModeMenu(BRect rect) ControlView::_AddDrawingModeMenu()
{ {
fDrawingModeMenu = new BMenu("drawingmodemenu"); fDrawingModeMenu = new BPopUpMenu("drawingmodemenu");
BMessage* drawingMsg = NULL; BMessage* drawingMsg = NULL;
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG); drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
@@ -480,11 +456,8 @@ ControlView::_AddDrawingModeMenu(BRect rect)
fDrawingModeMenu->SetLabelFromMarked(true); fDrawingModeMenu->SetLabelFromMarked(true);
rect.bottom += 4; BMenuField* drawingModeMenuField = new BMenuField("FontMenuField",
BMenuField* drawingModeMenuField = new BMenuField(rect, "FontMenuField", B_TRANSLATE("Drawing mode:"), fDrawingModeMenu);
B_TRANSLATE("Drawing mode:"), fDrawingModeMenu, true);
drawingModeMenuField->SetDivider(
fDrawingModeMenu->StringWidth(B_TRANSLATE("Drawing mode:") + 5));
AddChild(drawingModeMenuField); AddChild(drawingModeMenuField);
} }
+5 -5
View File
@@ -9,7 +9,7 @@
#define CONTROL_VIEW_H #define CONTROL_VIEW_H
#include <View.h> #include <GroupView.h>
class BButton; class BButton;
@@ -24,9 +24,9 @@ class BSlider;
class BTextControl; class BTextControl;
class ControlView : public BView { class ControlView : public BGroupView {
public: public:
ControlView(BRect rect); ControlView();
virtual ~ControlView(); virtual ~ControlView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
@@ -35,8 +35,8 @@ class ControlView : public BView {
void SetTarget(BHandler* handler); void SetTarget(BHandler* handler);
private: private:
void _AddFontMenu(BRect rect); void _AddFontMenu();
void _AddDrawingModeMenu(BRect rect); void _AddDrawingModeMenu();
void _UpdateFontmenus(bool setInitialfont = false); void _UpdateFontmenus(bool setInitialfont = false);
void _DeselectOldItems(); void _DeselectOldItems();
+5 -2
View File
@@ -12,6 +12,7 @@
#include "FontDemoView.h" #include "FontDemoView.h"
#include <Catalog.h> #include <Catalog.h>
#include <GroupLayout.h>
#include <Window.h> #include <Window.h>
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -31,9 +32,11 @@ FontDemo::FontDemo()
BWindow* controlWindow = new BWindow(BRect(500, 30, 700, 420), B_TRANSLATE("Controls"), BWindow* controlWindow = new BWindow(BRect(500, 30, 700, 420), B_TRANSLATE("Controls"),
B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL, B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS); B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS);
ControlView* controlView = new ControlView(controlWindow->Bounds()); ControlView* controlView = new ControlView();
controlWindow->SetLayout(new BGroupLayout(B_VERTICAL));
controlWindow->AddChild(controlView); controlWindow->AddChild(controlView);
controlView->SetTarget(demoView); controlView->SetTarget(demoView);