diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index c739305bed..090f250730 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -99,24 +99,36 @@ UI::EventReturn UIScreen::OnBack(UI::EventParams &e) { } PopupScreen::PopupScreen(std::string title, std::string button1, std::string button2) - : title_(title), button1_(button1), button2_(button2) {} + : title_(title), button1_(button1), button2_(button2), box_(0) {} + +void PopupScreen::touch(const TouchInput &touch) { + if (!box_ || (touch.flags & TOUCH_DOWN) == 0 || touch.id != 0) { + UIDialogScreen::touch(touch); + return; + } + + if (!box_->GetBounds().Contains(touch.x, touch.y)) + screenManager()->finishDialog(this, DR_CANCEL); + + UIDialogScreen::touch(touch); +} void PopupScreen::CreateViews() { using namespace UI; root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); - LinearLayout *box = new LinearLayout(ORIENT_VERTICAL, + box_ = new LinearLayout(ORIENT_VERTICAL, 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); + root_->Add(box_); + box_->SetBG(UI::Drawable(0xFF303030)); + box_->SetHasDropShadow(true); View *title = new PopupHeader(title_); - box->Add(title); + box_->Add(title); - CreatePopupContents(box); + CreatePopupContents(box_); if (ShowButtons()) { // And the two buttons at the bottom. @@ -135,7 +147,7 @@ void PopupScreen::CreateViews() { buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK); #endif - box->Add(buttonRow); + box_->Add(buttonRow); } } diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 83456dad4d..e4eee000a8 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -45,6 +45,7 @@ public: virtual void CreatePopupContents(UI::ViewGroup *parent) = 0; virtual void CreateViews(); virtual bool isTransparent() { return true; } + virtual void touch(const TouchInput &touch); protected: virtual bool FillVertical() { return false; } @@ -55,6 +56,7 @@ private: UI::EventReturn OnOK(UI::EventParams &e); UI::EventReturn OnCancel(UI::EventParams &e); + UI::ViewGroup *box_; std::string title_; std::string button1_; std::string button2_; diff --git a/ui/view.cpp b/ui/view.cpp index 3c00098ed6..210c5a364c 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -297,7 +297,18 @@ void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const } void Choice::Draw(UIContext &dc) { - ClickableItem::Draw(dc); + if (!IsSticky()) { + ClickableItem::Draw(dc); + } else { + Style style = dc.theme->itemStyle; + if (down_) { + style = dc.theme->itemDownStyle; + } + if (HasFocus()) { + style = dc.theme->itemFocusedStyle; + } + dc.FillRect(style.background, bounds_); + } Style style = dc.theme->itemStyle; if (!IsEnabled()) @@ -313,7 +324,6 @@ void Choice::Draw(UIContext &dc) { if (selected_) { dc.Draw()->DrawImage(dc.theme->checkOn, bounds_.x2() - 40, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); } - // dc.draw->DrawText(dc.theme->uiFontSmaller, text_.c_str(), paddingX, paddingY, 0xFFFFFFFF, ALIGN_TOPLEFT); } void InfoItem::Draw(UIContext &dc) { diff --git a/ui/view.h b/ui/view.h index 2c4d45310a..1ad958ccc3 100644 --- a/ui/view.h +++ b/ui/view.h @@ -502,6 +502,9 @@ public: virtual void Draw(UIContext &dc); protected: + // hackery + virtual bool IsSticky() const { return false; } + std::string text_; std::string smallText_; ImageID atlasImage_; @@ -524,6 +527,9 @@ public: void Press() { down_ = true; dragging_ = false; } void Release() { down_ = false; dragging_ = false; } bool IsDown() { return down_; } +protected: + // hackery + virtual bool IsSticky() const { return true; } }; class InfoItem : public Item {