-
Notifications
You must be signed in to change notification settings - Fork 0
ButtonP Class Variables
Alex Ricciardi edited this page Feb 5, 2023
·
3 revisions
Note: The variables for this class are public.
//---- Font
Font font = GetFontDefault(); // Raylib default font
float fontSize = 32,
fontSpacing = 2.0f;
Color fontColor = RAYWHITE;
bool isRayFont = true;
//---- Text
string text = "Button";
Vector2 textSize = MeasureTextEx(font, text.c_str(), fontSize, fontSpacing),
oneCharSize = MeasureTextEx(font, "C", fontSize, fontSpacing);
//--- Button position, size, color
/*
The button size is computed from the font size and length of the text
See mutators to modify the button’s position,
the text’s position in the button, and the button’s size.
*/
bool txtResizeBtn = true;
float btnWidth = (textSize.x + 3.5f * oneCharSize.x),
btnHeight = textSize.y * (float)(2.0f * (textSize.y / fontSize));
Vector2 btnPos = { 750, 100 };
Rectangle rect{ btnPos.x, btnPos.y, btnWidth, btnHeight },
originalRect = rect;
//--- Centers text in button
Vector2 textPos =
{
rect.x + (rect.width - textSize.x) / 2,
rect.y + (rect.height - textSize.y) / 2
};
// Text position and size
Rectangle rectText{ textPos.x, textPos.y, textSize.x, textSize.y },
originalRectText = rectText;
//---- Button state
// Button and text image Shading Colors
Color btnHoverColor = GRAY,
btnPressedColor = DARKGRAY;
//---- Button Image
string imgPath; // Image path in secondary memory
Image img;
// Button textures
Texture2D btnIdle = LoadTextureFromImage(img); // Image converted to texture, uploaded to GPU memory (VRAM)
Texture2D btnHover = btnIdle;
Texture2D btnPressed = btnIdle;
Texture2D *btnLive = &btnIdle;
//---- Text Image
Image textImg;
Texture2D textIdle = LoadTextureFromImage(textImg);
Texture2D textHover = textIdle;
Texture2D textPressed = textIdle;
Texture2D *textLive = &textIdle;
// window
int windowWidth = GetScreenWidth();
int windowHeight = GetScreenHeight();
Vector2 windowScale = { (float)GetScreenWidth() / windowWidth, (float)GetScreenHeight() / windowHeight };