Add files via upload

This commit is contained in:
mrdude2478 2022-04-26 01:25:56 +01:00 committed by GitHub
parent f16ec3d521
commit 1105062b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2966 additions and 0 deletions

2512
include/Plutonium/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,224 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
# ICON is the filename of the icon (.jpg), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.json
# - config.json
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
#ROMFS := romfs
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lpu -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
# IMPORTANT! Change "$(CURDIR)/../Plutonium" to the path in which you have Plutonium
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../Plutonium
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif
ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif
ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif
ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif
ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
ifeq ($(strip $(APP_JSON)),)
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
else
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
endif
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
ifeq ($(strip $(APP_JSON)),)
all : $(OUTPUT).nro
ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif
else
all : $(OUTPUT).nsp
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
$(OUTPUT).nso : $(OUTPUT).elf
endif
$(OUTPUT).elf : $(OFILES)
$(OFILES_SRC) : $(HFILES_BIN)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -0,0 +1,36 @@
#pragma once
// Include Plutonium's main header
#include <pu/Plutonium>
// Define your main layout as a class inheriting from pu::Layout
class CustomLayout : public pu::ui::Layout {
private:
// An easy way to keep objects is to have them as private members
// Using ::Ref (of a Plutonium built-in object or any class having PU_SMART_CTOR) is an alias to a shared_ptr of the instance.
pu::ui::elm::TextBlock::Ref helloText;
public:
CustomLayout();
// Have ::Ref alias and ::New() static constructor
PU_SMART_CTOR(CustomLayout)
};
// Define your application (can't instantiate base class, so need to make a derived one)
class MainApplication : public pu::ui::Application {
private:
// Layout instance
CustomLayout::Ref layout;
public:
using Application::Application;
PU_SMART_CTOR(MainApplication)
// We need to define this, and use it to initialize everything
void OnLoad() override;
};

View File

@ -0,0 +1,37 @@
#include <MainApplication.hpp>
/*
// If you would like to initialize and finalize stuff before or after Plutonium, you can use libnx's userAppInit/userAppExit
extern "C" void userAppInit() {
// Initialize stuff
}
extern "C" void userAppExit() {
// Cleanup/finalize stuff
}
*/
// Main entrypoint
int main() {
// First create our renderer, where one can customize SDL or other stuff's initialization.
auto renderer_opts = pu::ui::render::RendererInitOptions(SDL_INIT_EVERYTHING, pu::ui::render::RendererHardwareFlags);
renderer_opts.UseImage(pu::ui::render::IMGAllFlags);
renderer_opts.UseAudio(pu::ui::render::MixerAllFlags);
renderer_opts.UseTTF();
auto renderer = pu::ui::render::Renderer::New(renderer_opts);
// Create our main application from the renderer
auto main = MainApplication::New(renderer);
// Prepare out application. This MUST be called or Show() will exit and nothing will be rendered.
main->Prepare();
// Show -> start rendering in an "infinite" loop
// If wou would like to show with a "fade in" from black-screen to the UI, use instead ->ShowWithFadeIn();
main->Show();
// Exit homebrew (Plutonium will handle all disposing of UI and renderer/application, don't worry!
return 0;
}

View File

