Skip to content

RyanTk03/SDL_Buttons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDL_Button

The SDL_Button library is a library for creating buttons with SDL.

Installation

  1. Clone the repository:
git clone https://github.com/RyanTk03/SDL_Buttons.git
  1. Include the header files in your project:
#include "../inc/BTN.h"

Compile your project with the SDL_Button library source files:

gcc your_files.c BTN.c -o main -lSDL2 -lSDL2_ttf -lSDL2_image

Usage

  1. Creating a button
BTN_Button* button = BTN_CreateButton(type, w, h, label, font);

type: the type of button (to be defined according to your needs) w: the width of the button h: the height of the button label: the text of the button font: the font to use for the button text

  1. Copying the button to the renderer
BTN_bool success = BTN_CopyButton(button, renderer, &dst);

renderer: the renderer to copy the button to dst: the coordinates (x, y) to copy the button to on the renderer

  1. Modifying the button 3.1. Modifying the button text
char *newLabel = "New text";
BTN_Setlabel(button, newLabel);

3.2. Modifying the button font

TTF_Font *newFont = TTF_OpenFont("path/to/font.ttf", size);
BTN_SetFont(button, newFont);

Modifying the button colors

BTN_Colors colors;
colors.backColor = (SDL_Color){255, 255, 255, 255};
colors.backColorOnHover = (SDL_Color){0, 0, 255, 128};
colors.labelColor = (SDL_Color){0, 0, 0, 255};
colors.labelColorOnHover = (SDL_Color){255, 255, 255, 255};
colors.borderColor = (SDL_Color){0, 0, 255, 128};
colors.borderColorOnHover = (SDL_Color){255, 0, 0, 128};

short colorKey = BTN_COLORS_KEY_BACK | BTN_COLORS_KEY_HBACK | BTN_COLORS_KEY_LABEL |
BTN_COLORS_KEY_HLABEL | BTN_COLORS_KEY_BORDER | BTN_COLORS_KEY_HBORDER;

SDL_bool modified = BTN_setColors(button, &colors, colorKey);

License

This library is distributed under the MIT license. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages