Reduce use of display.h (dp_xres, dp_yres) now that uicontext has bounds

This commit is contained in:
Henrik Rydgard 2014-02-10 12:38:23 +01:00
parent 8b6b491820
commit 4d00a9b4bc
10 changed files with 95 additions and 69 deletions

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "android/app-android.h"
#include "base/display.h"
#include "base/logging.h"
#include "gfx_es2/glsl_program.h"
@ -92,9 +93,11 @@ void EmuScreen::bootGame(const std::string &filename) {
coreParam.printfEmuLog = false;
coreParam.headLess = false;
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
if (g_Config.iInternalResolution == 0) {
coreParam.renderWidth = dp_xres;
coreParam.renderHeight = dp_yres;
coreParam.renderWidth = bounds.w;
coreParam.renderHeight = bounds.h;
} else {
if (g_Config.iInternalResolution < 0)
g_Config.iInternalResolution = 1;
@ -102,8 +105,10 @@ void EmuScreen::bootGame(const std::string &filename) {
coreParam.renderHeight = 272 * g_Config.iInternalResolution;
}
coreParam.pixelWidth = pixel_xres;
coreParam.pixelHeight = pixel_yres;
// If bounds is set to be smaller than the actual pixel resolution of the display, respect that.
// TODO: Should be able to use g_dpi_scale here instead. Might want to store the dpi scale in the UI context too.
coreParam.pixelWidth = pixel_xres * bounds.w / dp_xres;
coreParam.pixelHeight = pixel_yres * bounds.h / dp_yres;
std::string error_string;
if (!PSP_InitStart(coreParam, &error_string)) {
@ -613,7 +618,7 @@ void EmuScreen::render() {
}
if (!osm.IsEmpty()) {
osm.Draw(ui_draw2d);
osm.Draw(ui_draw2d, screenManager()->getUIContext()->GetBounds());
}
if (g_Config.bShowDebugStats) {
@ -642,9 +647,11 @@ void EmuScreen::render() {
default:
return;
}
float xres = screenManager()->getUIContext()->GetBounds().w;
ui_draw2d.SetFontScale(0.7f, 0.7f);
ui_draw2d.DrawText(UBUNTU24, fpsbuf, dp_xres - 8, 12, 0xc0000000, ALIGN_TOPRIGHT | FLAG_DYNAMIC_ASCII);
ui_draw2d.DrawText(UBUNTU24, fpsbuf, dp_xres - 10, 10, 0xFF3fFF3f, ALIGN_TOPRIGHT | FLAG_DYNAMIC_ASCII);
ui_draw2d.DrawText(UBUNTU24, fpsbuf, xres - 8, 12, 0xc0000000, ALIGN_TOPRIGHT | FLAG_DYNAMIC_ASCII);
ui_draw2d.DrawText(UBUNTU24, fpsbuf, xres - 10, 10, 0xFF3fFF3f, ALIGN_TOPRIGHT | FLAG_DYNAMIC_ASCII);
ui_draw2d.SetFontScale(1.0f, 1.0f);
}

View File

@ -15,6 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "base/display.h" // Only to check screen aspect ratio with pixel_yres/pixel_xres
#include "base/colorutil.h"
#include "base/timeutil.h"
#include "math/curves.h"

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "GamepadEmu.h"
#include "base/display.h"
#include "base/colorutil.h"
#include "base/NativeApp.h"
#include "math/math_util.h"

View File

@ -15,7 +15,6 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "base/display.h"
#include "base/colorutil.h"
#include "base/timeutil.h"
#include "gfx_es2/draw_buffer.h"
@ -67,34 +66,38 @@ static const uint32_t colors[4] = {
0xC0FFFFFF,
};
void DrawBackground(float alpha) {
void DrawBackground(UIContext &dc, float alpha = 1.0f) {
static float xbase[100] = {0};
static float ybase[100] = {0};
static int last_dp_xres = 0;
static int last_dp_yres = 0;
if (xbase[0] == 0.0f || last_dp_xres != dp_xres || last_dp_yres != dp_yres) {
float xres = dc.GetBounds().w;
float yres = dc.GetBounds().h;
static int last_xres = 0;
static int last_yres = 0;
if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) {
GMRng rng;
for (int i = 0; i < 100; i++) {
xbase[i] = rng.F() * dp_xres;
ybase[i] = rng.F() * dp_yres;
xbase[i] = rng.F() * xres;
ybase[i] = rng.F() * yres;
}
last_dp_xres = dp_xres;
last_dp_yres = dp_yres;
last_xres = xres;
last_yres = yres;
}
glstate.depthWrite.set(GL_TRUE);
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(0.1f,0.2f,0.43f,1.0f);
glClearColor(0.1f, 0.2f, 0.43f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
int img = I_BG;
#ifdef GOLD
img = I_BG_GOLD;
#endif
ui_draw2d.DrawImageStretch(img, 0, 0, dp_xres, dp_yres);
ui_draw2d.DrawImageStretch(img, 0, 0, xres, yres);
float t = time_now();
for (int i = 0; i < 100; i++) {
float x = xbase[i];
float y = ybase[i] + 40*cos(i * 7.2 + t * 1.3);
float angle = sin(i + t);
float y = ybase[i] + 40 * cosf(i * 7.2f + t * 1.3f);
float angle = sinf(i + t);
int n = i & 3;
ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f));
}
@ -115,11 +118,11 @@ void DrawGameBackground(UIContext &dc, const std::string &gamePath) {
}
if (hasPic) {
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1, color);
dc.Draw()->DrawTexRect(0,0, dc.GetBounds().w, dc.GetBounds().h, 0,0,1,1, color);
dc.Flush();
dc.RebindTexture();
} else {
::DrawBackground(1.0f);
::DrawBackground(dc, 1.0f);
dc.RebindTexture();
dc.Flush();
}
@ -135,7 +138,7 @@ void HandleCommonMessages(const char *message, const char *value, ScreenManager
}
void UIScreenWithBackground::DrawBackground(UIContext &dc) {
::DrawBackground(1.0f);
::DrawBackground(dc, 1.0f);
dc.Flush();
}
@ -176,7 +179,7 @@ UI::EventReturn UIDialogScreenWithBackground::OnLanguageChange(UI::EventParams &
}
void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) {
::DrawBackground(1.0f);
::DrawBackground(dc);
dc.Flush();
}
@ -367,33 +370,38 @@ void LogoScreen::render() {
UIContext &dc = *screenManager()->getUIContext();
float xres = dc.GetBounds().w;
float yres = dc.GetBounds().h;
dc.Begin();
float t = (float)frames_ / 60.0f;
float alpha = t;
if (t > 1.0f) alpha = 1.0f;
if (t > 1.0f)
alpha = 1.0f;
float alphaText = alpha;
if (t > 2.0f) alphaText = 3.0f - t;
if (t > 2.0f)
alphaText = 3.0f - t;
::DrawBackground(alpha);
::DrawBackground(dc, alpha);
I18NCategory *c = GetI18NCategory("PSPCredits");
char temp[256];
sprintf(temp, "%s Henrik Rydg\xc3\xa5rd", c->T("created", "Created by"));
#ifdef GOLD
dc.Draw()->DrawImage(I_ICONGOLD, (dp_xres / 2) - 120, (dp_yres / 2) - 30, 1.2f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.Draw()->DrawImage(I_ICONGOLD, (xres / 2) - 120, (yres / 2) - 30, 1.2f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
#else
dc.Draw()->DrawImage(I_ICON, (dp_xres / 2) - 120, (dp_yres / 2) - 30, 1.2f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.Draw()->DrawImage(I_ICON, (xres / 2) - 120, (yres / 2) - 30, 1.2f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
#endif
dc.Draw()->DrawImage(I_LOGO, (dp_xres / 2) + 40, dp_yres / 2 - 30, 1.5f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
//dc.Draw()->DrawTextShadow(UBUNTU48, "PPSSPP", dp_xres / 2, dp_yres / 2 - 30, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.Draw()->DrawImage(I_LOGO, (xres / 2) + 40, yres / 2 - 30, 1.5f, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
//dc.Draw()->DrawTextShadow(UBUNTU48, "PPSSPP", xres / 2, yres / 2 - 30, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.Draw()->SetFontScale(1.0f, 1.0f);
dc.SetFontStyle(dc.theme->uiFont);
dc.DrawText(temp, dp_xres / 2, dp_yres / 2 + 40, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.DrawText(c->T("license", "Free Software under GPL 2.0"), dp_xres / 2, dp_yres / 2 + 70, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.DrawText("www.ppsspp.org", dp_xres / 2, dp_yres / 2 + 130, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.DrawText(temp, xres / 2, yres / 2 + 40, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.DrawText(c->T("license", "Free Software under GPL 2.0"), xres / 2, yres / 2 + 70, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
dc.DrawText("www.ppsspp.org", xres / 2, yres / 2 + 130, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
if (boot_filename.size()) {
ui_draw2d.DrawTextShadow(UBUNTU24, boot_filename.c_str(), dp_xres / 2, dp_yres / 2 + 180, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
ui_draw2d.DrawTextShadow(UBUNTU24, boot_filename.c_str(), xres / 2, yres / 2 + 180, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER);
}
dc.End();
@ -593,6 +601,7 @@ void CreditsScreen::render() {
c->T("info5", "PSP is a trademark by Sony, Inc."),
};
// TODO: This is kinda ugly, done on every frame...
char temp[256];
sprintf(temp, "PPSSPP %s", PPSSPP_GIT_VERSION);
@ -600,16 +609,17 @@ void CreditsScreen::render() {
UIContext &dc = *screenManager()->getUIContext();
dc.Begin();
const Bounds &bounds = dc.GetBounds();
const int numItems = ARRAY_SIZE(credits);
int itemHeight = 36;
int totalHeight = numItems * itemHeight + dp_yres + 200;
int y = dp_yres - (frames_ % totalHeight);
int totalHeight = numItems * itemHeight + bounds.h + 200;
int y = bounds.y2() - (frames_ % totalHeight);
for (int i = 0; i < numItems; i++) {
float alpha = linearInOut(y+32, 64, dp_yres - 192, 64);
float alpha = linearInOut(y+32, 64, bounds.y2() - 192, 64);
if (alpha > 0.0f) {
dc.SetFontScale(ease(alpha), ease(alpha));
dc.DrawText(credits[i], dp_xres/2, y, whiteAlpha(alpha), ALIGN_HCENTER);
dc.DrawText(credits[i], dc.GetBounds().centerX(), y, whiteAlpha(alpha), ALIGN_HCENTER);
dc.SetFontScale(1.0f, 1.0f);
}
y += itemHeight;

View File

@ -33,6 +33,7 @@
#include "ext/jpge/jpge.h"
#endif
#include "base/display.h"
#include "base/logging.h"
#include "base/mutex.h"
#include "base/NativeApp.h"
@ -495,6 +496,7 @@ void NativeInitGraphics() {
uiContext->Init(UIShader_Get(), UIShader_GetPlain(), uiTexture, &ui_draw2d, &ui_draw2d_front);
if (uiContext->Text())
uiContext->Text()->SetFont("Tahoma", 20, 0);
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
screenManager->setUIContext(uiContext);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -577,7 +579,7 @@ void TakeScreenshot() {
#endif
}
void DrawDownloadsOverlay(UIContext &ctx) {
void DrawDownloadsOverlay(UIContext &dc) {
// Thin bar at the top of the screen like Chrome.
std::vector<float> progress = g_DownloadManager.GetCurrentProgress();
if (progress.empty()) {
@ -591,16 +593,16 @@ void DrawDownloadsOverlay(UIContext &ctx) {
0xFF777777,
};
ctx.Begin();
dc.Begin();
int h = 5;
for (size_t i = 0; i < progress.size(); i++) {
float barWidth = 10 + (dp_xres - 10) * progress[i];
float barWidth = 10 + (dc.GetBounds().w - 10) * progress[i];
Bounds bounds(0, h * i, barWidth, h);
UI::Drawable solid(colors[i & 3]);
ctx.FillRect(solid, bounds);
dc.FillRect(solid, bounds);
}
ctx.End();
ctx.Flush();
dc.End();
dc.Flush();
}
void NativeRender() {
@ -616,8 +618,11 @@ void NativeRender() {
glstate.viewport.set(0, 0, pixel_xres, pixel_yres);
glstate.Restore();
float xres = uiContext->GetBounds().w;
float yres = uiContext->GetBounds().h;
// Apply the UIContext bounds as a 2D transformation matrix.
Matrix4x4 ortho;
ortho.setOrtho(0.0f, dp_xres, dp_yres, 0.0f, -1.0f, 1.0f);
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
glsl_bind(UIShader_Get());
glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr());
@ -776,6 +781,7 @@ void NativeMessageReceived(const char *message, const char *value) {
}
void NativeResized() {
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
}
void NativeShutdown() {

View File

@ -2,13 +2,12 @@
#include "UI/ui_atlas.h"
#include "base/colorutil.h"
#include "base/display.h"
#include "base/timeutil.h"
#include "gfx_es2/draw_buffer.h"
OnScreenMessages osm;
void OnScreenMessages::Draw(DrawBuffer &draw) {
void OnScreenMessages::Draw(DrawBuffer &draw, const Bounds &bounds) {
// First, clean out old messages.
std::lock_guard<std::recursive_mutex> guard(mutex_);
@ -34,9 +33,9 @@ restart:
// Messages that are wider than the screen are left-aligned instead of centered.
float tw, th;
draw.MeasureText(UBUNTU24, iter->text.c_str(), &tw, &th);
float x = dp_xres / 2;
float x = bounds.centerX();
int align = ALIGN_TOP | ALIGN_HCENTER;
if (tw > dp_xres) {
if (tw > bounds.w) {
align = ALIGN_TOP | ALIGN_LEFT;
x = 2;
}

View File

@ -4,6 +4,7 @@
#include <list>
#include "base/basictypes.h"
#include "math/geom2d.h"
#include "Common/StdMutex.h"
class DrawBuffer;
@ -12,7 +13,7 @@ class OnScreenMessages {
public:
void Show(const std::string &message, float duration_s = 1.0f, uint32_t color = 0xFFFFFF, int icon = -1, bool checkUnique = true);
void ShowOnOff(const std::string &message, bool b, float duration_s = 1.0f, uint32_t color = 0xFFFFFF, int icon = -1);
void Draw(DrawBuffer &draw);
void Draw(DrawBuffer &draw, const Bounds &bounds);
bool IsEmpty() const { return messages_.empty(); }
private:

View File

@ -17,16 +17,18 @@
#include <vector>
#include "base/display.h"
#include "base/colorutil.h"
#include "gfx_es2/draw_buffer.h"
#include "i18n/i18n.h"
#include "ui/ui_context.h"
#include "ui_atlas.h"
#include "TouchControlLayoutScreen.h"
#include "TouchControlVisibilityScreen.h"
#include "Core/Config.h"
#include "Core/System.h"
#include "base/colorutil.h"
#include "ui/ui_context.h"
#include "ui_atlas.h"
#include "gfx_es2/draw_buffer.h"
#include "GamepadEmu.h"
#include "i18n/i18n.h"
static const int leftColumnWidth = 140;
@ -34,16 +36,6 @@ static u32 GetButtonColor() {
return g_Config.iTouchButtonStyle == 1 ? 0xFFFFFF : 0xc0b080;
}
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
static inline float toFullscreenCoord(int screenx) {
return (float)(screenx - leftColumnWidth) / (dp_xres - leftColumnWidth);
}
// convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres)
static inline int fromFullscreenCoord(float controllerX) {
return leftColumnWidth + (dp_xres - leftColumnWidth) * controllerX;
};
class DragDropButton : public MultiTouchButton {
public:
DragDropButton(float &x, float &y, int bgImg, int img, float &scale)
@ -71,6 +63,16 @@ public:
virtual void SetSpacing(float s) { }
private:
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
inline float toFullscreenCoord(int screenx) {
return (float)(screenx - leftColumnWidth) / (dp_xres - leftColumnWidth);
}
// convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres)
inline int fromFullscreenCoord(float controllerX) {
return leftColumnWidth + (dp_xres - leftColumnWidth) * controllerX;
};
float &x_, &y_;
float &theScale_;
};

View File

@ -1,6 +1,5 @@
// NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
#include "base/display.h"
#include "base/timeutil.h"
#include "base/NativeApp.h"
#include "base/mutex.h"
@ -60,7 +59,6 @@ void EmuThread_Stop()
}
globalUIState = UISTATE_EXIT;
// DSound_UpdateSound();
Core_Stop();
Core_WaitInactive(800);
if (WAIT_TIMEOUT == WaitForSingleObject(emuThread, 800))

2
native

@ -1 +1 @@
Subproject commit cbd28980da5b71d3485e8ccf43c752fcef1a4d72
Subproject commit f73890f0b2f74b852e86a5b8f33056fe1790ec5d