Skip to content

Commit

Permalink
asadad
Browse files Browse the repository at this point in the history
  • Loading branch information
repiazza committed Jan 17, 2024
1 parent f5ecbd0 commit 3d5bffb
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 105 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ NCURSESADDONLIBS = -lncurses

ifdef _WIN32
NCURSESADDONLIBS += -DNCURSES_STATIC
SDLADDONLIBS += -lSDL_ttf
CCOPT += -LC:/msys64/mingw64/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
LIBS = -LC:/msys64/mingw64/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
SDLADDONLIBS += -lSDL2_ttf
# CCOPT += -LC:/msys64/mingw64/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
# LIBS = -LC:/msys64/mingw64/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
CCOPT += -LC:/msys64/mingw32/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
LIBS = -LC:/msys64/mingw32/bin/../lib -lmingw32 $(SDLADDONLIBS) $(NCURSESADDONLIBS) -mwindows -D_WIN32
endif

ifdef LINUX
Expand Down
Binary file added fonts/FiraCode.ttf
Binary file not shown.
6 changes: 3 additions & 3 deletions include/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ int iBUTTON_CheckInteraction(SDL_Event *pSDL_EVENT_Ev, int iXCursor, int iYCurso
int iBUTTON_AddToList(SDL_Rect *pSDL_RECT_Btm, int iAction){
STRUCT_BUTTON_LIST *pstWrkButtonList;

eMovAction eMvAct = (eMovAction)iAction;
eBtnAction eBtnAct = (eBtnAction)iAction;

for ( pstWrkButtonList = &gstButtonList; pstWrkButtonList->pstNext != NULL; pstWrkButtonList = pstWrkButtonList->pstNext );

if ( pstWrkButtonList->iAction == 0 && pstWrkButtonList == &gstButtonList){
pstWrkButtonList->pSDL_RECT_Button = pSDL_RECT_Btm;
pstWrkButtonList->iAction = eMvAct;
pstWrkButtonList->iAction = eBtnAct;
pstWrkButtonList->pstNext = NULL;
return 0;
}
Expand All @@ -47,7 +47,7 @@ int iBUTTON_AddToList(SDL_Rect *pSDL_RECT_Btm, int iAction){
memset(pstWrkButtonList->pstNext, 0, sizeof(STRUCT_BUTTON_LIST));
pstWrkButtonList = pstWrkButtonList->pstNext;
pstWrkButtonList->pSDL_RECT_Button = pSDL_RECT_Btm;
pstWrkButtonList->iAction = eMvAct;
pstWrkButtonList->iAction = eBtnAct;
pstWrkButtonList->pstNext = NULL;

return 0;
Expand Down
12 changes: 8 additions & 4 deletions include/cattie.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// #define gstCmdLine.szWinHeight 800
#define WINDOW_RATIO gstCmdLine.szWinWidth/gstCmdLine.szWinHeight

#define REDRAW_NONE 0
#define REDRAW_IMAGE 1
#define ERROR_WALKING 10

Expand All @@ -37,13 +38,15 @@
#define BUTTON_DIRECTION 1
#define BUTTON_CONFIRM 2
#define BUTTON_ERASE 3
#define BUTTON_CONFIGURE 4

#define PLAYER_IMG_PATH_IDX 0
#define FORWARD_IMG_PATH_IDX 1
#define LASER_IMG_PATH_IDX 2
#define ROTATE_IMG_PATH_IDX 3
#define GEAR_IMG_PATH_IDX 4

#define _MAX_IMG_PATH 4
// #define _MAX_IMG_PATH 4

#define DEVELOPER "Renato Fermi & Gustavo Bacagine"
#define VERSION "1.0"
Expand Down Expand Up @@ -73,13 +76,14 @@
END_SQUARE
} eSqType;

typedef enum MovementAction{
typedef enum ButtonAction{
FORWARD = 1,
TURN,
FIRE_LASER,
ERASE,
CONFIRM
} eMovAction;
CONFIRM,
CONFIGURE
} eBtnAction;

typedef enum WindRose{
NORTH = 1,
Expand Down
16 changes: 16 additions & 0 deletions include/font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <SDL2/SDL_ttf.h>
#include <stdio.h>

#define PATH_TO_TTF "fonts"
#define TTF_FONT_TITLE "FiraCode.ttf"


TTF_Font *ttfSDL_InitFont(){
char szFontPath[_MAX_PATH];

if ( TTF_Init() )
return NULL;

sprintf(szFontPath, "%s/%s", PATH_TO_TTF, TTF_FONT_TITLE);
return TTF_OpenFont(szFontPath, 16);
}
138 changes: 92 additions & 46 deletions include/menu.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include <font.h>

#ifndef _CATTIE_H_INC
#include <cattie.h>
Expand All @@ -8,57 +9,102 @@

#define MAX_MENU_OPTIONS 6

enum eMenuOption{
MENU_OPT_1 = 0,
MENU_OPT_2 ,
MENU_OPT_3 ,
MENU_OPT_4 ,
MENU_OPT_5 ,
MENU_OPT_EXIT // 5
} eMenuOption;

extern int giMENU_SelectedItem;
int gbDrawMenu = TRUE;

void vInitMenu(SDL_Rect *pSDL_RECT_Mn, int iOptionCt){
SDL_Rect *pSDL_RECT_Wrk;
int iInitCt = 0;
int iMenuOptWidth = iOptionCt*20;
int iMenuOptHeight = iMenuOptWidth;
for ( pSDL_RECT_Wrk = pSDL_RECT_Mn;
iInitCt < iOptionCt;
pSDL_RECT_Wrk++, iInitCt++ ){
pSDL_RECT_Wrk->x= atoi(gstCmdLine.szWinWidth) / 2 - iMenuOptWidth;
pSDL_RECT_Wrk->y= atoi(gstCmdLine.szWinHeight) / 2 - iMenuOptHeight;
iMenuOptHeight -=20;
pSDL_RECT_Wrk->w = 100;
pSDL_RECT_Wrk->h = 25;
}
}
void vInitMenu(SDL_Rect *pSDL_RECT_Mn, int iOptionCt) {
SDL_Rect *pSDL_RECT_Wrk;
int iInitCt = 0;
int iMenuOptWidth = iOptionCt * 20;
int iMenuOptHeight = iMenuOptWidth;

void vMENU_HandleKey(SDL_Keycode peSDL_KeyCode){
switch (peSDL_KeyCode) {
case SDLK_UP:

giMENU_SelectedItem--;
if (giMENU_SelectedItem < 0) {
giMENU_SelectedItem = MAX_MENU_OPTIONS-1;
}
break;
case SDLK_DOWN:
giMENU_SelectedItem++;
if (giMENU_SelectedItem >= MAX_MENU_OPTIONS) {
giMENU_SelectedItem = 0;
}
break;
case SDLK_RETURN:
// Handle menu item selection
break;
}
for (pSDL_RECT_Wrk = pSDL_RECT_Mn; iInitCt < iOptionCt; pSDL_RECT_Wrk++, iInitCt++) {
pSDL_RECT_Wrk->x = atoi(gstCmdLine.szWinWidth) / 2 - iMenuOptWidth;
pSDL_RECT_Wrk->y = atoi(gstCmdLine.szWinHeight) / 2 - iMenuOptHeight;
iMenuOptHeight -= 20;
pSDL_RECT_Wrk->w = 100;
pSDL_RECT_Wrk->h = 25;
}
}

void vDrawMenu(SDL_Renderer *renderer, SDL_Rect *pSDL_RECT_Mn, int iOptionCt){
int iInitCt = 0;
SDL_Rect *pSDL_RECT_Wrk;
for ( pSDL_RECT_Wrk = pSDL_RECT_Mn;
iInitCt < iOptionCt;
pSDL_RECT_Wrk++, iInitCt++) {
if (iInitCt == giMENU_SelectedItem) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
void vDrawMenu(SDL_Renderer *renderer, SDL_Rect *pSDL_RECT_Mn, char **ppszOptionTitle, int iOptionCt, TTF_Font *font) {
int iInitCt = 0;
SDL_Rect *pSDL_RECT_Wrk;
SDL_Color textColor = {0, 0, 0, 255};

if ( gbDrawMenu == FALSE )
return ;
for (pSDL_RECT_Wrk = pSDL_RECT_Mn; iInitCt < iOptionCt; pSDL_RECT_Wrk++, iInitCt++) {
if (iInitCt == giMENU_SelectedItem) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
}

SDL_RenderFillRect(renderer, pSDL_RECT_Wrk);

// Render text on the menu option
SDL_Surface *textSurface = TTF_RenderText_Solid(font, ppszOptionTitle[iInitCt], textColor);
SDL_Texture *textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);

SDL_Rect textRect;
textRect.x = pSDL_RECT_Wrk->x + (pSDL_RECT_Wrk->w - textSurface->w) / 2;
textRect.y = pSDL_RECT_Wrk->y + (pSDL_RECT_Wrk->h - textSurface->h) / 2;
textRect.w = textSurface->w;
textRect.h = textSurface->h;

SDL_RenderCopy(renderer, textTexture, NULL, &textRect);

SDL_FreeSurface(textSurface);
SDL_DestroyTexture(textTexture);
}
else {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
}

// Update vMENU_HandleKey function to handle text rendering
void vMENU_HandleKey(SDL_Keycode peSDL_KeyCode, char **ppszOptionTitle) {
if ( gbDrawMenu == FALSE )
return ;
switch (peSDL_KeyCode) {
case SDLK_UP:
giMENU_SelectedItem--;
if (giMENU_SelectedItem < 0) {
giMENU_SelectedItem = MAX_MENU_OPTIONS - 1;
}
break;
case SDLK_DOWN:
giMENU_SelectedItem++;
if (giMENU_SelectedItem >= MAX_MENU_OPTIONS) {
giMENU_SelectedItem = 0;
}
break;
case SDLK_RETURN:
if (giMENU_SelectedItem >= MAX_MENU_OPTIONS || giMENU_SelectedItem < 0)
break;

if (DEBUG_MSGS)
vTraceVarArgs("Pressed ENTER Menu Choice[%d]=[%s]", giMENU_SelectedItem, ppszOptionTitle[giMENU_SelectedItem]);

if ( giMENU_SelectedItem == MENU_OPT_EXIT )
gbDrawMenu = FALSE;

// Handle menu item selection
break;
}
SDL_RenderFillRect(renderer, pSDL_RECT_Wrk);
}
}

void vMENU_ToggleVisibility(){
if ( gbDrawMenu == FALSE )
gbDrawMenu = TRUE;

return ;
}

Loading

0 comments on commit 3d5bffb

Please sign in to comment.