résolution bug du createButtonTexture

merge-requests/1/merge
Mathis RIBEMONT 4 years ago
parent d4975d24f0
commit 4857a08df2

@ -25,8 +25,8 @@ SDL_Texture* createTextureFromPath(SDL_Renderer* renderer, char* path);
* \param[in] background_color The color of the background
* \param[in] thickness The thickness of the texture
* \param[in] padding The padding around the text in the button
* \param[in] sizex The width of the texture. You have to apply to the width of the button
* \param[in] sizey The height of the texture. You have to apply to the height of the button
* \param[out] sizex The width of the texture. You have to apply it to the width of the button
* \param[out] sizey The height of the texture. You have to apply it to the height of the button
* \param[in] renderer The renderer you want the texture to be associated
* \return Return texture created on success. Else return NULL and print the error on STDERR.
*/

@ -7,7 +7,8 @@ P_Button createButton(SDL_Texture* texture, SDL_Texture* hoverTexture ,const int
{
// Declarations
P_Button b = { .rect = { .x = coordx, .y = coordy, .w = sizex, .h = sizey }, .onClick = onClick, .drawn = false};
if(onClick == NULL)
fprintf(stderr, "Attention: aucune action onClick n'est passé au bouton.\n");
b.texture = texture;
b.hoverTexture = hoverTexture;
return b;
@ -15,6 +16,7 @@ P_Button createButton(SDL_Texture* texture, SDL_Texture* hoverTexture ,const int
bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button)
{
SDL_SetRenderTarget(renderer, NULL);
if(SDL_RenderCopy(renderer,button->hover && button->hoverTexture != NULL ? button->hoverTexture : button->texture,NULL,&(button->rect)))
{
fprintf(stderr,"Warning: %s\n",SDL_GetError());

@ -50,7 +50,7 @@ SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int size, SD
SDL_Texture* message = SDL_CreateTextureFromSurface(renderer, surfaceMessage);
int minx,maxx,miny,maxy,advance;
if(TTF_GlyphMetrics(font,text,&minx,&maxx,&miny,&maxy,&advance)==-1){
if(TTF_GlyphMetrics(font,'a',&minx,&maxx,&miny,&maxy,&advance)==-1){
printf("%s\n",TTF_GetError());
}
/*else {
@ -64,7 +64,7 @@ SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int size, SD
SDL_Rect Message_rect; //create a rect
Message_rect.x = padding+thickness+minx; //controls the rect's x coordinate
Message_rect.y = padding+thickness; // controls the rect's y coordinte
Message_rect.w = strlen(text)*size*2/3; // controls the width of the rect
Message_rect.w = (int)(strlen(text)*size*2/3); // controls the width of the rect
Message_rect.h = size; // controls the height of the rect
//pour les contour d'abord
@ -74,12 +74,14 @@ SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int size, SD
button_rect.w = Message_rect.w+2*(padding+thickness)+minx;
button_rect.h = Message_rect.h+2*(padding+thickness);
SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET,button_rect.w,button_rect.h);
SDL_SetRenderDrawColor(renderer, border_color.r,border_color.g,border_color.b,0);
SDL_SetRenderTarget(renderer, texture);
SDL_SetRenderDrawColor(renderer, border_color.r,border_color.g,border_color.b,0);
SDL_RenderFillRect(renderer, &button_rect);
*sizex = button_rect.w;
*sizey = button_rect.h;
if(sizex != NULL)
*sizex = button_rect.w;
if(sizey != NULL)
*sizey = button_rect.h;
//pour le background
button_rect.x = thickness;
@ -91,5 +93,7 @@ SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int size, SD
SDL_SetRenderDrawColor(renderer, border_color.r,border_color.g,border_color.b,0);
SDL_RenderCopy(renderer, message, NULL, &Message_rect);
SDL_SetRenderTarget(renderer, NULL);
return texture;
}

Loading…
Cancel
Save