Merge "vr_ui: drawing changes"
This commit is contained in:
commit
9a874a4e5f
4 changed files with 97 additions and 30 deletions
|
@ -149,8 +149,8 @@ int ScreenRecoveryUI::GetProgressBaseline() const {
|
|||
int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
|
||||
gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
|
||||
gr_get_height(progressBarFill);
|
||||
int bottom_gap = (gr_fb_height() - elements_sum) / 2;
|
||||
return gr_fb_height() - bottom_gap - gr_get_height(progressBarFill);
|
||||
int bottom_gap = (ScreenHeight() - elements_sum) / 2;
|
||||
return ScreenHeight() - bottom_gap - gr_get_height(progressBarFill);
|
||||
}
|
||||
|
||||
// Clear the screen and draw the currently selected background icon (if any).
|
||||
|
@ -159,25 +159,24 @@ void ScreenRecoveryUI::draw_background_locked() {
|
|||
pagesIdentical = false;
|
||||
gr_color(0, 0, 0, 255);
|
||||
gr_clear();
|
||||
|
||||
if (currentIcon != NONE) {
|
||||
if (max_stage != -1) {
|
||||
int stage_height = gr_get_height(stageMarkerEmpty);
|
||||
int stage_width = gr_get_width(stageMarkerEmpty);
|
||||
int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
|
||||
int y = gr_fb_height() - stage_height - kMarginHeight;
|
||||
int x = (ScreenWidth() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
|
||||
int y = ScreenHeight() - stage_height - kMarginHeight;
|
||||
for (int i = 0; i < max_stage; ++i) {
|
||||
GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
|
||||
gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
|
||||
DrawSurface(stage_surface, 0, 0, stage_width, stage_height, x, y);
|
||||
x += stage_width;
|
||||
}
|
||||
}
|
||||
|
||||
GRSurface* text_surface = GetCurrentText();
|
||||
int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
|
||||
int text_x = (ScreenWidth() - gr_get_width(text_surface)) / 2;
|
||||
int text_y = GetTextBaseline();
|
||||
gr_color(255, 255, 255, 255);
|
||||
gr_texticon(text_x, text_y, text_surface);
|
||||
DrawTextIcon(text_x, text_y, text_surface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,21 +187,21 @@ void ScreenRecoveryUI::draw_foreground_locked() {
|
|||
GRSurface* frame = GetCurrentFrame();
|
||||
int frame_width = gr_get_width(frame);
|
||||
int frame_height = gr_get_height(frame);
|
||||
int frame_x = (gr_fb_width() - frame_width) / 2;
|
||||
int frame_x = (ScreenWidth() - frame_width) / 2;
|
||||
int frame_y = GetAnimationBaseline();
|
||||
gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
|
||||
DrawSurface(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
|
||||
}
|
||||
|
||||
if (progressBarType != EMPTY) {
|
||||
int width = gr_get_width(progressBarEmpty);
|
||||
int height = gr_get_height(progressBarEmpty);
|
||||
|
||||
int progress_x = (gr_fb_width() - width) / 2;
|
||||
int progress_x = (ScreenWidth() - width) / 2;
|
||||
int progress_y = GetProgressBaseline();
|
||||
|
||||
// Erase behind the progress bar (in case this was a progress-only update)
|
||||
gr_color(0, 0, 0, 255);
|
||||
gr_fill(progress_x, progress_y, width, height);
|
||||
DrawFill(progress_x, progress_y, width, height);
|
||||
|
||||
if (progressBarType == DETERMINATE) {
|
||||
float p = progressScopeStart + progress * progressScopeSize;
|
||||
|
@ -211,19 +210,19 @@ void ScreenRecoveryUI::draw_foreground_locked() {
|
|||
if (rtl_locale_) {
|
||||
// Fill the progress bar from right to left.
|
||||
if (pos > 0) {
|
||||
gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
|
||||
progress_y);
|
||||
DrawSurface(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
|
||||
progress_y);
|
||||
}
|
||||
if (pos < width - 1) {
|
||||
gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
|
||||
DrawSurface(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
|
||||
}
|
||||
} else {
|
||||
// Fill the progress bar from left to right.
|
||||
if (pos > 0) {
|
||||
gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
|
||||
DrawSurface(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
|
||||
}
|
||||
if (pos < width - 1) {
|
||||
gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
|
||||
DrawSurface(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,8 +334,21 @@ void ScreenRecoveryUI::CheckBackgroundTextImages(const std::string& saved_locale
|
|||
SetLocale(saved_locale);
|
||||
}
|
||||
|
||||
int ScreenRecoveryUI::ScreenWidth() const {
|
||||
return gr_fb_width();
|
||||
}
|
||||
|
||||
int ScreenRecoveryUI::ScreenHeight() const {
|
||||
return gr_fb_height();
|
||||
}
|
||||
|
||||
void ScreenRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
|
||||
int dy) const {
|
||||
gr_blit(surface, sx, sy, w, h, dx, dy);
|
||||
}
|
||||
|
||||
int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
|
||||
gr_fill(0, y + 4, gr_fb_width(), y + 6);
|
||||
gr_fill(0, y + 4, ScreenWidth(), y + 6);
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
@ -344,6 +356,14 @@ void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) con
|
|||
gr_fill(x, y, x + width, y + height);
|
||||
}
|
||||
|
||||
void ScreenRecoveryUI::DrawFill(int x, int y, int w, int h) const {
|
||||
gr_fill(x, y, w, h);
|
||||
}
|
||||
|
||||
void ScreenRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
|
||||
gr_texticon(x, y, surface);
|
||||
}
|
||||
|
||||
int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
|
||||
gr_text(gr_sys_font(), x, y, line, bold);
|
||||
return char_height_ + 4;
|
||||
|
@ -432,7 +452,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
|
|||
if (i == menu_sel) {
|
||||
// Draw the highlight bar.
|
||||
SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
|
||||
DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
|
||||
DrawHighlightBar(0, y - 2, ScreenWidth(), char_height_ + 4);
|
||||
// Bold white text for the selected item.
|
||||
SetColor(MENU_SEL_FG);
|
||||
y += DrawTextLine(x, y, menu_[i].c_str(), true);
|
||||
|
@ -449,7 +469,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
|
|||
SetColor(LOG);
|
||||
int row = text_row_;
|
||||
size_t count = 0;
|
||||
for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
|
||||
for (int ty = ScreenHeight() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
|
||||
ty -= char_height_, ++count) {
|
||||
DrawTextLine(kMarginWidth, ty, text_[row], false);
|
||||
--row;
|
||||
|
@ -569,8 +589,8 @@ bool ScreenRecoveryUI::InitTextParams() {
|
|||
}
|
||||
|
||||
gr_font_size(gr_sys_font(), &char_width_, &char_height_);
|
||||
text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_;
|
||||
text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_;
|
||||
text_rows_ = (ScreenHeight() - kMarginHeight * 2) / char_height_;
|
||||
text_cols_ = (ScreenWidth() - kMarginWidth * 2) / char_width_;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
11
screen_ui.h
11
screen_ui.h
|
@ -124,12 +124,23 @@ class ScreenRecoveryUI : public RecoveryUI {
|
|||
virtual int GetProgressBaseline() const;
|
||||
virtual int GetTextBaseline() const;
|
||||
|
||||
// Returns pixel width of draw buffer.
|
||||
virtual int ScreenWidth() const;
|
||||
// Returns pixel height of draw buffer.
|
||||
virtual int ScreenHeight() const;
|
||||
|
||||
// Draws a highlight bar at (x, y) - (x + width, y + height).
|
||||
virtual void DrawHighlightBar(int x, int y, int width, int height) const;
|
||||
// Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
|
||||
virtual int DrawHorizontalRule(int y) const;
|
||||
// Draws a line of text. Returns the offset it should be moving along Y-axis.
|
||||
virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
|
||||
// Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
|
||||
virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
|
||||
// Draws rectangle at (x, y) - (x + w, y + h).
|
||||
virtual void DrawFill(int x, int y, int w, int h) const;
|
||||
// Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
|
||||
virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
|
||||
// Draws multiple text lines. Returns the offset it should be moving along Y-axis.
|
||||
int DrawTextLines(int x, int y, const char* const* lines) const;
|
||||
// Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
|
||||
|
|
44
vr_ui.cpp
44
vr_ui.cpp
|
@ -20,16 +20,46 @@
|
|||
|
||||
VrRecoveryUI::VrRecoveryUI() : kStereoOffset(RECOVERY_UI_VR_STEREO_OFFSET) {}
|
||||
|
||||
bool VrRecoveryUI::InitTextParams() {
|
||||
if (!ScreenRecoveryUI::InitTextParams()) return false;
|
||||
int mid_divide = gr_fb_width() / 2;
|
||||
text_cols_ = (mid_divide - kMarginWidth - kStereoOffset) / char_width_;
|
||||
return true;
|
||||
int VrRecoveryUI::ScreenWidth() const {
|
||||
return gr_fb_width() / 2;
|
||||
}
|
||||
|
||||
int VrRecoveryUI::ScreenHeight() const {
|
||||
return gr_fb_height();
|
||||
}
|
||||
|
||||
void VrRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
|
||||
int dy) const {
|
||||
gr_blit(surface, sx, sy, w, h, dx + kStereoOffset, dy);
|
||||
gr_blit(surface, sx, sy, w, h, dx - kStereoOffset + ScreenWidth(), dy);
|
||||
}
|
||||
|
||||
void VrRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
|
||||
gr_texticon(x + kStereoOffset, y, surface);
|
||||
gr_texticon(x - kStereoOffset + ScreenWidth(), y, surface);
|
||||
}
|
||||
|
||||
int VrRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
|
||||
int mid_divide = gr_fb_width() / 2;
|
||||
gr_text(gr_sys_font(), x + kStereoOffset, y, line, bold);
|
||||
gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, y, line, bold);
|
||||
gr_text(gr_sys_font(), x - kStereoOffset + ScreenWidth(), y, line, bold);
|
||||
return char_height_ + 4;
|
||||
}
|
||||
|
||||
int VrRecoveryUI::DrawHorizontalRule(int y) const {
|
||||
y += 4;
|
||||
gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + 2);
|
||||
gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
|
||||
gr_fb_width() - kMarginWidth - kStereoOffset, y + 2);
|
||||
return y + 4;
|
||||
}
|
||||
|
||||
void VrRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
|
||||
gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + height);
|
||||
gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
|
||||
gr_fb_width() - kMarginWidth - kStereoOffset, y + height);
|
||||
}
|
||||
|
||||
void VrRecoveryUI::DrawFill(int x, int y, int w, int h) const {
|
||||
gr_fill(x + kStereoOffset, y, w, h);
|
||||
gr_fill(x - kStereoOffset + ScreenWidth(), y, w, h);
|
||||
}
|
||||
|
|
8
vr_ui.h
8
vr_ui.h
|
@ -28,8 +28,14 @@ class VrRecoveryUI : public ScreenRecoveryUI {
|
|||
// Can vary per device depending on screen size and lens distortion.
|
||||
const int kStereoOffset;
|
||||
|
||||
bool InitTextParams() override;
|
||||
int ScreenWidth() const override;
|
||||
int ScreenHeight() const override;
|
||||
|
||||
void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const override;
|
||||
int DrawHorizontalRule(int y) const override;
|
||||
void DrawHighlightBar(int x, int y, int width, int height) const override;
|
||||
void DrawFill(int x, int y, int w, int h) const override;
|
||||
void DrawTextIcon(int x, int y, GRSurface* surface) const override;
|
||||
int DrawTextLine(int x, int y, const char* line, bool bold) const override;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue