Skip to content

Commit

Permalink
Clean up of GUI Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndreiM committed Jul 27, 2024
1 parent 32abf29 commit a0999c1
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 127 deletions.
159 changes: 98 additions & 61 deletions src/Juka/GUI/Clicked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,92 +10,129 @@ public class Clicked
public static void itemclicked()
{

if (currentscreen == 0)
if (currentscreen == Menus.MenuMain)
{
for (int i = 0; i < menuOptions[Menus.MenuMain].Count; i++)
{
for (int i = 0; i < menuOptions[Menus.MenuMain].Count; i++)
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = menuDescript[Menus.MenuMain][i].X, y = menuDescript[Menus.MenuMain][i].Y, w = menuDescript[Menus.MenuMain][i].Width, h = menuDescript[Menus.MenuMain][i].Height };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
{
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = boxX, y = boxY * (i + 1) - 10, w = boxW, h = boxH };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
if (menuOptions[Menus.MenuMain][i] == "Exit")
{
if (menuOptions[Menus.MenuMain][i] == "Exit")
{
quit = true;
}
else if (menuOptions[Menus.MenuMain][i] == "Run File")
{
currentscreen = Menus.MenuJuka;
}
else if (menuOptions[Menus.MenuMain][i] == "Update/Install")
{
currentscreen = Menus.MenuInstall;
}
else if (menuOptions[Menus.MenuMain][i] == "Media Downloader")
{
Helper.GenerateMedia();
currentscreen = Menus.MediaPlayer;
}
else
{
Console.WriteLine("Selected option: " + menuOptions[Menus.MenuMain][i]);
}
quit = true;
}
else if (menuOptions[Menus.MenuMain][i] == "Run File")
{
currentscreen = Menus.MenuJuka;
}
else if (menuOptions[Menus.MenuMain][i] == "Update/Install")
{
currentscreen = Menus.MenuInstall;
}
else if (menuOptions[Menus.MenuMain][i] == "Media Downloader")
{
Helper.GenerateMedia();
currentscreen = Menus.MediaPlayer;
}
else
{
Console.WriteLine("Selected option: " + menuOptions[Menus.MenuMain][i]);
}
}
}
else if (currentscreen == Menus.MenuJuka)
}
else if (currentscreen == Menus.MenuJuka)
{
for (int i = 0; i < menuOptions[Menus.MenuJuka].Count; i++)
{
for (int i = 0; i < menuOptions[Menus.MenuJuka].Count; i++)
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = menuDescript[Menus.MenuJuka][i].X, y = menuDescript[Menus.MenuJuka][i].Y, w = menuDescript[Menus.MenuJuka][i].Width, h = menuDescript[Menus.MenuJuka][i].Height };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
{
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = boxX, y = boxY * (i + 1) - 10, w = boxW, h = boxH };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
if (menuOptions[Menus.MenuJuka][i] == "Back")
{
if (menuOptions[Menus.MenuJuka][i] == "Back")
{
currentscreen = 0;
}
else
{
filetoexecute = menuOptions[Menus.MenuJuka][i];
Helper.generateProgram();
currentscreen = Menus.RanJuka;
}
currentscreen = 0;
}
else
{
filetoexecute = menuOptions[Menus.MenuJuka][i];
Helper.generateProgram();
currentscreen = Menus.RanJuka;
}
}
}
else if (currentscreen == Menus.RanJuka)
{
currentscreen = Menus.MenuJuka;
}
else if (currentscreen == Menus.MediaPlayer)
}
else if (currentscreen == Menus.RanJuka)
{
currentscreen = Menus.MenuJuka;
}
else if (currentscreen == Menus.MediaPlayer)
{
for (int i = 0; i < videoInfos.Count + 1; i++)
{
for (int i = 0; i < videoInfos.Count + 1; i++)
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = 160, y = 190 + fontSizeC * (i + 1) + 5, w = 1280 - 160, h = fontSizeC };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
{
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = 160, y = 190 + fontSizeC * (i + 1) + 5, w = 1280 - 160, h = fontSizeC };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
if (i == videoInfos.Count)
{
currentscreen = 0;
}
else
{
if (i == videoInfos.Count)
{
currentscreen = 0;
}
else
{

var VedioUrl = "https://www.youtube.com/embed/" + videoInfos[i].VideoId + ".mp4";
var youTube = YouTube.Default;
var video = youTube.GetVideo(VedioUrl);
File.WriteAllBytes(videoInfos[i].VideoId + ".mp4", video.GetBytes());
var VedioUrl = "https://www.youtube.com/embed/" + videoInfos[i].VideoId + ".mp4";
var youTube = YouTube.Default;
var video = youTube.GetVideo(VedioUrl);
File.WriteAllBytes(videoInfos[i].VideoId + ".mp4", video.GetBytes());

myfile = videoInfos[i].VideoId + ".mp4";
myfile = videoInfos[i].VideoId + ".mp4";

currentscreen = Menus.MediaDownloaded;
}
}
}
}
else if (currentscreen == Menus.MediaDownloaded)
{
}
else if (currentscreen == Menus.MediaDownloaded)
{
currentscreen = Menus.MediaPlayer;
}
else if (currentscreen == Menus.MenuInstall)
{
for (int i = 0; i < menuOptions[Menus.MenuInstall].Count; i++)
{
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = menuDescript[Menus.MenuInstall][i].X, y = menuDescript[Menus.MenuInstall][i].Y, w = menuDescript[Menus.MenuInstall][i].Width, h = menuDescript[Menus.MenuInstall][i].Height };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
{
if (menuOptions[Menus.MenuInstall][i] == "Back")
{
currentscreen = Menus.MenuMain;
}
else if(menuOptions[Menus.MenuInstall][i] == "Update Juka")
{
currentscreen = Menus.MenuInstallJuka;
}
}
}
}
else if (currentscreen == Menus.MenuInstallJuka)
{
for (int i = 0; i < menuOptions[Menus.MenuInstallJuka].Count; i++)
{
SDL.SDL_Rect optionRect = new SDL.SDL_Rect { x = menuDescript[Menus.MenuInstallJuka][i].X, y = menuDescript[Menus.MenuInstallJuka][i].Y, w = menuDescript[Menus.MenuInstallJuka][i].Width, h = menuDescript[Menus.MenuInstallJuka][i].Height };
if (Helper.HandleSelection(mouseX, mouseY, optionRect))
{
if (menuOptions[Menus.MenuInstallJuka][i] == "Back")
{
currentscreen = Menus.MenuInstall;
}
else if (menuOptions[Menus.MenuInstallJuka][i] == "Install")
{


}
}
}
}
}
}

}
16 changes: 14 additions & 2 deletions src/Juka/GUI/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SDL2;
using static SDL2.SDL;

