Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dcd1e440 authored by James Christopher Adduono's avatar James Christopher Adduono Committed by Dees Troy
Browse files

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
parent b29a5e27
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ endif
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
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,12 @@ using namespace rapidxml;
#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
{
+22 −5
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ std::vector<language_struct> Language_List;

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 @@ int PageSet::LoadDetails(LoadingContext& ctx, xml_node<>* root)
				}
#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 @@ int PageSet::LoadVariables(xml_node<>* vars)
				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 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string
		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 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string
		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) {