diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index e69673e711..a0fc9f5aab 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -487,7 +487,7 @@ void Choice::Draw(UIContext &dc) { } if (image_.isValid() && text_.empty()) { - dc.Draw()->DrawImage(image_, bounds_.centerX(), bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImageRotated(image_, bounds_.centerX(), bounds_.centerY(), imgScale_, imgRot_, style.fgColor, imgFlipH_); } else { dc.SetFontStyle(dc.theme->uiFont); @@ -498,6 +498,7 @@ void Choice::Draw(UIContext &dc) { const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(image_); paddingX += image->w + 12; availWidth -= image->w + 12; + // TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now) dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER); } @@ -508,7 +509,7 @@ void Choice::Draw(UIContext &dc) { dc.DrawTextRect(text_.c_str(), bounds_, style.fgColor, ALIGN_CENTER | FLAG_WRAP_TEXT); } else { if (rightIconImage_.isValid()) { - dc.Draw()->DrawImage(rightIconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), 0.5f, style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImageRotated(rightIconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), rightIconScale_, rightIconRot_, style.fgColor, rightIconFlipH_); } Bounds textBounds(bounds_.x + paddingX + textPadding_.left, bounds_.y, availWidth, bounds_.h); dc.DrawTextRect(text_.c_str(), textBounds, style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT); diff --git a/Common/UI/View.h b/Common/UI/View.h index 710c7634ea..2b56716028 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -695,6 +695,8 @@ public: : ClickableItem(layoutParams), text_(text), smallText_(smallText), image_(ImageID::invalid()) {} Choice(ImageID image, LayoutParams *layoutParams = nullptr) : ClickableItem(layoutParams), image_(image), rightIconImage_(ImageID::invalid()) {} + Choice(ImageID image, float imgScale, float imgRot, bool imgFlipH = false, LayoutParams *layoutParams = nullptr) + : ClickableItem(layoutParams), image_(image), rightIconImage_(ImageID::invalid()), imgScale_(imgScale), imgRot_(imgRot), imgFlipH_(imgFlipH) {} void Click() override; virtual void HighlightChanged(bool highlighted); @@ -704,7 +706,10 @@ public: virtual void SetCentered(bool c) { centered_ = c; } - virtual void SetIcon(ImageID iconImage) { + virtual void SetIcon(ImageID iconImage, float scale = 1.0f, float rot = 0.0f, bool flipH = false) { + rightIconScale_ = scale; + rightIconRot_ = rot; + rightIconFlipH_ = flipH; rightIconImage_ = iconImage; } @@ -716,10 +721,16 @@ protected: std::string text_; std::string smallText_; ImageID image_; // Centered if no text, on the left if text. - ImageID rightIconImage_ = ImageID::invalid(); // Shows in the right. Only used for the Gold icon on the main menu. + ImageID rightIconImage_ = ImageID::invalid(); // Shows in the right. + float rightIconScale_; + float rightIconRot_; + bool rightIconFlipH_; Padding textPadding_; bool centered_ = false; bool highlighted_ = false; + float imgScale_ = 1.0f; + float imgRot_ = 0.0f; + bool imgFlipH_ = false; private: bool selected_ = false; diff --git a/UI/ComboKeyMappingScreen.cpp b/UI/ComboKeyMappingScreen.cpp index 32a8cda256..931c0b0d9b 100644 --- a/UI/ComboKeyMappingScreen.cpp +++ b/UI/ComboKeyMappingScreen.cpp @@ -32,6 +32,62 @@ #include "UI/ComboKeyMappingScreen.h" +class ButtonShapeScreen : public PopupScreen { +public: + ButtonShapeScreen(std::string title, int *setting) : PopupScreen(title), setting_(setting) {} + + void CreatePopupContents(UI::ViewGroup *parent) override { + using namespace UI; + using namespace CustomKey; + + ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)); + LinearLayout *items = new LinearLayoutList(ORIENT_VERTICAL); + + for (int i = 0; i < ARRAY_SIZE(comboKeyShapes); ++i) { + Choice *c = items->Add(new Choice(ImageID(comboKeyShapes[i].l), 0.6f, comboKeyShapes[i].r*PI/180, comboKeyShapes[i].f)); + c->OnClick.Add([=](UI::EventParams &e) { + *setting_ = i; + TriggerFinish(DR_OK); + return UI::EVENT_DONE; + }); + } + + scroll->Add(items); + parent->Add(scroll); + } + +private: + int *setting_; +}; + +class ButtonIconScreen : public PopupScreen { +public: + ButtonIconScreen(std::string title, int *setting) : PopupScreen(title), setting_(setting) {} + + void CreatePopupContents(UI::ViewGroup *parent) override { + using namespace UI; + using namespace CustomKey; + + ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)); + LinearLayout *items = new LinearLayoutList(ORIENT_VERTICAL); + + for (int i = 0; i < ARRAY_SIZE(comboKeyImages); ++i) { + Choice *c = items->Add(new Choice(ImageID(comboKeyImages[i].i), 1.0f, comboKeyImages[i].r*PI/180)); + c->OnClick.Add([=](UI::EventParams &e) { + *setting_ = i; + TriggerFinish(DR_OK); + return UI::EVENT_DONE; + }); + } + + scroll->Add(items); + parent->Add(scroll); + } + +private: + int *setting_; +}; + class ButtonPreview : public UI::View { public: ButtonPreview(ImageID bgImg, ImageID img, float rotationIcon, bool flipShape, float rotationShape, int x, int y) @@ -155,20 +211,27 @@ void ComboKeyScreen::CreateViews() { vertLayout->Add(new ItemHeader(co->T("Button style"))); vertLayout->Add(new CheckBox(show, co->T("Visible"))); - // All icon and name are defined in GamepadEmu.h - static const char *imageNames[ARRAY_SIZE(comboKeyImages)]; - for (int i = 0; i < ARRAY_SIZE(imageNames); ++i) { - imageNames[i] = comboKeyImages[i].n; - } - PopupMultiChoice *icon = vertLayout->Add(new PopupMultiChoice(&(cfg->image), co->T("Icon"), imageNames, 0, ARRAY_SIZE(imageNames), mc->GetName(), screenManager())); - icon->OnChoice.Handle(this, &ComboKeyScreen::onCombo); - - // All shape and name are defined in GamepadEmu.h - static const char *shapeNames[ARRAY_SIZE(comboKeyShapes)]; - for (int i = 0; i < ARRAY_SIZE(shapeNames); ++i) { - shapeNames[i] = comboKeyShapes[i].n; - } - vertLayout->Add(new PopupMultiChoice(&(cfg->shape), co->T("Shape"), shapeNames, 0, ARRAY_SIZE(shapeNames), mc->GetName(), screenManager()))->OnChoice.Handle(this, &ComboKeyScreen::onCombo); + Choice *icon = vertLayout->Add(new Choice(co->T("Icon"))); + icon->SetIcon(ImageID(comboKeyImages[cfg->image].i), 1.0f, comboKeyImages[cfg->image].r*PI/180); // Set right icon on the choice + icon->OnClick.Add([=](UI::EventParams &e) { + auto iconScreen = new ButtonIconScreen(co->T("Icon"), &(cfg->image)); + if (e.v) + iconScreen->SetPopupOrigin(e.v); + + screenManager()->push(iconScreen); + return UI::EVENT_DONE; + }); + + Choice *shape = vertLayout->Add(new Choice(co->T("Shape"))); + shape->SetIcon(ImageID(comboKeyShapes[cfg->shape].l), 0.6f, comboKeyShapes[cfg->shape].r*PI/180, comboKeyShapes[cfg->shape].f); // Set right icon on the choice + shape->OnClick.Add([=](UI::EventParams &e) { + auto shape = new ButtonShapeScreen(co->T("Shape"), &(cfg->shape)); + if (e.v) + shape->SetPopupOrigin(e.v); + + screenManager()->push(shape); + return UI::EVENT_DONE; + }); vertLayout->Add(new ItemHeader(co->T("Button Binding"))); vertLayout->Add(new CheckBox(&(cfg->toggle), co->T("Toggle mode"))); @@ -249,6 +312,11 @@ void ComboKeyScreen::saveArray() { } } +void ComboKeyScreen::dialogFinished(const Screen *dialog, DialogResult result) { + saveArray(); + RecreateViews(); +} + void ComboKeyScreen::onFinish(DialogResult result) { saveArray(); g_Config.Save("ComboKeyScreen::onFinish"); @@ -258,9 +326,3 @@ UI::EventReturn ComboKeyScreen::ChoiceEventHandler::onChoiceClick(UI::EventParam checkbox_->Toggle(); return UI::EVENT_DONE; }; - -UI::EventReturn ComboKeyScreen::onCombo(UI::EventParams &e) { - saveArray(); - CreateViews(); - return UI::EVENT_DONE; -} diff --git a/UI/ComboKeyMappingScreen.h b/UI/ComboKeyMappingScreen.h index aa4fd71a06..4ee477444d 100644 --- a/UI/ComboKeyMappingScreen.h +++ b/UI/ComboKeyMappingScreen.h @@ -32,7 +32,10 @@ public: void CreateViews() override; void onFinish(DialogResult result) override; - UI::EventReturn onCombo(UI::EventParams &e); + +protected: + void dialogFinished(const Screen *dialog, DialogResult result) override; + private: void saveArray(); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 5e27198fe9..1baa87abb1 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1130,7 +1130,7 @@ void MainScreen::CreateViews() { if (!System_GetPropertyBool(SYSPROP_APP_GOLD)) { Choice *gold = rightColumnItems->Add(new Choice(mm->T("Buy PPSSPP Gold"))); gold->OnClick.Handle(this, &MainScreen::OnSupport); - gold->SetIcon(ImageID("I_ICONGOLD")); + gold->SetIcon(ImageID("I_ICONGOLD"), 0.5f); } #if !PPSSPP_PLATFORM(UWP)