From f075c8fd560588a672bc27806b8929a5f19ca7cc Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 28 May 2013 00:32:00 +0200 Subject: [PATCH] Merge DrawContext into UIContext. --- Android.mk | 4 ++- math/geom2d.h | 2 ++ native.vcxproj | 2 -- native.vcxproj.filters | 2 -- ui/drawing.cpp | 45 ------------------------- ui/drawing.h | 34 ------------------- ui/screen.cpp | 34 +++++++------------ ui/ui_context.cpp | 28 ++++++++++++++++ ui/ui_context.h | 24 ++++++++++++++ ui/view.cpp | 74 +++++++++++++++++++++--------------------- ui/view.h | 44 ++++++++++++------------- ui/viewgroup.cpp | 18 +++++----- ui/viewgroup.h | 18 +++++----- 13 files changed, 145 insertions(+), 184 deletions(-) delete mode 100644 ui/drawing.cpp delete mode 100644 ui/drawing.h diff --git a/Android.mk b/Android.mk index 9edfc363db..711551eae3 100644 --- a/Android.mk +++ b/Android.mk @@ -59,11 +59,13 @@ LOCAL_SRC_FILES :=\ image/zim_load.cpp \ image/zim_save.cpp \ image/png_load.cpp \ + ui/view.cpp \ + ui/viewgroup.cpp \ + ui/drawing.cpp \ ui/ui.cpp \ ui/ui_context.cpp \ ui/screen.cpp \ ui/virtual_input.cpp \ - ui/drawing.cpp \ util/random/perlin.cpp \ util/text/utf8.cpp diff --git a/math/geom2d.h b/math/geom2d.h index d165c80e4e..fd8357de40 100644 --- a/math/geom2d.h +++ b/math/geom2d.h @@ -1,5 +1,7 @@ #pragma once +#include + struct Point { Point() {} Point(float x_, float y_) : x(x_), y(y_) {} diff --git a/native.vcxproj b/native.vcxproj index 0fc33aa6a5..e40dd0368e 100644 --- a/native.vcxproj +++ b/native.vcxproj @@ -233,7 +233,6 @@ - @@ -350,7 +349,6 @@ - diff --git a/native.vcxproj.filters b/native.vcxproj.filters index ffe8acd256..4f0491e784 100644 --- a/native.vcxproj.filters +++ b/native.vcxproj.filters @@ -263,7 +263,6 @@ math - @@ -466,7 +465,6 @@ ui - diff --git a/ui/drawing.cpp b/ui/drawing.cpp deleted file mode 100644 index 01a1e3f0be..0000000000 --- a/ui/drawing.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "base/display.h" -#include "ui/drawing.h" -#include "gfx_es2/draw_buffer.h" -#include "gfx_es2/gl_state.h" - -DrawContext::DrawContext() { - -} - -DrawContext::~DrawContext() { - -} - -// TODO: Support transformed bounds using stencil -void DrawContext::PushScissor(const Bounds &bounds) { - Flush(); - scissorStack_.push_back(bounds); - ActivateTopScissor(); -} - -void DrawContext::PopScissor() { - Flush(); - scissorStack_.pop_back(); - ActivateTopScissor(); -} - -void DrawContext::ActivateTopScissor() { - if (scissorStack_.size()) { - const Bounds &bounds = scissorStack_.back(); - int x = g_dpi_scale * bounds.x; - int y = g_dpi_scale * (dp_yres - bounds.y2()); - int w = g_dpi_scale * bounds.w; - int h = g_dpi_scale * bounds.h; - - glstate.scissorRect.set(x,y,w,h); - glstate.scissorTest.enable(); - } else { - glstate.scissorTest.disable(); - } -} - -void DrawContext::Flush() { - draw->Flush(true); - drawTop->Flush(true); -} \ No newline at end of file diff --git a/ui/drawing.h b/ui/drawing.h deleted file mode 100644 index f7677f4ede..0000000000 --- a/ui/drawing.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include "math/geom2d.h" -#include "gfx/texture_atlas.h" - -// Kind of ugly connection to UI. -namespace UI { - struct Theme; -} - -class DrawBuffer; - -class DrawContext { -public: - DrawContext(); - ~DrawContext(); - - DrawBuffer *draw; - DrawBuffer *drawTop; - const UI::Theme *theme; - - // TODO: Support transformed bounds using stencil - void PushScissor(const Bounds &bounds); - void PopScissor(); - - void ActivateTopScissor(); - - void Flush(); - -private: - std::vector scissorStack_; -}; \ No newline at end of file diff --git a/ui/screen.cpp b/ui/screen.cpp index d74ceb627a..db81e59155 100644 --- a/ui/screen.cpp +++ b/ui/screen.cpp @@ -38,11 +38,9 @@ void ScreenManager::update(InputState &input) { } } -void ScreenManager::switchToNext() -{ +void ScreenManager::switchToNext() { Layer temp = {0, 0}; - if (!stack_.empty()) - { + if (!stack_.empty()) { temp = stack_.back(); stack_.pop_back(); } @@ -52,8 +50,7 @@ void ScreenManager::switchToNext() nextScreen_ = 0; } -void ScreenManager::touch(const TouchInput &touch) -{ +void ScreenManager::touch(const TouchInput &touch) { if (stack_.size()) { stack_.back().screen->touch(touch); return; @@ -62,16 +59,12 @@ void ScreenManager::touch(const TouchInput &touch) void ScreenManager::render() { if (stack_.size()) { - switch (stack_.back().flags) - { + switch (stack_.back().flags) { case LAYER_SIDEMENU: - if (stack_.size() == 1) - { + if (stack_.size() == 1) { ELOG("Can't have sidemenu over nothing"); break; - } - else - { + } else { auto iter = stack_.end(); iter--; iter--; @@ -94,8 +87,7 @@ void ScreenManager::render() { processFinishDialog(); } -void ScreenManager::sendMessage(const char *msg, const char *value) -{ +void ScreenManager::sendMessage(const char *msg, const char *value) { if (stack_.size()) stack_.back().screen->sendMessage(msg, value); } @@ -144,10 +136,8 @@ void ScreenManager::pop() { } } -void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) -{ - if (dialog != stack_.back().screen) - { +void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) { + if (dialog != stack_.back().screen) { ELOG("Wrong dialog being finished!"); return; } @@ -159,10 +149,8 @@ void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) dialogResult_ = result; } -void ScreenManager::processFinishDialog() -{ - if (dialogFinished_) - { +void ScreenManager::processFinishDialog() { + if (dialogFinished_) { if (stack_.size()) { stack_.pop_back(); } diff --git a/ui/ui_context.cpp b/ui/ui_context.cpp index 731b105982..00fd157cf8 100644 --- a/ui/ui_context.cpp +++ b/ui/ui_context.cpp @@ -68,4 +68,32 @@ void UIContext::End() { UIEnd(); Flush(); +} + +// TODO: Support transformed bounds using stencil +void UIContext::PushScissor(const Bounds &bounds) { + Flush(); + scissorStack_.push_back(bounds); + ActivateTopScissor(); +} + +void UIContext::PopScissor() { + Flush(); + scissorStack_.pop_back(); + ActivateTopScissor(); +} + +void UIContext::ActivateTopScissor() { + if (scissorStack_.size()) { + const Bounds &bounds = scissorStack_.back(); + int x = g_dpi_scale * bounds.x; + int y = g_dpi_scale * (dp_yres - bounds.y2()); + int w = g_dpi_scale * bounds.w; + int h = g_dpi_scale * bounds.h; + + glstate.scissorRect.set(x,y,w,h); + glstate.scissorTest.enable(); + } else { + glstate.scissorTest.disable(); + } } \ No newline at end of file diff --git a/ui/ui_context.h b/ui/ui_context.h index ba87378d87..5552290f98 100644 --- a/ui/ui_context.h +++ b/ui/ui_context.h @@ -1,5 +1,10 @@ #pragma once +#include + +#include "math/geom2d.h" +#include "gfx/texture_atlas.h" + // Everything you need to draw a UI collected into a single unit that can be passed around. // Everything forward declared so this header is safe everywhere. @@ -7,6 +12,13 @@ struct GLSLProgram; class Texture; class DrawBuffer; +// Kind of ugly connection to UI. +namespace UI { + struct Theme; +} + +class DrawBuffer; + // Who should own this? Really not sure. class UIContext { public: @@ -27,6 +39,16 @@ public: void RebindTexture() const; + // TODO: Support transformed bounds using stencil + void PushScissor(const Bounds &bounds); + void PopScissor(); + + void ActivateTopScissor(); + + DrawBuffer *Draw() const { return uidrawbuffer_; } + + const UI::Theme *theme; + private: // TODO: Collect these into a UIContext const GLSLProgram *uishader_; @@ -34,4 +56,6 @@ private: Texture *uitexture_; DrawBuffer *uidrawbuffer_; DrawBuffer *uidrawbufferTop_; + + std::vector scissorStack_; }; diff --git a/ui/view.cpp b/ui/view.cpp index 89151bc95f..6234d6533a 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -5,7 +5,7 @@ #include "gfx/texture_atlas.h" #include "ui/ui.h" #include "ui/view.h" -#include "ui/drawing.h" +#include "ui/ui_context.h" namespace UI { @@ -76,7 +76,7 @@ void Event::Update() { } } -void View::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void View::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { float contentW = 0.0f, contentH = 0.0f; GetContentDimensions(dc, contentW, contentH); MeasureBySpec(layoutParams_->width, contentW, horiz, &measuredWidth_); @@ -85,7 +85,7 @@ void View::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { // Default values -void View::GetContentDimensions(const DrawContext &dc, float &w, float &h) const { +void View::GetContentDimensions(const UIContext &dc, float &w, float &h) const { w = 10.0f; h = 10.0f; } @@ -135,78 +135,78 @@ void Clickable::Update(const InputState &input_state) { } } -void ClickableItem::Draw(DrawContext &dc) { +void ClickableItem::Draw(UIContext &dc) { if (down_) { - dc.draw->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.bgColor); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.bgColor); } else if (HasFocus()) { - dc.draw->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemFocusedStyle.bgColor); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemFocusedStyle.bgColor); } } -void Choice::Draw(DrawContext &dc) { +void Choice::Draw(UIContext &dc) { ClickableItem::Draw(dc); int paddingX = 4; int paddingY = 4; - dc.draw->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); // dc.draw->DrawText(dc.theme->uiFontSmaller, text_.c_str(), paddingX, paddingY, 0xFFFFFFFF, ALIGN_TOPLEFT); } -void InfoItem::Draw(DrawContext &dc) { +void InfoItem::Draw(UIContext &dc) { int paddingX = 4; int paddingY = 4; - dc.draw->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); - dc.draw->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER | ALIGN_RIGHT); - dc.draw->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER | ALIGN_RIGHT); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); } -void ItemHeader::Draw(DrawContext &dc) { - dc.draw->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFF707070, ALIGN_LEFT); - dc.draw->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.bgColor); +void ItemHeader::Draw(UIContext &dc) { + dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFF707070, ALIGN_LEFT); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.bgColor); } -void CheckBox::Draw(DrawContext &dc) { +void CheckBox::Draw(UIContext &dc) { ClickableItem::Draw(dc); int paddingX = 80; int paddingY = 4; - dc.draw->DrawImage(dc.theme->checkOn, bounds_.x + 30, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); - dc.draw->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); + dc.Draw()->DrawImage(dc.theme->checkOn, bounds_.x + 30, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); // dc.draw->DrawText(dc.theme->uiFontSmaller, text_.c_str(), paddingX, paddingY, 0xFFFFFFFF, ALIGN_TOPLEFT); } -void Button::GetContentDimensions(const DrawContext &dc, float &w, float &h) const { - dc.draw->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); +void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const { + dc.Draw()->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); } -void Button::Draw(DrawContext &dc) { +void Button::Draw(UIContext &dc) { int image = down_ ? dc.theme->buttonImage : dc.theme->buttonSelected; Style style = dc.theme->buttonStyle; if (HasFocus()) style = dc.theme->buttonFocusedStyle; if (down_) style = dc.theme->buttonDownStyle; - dc.draw->DrawImage4Grid(dc.theme->buttonImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), style.bgColor); - dc.draw->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.centerX(), bounds_.centerY(), style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImage4Grid(dc.theme->buttonImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), style.bgColor); + dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.centerX(), bounds_.centerY(), style.fgColor, ALIGN_CENTER); } -void ImageView::GetContentDimensions(const DrawContext &dc, float &w, float &h) const { - const AtlasImage &img = dc.draw->GetAtlas()->images[atlasImage_]; +void ImageView::GetContentDimensions(const UIContext &dc, float &w, float &h) const { + const AtlasImage &img = dc.Draw()->GetAtlas()->images[atlasImage_]; // TODO: involve sizemode w = img.w; h = img.h; } -void ImageView::Draw(DrawContext &dc) { +void ImageView::Draw(UIContext &dc) { // TODO: involve sizemode - dc.draw->DrawImage(atlasImage_, bounds_.x, bounds_.y, bounds_.w, bounds_.h, 0xFFFFFFFF); + dc.Draw()->DrawImage(atlasImage_, bounds_.x, bounds_.y, bounds_.w, bounds_.h, 0xFFFFFFFF); } -void TextView::GetContentDimensions(const DrawContext &dc, float &w, float &h) const { - dc.draw->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); +void TextView::GetContentDimensions(const UIContext &dc, float &w, float &h) const { + dc.Draw()->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); } -void TextView::Draw(DrawContext &dc) { +void TextView::Draw(UIContext &dc) { // TODO: involve sizemode - dc.draw->DrawTextRect(dc.theme->uiFont, text_.c_str(), bounds_.x, bounds_.y, bounds_.w, bounds_.h, 0xFFFFFFFF); + dc.Draw()->DrawTextRect(dc.theme->uiFont, text_.c_str(), bounds_.x, bounds_.y, bounds_.w, bounds_.h, 0xFFFFFFFF); } void TriggerButton::Touch(const TouchInput &input) { @@ -233,13 +233,13 @@ void TriggerButton::Touch(const TouchInput &input) { } } -void TriggerButton::Draw(DrawContext &dc) { - dc.draw->DrawImage(imageBackground_, bounds_.centerX(), bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_CENTER); - dc.draw->DrawImage(imageForeground_, bounds_.centerX(), bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_CENTER); +void TriggerButton::Draw(UIContext &dc) { + dc.Draw()->DrawImage(imageBackground_, bounds_.centerX(), bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_CENTER); + dc.Draw()->DrawImage(imageForeground_, bounds_.centerX(), bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_CENTER); } -void TriggerButton::GetContentDimensions(const DrawContext &dc, float &w, float &h) const { - const AtlasImage &image = dc.draw->GetAtlas()->images[imageBackground_]; +void TriggerButton::GetContentDimensions(const UIContext &dc, float &w, float &h) const { + const AtlasImage &image = dc.Draw()->GetAtlas()->images[imageBackground_]; w = image.w; h = image.h; } @@ -282,7 +282,7 @@ void TabStrip::Draw(DrawContext &dc) { } }*/ -void Fill(DrawContext &dc, const Bounds &bounds, const Drawable &drawable) { +void Fill(UIContext &dc, const Bounds &bounds, const Drawable &drawable) { if (drawable.type == DRAW_SOLID_COLOR) { } diff --git a/ui/view.h b/ui/view.h index 90799b4421..7d5f4466a3 100644 --- a/ui/view.h +++ b/ui/view.h @@ -30,7 +30,7 @@ struct TouchInput; struct InputState; class DrawBuffer; -class DrawContext; +class UIContext; // I don't generally like namespaces but I think we do need one for UI, so many potentially-clashing names. namespace UI { @@ -139,7 +139,7 @@ enum EventReturn { class ViewGroup; -void Fill(DrawContext &dc, const Bounds &bounds, const Drawable &drawable); +void Fill(UIContext &dc, const Bounds &bounds, const Drawable &drawable); struct MeasureSpec { MeasureSpec(MeasureSpecType t, float s = 0.0f) : type(t), size(s) {} @@ -232,15 +232,15 @@ public: } // Views don't do anything here in Layout, only containers implement this. - virtual void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + virtual void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); virtual void Layout() {} - virtual void Draw(DrawContext &dc) {} + virtual void Draw(UIContext &dc) {} virtual float GetMeasuredWidth() const { return measuredWidth_; } virtual float GetMeasuredHeight() const { return measuredHeight_; } // Override this for easy standard behaviour. No need to override Measure. - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const; + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; // Called when the layout is done. void SetBounds(Bounds bounds) { bounds_ = bounds; } @@ -317,8 +317,8 @@ public: Button(const std::string &text, LayoutParams *layoutParams = 0) : Clickable(layoutParams), text_(text) {} - virtual void Draw(DrawContext &dc); - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const; + virtual void Draw(UIContext &dc); + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; private: Style style_; @@ -333,8 +333,8 @@ public: : View(layoutParams), down_(0.0), bitField_(bitField), bit_(bit), imageBackground_(imageBackground), imageForeground_(imageForeground) {} virtual void Touch(const TouchInput &input); - virtual void Draw(DrawContext &dc); - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const; + virtual void Draw(UIContext &dc); + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; private: int down_; // bitfield of pressed fingers, translates into bitField @@ -357,7 +357,7 @@ public: layoutParams_->height = 80; } - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const { + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const { w = 0.0f; h = 0.0f; } @@ -370,13 +370,13 @@ public: layoutParams_->height = 80; } - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const { + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const { w = 0.0f; h = 0.0f; } // Draws the item background. - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); }; // Use to trigger something or open a submenu screen. @@ -385,7 +385,7 @@ public: Choice(const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0) : ClickableItem(layoutParams), text_(text), smallText_(smallText) {} - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); private: std::string text_; @@ -397,7 +397,7 @@ public: InfoItem(const std::string &text, const std::string &rightText, LayoutParams *layoutParams = 0) : Item(layoutParams), text_(text), rightText_(rightText) {} - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); private: std::string text_; @@ -411,7 +411,7 @@ public: layoutParams_->width = FILL_PARENT; layoutParams_->height = 26; } - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); private: std::string text_; }; @@ -423,7 +423,7 @@ public: OnClick.Add(std::bind(&CheckBox::OnClicked, this, std::placeholders::_1)); } - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); EventReturn OnClicked(const EventParams &e) { if (toggle_) @@ -444,10 +444,10 @@ class Spacer : public InertView { public: Spacer(LayoutParams *layoutParams = 0) : InertView(layoutParams) {} - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) { + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) { w = 0.0f; h = 0.0f; } - virtual void Draw(DrawContext &dc) {} + virtual void Draw(UIContext &dc) {} }; class TextView : public InertView { @@ -455,8 +455,8 @@ public: TextView(int font, const std::string &text, LayoutParams *layoutParams = 0) : InertView(layoutParams), font_(font), text_(text) {} - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const; - virtual void Draw(DrawContext &dc); + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; + virtual void Draw(UIContext &dc); private: std::string text_; @@ -472,8 +472,8 @@ public: ImageView(int atlasImage, ImageSizeMode sizeMode, LayoutParams *layoutParams = 0) : InertView(layoutParams), atlasImage_(atlasImage), sizeMode_(sizeMode) {} - virtual void GetContentDimensions(const DrawContext &dc, float &w, float &h) const; - virtual void Draw(DrawContext &dc); + virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; + virtual void Draw(UIContext &dc); private: int atlasImage_; diff --git a/ui/viewgroup.cpp b/ui/viewgroup.cpp index 2c9d4e72e7..03ec7757a3 100644 --- a/ui/viewgroup.cpp +++ b/ui/viewgroup.cpp @@ -1,6 +1,6 @@ #include "base/display.h" #include "base/logging.h" -#include "ui/drawing.h" +#include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" @@ -36,7 +36,7 @@ void ViewGroup::Touch(const TouchInput &input) { } } -void ViewGroup::Draw(DrawContext &dc) { +void ViewGroup::Draw(UIContext &dc) { for (auto iter = views_.begin(); iter != views_.end(); ++iter) { // TODO: If there is a transformation active, transform input coordinates accordingly. (*iter)->Draw(dc); @@ -191,7 +191,7 @@ void MoveFocus(ViewGroup *root, FocusDirection direction) { } } -void LinearLayout::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { if (views_.empty()) { MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_); MeasureBySpec(layoutParams_->height, 0.0f, vert, &measuredHeight_); @@ -325,7 +325,7 @@ void LinearLayout::Layout() { } } -void FrameLayout::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void FrameLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { if (views_.empty()) { MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_); MeasureBySpec(layoutParams_->height, 0.0f, vert, &measuredHeight_); @@ -341,7 +341,7 @@ void FrameLayout::Layout() { } -void ScrollView::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { // Respect margins Margins margins; const LinearLayoutParams *params = dynamic_cast(views_[0]->GetLayoutParams()); @@ -415,7 +415,7 @@ void ScrollView::Touch(const TouchInput &input) { } } -void ScrollView::Draw(DrawContext &dc) { +void ScrollView::Draw(UIContext &dc) { dc.PushScissor(bounds_); views_[0]->Draw(dc); dc.PopScissor(); @@ -455,7 +455,7 @@ void ScrollView::ScrollTo(float newScrollPos) { scrollPos_ = newScrollPos; } -void GridLayout::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void GridLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { MeasureSpecType measureType = settings_.fillCells ? EXACTLY : AT_MOST; for (size_t i = 0; i < views_.size(); i++) { @@ -473,7 +473,7 @@ void GridLayout::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec v MeasureBySpec(layoutParams_->height, estimatedHeight, vert, &measuredHeight_); } -void AnchorLayout::Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) { +void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) { MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_); MeasureBySpec(layoutParams_->height, 0.0f, horiz, &measuredHeight_); @@ -557,7 +557,7 @@ void GridLayout::Layout() { } } -void LayoutViewHierarchy(const DrawContext &dc, ViewGroup *root) { +void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root) { Bounds rootBounds; rootBounds.x = 0; rootBounds.y = 0; diff --git a/ui/viewgroup.h b/ui/viewgroup.h index de4c691198..8c55a3387a 100644 --- a/ui/viewgroup.h +++ b/ui/viewgroup.h @@ -23,11 +23,11 @@ public: virtual void Touch(const TouchInput &input); // By default, a container will layout to its own bounds. - virtual void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert) = 0; + virtual void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) = 0; virtual void Layout() = 0; virtual void Update(const InputState &input_state); - virtual void Draw(DrawContext &dc); + virtual void Draw(UIContext &dc); // These should be unused. virtual float GetContentWidth() const { return 0.0f; } @@ -51,7 +51,7 @@ protected: // A frame layout contains a single child view (normally). class FrameLayout : public ViewGroup { public: - void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); }; @@ -76,7 +76,7 @@ public: class AnchorLayout : public ViewGroup { public: AnchorLayout(LayoutParams *layoutParams = 0) : ViewGroup(layoutParams) {} - void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); }; @@ -108,7 +108,7 @@ public: LinearLayout(Orientation orientation, LayoutParams *layoutParams = 0) : ViewGroup(layoutParams), spacing_(5), orientation_(orientation), defaultMargins_(0) {} - void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); private: @@ -139,7 +139,7 @@ public: ELOG("GridLayout: Vertical layouts not yet supported"); } - void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); private: @@ -152,11 +152,11 @@ public: ScrollView(Orientation orientation, LayoutParams *layoutParams = 0) : ViewGroup(layoutParams), orientation_(orientation), scrollPos_(0) {} - void Measure(const DrawContext &dc, MeasureSpec horiz, MeasureSpec vert); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); void Touch(const TouchInput &input); - void Draw(DrawContext &dc); + void Draw(UIContext &dc); void ScrollTo(float newScrollPos); @@ -175,7 +175,7 @@ class ViewPager : public ScrollView { public: }; -void LayoutViewHierarchy(const DrawContext &dc, ViewGroup *root); +void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root); void UpdateViewHierarchy(const InputState &input_state, ViewGroup *root); } // namespace UI \ No newline at end of file