Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rotating the screen #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions HaD_Badge.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ void* nullptr;
SDL_Window *win;
SDL_Renderer *ren;

//Which way the display is rotated (which way "up" is)
#define ROTATION UP

#if ROTATION == UP
#define ROT_XX 1
#define ROT_YY 1
#define ROT_XY 0
#define ROT_YX 0
#elif ROTATION == RIGHT
#define ROT_XX 0
#define ROT_YY 0
#define ROT_XY -1
#define ROT_YX 1
#elif ROTATION == DOWN
#define ROT_XX -1
#define ROT_YY -1
#define ROT_XY 0
#define ROT_YX 0
#elif ROTATION == LEFT
#define ROT_XX 0
#define ROT_YY 0
#define ROT_XY 1
#define ROT_YX -1
#endif

//These display size values are specific to the SDL2 emulator
#define PIXELRADIUS 8
#define PIXELSPACING 5
Expand Down Expand Up @@ -51,12 +76,19 @@ void initDisplay(void) {
printf("SDL_Init Error: %s\n", SDL_GetError());
}

int width =
(ROT_XX != 0 ? 1 : 0) * ((TOTPIXELX*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING) +
(ROT_XY != 0 ? 1 : 0) * ((TOTPIXELY*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING);
int height =
(ROT_YY != 0 ? 1 : 0) * ((TOTPIXELY*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING) +
(ROT_YX != 0 ? 1 : 0) * ((TOTPIXELX*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING);

win = SDL_CreateWindow(
"sdlTest",
100,
100,
(TOTPIXELX*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING,
(TOTPIXELY*(PIXELSPACING+PIXELRADIUS+PIXELRADIUS))+PIXELSPACING,
width,
height,
SDL_WINDOW_SHOWN);

if (win == nullptr) {
Expand Down Expand Up @@ -93,10 +125,20 @@ void displayPixel(uint8_t x, uint8_t y, uint8_t state) {
void showSDLpixel(uint8_t x, uint8_t y, uint8_t state){
uint8_t color = GREY;
if (state) { color = RED; }
int newX = (x * ROT_XX) + (y * ROT_XY);
int newY = (x * ROT_YX) + (y * ROT_YY);
if(ROT_XX + ROT_XY < 0)
{
newX = (-ROT_XX * (TOTPIXELX - 1)) + (-ROT_XY * (TOTPIXELY - 1)) + newX;
}
if(ROT_YY + ROT_YX < 0)
{
newY = (-ROT_YX * (TOTPIXELX - 1)) + (-ROT_YY * (TOTPIXELY - 1)) + newY;
}
filledCircleRGBA(
ren,
(x*(PIXELRADIUS+PIXELRADIUS+PIXELSPACING))+PIXELRADIUS+PIXELSPACING,
(y*(PIXELRADIUS+PIXELRADIUS+PIXELSPACING))+PIXELRADIUS+PIXELSPACING,
(newX*(PIXELRADIUS+PIXELRADIUS+PIXELSPACING))+PIXELRADIUS+PIXELSPACING,
(newY*(PIXELRADIUS+PIXELRADIUS+PIXELSPACING))+PIXELRADIUS+PIXELSPACING,
PIXELRADIUS,
colors[color][0],
colors[color][1],
Expand Down