mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
fix(cppcheck): more clang format fix
This commit is contained in:
parent
e6f6f14b37
commit
7bfb3af0da
@ -805,10 +805,11 @@ void GfxRenderer::drawBitmap1Bit(const Bitmap& bitmap, const int x, const int y,
|
||||
free(rowBytes);
|
||||
}
|
||||
|
||||
void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h) const {
|
||||
void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w,
|
||||
const int h) const {
|
||||
// Similar to drawBitmap1Bit but strictly skips 1s (white) in the source 1-bit data
|
||||
// The Bitmap reader returns 2-bit packed data where 0-2=Black and 3=White for 1-bit sources
|
||||
|
||||
|
||||
float scale = 1.0f;
|
||||
bool isScaled = false;
|
||||
if (w > 0) {
|
||||
@ -839,11 +840,11 @@ void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const
|
||||
}
|
||||
|
||||
const int bmpYOffset = bitmap.isTopDown() ? bmpY : bitmap.getHeight() - 1 - bmpY;
|
||||
|
||||
|
||||
// Calculate target Y span
|
||||
int startY = y + static_cast<int>(std::floor(bmpYOffset * scale));
|
||||
int endY = y + static_cast<int>(std::floor((bmpYOffset + 1) * scale));
|
||||
|
||||
|
||||
// Clamp to screen
|
||||
if (startY < 0) startY = 0;
|
||||
if (endY > getScreenHeight()) endY = getScreenHeight();
|
||||
@ -853,7 +854,7 @@ void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const
|
||||
// Calculate target X span
|
||||
int startX = x + static_cast<int>(std::floor(bmpX * scale));
|
||||
int endX = x + static_cast<int>(std::floor((bmpX + 1) * scale));
|
||||
|
||||
|
||||
if (startX < 0) startX = 0;
|
||||
if (endX > getScreenWidth()) endX = getScreenWidth();
|
||||
if (startX >= endX) continue;
|
||||
@ -864,7 +865,7 @@ void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const
|
||||
if (val < 3) {
|
||||
for (int sy = startY; sy < endY; sy++) {
|
||||
for (int sx = startX; sx < endX; sx++) {
|
||||
drawPixel(sx, sy, true); // Black
|
||||
drawPixel(sx, sy, true); // Black
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -945,11 +946,11 @@ void GfxRenderer::drawRoundedBitmap(const Bitmap& bitmap, const int x, const int
|
||||
}
|
||||
|
||||
const int bmpYOffset = bitmap.isTopDown() ? bmpY : bitmap.getHeight() - 1 - bmpY;
|
||||
|
||||
|
||||
// Calculate target Y span
|
||||
int startY = y + static_cast<int>(std::floor(bmpYOffset * scale));
|
||||
int endY = y + static_cast<int>(std::floor((bmpYOffset + 1) * scale));
|
||||
|
||||
|
||||
if (startY < 0) startY = 0;
|
||||
if (endY > getScreenHeight()) endY = getScreenHeight();
|
||||
if (startY >= endY) continue;
|
||||
@ -957,7 +958,7 @@ void GfxRenderer::drawRoundedBitmap(const Bitmap& bitmap, const int x, const int
|
||||
for (int bmpX = 0; bmpX < bitmap.getWidth(); bmpX++) {
|
||||
int startX = x + static_cast<int>(std::floor(bmpX * scale));
|
||||
int endX = x + static_cast<int>(std::floor((bmpX + 1) * scale));
|
||||
|
||||
|
||||
if (startX < 0) startX = 0;
|
||||
if (endX > getScreenWidth()) endX = getScreenWidth();
|
||||
if (startX >= endX) continue;
|
||||
@ -968,7 +969,7 @@ void GfxRenderer::drawRoundedBitmap(const Bitmap& bitmap, const int x, const int
|
||||
if (renderMode == BW) {
|
||||
pixelBlack = (val < 2);
|
||||
} else if (renderMode == GRAYSCALE_MSB) {
|
||||
pixelBlack = (val < 3); // Draw all non-white as black for icons/covers
|
||||
pixelBlack = (val < 3); // Draw all non-white as black for icons/covers
|
||||
} else if (renderMode == GRAYSCALE_LSB) {
|
||||
pixelBlack = (val == 0);
|
||||
}
|
||||
|
||||
@ -78,7 +78,8 @@ class GfxRenderer {
|
||||
float cropY = 0) const;
|
||||
void drawBitmap1Bit(const Bitmap& bitmap, const int x, const int y, const int maxWidth, const int maxHeight) const;
|
||||
void drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h) const;
|
||||
void drawRoundedBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h, const int radius) const;
|
||||
void drawRoundedBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h,
|
||||
const int radius) const;
|
||||
void draw2BitImage(const uint8_t data[], int x, int y, int w, int h) const;
|
||||
void fillPolygon(const int* xPoints, const int* yPoints, int numPoints, bool state = true) const;
|
||||
|
||||
|
||||
@ -262,67 +262,67 @@ class Label : public UIElement {
|
||||
// Binary search for cut point
|
||||
int len = remaining.length();
|
||||
int cut = len;
|
||||
|
||||
|
||||
// Find split point
|
||||
// Optimistic start: approximate chars that fit
|
||||
int avgCharWidth = renderer.getTextWidth(fontId, "a");
|
||||
int avgCharWidth = renderer.getTextWidth(fontId, "a");
|
||||
if (avgCharWidth < 1) avgCharWidth = 8;
|
||||
int approxChars = absW / avgCharWidth;
|
||||
int approxChars = absW / avgCharWidth;
|
||||
if (approxChars < 1) approxChars = 1;
|
||||
if (approxChars >= len) approxChars = len - 1;
|
||||
|
||||
|
||||
// Refine from approxChars
|
||||
int w = renderer.getTextWidth(fontId, remaining.substr(0, approxChars).c_str());
|
||||
if (w < absW) {
|
||||
// Grow
|
||||
for (int i = approxChars; i <= len; i++) {
|
||||
if (renderer.getTextWidth(fontId, remaining.substr(0, i).c_str()) > absW) {
|
||||
cut = i - 1;
|
||||
break;
|
||||
}
|
||||
cut = i;
|
||||
}
|
||||
// Grow
|
||||
for (int i = approxChars; i <= len; i++) {
|
||||
if (renderer.getTextWidth(fontId, remaining.substr(0, i).c_str()) > absW) {
|
||||
cut = i - 1;
|
||||
break;
|
||||
}
|
||||
cut = i;
|
||||
}
|
||||
} else {
|
||||
// Shrink
|
||||
for (int i = approxChars; i > 0; i--) {
|
||||
if (renderer.getTextWidth(fontId, remaining.substr(0, i).c_str()) <= absW) {
|
||||
cut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Shrink
|
||||
for (int i = approxChars; i > 0; i--) {
|
||||
if (renderer.getTextWidth(fontId, remaining.substr(0, i).c_str()) <= absW) {
|
||||
cut = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find last space before cut
|
||||
if (cut < (int)remaining.length()) {
|
||||
int space = -1;
|
||||
for (int i = cut; i > 0; i--) {
|
||||
if (remaining[i] == ' ') {
|
||||
space = i;
|
||||
break;
|
||||
}
|
||||
int space = -1;
|
||||
for (int i = cut; i > 0; i--) {
|
||||
if (remaining[i] == ' ') {
|
||||
space = i;
|
||||
break;
|
||||
}
|
||||
if (space != -1) cut = space;
|
||||
}
|
||||
if (space != -1) cut = space;
|
||||
}
|
||||
|
||||
std::string line = remaining.substr(0, cut);
|
||||
|
||||
|
||||
// If we're at the last allowed line but still have more text
|
||||
if ((int)lines.size() == maxLines - 1 && cut < (int)remaining.length()) {
|
||||
if (ellipsis) {
|
||||
line = renderer.truncatedText(fontId, remaining.c_str(), absW);
|
||||
}
|
||||
lines.push_back(line);
|
||||
break;
|
||||
if (ellipsis) {
|
||||
line = renderer.truncatedText(fontId, remaining.c_str(), absW);
|
||||
}
|
||||
lines.push_back(line);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
lines.push_back(line);
|
||||
// Advance
|
||||
if (cut < (int)remaining.length()) {
|
||||
// Skip the space if check
|
||||
if (remaining[cut] == ' ') cut++;
|
||||
remaining = remaining.substr(cut);
|
||||
// Skip the space if check
|
||||
if (remaining[cut] == ' ') cut++;
|
||||
remaining = remaining.substr(cut);
|
||||
} else {
|
||||
remaining = "";
|
||||
remaining = "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -332,29 +332,29 @@ class Label : public UIElement {
|
||||
}
|
||||
lines.push_back(finalText);
|
||||
}
|
||||
|
||||
|
||||
// Draw lines
|
||||
int totalTextHeight = lines.size() * lineHeight;
|
||||
int startY = absY;
|
||||
|
||||
|
||||
// Vertical centering
|
||||
if (absH > 0 && totalTextHeight < absH) {
|
||||
startY = absY + (absH - totalTextHeight) / 2;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
int lineWidth = renderer.getTextWidth(fontId, lines[i].c_str());
|
||||
int drawX = absX;
|
||||
|
||||
if (alignment == Alignment::Center && absW > 0) {
|
||||
drawX = absX + (absW - lineWidth) / 2;
|
||||
} else if (alignment == Alignment::Right && absW > 0) {
|
||||
drawX = absX + absW - lineWidth;
|
||||
}
|
||||
|
||||
renderer.drawText(fontId, drawX, startY + i * lineHeight, lines[i].c_str(), black);
|
||||
int lineWidth = renderer.getTextWidth(fontId, lines[i].c_str());
|
||||
int drawX = absX;
|
||||
|
||||
if (alignment == Alignment::Center && absW > 0) {
|
||||
drawX = absX + (absW - lineWidth) / 2;
|
||||
} else if (alignment == Alignment::Right && absW > 0) {
|
||||
drawX = absX + absW - lineWidth;
|
||||
}
|
||||
|
||||
renderer.drawText(fontId, drawX, startY + i * lineHeight, lines[i].c_str(), black);
|
||||
}
|
||||
|
||||
|
||||
markClean();
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
#include "BasicElements.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "Bitmap.h"
|
||||
#include "ListElement.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "ThemeTypes.h"
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
namespace ThemeEngine {
|
||||
|
||||
@ -23,7 +24,7 @@ void BitmapElement::draw(const GfxRenderer& renderer, const ThemeContext& contex
|
||||
|
||||
// Resolve simplified or relative paths
|
||||
if (path.find('/') == std::string::npos || (path.length() > 0 && path[0] != '/')) {
|
||||
path = ThemeManager::get().getAssetPath(path);
|
||||
path = ThemeManager::get().getAssetPath(path);
|
||||
}
|
||||
|
||||
// 1. Check if we have a cached 1-bit render
|
||||
@ -47,46 +48,46 @@ void BitmapElement::draw(const GfxRenderer& renderer, const ThemeContext& contex
|
||||
|
||||
// 2. Try Streaming (Absolute paths, large images)
|
||||
if (path.length() > 0 && path[0] == '/') {
|
||||
FsFile file;
|
||||
if (SdMan.openFileForRead("HOME", path, file)) {
|
||||
Bitmap bmp(file, true); // (file, dithering=true)
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
// Center logic
|
||||
int drawX = absX;
|
||||
int drawY = absY;
|
||||
if (bmp.getWidth() < absW) drawX += (absW - bmp.getWidth()) / 2;
|
||||
if (bmp.getHeight() < absH) drawY += (absH - bmp.getHeight()) / 2;
|
||||
|
||||
if (borderRadius > 0) {
|
||||
renderer.drawRoundedBitmap(bmp, drawX, drawY, absW, absH, borderRadius);
|
||||
} else {
|
||||
renderer.drawBitmap(bmp, drawX, drawY, absW, absH);
|
||||
}
|
||||
drawSuccess = true;
|
||||
}
|
||||
file.close();
|
||||
FsFile file;
|
||||
if (SdMan.openFileForRead("HOME", path, file)) {
|
||||
Bitmap bmp(file, true); // (file, dithering=true)
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
// Center logic
|
||||
int drawX = absX;
|
||||
int drawY = absY;
|
||||
if (bmp.getWidth() < absW) drawX += (absW - bmp.getWidth()) / 2;
|
||||
if (bmp.getHeight() < absH) drawY += (absH - bmp.getHeight()) / 2;
|
||||
|
||||
if (borderRadius > 0) {
|
||||
renderer.drawRoundedBitmap(bmp, drawX, drawY, absW, absH, borderRadius);
|
||||
} else {
|
||||
renderer.drawBitmap(bmp, drawX, drawY, absW, absH);
|
||||
}
|
||||
drawSuccess = true;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Fallback to RAM Cache (Standard method)
|
||||
if (!drawSuccess) {
|
||||
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(path);
|
||||
if (data && !data->empty()) {
|
||||
Bitmap bmp(data->data(), data->size());
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
int drawX = absX;
|
||||
int drawY = absY;
|
||||
if (bmp.getWidth() < absW) drawX += (absW - bmp.getWidth()) / 2;
|
||||
if (bmp.getHeight() < absH) drawY += (absH - bmp.getHeight()) / 2;
|
||||
|
||||
if (borderRadius > 0) {
|
||||
renderer.drawRoundedBitmap(bmp, drawX, drawY, absW, absH, borderRadius);
|
||||
} else {
|
||||
renderer.drawBitmap(bmp, drawX, drawY, absW, absH);
|
||||
}
|
||||
drawSuccess = true;
|
||||
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(path);
|
||||
if (data && !data->empty()) {
|
||||
Bitmap bmp(data->data(), data->size());
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
int drawX = absX;
|
||||
int drawY = absY;
|
||||
if (bmp.getWidth() < absW) drawX += (absW - bmp.getWidth()) / 2;
|
||||
if (bmp.getHeight() < absH) drawY += (absH - bmp.getHeight()) / 2;
|
||||
|
||||
if (borderRadius > 0) {
|
||||
renderer.drawRoundedBitmap(bmp, drawX, drawY, absW, absH, borderRadius);
|
||||
} else {
|
||||
renderer.drawBitmap(bmp, drawX, drawY, absW, absH);
|
||||
}
|
||||
}
|
||||
drawSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Cache result if successful
|
||||
|
||||
Loading…
Reference in New Issue
Block a user