Add proper icon and menu

This commit is contained in:
2024-12-12 15:51:19 +01:00
parent 682963e886
commit 566e066bdc
7 changed files with 37 additions and 7 deletions

View File

@@ -55,4 +55,5 @@ endif()
# Options pour la liaison statique en mode release
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
target_sources(bloubloulespoissons PRIVATE resource.rc)
endif()

BIN
img/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -326,6 +326,8 @@ int main(int argc, char* args[]) {
menu.addText("Main", (windowWidth/2) - 300, 50, 600, 100, "BloubBloub les poissons", 1024);
menu.addImage("Main", (windowWidth/2) - 100, 150, 200, 200, "../img/logo.png");
menu.addText("Multi-Join", (windowWidth/2) - 100, 50, 200, 100, "Join", 1024);
menu.addButton("Main", (windowWidth/2) - 100, windowHeight/2 - 25, 200, 50, "Solo", 1024, [](){

View File

@@ -1,14 +1,18 @@
#include "menu.h"
void Menu::draw(SDL_Renderer* renderer){
void Menu::draw(SDL_Renderer* renderer) {
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, backgroundTxt, nullptr, &backgroundRect);
if(pages.size() > 0){
if(currentPage == -1 && pages.size() > 0){
if (pages.size() > 0) {
if (currentPage == -1 && pages.size() > 0) {
currentPage = 0;
}
for(Text& text : pages[currentPage].texts){
for (ImagePage image : pages[currentPage].images) {
SDL_RenderCopy(renderer, image.image, nullptr, &image.rect);
}
for (Text& text : pages[currentPage].texts) {
SDL_RenderCopy(renderer, text.txt, nullptr, &text.rect);
}
@@ -16,13 +20,12 @@ void Menu::draw(SDL_Renderer* renderer){
SDL_GetMouseState(&mouseX, &mouseY);
bool hover = false;
for(Button& button : pages[currentPage].buttons){
for (Button& button : pages[currentPage].buttons) {
SDL_SetRenderDrawColor(renderer, button.bgColor.r, button.bgColor.g, button.bgColor.b, button.bgColor.a);
SDL_RenderFillRect(renderer, &button.rect);
SDL_RenderCopy(renderer, button.txt, nullptr, &button.txtRect);
if (button.isTextInput) {
// Afficher le texte saisi
TTF_Font* font_txt = TTF_OpenFont("../fonts/arial.ttf", 24);
SDL_Surface* textSurface = TTF_RenderText_Solid(font_txt, button.inputText.c_str(), button.fontColor);
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
@@ -167,4 +170,21 @@ void Menu::addPage(std::string title){
std::vector<Button> Menu::getButtons(){
return pages[currentPage].buttons;
}
void Menu::addImage(std::string page, int x, int y, int w, int h, std::string path) {
for (Page& p : pages) {
if (p.title == page) {
SDL_Surface* imageSurface = IMG_Load(path.c_str());
if (imageSurface == nullptr) {
std::cerr << "Erreur de chargement de l'image: " << IMG_GetError() << std::endl;
return;
}
SDL_Texture* imageTexture = SDL_CreateTextureFromSurface(renderer, imageSurface);
SDL_FreeSurface(imageSurface);
SDL_Rect imageRect = {x, y, w, h};
p.images.push_back(ImagePage(imageTexture, imageRect));
}
}
}

7
menu.h
View File

@@ -27,11 +27,16 @@ struct Text {
SDL_Rect txtRect;
};
struct ImagePage {
SDL_Texture* image;
SDL_Rect rect;
};
struct Page {
std::string title;
std::vector<Button> buttons;
std::vector<Text> texts;
std::vector<ImagePage> images;
};
class Menu {
@@ -76,6 +81,8 @@ class Menu {
void addPage(std::string title);
void addImage(std::string page, int x, int y, int w, int h, std::string path);
std::vector<Button> getButtons();
};

View File

@@ -1 +1 @@
IDI_ICON1 ICON "../img/logo.png"
IDI_ICON1 ICON "../img/logo.ico"