Skip to content

Commit

Permalink
Restructure of GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndreiM committed Jul 26, 2024
1 parent 3362447 commit 0d05ae5
Show file tree
Hide file tree
Showing 12 changed files with 755 additions and 754 deletions.
100 changes: 100 additions & 0 deletions src/Juka/GUI/Clicked.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using SDL2;
using VideoLibrary;
using static Juka.GUI.Globals;

namespace Juka.GUI
{
public class Clicked
{
public static void itemclicked()
{

if (currentscreen == 0)
{
for (int i = 0; i < menuOptions[Menus.MenuMain].Count; i++)
{
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")
{
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)
{
for (int i = 0; i < menuOptions[Menus.MenuJuka].Count; i++)
{
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")
{
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)
{
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))
{
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());

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

currentscreen = Menus.MediaPlayer;
}
}
}
}
else if (currentscreen == Menus.MediaDownloaded)
{
currentscreen = Menus.MediaPlayer;
}
}
}

}
16 changes: 16 additions & 0 deletions src/Juka/GUI/Colors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using SDL2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Juka.GUI
{
public static class Colors
{
public static SDL.SDL_Color colorWhite = new SDL.SDL_Color() { a = 255, r=255, g=255, b=255 };
public static SDL.SDL_Color colorBlack = new SDL.SDL_Color() { a = 255, r = 0, g = 0, b = 0 };
public static SDL.SDL_Color colorRed = new SDL.SDL_Color() { a = 255, r = 255, g = 0, b = 0 };
}
}
135 changes: 135 additions & 0 deletions src/Juka/GUI/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using SDL2;
using static Juka.GUI.Globals;

namespace Juka.GUI
{
public static class Controller
{
public static void MouseHandler()
{
SDL.SDL_Event e;
while (SDL.SDL_PollEvent(out e) != 0)
{
switch (e.type)
{
case SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION:
switch ((SDL.SDL_GameControllerAxis)e.caxis.axis)
{
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_MAX:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_INVALID:
mouseY += e.caxis.axisValue / 1000;
break;

case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
mouseX += e.caxis.axisValue / 1000;
break;
default:
break;
}
if (mouseX < 0)
{
mouseX = 0;
}
else if (mouseX > SCREEN_WIDTH - 12)
{
mouseX = SCREEN_WIDTH - 12;
}
if (mouseY < 0)
{
mouseY = 0;
}
else if (mouseY > SCREEN_HEIGHT - 12)
{
mouseY = SCREEN_HEIGHT - 12;
}
break;
case SDL.SDL_EventType.SDL_KEYDOWN:
keypressed = SDL.SDL_GetKeyName(e.key.keysym.sym);

if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_DOWN)
{
mouseY += 10;
}
else if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_UP)
{
mouseY -= 10;
}
else if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_LEFT)
{
mouseX -= 10;
}
else if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_RIGHT)
{
mouseX += 10;
}
break;
case SDL.SDL_EventType.SDL_MOUSEMOTION:
// Get the current mouse position
mouseX = e.motion.x;
mouseY = e.motion.y;
break;
case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN:
keypressed = e.cbutton.button.ToString();
if (rumble)
{
// Rumble the controller
SDL.SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 2000); // Strong rumble for 1 second
}

SDL.SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 2000); // Strong rumble for 1 second


switch ((SDL.SDL_GameControllerButton)e.cbutton.button)
{
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE:
currentscreen = Menus.MenuMain;
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X:
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y:
currentscreen = Menus.MenuMain;
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A:
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B:
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START:
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
Clicked.itemclicked();
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP:
mouseY -= 10;
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN:
mouseY += 10;
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT:
mouseX -= 10;
break;
case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
mouseX += 10;
break;
default:
Clicked.itemclicked();
break;
}
break;
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
if (e.button.button == SDL.SDL_BUTTON_LEFT)
{
Clicked.itemclicked();
}
else if (e.button.button == SDL.SDL_BUTTON_RIGHT)
{
currentscreen = 0;
}
break;

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

namespace Juka.GUI
{
public static class Globals
{
//Juka Related
public static string openFont = "open-sans.ttf";
public static string logo = "jukalogo.png";

public static int fontSize = 64;
public static int fontSizeC = 24;

public static Dictionary<string, string> systemInfo = SelfUpdate.GetSystemInfo();
public static string version = CurrentVersion.GetVersion();

//SDL2
public static int SCREEN_WIDTH = 1280;
public static int SCREEN_HEIGHT = 720;

public static string keypressed = SDL.SDL_GetKeyName(SDL.SDL_Keycode.SDLK_UNDEFINED);
public static bool rumble = false;

public static nint window = nint.Zero;
public static nint renderer = nint.Zero;
public static nint font = nint.Zero;

public static nint controller; //GET THE CONTROLLER
public static bool quit = false; //Render UNTIL QUIT

// Screen Selection
public static int mouseX = SCREEN_WIDTH / 2;
public static int mouseY = SCREEN_HEIGHT / 2;

public enum Menus
{
MenuMain,
MenuJuka,
RanJuka,
MediaPlayer,
MediaDownloaded,
MenuInstall
}

//
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
//

// WHERE TO PUT MENU CONTENT AND OFFSET
public static int boxX = 0;
public static int boxY = 0;
public static int boxW = 0;
public static int boxH = 0;


// Juka Run
public static string filetoexecute = "";
public static List<string> multioutput = new List<string>();

// Video
public static string myfile = "";
public static List<VideoInfo> videoInfos = new List<VideoInfo>();

//Current Screen
public static Menus currentscreen = Menus.MenuMain;
}
}
Loading

0 comments on commit 0d05ae5

Please sign in to comment.