Browse Source

recovery: Scale logo image if necessary

Some unified devices (like find7) have differing screen sizes and
choose the larger size for resources.  Handle this by scaling the
logo image dynamically rather than adding more specialized logic
to the device tree.

A complete solution would also scale all of the UI elements (back
icon and main menu icons).  But these are not as sensitive to
screen size and scaling them is not currently necessary.

Change-Id: Ibab0cedd3b15b5fcb7e63595b67119dd7c296f6a
Tom Marshall 3 years ago
parent
commit
c83ed2b195
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      screen_ui.cpp

+ 16
- 1
screen_ui.cpp View File

@@ -901,7 +901,22 @@ bool ScreenRecoveryUI::Init(const std::string& locale) {
901 901
   // Set up the locale info.
902 902
   SetLocale(locale);
903 903
 
904
-  LoadBitmap("logo_image", &logo_image);
904
+  // Load logo and scale it if necessary
905
+  // Note 2/45 is our standard margin on each side so the maximum image
906
+  // width is 41/45 of the screen width.
907
+  GRSurface* image;
908
+  LoadBitmap("logo_image", &image);
909
+  if ((int)gr_get_width(image) > gr_fb_width() * 41 / 45) {
910
+      float scale = (float)gr_fb_width() / (float)gr_get_width(image) *
911
+                    (41.0f / 45.0f);
912
+      GRSurface* scaled_image;
913
+      res_create_scaled_surface(&scaled_image, image, scale, scale);
914
+      logo_image = scaled_image;
915
+      res_free_surface(image);
916
+  } else {
917
+      logo_image = image;
918
+  }
919
+
905 920
   LoadBitmap("ic_back", &ic_back);
906 921
   LoadBitmap("ic_back_sel", &ic_back_sel);
907 922