@ -0,0 +1,53 @@
#include <MainApplication.hpp>
// Implement all the layout/application functions here
CustomLayout::CustomLayout() : Layout::Layout() {
// Create the TextBlock instance with the text we want
this->helloText = pu::ui::elm::TextBlock::New(300, 300, "Press X to answer my question");
// Add the instance to the layout. IMPORTANT! this MUST be done for them to be used, having them as members is not enough (just a simple way to keep them)
this->Add(this->helloText);
}
void MainApplication::OnLoad() {
// Create the layout (calling the smart constructor above)
this->layout = CustomLayout::New();
// Load the layout. In applications layouts are loaded, not added into a container (you don't select an added layout, just load it from this function)
// Simply explained: loading layout = the application will render that layout in the very next frame
this->LoadLayout(this->layout);
// Set a function when input is caught. This input handling will be the first one to be handled (before Layout or any Elements)
// Using a lambda function here to simplify things
// You can use member functions via std::bind() C++ wrapper
this->SetOnInput([&](const u64 keys_down, const u64 keys_up, const u64 keys_held, const pu::ui::TouchPoint touch_pos) {
// If X is pressed, start with our dialog questions!
if(keys_down & HidNpadButton_X) {
int opt = this->CreateShowDialog("Question", "Do you like apples?", { "Yes!", "No...", "Cancel" }, true); // (using latest option as cancel option)
// -1 and -2 are similar, but if the user cancels manually -1 is set, other types or cancel should be -2.
if((opt == -1) || (opt == -2)) {
this->CreateShowDialog("Cancel", "Last question was canceled.", { "Ok" }, true); // If we will ignore the option, it doesn't matter if this is true or false
}
else {
// Otherwise, opt will be the index of the options we passed to the dialog
switch(opt) {
// "Yes!" was selected
case 0: {
this->CreateShowDialog("Answer", "Really? I like apples too!", { "Ok" }, true); // Same here ^
break;
}
// "No..." was selected
case 1: {
this->CreateShowDialog("Answer", "Oh, bad news then...", { "Ok" }, true); // And here ^
break;
}
}
}
}
// If + is pressed, exit application
else if(keys_down & HidNpadButton_Plus) {
this->Close();
}
});
}

19
include/Plutonium/LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2018-2019 XorTroll
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,12 @@
.PHONY: all clean
export PU_MAJOR := 0
export PU_MINOR := 3
export PU_MICRO := 0
all:
@$(MAKE) -C Plutonium/
clean:
@$(MAKE) clean -C Plutonium/

View File

@ -0,0 +1,68 @@
# Plutonium - an easy-to-use UI framework for Nintendo Switch homebrew
## What is Plutonium?
Plutonium is a high-level, C++ graphics library with the aim of making Nintendo Switch homebrew UIs in a more user-firendly way.
It uses libnx and SDL2, so both libraries are required.
To be more exact, this libraries should be installed via pacman:
```
switch-sdl2 switch-sdl2_ttf switch-sdl2_image switch-sdl2_gfx switch-sdl2_mixer switch-mesa switch-glad switch-glm switch-libdrm_nouveau switch-libwebp switch-libpng switch-freetype switch-bzip2 switch-libjpeg-turbo switch-opusfile switch-libopus
```
## Internal structure and performance
Plutonium internally uses SDL2 for UI rendering.
Plutonium's API is based on WPF/WinForms's system. The user doesn't directly interact with the rendering, as it's done via a main rendering system and different objects to render.
Check the [basic example](Example) for a basic usage of the libraries. In case you want to see a really powerful app which really shows what Plutonium is capable of, take a look at [Goldleaf](https://github.com/XorTroll/Goldleaf), [uLaunch](https://github.com/XorTroll/uLaunch) or many other homebrew apps made using this libraries.
Check the [documentation](https://XorTroll.github.io/Plutonium/) for a more detailed explanation of the library's usage.
## Using this libraries
On the [releases](https://github.com/XorTroll/Plutonium/releases) page you have all the released versions. All of them are zipped files, containing `include` and `lib` directories.
### Simple project layout
This is how a regular Plutonium project would (more or less) have its Makefile and project layout using Plutonium:
- Makefile
```Makefile
...
LIBS := -lpu -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/Plutonium
...
```
- Project directory
```txt
Project
|
|-- Makefile
|-- source
|-- include
|-- Plutonium
|
|-- include
|-- lib
```
## Building
Clone the repository, cd into `Plutonium` directory and run `make`.
You will need devkitPro, libnx and all the libraries mentioned above installed via pacman.
## Support
If you would like to be more informed about my projects' status and support, you should check [my Discord server](https://discord.gg/3KpFyaH). It's a simple server for Nintendo homebrew and hacking stuff, focused on my projects. If you would like to take part in testing .
If you like my work, you should take a look at my [Patreon](https://patreon.com/xortroll) page!

View File

@ -0,0 +1,5 @@
# Plutonium API documentation
- Welcome to Plutonium library's documentation! You can browse the API's documentation here.
- More stuff will be added soon, like more info here, function and class descriptions...