From 0f772e5a90b559d3b24b3f2a6239ac76bc038cce Mon Sep 17 00:00:00 2001 From: Aleksei Dynda Date: Sat, 19 Aug 2023 18:59:40 +1000 Subject: [PATCH] Replacing macro name (min, max) -> (lcd_gfx_min, lcd_gfx_max) #109 --- examples/demos/sh1107_demo/sh1107_demo.ino | 3 ++- examples/games/arkanoid/arkanoid.ino | 8 ++++---- examples/games/lode_runner/lode_runner.ino | 16 ++++++++-------- .../lode_runner_ili9341/lode_runner_ili9341.ino | 16 ++++++++-------- examples/wio_terminal/lode_runner/src/main.cpp | 16 ++++++++-------- src/lcd_hal/linux/io.h | 4 ++-- src/lcd_hal/linux/platform.cpp | 8 ++++---- src/nano_gfx_types.h | 16 ++++++++-------- src/v2/gui/menu.h | 10 +++++----- src/v2/lcd/base/ssd1306_common.inl | 12 ++++++------ src/v2/nano_engine/tiler.h | 2 +- 11 files changed, 56 insertions(+), 55 deletions(-) diff --git a/examples/demos/sh1107_demo/sh1107_demo.ino b/examples/demos/sh1107_demo/sh1107_demo.ino index a0a54790..4db2120b 100644 --- a/examples/demos/sh1107_demo/sh1107_demo.ino +++ b/examples/demos/sh1107_demo/sh1107_demo.ino @@ -40,7 +40,8 @@ #include "lcdgfx_gui.h" #include "owl.h" -DisplaySH1107_128x64_I2C display(-1); // or (-1,{busId, addr, scl, sda, frequency}). This line is suitable for most platforms by default +//DisplaySH1107_128x64_I2C display(-1); // or (-1,{busId, addr, scl, sda, frequency}). This line is suitable for most platforms by default +DisplaySH1107_128x64_I2C display(-1, {-1, 0x3C, -1, -1, 10000000}); // or (-1,{busId, addr, scl, sda, frequency}). This line is suitable for most platforms by default //DisplaySH1107_128x64_SPI display(-1,{-1, 0, 1, 0, -1, -1); // Use this line for nano pi (RST not used, 0=CE, gpio1=D/C) //DisplaySH1107_128x64_SPI display(3,{-1, 4, 5, 0,-1,-1}); // Use this line for Atmega328p (3=RST, 4=CE, 5=D/C) //DisplaySH1107_128x64_SPI display(24,{-1, 0, 23, 0,-1,-1}); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C) diff --git a/examples/games/arkanoid/arkanoid.ino b/examples/games/arkanoid/arkanoid.ino index ec3b35f0..30f58061 100644 --- a/examples/games/arkanoid/arkanoid.ino +++ b/examples/games/arkanoid/arkanoid.ino @@ -178,7 +178,7 @@ void drawIntro() void drawStatusPanel() { display.setColor(RGB_COLOR8(255,0,0)); - for(uint8_t i=0; i> 1); hSpeed = (nextx - middle) / (platformWidth >> (SPEED_SHIFT + 1)); - vSpeed = -max(4 - abs(hSpeed), 2); + vSpeed = -lcd_gfx_max(4 - abs(hSpeed), 2); beep(20,600); } /* Check screen hit */ diff --git a/examples/games/lode_runner/lode_runner.ino b/examples/games/lode_runner/lode_runner.ino index 0b6a5a05..24b5e25f 100644 --- a/examples/games/lode_runner/lode_runner.ino +++ b/examples/games/lode_runner/lode_runner.ino @@ -131,11 +131,11 @@ static bool onDraw() { engine.worldCoordinates(); NanoRect blocks = rect_to_blocks( engine.getCanvas().rect() ); - for (uint8_t row = max(0,blocks.p1.y); - row <= min(13,blocks.p2.y); row++) + for (uint8_t row = lcd_gfx_max(0,blocks.p1.y); + row <= lcd_gfx_min(13,blocks.p2.y); row++) { - for (uint8_t col = max(0,blocks.p1.x); - col <= min(23,blocks.p2.x); col++) + for (uint8_t col = lcd_gfx_max(0,blocks.p1.x); + col <= lcd_gfx_min(23,blocks.p2.x); col++) { uint8_t blockType = block_value({col,row}); if (blockType != 0) @@ -160,19 +160,19 @@ static NanoPoint calc_new_screen_position() NanoPoint position = engine.getPosition() + game_window.p1; if (player.x() - position.x >= game_window.width() - 24) { - position.x = min(player.x() - (game_window.width() - 24), 128); + position.x = lcd_gfx_min(player.x() - (game_window.width() - 24), 128); } else if (player.x() - position.x < 24) { - position.x = max(0, player.x() - 24); + position.x = lcd_gfx_max(0, player.x() - 24); } if (player.y() - position.y >= game_window.height() - 24) { - position.y = min(player.y() - (game_window.height() - 24), 64); + position.y = lcd_gfx_min(player.y() - (game_window.height() - 24), 64); } else if (player.y() - position.y < 24) { - position.y = max(0, player.y() - 24); + position.y = lcd_gfx_max(0, player.y() - 24); } return position - game_window.p1; } diff --git a/examples/games/lode_runner_ili9341/lode_runner_ili9341.ino b/examples/games/lode_runner_ili9341/lode_runner_ili9341.ino index dfb7dc15..2e7e91de 100644 --- a/examples/games/lode_runner_ili9341/lode_runner_ili9341.ino +++ b/examples/games/lode_runner_ili9341/lode_runner_ili9341.ino @@ -131,11 +131,11 @@ static bool onDraw() { engine.worldCoordinates(); NanoRect blocks = rect_to_blocks( engine.getCanvas().rect() ); - for (uint8_t row = max(0,blocks.p1.y); - row <= min(13,blocks.p2.y); row++) + for (uint8_t row = lcd_gfx_max(0,blocks.p1.y); + row <= lcd_gfx_min(13,blocks.p2.y); row++) { - for (uint8_t col = max(0,blocks.p1.x); - col <= min((B_WIDTH-1),blocks.p2.x); col++) + for (uint8_t col = lcd_gfx_max(0,blocks.p1.x); + col <= lcd_gfx_min((B_WIDTH-1),blocks.p2.x); col++) { uint8_t blockType = block_value({col,row}); if (blockType != 0) @@ -160,19 +160,19 @@ static NanoPoint calc_new_screen_position() NanoPoint position = engine.getPosition() + game_window.p1; if (player.x() - position.x >= game_window.width() - 24) { - position.x = min(player.x() - (game_window.width() - 24), 128); + position.x = lcd_gfx_min(player.x() - (game_window.width() - 24), 128); } else if (player.x() - position.x < 24) { - position.x = max(0, player.x() - 24); + position.x = lcd_gfx_max(0, player.x() - 24); } if (player.y() - position.y >= game_window.height() - 24) { - position.y = min(player.y() - (game_window.height() - 24), 64); + position.y = lcd_gfx_min(player.y() - (game_window.height() - 24), 64); } else if (player.y() - position.y < 24) { - position.y = max(0, player.y() - 24); + position.y = lcd_gfx_max(0, player.y() - 24); } return position - game_window.p1; } diff --git a/examples/wio_terminal/lode_runner/src/main.cpp b/examples/wio_terminal/lode_runner/src/main.cpp index b51a36dd..5b8f0d3d 100644 --- a/examples/wio_terminal/lode_runner/src/main.cpp +++ b/examples/wio_terminal/lode_runner/src/main.cpp @@ -102,11 +102,11 @@ static bool onDraw() { engine.worldCoordinates(); NanoRect blocks = rect_to_blocks( engine.getCanvas().rect() ); - for (uint8_t row = max(0,blocks.p1.y); - row <= min(13,blocks.p2.y); row++) + for (uint8_t row = lcd_gfx_max(0,blocks.p1.y); + row <= lcd_gfx_min(13,blocks.p2.y); row++) { - for (uint8_t col = max(0,blocks.p1.x); - col <= min((B_WIDTH-1),blocks.p2.x); col++) + for (uint8_t col = lcd_gfx_max(0,blocks.p1.x); + col <= lcd_gfx_min((B_WIDTH-1),blocks.p2.x); col++) { uint8_t blockType = block_value({col,row}); if (blockType != 0) @@ -131,19 +131,19 @@ static NanoPoint calc_new_screen_position() NanoPoint position = engine.getPosition() + game_window.p1; if (player.x() - position.x >= game_window.width() - 48) { - position.x = min(player.x() - (game_window.width() - 96), 128); + position.x = lcd_gfx_min(player.x() - (game_window.width() - 96), 128); } else if (player.x() - position.x < 48) { - position.x = max(0, player.x() - 96); + position.x = lcd_gfx_max(0, player.x() - 96); } if (player.y() - position.y >= game_window.height() - 48) { - position.y = min(player.y() - (game_window.height() - 96), 64); + position.y = lcd_gfx_min(player.y() - (game_window.height() - 96), 64); } else if (player.y() - position.y < 48) { - position.y = max(0, player.y() - 96); + position.y = lcd_gfx_max(0, player.y() - 96); } return position - game_window.p1; } diff --git a/src/lcd_hal/linux/io.h b/src/lcd_hal/linux/io.h index 4b77e462..c71dafcc 100644 --- a/src/lcd_hal/linux/io.h +++ b/src/lcd_hal/linux/io.h @@ -52,8 +52,8 @@ extern "C" { #endif - int min(int a, int b); - int max(int a, int b); + int lcd_gfx_min(int a, int b); + int lcd_gfx_max(int a, int b); static inline char *utoa(unsigned int num, char *str, int radix) { diff --git a/src/lcd_hal/linux/platform.cpp b/src/lcd_hal/linux/platform.cpp index e7fd3725..9438b0b8 100644 --- a/src/lcd_hal/linux/platform.cpp +++ b/src/lcd_hal/linux/platform.cpp @@ -348,11 +348,11 @@ uint32_t lcd_micros(void) return ts.tv_sec * 1000000 + ts.tv_nsec / 1000; } -int min(int a, int b) +int lcd_gfx_min(int a, int b) { return a < b ? a : b; } -int max(int a, int b) +int lcd_gfx_max(int a, int b) { return a > b ? a : b; } @@ -403,11 +403,11 @@ uint32_t lcd_micros(void) return ts.tv_sec * 1000000 + ts.tv_nsec / 1000; }; -int min(int a, int b) +int lcd_gfx_min(int a, int b) { return a < b ? a : b; } -int max(int a, int b) +int lcd_gfx_max(int a, int b) { return a > b ? a : b; } diff --git a/src/nano_gfx_types.h b/src/nano_gfx_types.h index 3e6453b4..20b77e87 100644 --- a/src/nano_gfx_types.h +++ b/src/nano_gfx_types.h @@ -31,14 +31,14 @@ #include "lcd_hal/io.h" #include "canvas/canvas_types.h" -#ifndef min +#ifndef lcd_gfx_min /** Macros returning minimum of 2 numbers */ -#define min(a, b) ((a) < (b) ? (a) : (b)) +#define lcd_gfx_min(a, b) ((a) < (b) ? (a) : (b)) #endif -#ifndef max +#ifndef lcd_gfx_max /** Macros returning maximum of 2 numbers */ -#define max(a, b) ((a) > (b) ? (a) : (b)) +#define lcd_gfx_max(a, b) ((a) > (b) ? (a) : (b)) #endif /** @@ -155,14 +155,14 @@ typedef struct SPRITE */ inline SSD1306_RECT getUpdateRect() const { - uint8_t left = min(x, lx); - uint8_t top = min(y, ly); - uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1)); + uint8_t left = lcd_gfx_min(x, lx); + uint8_t top = lcd_gfx_min(y, ly); + uint8_t right = lcd_gfx_max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1)); if ( ((uint8_t)(lx + w - 1) < w) && (right > 2 * w) ) { right = (uint8_t)(lx + w - 1); } - uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7)); + uint8_t bottom = lcd_gfx_max((uint8_t)(y + 7), (uint8_t)(ly + 7)); if ( ((uint8_t)(ly + 7) < 8) && (bottom > 16) ) { bottom = (uint8_t)(ly + 7); diff --git a/src/v2/gui/menu.h b/src/v2/gui/menu.h index 8a93fe31..0c8110a2 100644 --- a/src/v2/gui/menu.h +++ b/src/v2/gui/menu.h @@ -33,14 +33,14 @@ #include "canvas/rect.h" #include "canvas/font.h" -#ifndef min +#ifndef lcd_gfx_min /** Custom min function */ -#define min(x, y) ((x) < (y) ? (x) : (y)) +#define lcd_gfx_min(x, y) ((x) < (y) ? (x) : (y)) #endif -#ifndef max +#ifndef lcd_gfx_max /** Custom max function */ -#define max(x, y) ((x) > (y) ? (x) : (y)) +#define lcd_gfx_max(x, y) ((x) > (y) ? (x) : (y)) #endif /** @@ -168,7 +168,7 @@ template void LcdGfxMenu::show(D &d) updateSize(d); d.drawRect(4 + menu.left, 4 + menu.top, menu.width + menu.left - 5, menu.height + menu.top - 5); menu.scrollPosition = this->calculateScrollPosition(d, menu.selection); - for ( uint8_t i = menu.scrollPosition; i < min(menu.count, (menu.scrollPosition + getMaxScreenItems(d))); i++ ) + for ( uint8_t i = menu.scrollPosition; i < lcd_gfx_min(menu.count, (menu.scrollPosition + getMaxScreenItems(d))); i++ ) { this->drawMenuItem(d, i); } diff --git a/src/v2/lcd/base/ssd1306_common.inl b/src/v2/lcd/base/ssd1306_common.inl index 20333c5e..92c729bd 100644 --- a/src/v2/lcd/base/ssd1306_common.inl +++ b/src/v2/lcd/base/ssd1306_common.inl @@ -665,12 +665,12 @@ template void NanoDisplayOps::print(char c) this->write(intStr); } -#ifndef min -#define min(x, y) ((x) < (y) ? (x) : (y)) +#ifndef lcd_gfx_min +#define lcd_gfx_min(x, y) ((x) < (y) ? (x) : (y)) #endif -#ifndef max -#define max(x, y) ((x) > (y) ? (x) : (y)) +#ifndef lcd_gfx_max +#define lcd_gfx_max(x, y) ((x) > (y) ? (x) : (y)) #endif template static uint8_t getMaxScreenItems(NanoDisplayOps &display, SAppMenu *menu) @@ -743,7 +743,7 @@ template void NanoDisplayOps::showMenu(SAppMenu *menu) drawRect(4 + menu->left, 4 + menu->top, menu->width + menu->left - 5, menu->height + menu->top - 5); menu->scrollPosition = calculateScrollPosition(*this, menu, menu->selection); for ( uint8_t i = menu->scrollPosition; - i < min(menu->count, (menu->scrollPosition + getMaxScreenItems(*this, menu))); i++ ) + i < lcd_gfx_min(menu->count, (menu->scrollPosition + getMaxScreenItems(*this, menu))); i++ ) { drawMenuItem(*this, menu, i); } @@ -755,7 +755,7 @@ template void NanoDisplayOps::showMenuSmooth(SAppMenu * drawRect(4 + menu->left, 4 + menu->top, menu->width + menu->left - 5, menu->height + menu->top - 5); menu->scrollPosition = calculateScrollPosition(*this, menu, menu->selection); for ( uint8_t i = menu->scrollPosition; - i < min(menu->count, (menu->scrollPosition + getMaxScreenItems(*this, menu))); i++ ) + i < lcd_gfx_min(menu->count, (menu->scrollPosition + getMaxScreenItems(*this, menu))); i++ ) { drawMenuItemSmooth(*this, menu, i); } diff --git a/src/v2/nano_engine/tiler.h b/src/v2/nano_engine/tiler.h index be4b3409..e3d6d899 100644 --- a/src/v2/nano_engine/tiler.h +++ b/src/v2/nano_engine/tiler.h @@ -237,7 +237,7 @@ template class NanoEngineTiler if ( x1 < 0 ) x1 = 0; y1 = y1 / canvas.height(); - y2 = min((y2 / canvas.height()), NE_MAX_TILE_ROWS - 1); + y2 = lcd_gfx_min((y2 / canvas.height()), NE_MAX_TILE_ROWS - 1); for ( uint8_t x = x1 / canvas.width(); x <= (x2 / canvas.width()); x++ ) { for ( uint8_t y = y1; y <= y2; y++ )