Merge DrawContext into UIContext.

This commit is contained in:
Henrik Rydgard 2013-05-28 00:32:00 +02:00
parent cbf1b2d29d
commit f075c8fd56
13 changed files with 145 additions and 184 deletions

View File

@ -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

View File

@ -1,5 +1,7 @@
#pragma once
#include <cmath>
struct Point {
Point() {}
Point(float x_, float y_) : x(x_), y(y_) {}

View File

@ -233,7 +233,6 @@
<ClInclude Include="thread\thread.h" />
<ClInclude Include="thread\threadpool.h" />
<ClInclude Include="thread\threadutil.h" />
<ClInclude Include="ui\drawing.h" />
<ClInclude Include="ui\screen.h" />
<ClInclude Include="ui\ui.h" />
<ClInclude Include="ui\ui_context.h" />
@ -350,7 +349,6 @@
<ClCompile Include="thread\prioritizedworkqueue.cpp" />
<ClCompile Include="thread\threadpool.cpp" />
<ClCompile Include="thread\threadutil.cpp" />
<ClCompile Include="ui\drawing.cpp" />
<ClCompile Include="ui\screen.cpp" />
<ClCompile Include="ui\ui.cpp" />
<ClCompile Include="ui\ui_context.cpp" />

View File

@ -263,7 +263,6 @@
<ClInclude Include="math\geom2d.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="ui\drawing.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="gfx\gl_debug_log.cpp">
@ -466,7 +465,6 @@
<ClCompile Include="ui\viewgroup.cpp">
<Filter>ui</Filter>
</ClCompile>
<ClCompile Include="ui\drawing.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="gfx">

View File

@ -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);
}

View File

@ -1,34 +0,0 @@
#pragma once
#include <vector>
#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<Bounds> scissorStack_;
};

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -1,5 +1,10 @@
#pragma once
#include <vector>
#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<Bounds> scissorStack_;
};

View File

@ -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) {
}

View File

@ -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_;

View File

@ -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<const LinearLayoutParams*>(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;

View File

@ -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