This commit is contained in:
Marc
2023-01-21 12:55:27 +01:00
parent 7af164dd20
commit 781f4ba7be
8 changed files with 64 additions and 38 deletions
+14 -19
View File
@@ -1,34 +1,30 @@
#include "menu.h"
#include <SDL2/SDL_image.h>
#include "renderer.h"
#include "scaller.h"
static RenderId_t menuObjects[10];
static unsigned menuObjectsSize = 0;
int menu_render(int windowWidth, int windowHeight){
int menu_render(void){
SDL_Surface* buttonImageSurface = IMG_Load("./assets/img/start.png");
if(buttonImageSurface == NULL){
printf("cannot load");
return -1;
}
RenderObject_t buttonImage;
float buttonScale = 0.3f;
// float buttonX = ((float)windowWidth - (float)buttonImageSurface->w) / (2.f * (float)buttonImageSurface->w);
// float buttonY = ((float)windowHeight - (float)buttonImageSurface->h) / (2.f * (float)buttonImageSurface->h);
float buttonX = 0.5f - buttonScale * (float)buttonImageSurface->w / (2.f * (float)windowWidth);
float buttonY = 0.5f - buttonScale * (float)buttonImageSurface->h / (2.f * (float)windowHeight);
printf("buttonImageSurface->w: %d\n", buttonImageSurface->w);
printf("buttonImageSurface->h: %d\n", buttonImageSurface->h);
printf("windowWidth: %d\n", windowWidth);
printf("buttonX: %f\n", buttonX);
RenderObject_t buttonImage = {
buttonX,
buttonY,
0,
buttonScale,
buttonScale,
0,
buttonImageSurface
};
MonitorSize_t size = renderer_getMonitorSize();
float aspectRatio = (float)size.width / size.height;
buttonImage.x = 0.5f;
buttonImage.y = 0.5f;
scaller(buttonImageSurface, buttonScale, &buttonImage.width, &buttonImage.height);
placer(buttonImageSurface, buttonScale, &buttonImage.x, &buttonImage.y);
buttonImage.surface = buttonImageSurface;
menuObjects[menuObjectsSize] = renderer_renderObject(buttonImage);
++menuObjectsSize;
return 0;
@@ -40,4 +36,3 @@ void menu_remove(void){
}
menuObjectsSize = 0;
}