MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / onEnter

Method onEnter

src/activities/util/BmpViewerActivity.cpp:59–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59void BmpViewerActivity::onEnter() {
60 Activity::onEnter();
61
62 if (siblingImages.empty() && !filePath.empty()) {
63 loadSiblingImages();
64 }
65
66 HalFile file;
67
68 const auto pageWidth = renderer.getScreenWidth();
69 const auto pageHeight = renderer.getScreenHeight();
70 Rect popupRect = GUI.drawPopup(renderer, tr(STR_LOADING_POPUP));
71 GUI.fillPopupProgress(renderer, popupRect, 20); // Initial 20% progress
72 // 1. Open the file
73 if (Storage.openFileForRead("BMP", filePath, file)) {
74 Bitmap bitmap(file, true);
75
76 // 2. Parse headers to get dimensions
77 if (bitmap.parseHeaders() == BmpReaderError::Ok) {
78 int x, y;
79
80 if (bitmap.getWidth() > pageWidth || bitmap.getHeight() > pageHeight) {
81 float ratio = static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
82 const float screenRatio = static_cast<float>(pageWidth) / static_cast<float>(pageHeight);
83
84 if (ratio > screenRatio) {
85 // Wider than screen
86 x = 0;
87 y = std::round((static_cast<float>(pageHeight) - static_cast<float>(pageWidth) / ratio) / 2);
88 } else {
89 // Taller than screen
90 x = std::round((static_cast<float>(pageWidth) - static_cast<float>(pageHeight) * ratio) / 2);
91 y = 0;
92 }
93 } else {
94 // Center small images
95 x = (pageWidth - bitmap.getWidth()) / 2;
96 y = (pageHeight - bitmap.getHeight()) / 2;
97 }
98
99 // 4. Prepare Rendering
100 bool hasPrevious = (siblingImages.size() > 1 && currentImageIndex > 0);
101 bool hasNext = (siblingImages.size() > 1 && currentImageIndex != -1 &&
102 currentImageIndex < static_cast<int>(siblingImages.size()) - 1);
103
104 const auto labels =
105 mappedInput.mapLabels(tr(STR_BACK), tr(STR_SET_SLEEP_COVER), (hasPrevious ? "<" : ""), (hasNext ? ">" : ""));
106
107 GUI.fillPopupProgress(renderer, popupRect, 50);
108
109 renderer.clearScreen();
110 // Assuming drawBitmap defaults to 0,0 crop if omitted, or pass explicitly: drawBitmap(bitmap, x, y, pageWidth,
111 // pageHeight, 0, 0)
112 renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, 0, 0);
113
114 // Draw UI hints on the base layer
115 GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
116 // Single pass for non-grayscale images

Callers

nothing calls this directly

Calls 15

getScreenWidthMethod · 0.80
getScreenHeightMethod · 0.80
drawPopupMethod · 0.80
fillPopupProgressMethod · 0.80
openFileForReadMethod · 0.80
parseHeadersMethod · 0.80
mapLabelsMethod · 0.80
drawBitmapMethod · 0.80
emptyMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected