2013-06-03 19:57:40 +02:00
|
|
|
|
|
|
|
#include "ui/ui_screen.h"
|
|
|
|
#include "ui/ui_context.h"
|
|
|
|
#include "ui/screen.h"
|
|
|
|
|
2013-06-08 22:41:17 +02:00
|
|
|
UIScreen::UIScreen()
|
2013-06-09 01:21:08 +02:00
|
|
|
: Screen(), root_(0), recreateViews_(true) {
|
2013-06-08 22:41:17 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 13:30:47 +02:00
|
|
|
void UIScreen::DoRecreateViews() {
|
2013-06-08 22:41:17 +02:00
|
|
|
if (recreateViews_) {
|
2013-06-03 19:57:40 +02:00
|
|
|
delete root_;
|
|
|
|
root_ = 0;
|
|
|
|
CreateViews();
|
2013-06-09 01:21:08 +02:00
|
|
|
recreateViews_ = false;
|
2013-06-03 19:57:40 +02:00
|
|
|
}
|
2013-07-21 13:30:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIScreen::update(InputState &input) {
|
|
|
|
DoRecreateViews();
|
2013-06-03 19:57:40 +02:00
|
|
|
|
2013-07-20 12:04:24 +02:00
|
|
|
if (root_) {
|
|
|
|
UpdateViewHierarchy(input, root_);
|
|
|
|
} else {
|
|
|
|
ELOG("Tried to update without a view root");
|
|
|
|
}
|
2013-06-03 19:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIScreen::render() {
|
2013-07-21 13:30:47 +02:00
|
|
|
DoRecreateViews();
|
|
|
|
|
2013-06-08 22:41:17 +02:00
|
|
|
if (root_) {
|
|
|
|
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_);
|
|
|
|
|
|
|
|
screenManager()->getUIContext()->Begin();
|
2013-06-09 11:18:57 +02:00
|
|
|
DrawBackground(*screenManager()->getUIContext());
|
2013-06-08 22:41:17 +02:00
|
|
|
root_->Draw(*screenManager()->getUIContext());
|
|
|
|
screenManager()->getUIContext()->End();
|
|
|
|
screenManager()->getUIContext()->Flush();
|
|
|
|
} else {
|
|
|
|
ELOG("Tried to render without a view root");
|
|
|
|
}
|
2013-06-03 19:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIScreen::touch(const TouchInput &touch) {
|
2013-06-08 22:41:17 +02:00
|
|
|
if (root_) {
|
|
|
|
root_->Touch(touch);
|
|
|
|
} else {
|
|
|
|
ELOG("Tried to touch without a view root");
|
|
|
|
}
|
2013-06-03 19:57:40 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 12:34:39 +02:00
|
|
|
void UIScreen::key(const KeyInput &key) {
|
|
|
|
if (root_) {
|
|
|
|
root_->Key(key);
|
|
|
|
} else {
|
|
|
|
ELOG("Tried to key without a view root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 19:57:40 +02:00
|
|
|
UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {
|
|
|
|
screenManager()->finishDialog(this, DR_OK);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
2013-07-16 00:25:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
PopupScreen::PopupScreen(const std::string &title)
|
|
|
|
: title_(title) {}
|
|
|
|
|
|
|
|
void PopupScreen::CreateViews() {
|
|
|
|
using namespace UI;
|
|
|
|
|
|
|
|
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
2013-07-17 01:03:29 +02:00
|
|
|
LinearLayout *box = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(30, 30, 30, 30));
|
|
|
|
|
2013-07-16 00:25:08 +02:00
|
|
|
root_->Add(box);
|
|
|
|
box->SetBG(UI::Drawable(0xFF303030));
|
|
|
|
box->SetHasDropShadow(true);
|
|
|
|
|
|
|
|
View *title = new ItemHeader(title_);
|
|
|
|
box->Add(title);
|
|
|
|
|
|
|
|
CreatePopupContents(box);
|
|
|
|
|
|
|
|
// And the two buttons at the bottom.
|
|
|
|
ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL);
|
|
|
|
buttonRow->Add(new Button("OK", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK);
|
|
|
|
buttonRow->Add(new Button("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel);
|
|
|
|
box->Add(buttonRow);
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn PopupScreen::OnOK(UI::EventParams &e) {
|
|
|
|
OnCompleted();
|
|
|
|
screenManager()->finishDialog(this, DR_OK);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) {
|
|
|
|
screenManager()->finishDialog(this, DR_CANCEL);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
|
|
|
using namespace UI;
|
|
|
|
|
|
|
|
listView_ = parent->Add(new ListView(&adaptor_, new LinearLayoutParams(1.0)));
|
|
|
|
listView_->OnChoice.Handle(this, &ListPopupScreen::OnListChoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ListPopupScreen::OnListChoice(UI::EventParams &e) {
|
|
|
|
adaptor_.SetSelected(e.a);
|
|
|
|
OnChoice.Dispatch(e);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2013-07-17 01:03:29 +02:00
|
|
|
void ListPopupScreen::OnCompleted() {
|
|
|
|
callback_(adaptor_.GetSelected());
|
|
|
|
}
|
2013-07-18 10:25:30 +02:00
|
|
|
|
|
|
|
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
|
|
|
using namespace UI;
|
|
|
|
slider_ = parent->Add(new Slider(value_, minValue_, maxValue_));
|
|
|
|
}
|
2013-07-20 13:54:09 +02:00
|
|
|
|
|
|
|
void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
|
|
|
using namespace UI;
|
|
|
|
slider_ = parent->Add(new SliderFloat(value_, minValue_, maxValue_));
|
|
|
|
}
|