Skip to content

Commit

Permalink
Replacing macro name (min, max) -> (lcd_gfx_min, lcd_gfx_max) #109
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Aug 19, 2023
1 parent 79394c1 commit 0f772e5
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 55 deletions.
3 changes: 2 additions & 1 deletion examples/demos/sh1107_demo/sh1107_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions examples/games/arkanoid/arkanoid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void drawIntro()
void drawStatusPanel()
{
display.setColor(RGB_COLOR8(255,0,0));
for(uint8_t i=0; i<min(hearts,3); i++)
for(uint8_t i=0; i<lcd_gfx_min(hearts,3); i++)
{
display.drawBitmap1( RIGHT_EDGE + 4, 16 + (i<<3), 8, 8, heartSprite );
}
Expand Down Expand Up @@ -570,11 +570,11 @@ void movePlatform()
Key buttonCode = getPressedButton(0);
if (buttonCode == Key::BT_RIGHT)
{
platformPos = min(RIGHT_EDGE - LEFT_EDGE - 1 - platformWidth, platformPos + PLATFORM_SPEED);
platformPos = lcd_gfx_min(RIGHT_EDGE - LEFT_EDGE - 1 - platformWidth, platformPos + PLATFORM_SPEED);
}
if (buttonCode == Key::BT_LEFT)
{
platformPos = max(0, platformPos - PLATFORM_SPEED);
platformPos = lcd_gfx_max(0, platformPos - PLATFORM_SPEED);
}
if (platformPower != 0)
{
Expand Down Expand Up @@ -692,7 +692,7 @@ bool moveBall()
{
int middle = platformPos + (platformWidth >> 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 */
Expand Down
16 changes: 8 additions & 8 deletions examples/games/lode_runner/lode_runner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions examples/games/lode_runner_ili9341/lode_runner_ili9341.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions examples/wio_terminal/lode_runner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lcd_hal/linux/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/lcd_hal/linux/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/nano_gfx_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/v2/gui/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ template <typename D> 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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/v2/lcd/base/ssd1306_common.inl
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,12 @@ template <class O, class I> void NanoDisplayOps<O, I>::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 <class O, class I> static uint8_t getMaxScreenItems(NanoDisplayOps<O, I> &display, SAppMenu *menu)
Expand Down Expand Up @@ -743,7 +743,7 @@ template <class O, class I> void NanoDisplayOps<O, I>::showMenu(SAppMenu *menu)
drawRect(4 + menu->left, 4 + menu->top, menu->width + menu->left - 5, menu->height + menu->top - 5);
menu->scrollPosition = calculateScrollPosition<O, I>(*this, menu, menu->selection);
for ( uint8_t i = menu->scrollPosition;
i < min(menu->count, (menu->scrollPosition + getMaxScreenItems<O, I>(*this, menu))); i++ )
i < lcd_gfx_min(menu->count, (menu->scrollPosition + getMaxScreenItems<O, I>(*this, menu))); i++ )
{
drawMenuItem<O, I>(*this, menu, i);
}
Expand All @@ -755,7 +755,7 @@ template <class O, class I> void NanoDisplayOps<O, I>::showMenuSmooth(SAppMenu *
drawRect(4 + menu->left, 4 + menu->top, menu->width + menu->left - 5, menu->height + menu->top - 5);
menu->scrollPosition = calculateScrollPosition<O, I>(*this, menu, menu->selection);
for ( uint8_t i = menu->scrollPosition;
i < min(menu->count, (menu->scrollPosition + getMaxScreenItems<O, I>(*this, menu))); i++ )
i < lcd_gfx_min(menu->count, (menu->scrollPosition + getMaxScreenItems<O, I>(*this, menu))); i++ )
{
drawMenuItemSmooth<O, I>(*this, menu, i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/nano_engine/tiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ template <class C, class D> 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++ )
Expand Down

0 comments on commit 0f772e5

Please sign in to comment.