Support theme width and height offsets
Current use condition is LG V20, where the secondary screen is
actually just a corner chunk of the main screen.
In this case, we need to shift the UI down some pixels in order
to see it all, but just using Y offsets resulted in losing
the rest of the GUI below.
Example in BoardConfig.mk:
# Shift TWRP off the secondary screen
TW_Y_OFFSET := 160
TW_H_OFFSET := -160
Change-Id: I5a06638ba0d05e5b9fd8a6245c630d6ea3394f78
diff --git a/gui/Android.mk b/gui/Android.mk
index b514e5b..dab35a4 100644
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -67,6 +67,12 @@
ifneq ($(TW_Y_OFFSET),)
LOCAL_CFLAGS += -DTW_Y_OFFSET=$(TW_Y_OFFSET)
endif
+ifneq ($(TW_W_OFFSET),)
+ LOCAL_CFLAGS += -DTW_W_OFFSET=$(TW_W_OFFSET)
+endif
+ifneq ($(TW_H_OFFSET),)
+ LOCAL_CFLAGS += -DTW_H_OFFSET=$(TW_H_OFFSET)
+endif
ifeq ($(TW_ROUND_SCREEN), true)
LOCAL_CFLAGS += -DTW_ROUND_SCREEN
endif
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 2a95022..7506277 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -42,6 +42,12 @@
#ifndef TW_Y_OFFSET
#define TW_Y_OFFSET 0
#endif
+#ifndef TW_W_OFFSET
+#define TW_W_OFFSET 0
+#endif
+#ifndef TW_H_OFFSET
+#define TW_H_OFFSET 0
+#endif
class RenderObject
{
diff --git a/gui/pages.cpp b/gui/pages.cpp
index b6b7296..d7cb92d 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -71,6 +71,8 @@
int tw_x_offset = 0;
int tw_y_offset = 0;
+int tw_w_offset = 0;
+int tw_h_offset = 0;
// Helper routine to convert a string to a color declaration
int ConvertStrToColor(std::string str, COLOR* color)
@@ -895,16 +897,17 @@
}
#endif
if (width != 0 && height != 0) {
- float scale_w = ((float)gr_fb_width() - ((float)offx * 2.0)) / (float)width;
- float scale_h = ((float)gr_fb_height() - ((float)offy * 2.0)) / (float)height;
+ float scale_w = (((float)gr_fb_width() + (float)tw_w_offset) - ((float)offx * 2.0)) / (float)width;
+ float scale_h = (((float)gr_fb_height() + (float)tw_h_offset) - ((float)offy * 2.0)) / (float)height;
#ifdef TW_ROUND_SCREEN
- float scale_off_w = (float)gr_fb_width() / (float)width;
- float scale_off_h = (float)gr_fb_height() / (float)height;
+ float scale_off_w = ((float)gr_fb_width() + (float)tw_w_offset) / (float)width;
+ float scale_off_h = ((float)gr_fb_height() + (float)tw_h_offset) / (float)height;
tw_x_offset = offx * scale_off_w;
tw_y_offset = offy * scale_off_h;
#endif
if (scale_w != 1 || scale_h != 1) {
- LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i\n", scale_w, scale_h, tw_x_offset, tw_y_offset);
+ LOGINFO("Scaling theme width %fx and height %fx, offsets x: %i y: %i w: %i h: %i\n",
+ scale_w, scale_h, tw_x_offset, tw_y_offset, tw_w_offset, tw_h_offset);
set_scale_values(scale_w, scale_h);
}
}
@@ -1018,6 +1021,16 @@
child = child->next_sibling("variable");
continue;
}
+ if (strcmp(name->value(), "tw_w_offset") == 0) {
+ tw_w_offset = atoi(value->value());
+ child = child->next_sibling("variable");
+ continue;
+ }
+ if (strcmp(name->value(), "tw_h_offset") == 0) {
+ tw_h_offset = atoi(value->value());
+ child = child->next_sibling("variable");
+ continue;
+ }
p = persist ? atoi(persist->value()) : 0;
string temp = value->value();
string valstr = gui_parse_text(temp);
@@ -1340,6 +1353,8 @@
LOGINFO("Load XML directly\n");
tw_x_offset = TW_X_OFFSET;
tw_y_offset = TW_Y_OFFSET;
+ tw_w_offset = TW_W_OFFSET;
+ tw_h_offset = TW_H_OFFSET;
if (name != "splash") {
LoadLanguageList(NULL);
languageFile = LoadFileToBuffer(TWRES "languages/en.xml", NULL);
@@ -1351,6 +1366,8 @@
LOGINFO("Loading zip theme\n");
tw_x_offset = 0;
tw_y_offset = 0;
+ tw_w_offset = 0;
+ tw_h_offset = 0;
if (!TWFunc::Path_Exists(package))
return -1;
if (sysMapFile(package.c_str(), &map) != 0) {