mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-12-04 20:06:51 +00:00
Merge pull request #149 from bollu/ClickableHighlighting
highlighting UI items
This commit is contained in:
commit
4c14e16175
16
ui/view.cpp
16
ui/view.cpp
@ -154,6 +154,7 @@ void Clickable::FocusChanged(int focusFlags) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Clickable::Touch(const TouchInput &input) {
|
||||
if (!enabled_) {
|
||||
dragging_ = false;
|
||||
@ -276,12 +277,14 @@ ClickableItem::ClickableItem(LayoutParams *layoutParams) : Clickable(layoutParam
|
||||
|
||||
void ClickableItem::Draw(UIContext &dc) {
|
||||
Style style = dc.theme->itemStyle;
|
||||
|
||||
if (HasFocus()) {
|
||||
style = dc.theme->itemFocusedStyle;
|
||||
}
|
||||
if (down_) {
|
||||
style = dc.theme->itemDownStyle;
|
||||
}
|
||||
|
||||
dc.FillRect(style.background, bounds_);
|
||||
}
|
||||
|
||||
@ -297,11 +300,19 @@ void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const
|
||||
h += 16;
|
||||
}
|
||||
|
||||
void Choice::HighlightChanged(bool highlighted){
|
||||
highlighted_ = highlighted;
|
||||
};
|
||||
|
||||
|
||||
void Choice::Draw(UIContext &dc) {
|
||||
if (!IsSticky()) {
|
||||
ClickableItem::Draw(dc);
|
||||
} else {
|
||||
Style style = dc.theme->itemStyle;
|
||||
if (highlighted_) {
|
||||
style = dc.theme->itemHighlightedStyle;
|
||||
}
|
||||
if (down_) {
|
||||
style = dc.theme->itemDownStyle;
|
||||
}
|
||||
@ -369,7 +380,7 @@ void CheckBox::Draw(UIContext &dc) {
|
||||
Style style = dc.theme->itemStyle;
|
||||
if (!IsEnabled())
|
||||
style = dc.theme->itemDisabledStyle;
|
||||
|
||||
|
||||
dc.SetFontStyle(dc.theme->uiFont);
|
||||
dc.DrawText(text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER);
|
||||
dc.Draw()->DrawImage(image, bounds_.x2() - paddingX, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER);
|
||||
@ -381,10 +392,11 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
|
||||
|
||||
void Button::Draw(UIContext &dc) {
|
||||
Style style = dc.theme->buttonStyle;
|
||||
|
||||
if (HasFocus()) style = dc.theme->buttonFocusedStyle;
|
||||
if (down_) style = dc.theme->buttonDownStyle;
|
||||
if (!enabled_) style = dc.theme->buttonDisabledStyle;
|
||||
|
||||
|
||||
// dc.Draw()->DrawImage4Grid(style.image, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), style.bgColor);
|
||||
dc.FillRect(style.background, bounds_);
|
||||
float tw, th;
|
||||
|
15
ui/view.h
15
ui/view.h
@ -102,11 +102,13 @@ struct Theme {
|
||||
Style buttonFocusedStyle;
|
||||
Style buttonDownStyle;
|
||||
Style buttonDisabledStyle;
|
||||
Style buttonHighlightedStyle;
|
||||
|
||||
Style itemStyle;
|
||||
Style itemDownStyle;
|
||||
Style itemFocusedStyle;
|
||||
Style itemDisabledStyle;
|
||||
Style itemHighlightedStyle;
|
||||
|
||||
Style headerStyle;
|
||||
|
||||
@ -389,7 +391,7 @@ public:
|
||||
class Clickable : public View {
|
||||
public:
|
||||
Clickable(LayoutParams *layoutParams)
|
||||
: View(layoutParams), downCountDown_(0), dragging_(false), down_(false) {}
|
||||
: View(layoutParams), downCountDown_(0), dragging_(false), down_(false){}
|
||||
|
||||
virtual void Key(const KeyInput &input);
|
||||
virtual void Touch(const TouchInput &input);
|
||||
@ -504,13 +506,14 @@ public:
|
||||
class Choice : public ClickableItem {
|
||||
public:
|
||||
Choice(const std::string &text, LayoutParams *layoutParams = 0)
|
||||
: ClickableItem(layoutParams), text_(text), smallText_(), atlasImage_(-1), selected_(false), centered_(false) {}
|
||||
: ClickableItem(layoutParams), text_(text), smallText_(), atlasImage_(-1), selected_(false), centered_(false), highlighted_(false) {}
|
||||
Choice(const std::string &text, const std::string &smallText, bool selected = false, LayoutParams *layoutParams = 0)
|
||||
: ClickableItem(layoutParams), text_(text), smallText_(smallText), atlasImage_(-1), selected_(selected), centered_(false) {}
|
||||
: ClickableItem(layoutParams), text_(text), smallText_(smallText), atlasImage_(-1), selected_(selected), centered_(false), highlighted_(false) {}
|
||||
|
||||
Choice(ImageID image, LayoutParams *layoutParams = 0)
|
||||
: ClickableItem(layoutParams), atlasImage_(image), selected_(false) {}
|
||||
: ClickableItem(layoutParams), atlasImage_(image), selected_(false), highlighted_(false) {}
|
||||
|
||||
virtual void HighlightChanged(bool highlighted);
|
||||
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const;
|
||||
virtual void Draw(UIContext &dc);
|
||||
virtual void SetCentered(bool c) {
|
||||
@ -525,6 +528,7 @@ protected:
|
||||
std::string smallText_;
|
||||
ImageID atlasImage_;
|
||||
bool centered_;
|
||||
bool highlighted_;
|
||||
|
||||
private:
|
||||
bool selected_;
|
||||
@ -541,10 +545,11 @@ public:
|
||||
virtual void Key(const KeyInput &key);
|
||||
virtual void Touch(const TouchInput &touch);
|
||||
virtual void FocusChanged(int focusFlags);
|
||||
|
||||
|
||||
void Press() { down_ = true; dragging_ = false; }
|
||||
void Release() { down_ = false; dragging_ = false; }
|
||||
bool IsDown() { return down_; }
|
||||
|
||||
protected:
|
||||
// hackery
|
||||
virtual bool IsSticky() const { return true; }
|
||||
|
@ -885,6 +885,15 @@ void ChoiceStrip::SetSelection(int sel) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChoiceStrip::HighlightChoice(unsigned int choice){
|
||||
if (choice < (int)views_.size()){
|
||||
static_cast<StickyChoice *>(views_[choice])->HighlightChanged(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void ChoiceStrip::Key(const KeyInput &input) {
|
||||
if (input.flags & KEY_DOWN) {
|
||||
if (input.keyCode == NKCODE_BUTTON_L1 && selected_ > 0) {
|
||||
|
@ -242,11 +242,18 @@ public:
|
||||
|
||||
void AddChoice(const std::string &title);
|
||||
void AddChoice(ImageID buttonImage);
|
||||
|
||||
int GetSelection() const { return selected_; }
|
||||
void SetSelection(int sel);
|
||||
|
||||
void HighlightChoice(unsigned int choice);
|
||||
|
||||
|
||||
virtual void Key(const KeyInput &input);
|
||||
|
||||
void SetTopTabs(bool tabs) { topTabs_ = tabs; }
|
||||
void Draw(UIContext &dc);
|
||||
|
||||
Event OnChoice;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user