namespace Juka.GUI
{
Expand Down Expand Up @@ -45,12 +44,16 @@ public enum Menus
RanJuka,
MediaPlayer,
MediaDownloaded,
MenuInstall
MenuInstall,
MenuInstallJuka
}



//
public static Dictionary<Menus, List<string>> menuOptions = new Dictionary<Menus, List<string>>();
public static Dictionary<Menus, List<nint>> menuTextures= new Dictionary<Menus, List<nint>>(); // PRE-RENDER TEXTURES
public static Dictionary<Menus, List<Descript<int>>> menuDescript = new Dictionary<Menus, List<Descript<int>>>();
//

// WHERE TO PUT MENU CONTENT AND OFFSET
Expand All @@ -71,4 +74,13 @@ public enum Menus
//Current Screen
public static Menus currentscreen = Menus.MenuMain;
}

public class Descript<T>
{
public T X { get; set; }
public T Y { get; set; }
public T Width { get; set; }
public T Height { get; set; }
}

}
13 changes: 11 additions & 2 deletions src/Juka/GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public static Task GUI(string[] args)
menuOptions[Menus.MenuMain] = new List<string>() { "Run File", "Update/Install", "Media Downloader", "Exit" };
menuTextures[Menus.MenuMain] = Helper.GenerateMenu(menuOptions[Menus.MenuMain], menufont, Colors.colorWhite);

