Scaller
This commit is contained in:
+14
-19
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user