From 357966447d0eb9560dc5477cd8654c246eae2a8f Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 14 Aug 2013 23:29:27 +0200 Subject: [PATCH] More UI --- ui/ui_screen.cpp | 18 ++++++++++++++---- ui/ui_screen.h | 4 ++++ ui/view.cpp | 5 +++++ ui/view.h | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index 9e315c0e8e..ec6bc3f468 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -116,13 +116,13 @@ void PopupScreen::CreateViews() { root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); LinearLayout *box = new LinearLayout(ORIENT_VERTICAL, - new AnchorLayoutParams(450, FillVertical() ? dp_yres - 30 : WRAP_CONTENT, dp_xres / 2, dp_yres / 2, NONE, NONE, true)); + new AnchorLayoutParams(550, FillVertical() ? dp_yres - 30 : WRAP_CONTENT, dp_xres / 2, dp_yres / 2, NONE, NONE, true)); root_->Add(box); box->SetBG(UI::Drawable(0xFF303030)); box->SetHasDropShadow(true); - View *title = new ItemHeader(title_); + View *title = new PopupHeader(title_); box->Add(title); CreatePopupContents(box); @@ -170,10 +170,20 @@ void ListPopupScreen::OnCompleted() { void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; - slider_ = parent->Add(new Slider(value_, minValue_, maxValue_, new LinearLayoutParams(UI::Margins(10, 5)))); + sliderValue_ = *value_; + slider_ = parent->Add(new Slider(&sliderValue_, minValue_, maxValue_, new LinearLayoutParams(UI::Margins(10, 5)))); } void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; - slider_ = parent->Add(new SliderFloat(value_, minValue_, maxValue_)); + sliderValue_ = *value_; + slider_ = parent->Add(new SliderFloat(&sliderValue_, minValue_, maxValue_)); +} + +void SliderPopupScreen::OnCompleted() { + *value_ = sliderValue_; +} + +void SliderFloatPopupScreen::OnCompleted() { + *value_ = sliderValue_; } diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 430ffca612..39bad3d894 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -86,8 +86,10 @@ public: void CreatePopupContents(UI::ViewGroup *parent); private: + virtual void OnCompleted(); UI::Slider *slider_; int *value_; + int sliderValue_; int minValue_; int maxValue_; }; @@ -98,7 +100,9 @@ public: void CreatePopupContents(UI::ViewGroup *parent); private: + virtual void OnCompleted(); UI::SliderFloat *slider_; + float sliderValue_; float *value_; float minValue_; float maxValue_; diff --git a/ui/view.cpp b/ui/view.cpp index b0e5a32cd2..fa2154e297 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -320,6 +320,11 @@ void ItemHeader::Draw(UIContext &dc) { dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), 0xFFFFFFFF); } +void PopupHeader::Draw(UIContext &dc) { + dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 12, bounds_.centerY(), dc.theme->popupTitle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), 0xFFFFFFFF); +} + void CheckBox::Draw(UIContext &dc) { ClickableItem::Draw(dc); int paddingX = 8; diff --git a/ui/view.h b/ui/view.h index 58fb9f3cb4..5a40bacf9a 100644 --- a/ui/view.h +++ b/ui/view.h @@ -91,6 +91,8 @@ struct Theme { Style itemStyle; Style itemDownStyle; Style itemFocusedStyle; + + Style popupTitle; }; // The four cardinal directions should be enough, plus Prev/Next in "element order". @@ -530,6 +532,18 @@ private: std::string text_; }; +class PopupHeader : public Item { +public: + PopupHeader(const std::string &text, LayoutParams *layoutParams = 0) + : Item(layoutParams), text_(text) { + layoutParams_->width = FILL_PARENT; + layoutParams_->height = 64; + } + virtual void Draw(UIContext &dc); +private: + std::string text_; +}; + class CheckBox : public ClickableItem { public: CheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0)