menuOptions[Menus.MenuInstall] = new List<string>() { "Update Juka", "Update/Install Packages", "Back" };
menuTextures[Menus.MenuInstall] = Helper.GenerateMenu(menuOptions[Menus.MenuInstall], menufont, Colors.colorWhite);

menuOptions[Menus.MenuInstallJuka] = new List<string>() { "Install", "Back" };
menuTextures[Menus.MenuInstallJuka] = Helper.GenerateMenu(menuOptions[Menus.MenuInstallJuka], menufont, Colors.colorWhite);


//Juka Run
menuOptions[Menus.MenuJuka] = new List<string>();
Expand Down Expand Up @@ -167,9 +173,12 @@ public static Task GUI(string[] args)
}
else if (currentscreen == Menus.MenuInstall)
{

RenderMenuInstall();
}
else if (currentscreen == Menus.MenuInstallJuka)
{
RenderMenuJukaInstall();
}


Controller.MouseHandler();
SDL.SDL_Rect textRect2 = new SDL.SDL_Rect { x = mouseX, y = mouseY, w = 12, h = 12 };
Expand Down
102 changes: 40 additions & 62 deletions src/Juka/GUI/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,70 @@ namespace Juka.GUI
{
public static class Renderer
{
public static void RenderMenu()
{

int textW, textH;

SDL.SDL_QueryTexture(menuTextures[Menus.MenuMain][0], out _, out _, out textW, out textH);


// Calculate menu option positions (centered horizontally)
int optionX = (SCREEN_WIDTH - textW) / 2; // Placeholder for text width calculation
int optionY = SCREEN_HEIGHT / (menuOptions[Menus.MenuMain].Count + 1);

SDL.SDL_QueryTexture(menuTextures[Menus.MenuMain][0], out _, out _, out textW, out textH);
SDL.SDL_Rect menuBackgroundRect = new SDL.SDL_Rect { x = optionX - textW / 2 - 150, y = optionY - 10, w = textW + 300, h = optionY * menuOptions[Menus.MenuMain].Count - 80 };
public static void RenderHelper(int width = 300, Menus menu = Menus.MenuMain)
{
int height = 500;
SDL.SDL_Rect menuBackgroundRect = new SDL.SDL_Rect { x = (SCREEN_WIDTH / 2)-width/2, y = 130, w = width, h = height};
SDL.SDL_SetRenderDrawColor(renderer, 41, 42, 61, 255); // Juka background
SDL.SDL_RenderFillRect(renderer, ref menuBackgroundRect);

var textWtemp = textW;

// Iterate through menu options and render text
for (int i = 0; i < menuOptions[Menus.MenuMain].Count; ++i)
menuDescript[menu] = new List<Descript<int>>();
for (int i = 0; i < menuOptions[menu].Count; ++i)
{
SDL.SDL_QueryTexture(menuTextures[Menus.MenuMain][i], out _, out _, out textW, out textH);
int textW, textH;
SDL.SDL_QueryTexture(menuTextures[menu][i], out _, out _, out textW, out textH);
SDL.SDL_Rect srcTextRect = new SDL.SDL_Rect { x = 0, y = 0, w = textW, h = textH };
SDL.SDL_Rect textRect = new SDL.SDL_Rect { x = optionX - textW / 2, y = optionY * (i + 1), w = textW, h = textH };

int x = (SCREEN_WIDTH / 2) - textW / 2;
int y = 130 + textH + (height / menuOptions[menu].Count) * (i);
int w = textW;
int h = textH;

var menuOptionDescript = new Descript<int>
{
X = (SCREEN_WIDTH / 2) - width / 2,
Y = y - 10,
Width = width,
Height = h + 20
};
menuDescript[menu].Add(menuOptionDescript);

SDL.SDL_Rect textRect = new SDL.SDL_Rect { x = x, y = y, w = textW, h = textH };

// Render menu option text
SDL.SDL_RenderCopy(renderer, menuTextures[Menus.MenuMain][i], ref srcTextRect, ref textRect);
SDL.SDL_RenderCopy(renderer, menuTextures[menu][i], ref srcTextRect, ref textRect);

boxX = optionX - textWtemp / 2 - 150;
boxY = optionY;
boxW = textWtemp + 300;
boxH = textH + 20;
SDL.SDL_Rect textRect2 = new SDL.SDL_Rect { x = boxX, y = boxY * (i + 1) - 10, w = boxW, h = boxH };
SDL.SDL_Rect textRect2 = new SDL.SDL_Rect { x = (SCREEN_WIDTH / 2) - width / 2, y = y - 10, w = width, h = h+20 };
if (HandleSelection(mouseX, mouseY, textRect2))
{
SDL.SDL_SetRenderDrawColor(renderer, 255, 0, 0, 15); // Red highlight for selection
SDL.SDL_RenderDrawRect(renderer, ref textRect2);
}
}
}

public static void RenderMenu()
{
RenderHelper(300, Menus.MenuMain);
}


public static void RenderRun()
{
RenderHelper(600, Menus.MenuJuka);
}

int textW, textH;

SDL.SDL_QueryTexture(menuTextures[Menus.MenuJuka][0], out _, out _, out textW, out textH);


// Calculate menu option positions (centered horizontally)
int optionX = (SCREEN_WIDTH - textW) / 2; // Placeholder for text width calculation
int optionY = SCREEN_HEIGHT / (menuOptions[Menus.MenuJuka].Count + 1);

SDL.SDL_QueryTexture(menuTextures[Menus.MenuJuka][0], out _, out _, out textW, out textH);
SDL.SDL_Rect menuBackgroundRect = new SDL.SDL_Rect { x = optionX - textW / 2 - 150, y = optionY - 10, w = textW + 300, h = optionY * menuOptions[Menus.MenuMain].Count - 80 };
SDL.SDL_SetRenderDrawColor(renderer, 41, 42, 61, 255); // Juka background
SDL.SDL_RenderFillRect(renderer, ref menuBackgroundRect);

var textWtemp = textW;

// Iterate through menu options and render text
for (int i = 0; i < menuOptions[Menus.MenuJuka].Count; ++i)
{
SDL.SDL_QueryTexture(menuTextures[Menus.MenuJuka][i], out _, out _, out textW, out textH);
SDL.SDL_Rect srcTextRect = new SDL.SDL_Rect { x = 0, y = 0, w = textW, h = textH };
SDL.SDL_Rect textRect = new SDL.SDL_Rect { x = optionX - textW / 2, y = optionY * (i + 1), w = textW, h = textH };

// Render menu option text
SDL.SDL_RenderCopy(renderer, menuTextures[Menus.MenuJuka][i], ref srcTextRect, ref textRect);
public static void RenderMenuInstall()
{
RenderHelper(300, Menus.MenuInstall);
}

boxX = optionX - textWtemp / 2 - 150;
boxY = optionY;
boxW = textWtemp + 300;
boxH = textH + 20;
SDL.SDL_Rect textRect2 = new SDL.SDL_Rect { x = boxX, y = boxY * (i + 1) - 10, w = boxW, h = boxH };
if (HandleSelection(mouseX, mouseY, textRect2))
{
SDL.SDL_SetRenderDrawColor(renderer, 255, 0, 0, 15); // Red highlight for selection
SDL.SDL_RenderDrawRect(renderer, ref textRect2);
}
}
public static void RenderMenuJukaInstall()
{
RenderHelper(300, Menus.MenuInstallJuka);
}


public static void MediaStreamer(nint fontFooter, SDL.SDL_Color colorWhite, SDL.SDL_Color colorRed)
{
Expand Down

0 comments on commit a0999c1

Please sign in to comment.