Initial commit

This commit is contained in:
Niklas080208
2026-02-11 20:33:01 +01:00
commit 617265f004
145 changed files with 45252 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef BOREALIS_RESOURCES
#error BOREALIS_RESOURCES define missing
#endif
#define BOREALIS_ASSET(_str) BOREALIS_RESOURCES _str
// Library
#include <borealis/applet_frame.hpp>
#include <borealis/application.hpp>
#include <borealis/box_layout.hpp>
#include <borealis/button.hpp>
#include <borealis/crash_frame.hpp>
#include <borealis/dialog.hpp>
#include <borealis/dropdown.hpp>
#include <borealis/event.hpp>
#include <borealis/header.hpp>
#include <borealis/image.hpp>
#include <borealis/label.hpp>
#include <borealis/layer_view.hpp>
#include <borealis/list.hpp>
#include <borealis/logger.hpp>
#include <borealis/material_icon.hpp>
#include <borealis/notification_manager.hpp>
#include <borealis/popup_frame.hpp>
#include <borealis/progress_display.hpp>
#include <borealis/progress_spinner.hpp>
#include <borealis/rectangle.hpp>
#include <borealis/repeating_task.hpp>
#include <borealis/sidebar.hpp>
#include <borealis/staged_applet_frame.hpp>
#include <borealis/style.hpp>
#include <borealis/tab_frame.hpp>
#include <borealis/table.hpp>
#include <borealis/theme.hpp>
#include <borealis/thumbnail_frame.hpp>
#include <borealis/view.hpp>

View File

@@ -0,0 +1,68 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2020 WerWolv
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <functional>
#include <string>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
namespace brls
{
class View;
typedef std::function<bool(void)> ActionListener;
// ZL and ZR do not exist here because GLFW doesn't know them
enum class Key
{
A = GLFW_GAMEPAD_BUTTON_A,
B = GLFW_GAMEPAD_BUTTON_B,
X = GLFW_GAMEPAD_BUTTON_X,
Y = GLFW_GAMEPAD_BUTTON_Y,
LSTICK = GLFW_GAMEPAD_BUTTON_LEFT_THUMB,
RSTICK = GLFW_GAMEPAD_BUTTON_RIGHT_THUMB,
L = GLFW_GAMEPAD_BUTTON_LEFT_BUMPER,
R = GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER,
PLUS = GLFW_GAMEPAD_BUTTON_START,
MINUS = GLFW_GAMEPAD_BUTTON_BACK,
DLEFT = GLFW_GAMEPAD_BUTTON_DPAD_LEFT,
DUP = GLFW_GAMEPAD_BUTTON_DPAD_UP,
DRIGHT = GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,
DDOWN = GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
};
struct Action
{
Key key;
std::string hintText;
bool available;
bool hidden;
ActionListener actionListener;
bool operator==(const Key other)
{
return this->key == other;
}
};
} // namespace brls

View File

@@ -0,0 +1,178 @@
/* RetroArch - A frontend for libretro.
* Borealis, a Nintendo Switch UI Library
* Copyright (C) 2014-2017 - Jean-André Santoni
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2019 - natinusala
Copyright (C) 2019 - p-sam
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <functional>
namespace brls
{
typedef float (*easing_cb)(float, float, float, float);
typedef std::function<void(void*)> tween_cb;
enum menu_animation_ctl_state
{
MENU_ANIMATION_CTL_NONE = 0,
MENU_ANIMATION_CTL_DEINIT,
MENU_ANIMATION_CTL_CLEAR_ACTIVE,
MENU_ANIMATION_CTL_SET_ACTIVE
};
enum menu_animation_easing_type
{
/* Linear */
EASING_LINEAR = 0,
/* Quad */
EASING_IN_QUAD,
EASING_OUT_QUAD,
EASING_IN_OUT_QUAD,
EASING_OUT_IN_QUAD,
/* Cubic */
EASING_IN_CUBIC,
EASING_OUT_CUBIC,
EASING_IN_OUT_CUBIC,
EASING_OUT_IN_CUBIC,
/* Quart */
EASING_IN_QUART,
EASING_OUT_QUART,
EASING_IN_OUT_QUART,
EASING_OUT_IN_QUART,
/* Quint */
EASING_IN_QUINT,
EASING_OUT_QUINT,
EASING_IN_OUT_QUINT,
EASING_OUT_IN_QUINT,
/* Sine */
EASING_IN_SINE,
EASING_OUT_SINE,
EASING_IN_OUT_SINE,
EASING_OUT_IN_SINE,
/* Expo */
EASING_IN_EXPO,
EASING_OUT_EXPO,
EASING_IN_OUT_EXPO,
EASING_OUT_IN_EXPO,
/* Circ */
EASING_IN_CIRC,
EASING_OUT_CIRC,
EASING_IN_OUT_CIRC,
EASING_OUT_IN_CIRC,
/* Bounce */
EASING_IN_BOUNCE,
EASING_OUT_BOUNCE,
EASING_IN_OUT_BOUNCE,
EASING_OUT_IN_BOUNCE,
EASING_LAST
};
/* TODO:
* Add a reverse loop ticker for languages
* that read right to left */
enum menu_animation_ticker_type
{
TICKER_TYPE_BOUNCE = 0,
TICKER_TYPE_LOOP,
TICKER_TYPE_LAST
};
typedef uintptr_t menu_animation_ctx_tag;
typedef struct menu_animation_ctx_subject
{
size_t count;
const void* data;
} menu_animation_ctx_subject_t;
typedef struct menu_animation_ctx_entry
{
enum menu_animation_easing_type easing_enum;
uintptr_t tag;
float duration;
float target_value;
float* subject;
tween_cb cb;
tween_cb tick;
void* userdata;
} menu_animation_ctx_entry_t;
typedef struct menu_animation_ctx_ticker
{
bool selected;
size_t len;
uint64_t idx;
enum menu_animation_ticker_type type_enum;
char* s;
const char* str;
const char* spacer;
} menu_animation_ctx_ticker_t;
typedef float menu_timer_t;
typedef struct menu_timer_ctx_entry
{
float duration;
tween_cb cb;
tween_cb tick;
void* userdata;
} menu_timer_ctx_entry_t;
typedef struct menu_delayed_animation
{
menu_timer_t timer;
menu_animation_ctx_entry_t entry;
} menu_delayed_animation_t;
void menu_timer_start(menu_timer_t* timer, menu_timer_ctx_entry_t* timer_entry);
void menu_timer_kill(menu_timer_t* timer);
void menu_animation_init(void);
void menu_animation_free(void);
bool menu_animation_update(void);
bool menu_animation_ticker(menu_animation_ctx_ticker_t* ticker);
float menu_animation_get_delta_time(void);
bool menu_animation_is_active(void);
bool menu_animation_kill_by_tag(menu_animation_ctx_tag* tag);
void menu_animation_kill_by_subject(menu_animation_ctx_subject_t* subject);
bool menu_animation_push(menu_animation_ctx_entry_t* entry);
void menu_animation_push_delayed(unsigned delay, menu_animation_ctx_entry_t* entry);
bool menu_animation_ctl(enum menu_animation_ctl_state state, void* data);
uint64_t menu_animation_get_ticker_idx(void);
uint64_t menu_animation_get_ticker_slow_idx(void);
void menu_animation_get_highlight(float* gradient_x, float* gradient_y, float* color);
} // namespace brls

View File

@@ -0,0 +1,94 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/frame_context.hpp>
#include <borealis/hint.hpp>
#include <borealis/image.hpp>
#include <borealis/view.hpp>
#include <string>
namespace brls
{
enum class HeaderStyle
{
REGULAR,
POPUP // Only meant for PopupFrames. Using it in other contexts might cause weird behaviour
};
// A Horizon settings-like frame, with header and footer (no sidebar)
class AppletFrame : public View
{
private:
std::string title = "";
std::string footerText = "";
std::string subTitleLeft = "", subTitleRight = "";
View* icon = nullptr;
Hint* hint = nullptr;
View* contentView = nullptr;
bool slideOut = false;
bool slideIn = false;
ViewAnimation animation;
protected:
HeaderStyle headerStyle = HeaderStyle::REGULAR;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
unsigned leftPadding = 0;
unsigned rightPadding = 0;
public:
AppletFrame(bool padLeft, bool padRight);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
View* getDefaultFocus() override;
virtual bool onCancel();
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
void show(std::function<void(void)> cb, bool animate = true, ViewAnimation animation = ViewAnimation::FADE) override;
void hide(std::function<void(void)> cb, bool animated = true, ViewAnimation animation = ViewAnimation::FADE) override;
void onWindowSizeChanged() override;
void setTitle(std::string title);
void setFooterText(std::string footerText);
void setSubtitle(std::string left, std::string right);
void setIcon(unsigned char* buffer, size_t bufferSize);
void setIcon(std::string imagePath);
void setIcon(View* view);
virtual void setContentView(View* view);
bool hasContentView();
void setHeaderStyle(HeaderStyle headerStyle);
void setAnimateHint(bool animate)
{
this->hint->setAnimate(animate);
}
~AppletFrame();
};
} // namespace brls

View File

@@ -0,0 +1,204 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <nanovg.h>
#include <borealis/animations.hpp>
#include <borealis/frame_context.hpp>
#include <borealis/hint.hpp>
#include <borealis/label.hpp>
#include <borealis/logger.hpp>
#include <borealis/notification_manager.hpp>
#include <borealis/style.hpp>
#include <borealis/task_manager.hpp>
#include <borealis/theme.hpp>
#include <borealis/view.hpp>
#include <map>
#include <vector>
namespace brls
{
// The top-right framerate counter
class FramerateCounter : public Label
{
private:
retro_time_t lastSecond = 0;
unsigned frames = 0;
public:
FramerateCounter();
void frame(FrameContext* ctx) override;
};
class Application
{
public:
//Init with default style and theme (as close to HOS as possible)
static bool init(std::string title);
// Init with given style and theme
static bool init(std::string title, Style style, Theme theme);
static bool mainLoop();
/**
* Pushes a view on this applications's view stack
*
* The view will automatically be resized to take
* the whole screen and layout() will be called
*
* The view will gain focus if applicable
*/
static void pushView(View* view, ViewAnimation animation = ViewAnimation::FADE);
/**
* Pops the last pushed view from the stack
* and gives focus back where it was before
*/
static void popView(
ViewAnimation animation = ViewAnimation::FADE, std::function<void(void)> cb = []() {});
/**
* Gives the focus to the given view
* or clears the focus if given nullptr
*/
static void giveFocus(View* view);
static Style* getStyle();
static void setTheme(Theme theme);
static ThemeValues* getThemeValues();
static ThemeValues* getThemeValuesForVariant(ThemeVariant variant);
static ThemeVariant getThemeVariant();
static int loadFont(const char* fontName, const char* filePath);
static int loadFontFromMemory(const char* fontName, void* data, size_t size, bool freeData);
static int findFont(const char* fontName);
static FontStash* getFontStash();
static void notify(std::string text);
static void onGamepadButtonPressed(char button, bool repeating);
/**
* "Crashes" the app (displays a fullscreen CrashFrame)
*/
static void crash(std::string text);
static void quit();
/**
* Blocks any and all user inputs
*/
static void blockInputs();
/**
* Unblocks inputs after a call to
* blockInputs()
*/
static void unblockInputs();
static NVGcontext* getNVGContext();
static TaskManager* getTaskManager();
static NotificationManager* getNotificationManager();
static void setCommonFooter(std::string footer);
static std::string* getCommonFooter();
static void setDisplayFramerate(bool enabled);
static void toggleFramerateDisplay();
static void setMaximumFPS(unsigned fps);
// public so that the glfw callback can access it
inline static unsigned contentWidth, contentHeight;
inline static float windowScale;
static void resizeFramerateCounter();
static void resizeNotificationManager();
static GenericEvent* getGlobalFocusChangeEvent();
static VoidEvent* getGlobalHintsUpdateEvent();
static View* getCurrentFocus();
static std::string getTitle();
private:
inline static GLFWwindow* window;
inline static NVGcontext* vg;
inline static std::string title;
inline static TaskManager* taskManager;
inline static NotificationManager* notificationManager;
inline static FontStash fontStash;
inline static std::vector<View*> viewStack;
inline static std::vector<View*> focusStack;
inline static unsigned windowWidth, windowHeight;
inline static View* currentFocus;
inline static Theme currentTheme;
inline static ThemeVariant currentThemeVariant;
inline static GLFWgamepadstate oldGamepad;
inline static GLFWgamepadstate gamepad;
inline static Style currentStyle;
inline static unsigned blockInputsTokens = 0; // any value > 0 means inputs are blocked
inline static std::string commonFooter = "";
inline static FramerateCounter* framerateCounter = nullptr;
inline static float frameTime = 0.0f;
inline static View* repetitionOldFocus = nullptr;
inline static GenericEvent globalFocusChangeEvent;
inline static VoidEvent globalHintsUpdateEvent;
static void navigate(FocusDirection direction);
static void onWindowSizeChanged();
static void frame();
static void clear();
static void exit();
/**
* Handles actions for the currently focused view and
* the given button
* Returns true if at least one action has been fired
*/
static bool handleAction(char button);
};
} // namespace brls

View File

@@ -0,0 +1,173 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 WerWolv
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
#include <vector>
namespace brls
{
enum class BoxLayoutOrientation
{
VERTICAL,
HORIZONTAL
};
// TODO: Implement all gravity options for both orientations
enum class BoxLayoutGravity
{
DEFAULT, // left for horizontal, top for vertical
LEFT,
RIGHT,
TOP,
BOTTOM,
CENTER
};
class BoxLayoutChild
{
public:
View* view;
bool fill; // should the child fill the remaining space?
};
// A basic horizontal or vertical box layout :
// - Children can currently only be stretched to full width (vertical) or height (horizontal)
// - Only works with children with fixed width (horizontal) or height (vertical)
// TODO: More complex alignment and/or stretching parameters to children
class BoxLayout : public View
{
private:
BoxLayoutOrientation orientation;
unsigned spacing = 0;
bool resize = false; // should the view be resized according to children size after a layout?
BoxLayoutGravity gravity = BoxLayoutGravity::DEFAULT;
protected:
std::vector<BoxLayoutChild*> children;
size_t originalDefaultFocus = 0;
size_t defaultFocusedIndex = 0;
bool childFocused = false;
bool rememberFocus = false;
unsigned marginTop = 0;
unsigned marginRight = 0;
unsigned marginBottom = 0;
unsigned marginLeft = 0;
/**
* Should the BoxLayout apply spacing after
* this view?
*/
virtual void customSpacing(View* current, View* next, int* spacing) {}
public:
BoxLayout(BoxLayoutOrientation orientation, size_t defaultFocus = 0);
~BoxLayout();
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
View* getNextFocus(FocusDirection direction, void* parentUserdata) override;
View* getDefaultFocus() override;
void onChildFocusGained(View* child) override;
void onChildFocusLost(View* child) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
void onWindowSizeChanged() override;
/**
* Sets gravity
*/
void setGravity(BoxLayoutGravity gravity);
/**
* Sets spacing between views
*/
void setSpacing(unsigned spacing);
unsigned getSpacing();
/**
* Sets margins around views
* Bottom (vertical) or right (horizontal) are
* only effective if the last child is set to fill
*/
void setMargins(unsigned top, unsigned right, unsigned bottom, unsigned left);
void setMarginBottom(unsigned bottom);
/**
* Adds a view to this box layout
* If fill is set to true, the child will
* fill the remaining space
*/
void addView(View* view, bool fill = false, bool resetState = false);
/**
* Removes the view at specified
* The view will be freed if free
* is set to true (defaults to true)
*
* Warning: this method isn't correctly
* implemented - currently removing a view will
* most likely result in memory corruption
*/
void removeView(int index, bool free = true);
/**
* Removes all views
* from this layout
*/
void clear(bool free = true);
/**
* Returns true if this layout
* doesn't contain any views
*/
bool isEmpty();
bool isChildFocused();
void setFocusedIndex(unsigned index);
size_t getViewsCount();
View* getChild(size_t i);
/**
* If enabled, will force the layout to resize itself
* to match the children size
* Mandatory for using in a ScrollView
*/
void setResize(bool resize);
/**
* Should the default focus be set to the originally focused
* view (until the layout disappears)?
*/
void setRememberFocus(bool rememberFocus);
};
} // namespace brls

View File

@@ -0,0 +1,99 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/image.hpp>
#include <borealis/label.hpp>
#include <borealis/view.hpp>
namespace brls
{
enum class ButtonStyle
{
PLAIN = 0, // regular, plain button
BORDERED, // text and a border
BORDERLESS, // only text
CRASH, // same as borderless but with a different text color
DIALOG // same as borderless but with a different text color
};
enum class ButtonState
{
ENABLED = 0,
DISABLED
};
// A button
class Button : public View
{
private:
ButtonStyle style;
Label* label = nullptr;
Image* image = nullptr;
GenericEvent clickEvent;
LabelStyle getLabelStyle();
ButtonState state = ButtonState::ENABLED;
float cornerRadiusOverride = 0;
public:
Button(ButtonStyle style);
~Button();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
virtual bool onClick();
void layout(NVGcontext* vg, Style* style, FontStash* stash);
void getHighlightInsets(unsigned* top, unsigned* right, unsigned* bottom, unsigned* left) override;
ButtonState getState();
void setState(ButtonState state);
Button* setLabel(std::string label);
Button* setImage(std::string path);
Button* setImage(unsigned char* buffer, size_t bufferSize);
GenericEvent* getClickEvent();
View* getDefaultFocus() override
{
return this;
}
void setCornerRadius(float cornerRadius);
void getHighlightMetrics(Style* style, float* cornerRadius) override
{
if (cornerRadiusOverride)
*cornerRadius = cornerRadiusOverride;
else
*cornerRadius = style->Button.cornerRadius;
}
bool isHighlightBackgroundEnabled() override
{
return false;
}
};
} // namespace brls

View File

@@ -0,0 +1,55 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/button.hpp>
#include <borealis/hint.hpp>
#include <borealis/label.hpp>
#include <borealis/view.hpp>
namespace brls
{
// A screen similar to the "The software has closed" dialog
// pressing OK will exit the app
class CrashFrame : public View
{
private:
Label* label;
Button* button;
Hint* hint;
public:
CrashFrame(std::string text);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void onShowAnimationEnd() override;
View* getDefaultFocus() override;
bool isTranslucent() override
{
return true; // have it always translucent to disable fade out animation
}
~CrashFrame();
};
} // namespace brls

View File

@@ -0,0 +1,95 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/box_layout.hpp>
#include <borealis/view.hpp>
namespace brls
{
// TODO: Add a "can be cancelled with B" flag
// TODO: Add buttons at creation time
// TODO: Add the blurred dialog type once the blur is finished
class DialogButton
{
public:
std::string label;
GenericEvent::Callback cb;
};
// A modal dialog with zero to three buttons
// and anything as content
// Create the dialog then use open() and close()
class Dialog : public View
{
private:
View* contentView = nullptr;
unsigned frameX, frameY, frameWidth, frameHeight;
std::vector<DialogButton*> buttons;
BoxLayout* verticalButtonsLayout = nullptr;
BoxLayout* horizontalButtonsLayout = nullptr;
void rebuildButtons();
unsigned getButtonsHeight();
bool cancelable = true;
public:
Dialog(std::string text);
Dialog(View* contentView);
~Dialog();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
View* getDefaultFocus() override;
virtual bool onCancel();
/**
* Adds a button to this dialog, with a maximum of three
* The position depends on the add order
*
* Adding a button after the dialog has been opened is
* NOT SUPPORTED
*/
void addButton(std::string label, GenericEvent::Callback cb);
/**
* A cancelable dialog is closed when
* the user presses B (defaults to true)
*
* A dialog without any buttons cannot
* be cancelable
*/
void setCancelable(bool cancelable);
void open();
void close(std::function<void(void)> cb = []() {});
bool isTranslucent() override
{
return true;
}
};
} // namespace brls

View File

@@ -0,0 +1,80 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019-2020 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/event.hpp>
#include <borealis/list.hpp>
#include <borealis/view.hpp>
#include <string>
namespace brls
{
// Fired when the user has selected a value
//
// Parameter is either the selected value index
// or -1 if the user cancelled
//
// Assume that the Dropdown is deleted
// as soon as this function is called
typedef Event<int> ValueSelectedEvent;
// Allows the user to select between multiple
// values
// Use Dropdown::open()
class Dropdown : public View
{
private:
Dropdown(std::string title, std::vector<std::string> values, ValueSelectedEvent::Callback cb, size_t selected = 0);
std::string title;
int valuesCount;
ValueSelectedEvent valueEvent;
List* list;
Hint* hint;
float topOffset; // for slide in animation
protected:
unsigned getShowAnimationDuration(ViewAnimation animation) override;
public:
~Dropdown();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
View* getDefaultFocus() override;
virtual bool onCancel();
void show(std::function<void(void)> cb, bool animate = true, ViewAnimation animation = ViewAnimation::FADE) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
static void open(std::string title, std::vector<std::string> values, ValueSelectedEvent::Callback cb, int selected = -1);
bool isTranslucent() override
{
return true || View::isTranslucent();
}
};
} // namespace brls

View File

@@ -0,0 +1,75 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2020 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <algorithm>
#include <functional>
#include <list>
namespace brls
{
// Simple observer pattern implementation
//
// Usage:
// 1. typedef your event type
// 2. create as many events as you want using that type
// 3. call subscribe on the events with your observers
// 4. call fire when you want to fire the events
// it wil return true if at least one subscriber exists
// for that event
template <typename... Ts>
class Event
{
public:
typedef std::function<void(Ts...)> Callback;
typedef std::list<Callback> CallbacksList;
typedef typename CallbacksList::iterator Subscription;
Subscription subscribe(Callback cb);
void unsubscribe(Subscription subscription);
bool fire(Ts... args);
private:
CallbacksList callbacks;
};
template <typename... Ts>
typename Event<Ts...>::Subscription Event<Ts...>::subscribe(Event<Ts...>::Callback cb)
{
this->callbacks.push_back(cb);
return --this->callbacks.end();
}
template <typename... Ts>
void Event<Ts...>::unsubscribe(Event<Ts...>::Subscription subscription)
{
this->callbacks.erase(subscription);
}
template <typename... Ts>
bool Event<Ts...>::fire(Ts... args)
{
for (Callback cb : this->callbacks)
cb(args...);
return !this->callbacks.empty();
}
}; // namespace brls

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (boolean.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_SDK_BOOLEAN_H
#define __LIBRETRO_SDK_BOOLEAN_H
#ifndef __cplusplus
#if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(SN_TARGET_PS3)
/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */
#define bool unsigned char
#define true 1
#define false 0
#else
#include <stdbool.h>
#endif
#endif
#endif

View File

@@ -0,0 +1,59 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (strl.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_SDK_COMPAT_STRL_H
#define __LIBRETRO_SDK_COMPAT_STRL_H
#include <string.h>
#include <stddef.h>
#if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H)
#include "../../../config.h"
#endif
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
#ifdef __MACH__
#ifndef HAVE_STRL
#define HAVE_STRL
#endif
#endif
#ifndef HAVE_STRL
/* Avoid possible naming collisions during link since
* we prefer to use the actual name. */
#define strlcpy(dst, src, size) strlcpy_retro__(dst, src, size)
#define strlcat(dst, src, size) strlcat_retro__(dst, src, size)
size_t strlcpy(char *dest, const char *source, size_t size);
size_t strlcat(char *dest, const char *source, size_t size);
#endif
char *strldup(const char *s, size_t n);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,67 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (utf.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef _LIBRETRO_ENCODINGS_UTF_H
#define _LIBRETRO_ENCODINGS_UTF_H
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
enum CodePage
{
CODEPAGE_LOCAL = 0, /* CP_ACP */
CODEPAGE_UTF8 = 65001 /* CP_UTF8 */
};
size_t utf8_conv_utf32(uint32_t *out, size_t out_chars,
const char *in, size_t in_size);
bool utf16_conv_utf8(uint8_t *out, size_t *out_chars,
const uint16_t *in, size_t in_size);
size_t utf8len(const char *string);
size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars);
const char *utf8skip(const char *str, size_t chars);
uint32_t utf8_walk(const char **string);
bool utf16_to_char_string(const uint16_t *in, char *s, size_t len);
char* utf8_to_local_string_alloc(const char *str);
char* local_to_utf8_string_alloc(const char *str);
wchar_t* utf8_to_utf16_string_alloc(const char *str);
char* utf16_to_utf8_string_alloc(const wchar_t *str);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,75 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (features_cpu.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef _LIBRETRO_SDK_CPU_INFO_H
#define _LIBRETRO_SDK_CPU_INFO_H
#include <retro_common_api.h>
#include <stdint.h>
#include <libretro.h>
RETRO_BEGIN_DECLS
/**
* cpu_features_get_perf_counter:
*
* Gets performance counter.
*
* Returns: performance counter.
**/
retro_perf_tick_t cpu_features_get_perf_counter(void);
/**
* cpu_features_get_time_usec:
*
* Gets time in microseconds, from an undefined epoch.
* The epoch may change between computers or across reboots.
*
* Returns: time in microseconds
**/
retro_time_t cpu_features_get_time_usec(void);
/**
* cpu_features_get:
*
* Gets CPU features.
*
* Returns: bitmask of all CPU features available.
**/
uint64_t cpu_features_get(void);
/**
* cpu_features_get_core_amount:
*
* Gets the amount of available CPU cores.
*
* Returns: amount of CPU cores available.
**/
unsigned cpu_features_get_core_amount(void);
void cpu_features_get_model_name(char *name, int len);
RETRO_END_DECLS
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_assert.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __RETRO_ASSERT_H
#define __RETRO_ASSERT_H
#include <assert.h>
#ifdef RARCH_INTERNAL
#include <stdio.h>
#define retro_assert(cond) do { \
if (!(cond)) { printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__); abort(); } \
} while(0)
#else
#define retro_assert(cond) assert(cond)
#endif
#endif

View File

@@ -0,0 +1,117 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_common_api.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef _LIBRETRO_COMMON_RETRO_COMMON_API_H
#define _LIBRETRO_COMMON_RETRO_COMMON_API_H
/*
This file is designed to normalize the libretro-common compiling environment
for public API headers. This should be leaner than a normal compiling environment,
since it gets #included into other project's sources.
*/
/* ------------------------------------ */
/*
Ordinarily we want to put #ifdef __cplusplus extern "C" in C library
headers to enable them to get used by c++ sources.
However, we want to support building this library as C++ as well, so a
special technique is called for.
*/
#define RETRO_BEGIN_DECLS
#define RETRO_END_DECLS
#ifdef __cplusplus
#ifdef CXX_BUILD
/* build wants everything to be built as c++, so no extern "C" */
#else
#undef RETRO_BEGIN_DECLS
#undef RETRO_END_DECLS
#define RETRO_BEGIN_DECLS extern "C" {
#define RETRO_END_DECLS }
#endif
#else
/* header is included by a C source file, so no extern "C" */
#endif
/*
IMO, this non-standard ssize_t should not be used.
However, it's a good example of how to handle something like this.
*/
#ifdef _MSC_VER
#ifndef HAVE_SSIZE_T
#define HAVE_SSIZE_T
#if defined(_WIN64)
typedef __int64 ssize_t;
#elif defined(_WIN32)
typedef int ssize_t;
#endif
#endif
#elif defined(__MACH__)
#include <sys/types.h>
#endif
#ifdef _MSC_VER
#if _MSC_VER >= 1800
#include <inttypes.h>
#else
#ifndef PRId64
#define PRId64 "I64d"
#define PRIu64 "I64u"
#define PRIuPTR "Iu"
#endif
#endif
#else
/* C++11 says this one isn't needed, but apparently (some versions of) mingw require it anyways */
/* https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format */
/* https://github.com/libretro/RetroArch/issues/6009 */
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#endif
#ifndef PRId64
#error "inttypes.h is being screwy"
#endif
#define STRING_REP_INT64 "%" PRId64
#define STRING_REP_UINT64 "%" PRIu64
#define STRING_REP_USIZE "%" PRIuPTR
/*
I would like to see retro_inline.h moved in here; possibly boolean too.
rationale: these are used in public APIs, and it is easier to find problems
and write code that works the first time portably when theyre included uniformly
than to do the analysis from scratch each time you think you need it, for each feature.
Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h,
then you should pay the price everywhere, so you can see how much grief it will cause.
Of course, another school of thought is that you should do as little damage as possible
in as few places as possible...
*/
/* _LIBRETRO_COMMON_RETRO_COMMON_API_H */
#endif

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_inline.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_SDK_INLINE_H
#define __LIBRETRO_SDK_INLINE_H
#ifndef INLINE
#if defined(_WIN32) || defined(__INTEL_COMPILER)
#define INLINE __inline
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
#define INLINE inline
#elif defined(__GNUC__)
#define INLINE __inline__
#else
#define INLINE
#endif
#endif
#endif

View File

@@ -0,0 +1,94 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_math.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef _LIBRETRO_COMMON_MATH_H
#define _LIBRETRO_COMMON_MATH_H
#include <stdint.h>
#if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(_WIN32) && defined(_XBOX)
#include <Xtl.h>
#endif
#include <limits.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
#include <retro_inline.h>
#ifndef M_PI
#if !defined(USE_MATH_DEFINES)
#define M_PI 3.14159265358979323846264338327
#endif
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/**
* next_pow2:
* @v : initial value
*
* Get next power of 2 value based on initial value.
*
* Returns: next power of 2 value (derived from @v).
**/
static INLINE uint32_t next_pow2(uint32_t v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
}
/**
* prev_pow2:
* @v : initial value
*
* Get previous power of 2 value based on initial value.
*
* Returns: previous power of 2 value (derived from @v).
**/
static INLINE uint32_t prev_pow2(uint32_t v)
{
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return v - (v >> 1);
}
#endif

View File

@@ -0,0 +1,182 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_miscellaneous.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __RARCH_MISCELLANEOUS_H
#define __RARCH_MISCELLANEOUS_H
#define RARCH_MAX_SUBSYSTEMS 10
#define RARCH_MAX_SUBSYSTEM_ROMS 10
#include <stdint.h>
#include <boolean.h>
#include <retro_inline.h>
#if defined(_WIN32) && !defined(_XBOX)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#elif defined(_WIN32) && defined(_XBOX)
#include <Xtl.h>
#endif
#if defined(__CELLOS_LV2__)
#include <sys/fs_external.h>
#endif
#include <limits.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
static INLINE void bits_or_bits(uint32_t *a, uint32_t *b, uint32_t count)
{
uint32_t i;
for (i = 0; i < count;i++)
a[i] |= b[i];
}
static INLINE void bits_clear_bits(uint32_t *a, uint32_t *b, uint32_t count)
{
uint32_t i;
for (i = 0; i < count;i++)
a[i] &= ~b[i];
}
static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count)
{
uint32_t i;
for (i = 0; i < count; i++)
{
if (ptr[i] != 0)
return true;
}
return false;
}
#ifndef PATH_MAX_LENGTH
#if defined(__CELLOS_LV2__)
#define PATH_MAX_LENGTH CELL_FS_MAX_FS_PATH_LENGTH
#elif defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS)
#define PATH_MAX_LENGTH 512
#else
#define PATH_MAX_LENGTH 4096
#endif
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define BITS_GET_ELEM(a, i) ((a).data[i])
#define BITS_GET_ELEM_PTR(a, i) ((a)->data[i])
#define BIT_SET(a, bit) ((a)[(bit) >> 3] |= (1 << ((bit) & 7)))
#define BIT_CLEAR(a, bit) ((a)[(bit) >> 3] &= ~(1 << ((bit) & 7)))
#define BIT_GET(a, bit) (((a)[(bit) >> 3] >> ((bit) & 7)) & 1)
#define BIT16_SET(a, bit) ((a) |= (1 << ((bit) & 15)))
#define BIT16_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 15)))
#define BIT16_GET(a, bit) (((a) >> ((bit) & 15)) & 1)
#define BIT16_CLEAR_ALL(a) ((a) = 0)
#define BIT32_SET(a, bit) ((a) |= (1 << ((bit) & 31)))
#define BIT32_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 31)))
#define BIT32_GET(a, bit) (((a) >> ((bit) & 31)) & 1)
#define BIT32_CLEAR_ALL(a) ((a) = 0)
#define BIT64_SET(a, bit) ((a) |= (UINT64_C(1) << ((bit) & 63)))
#define BIT64_CLEAR(a, bit) ((a) &= ~(UINT64_C(1) << ((bit) & 63)))
#define BIT64_GET(a, bit) (((a) >> ((bit) & 63)) & 1)
#define BIT64_CLEAR_ALL(a) ((a) = 0)
#define BIT128_SET(a, bit) ((a).data[(bit) >> 5] |= (1 << ((bit) & 31)))
#define BIT128_CLEAR(a, bit) ((a).data[(bit) >> 5] &= ~(1 << ((bit) & 31)))
#define BIT128_GET(a, bit) (((a).data[(bit) >> 5] >> ((bit) & 31)) & 1)
#define BIT128_CLEAR_ALL(a) memset(&(a), 0, sizeof(a))
#define BIT128_SET_PTR(a, bit) BIT128_SET(*a, bit)
#define BIT128_CLEAR_PTR(a, bit) BIT128_CLEAR(*a, bit)
#define BIT128_GET_PTR(a, bit) BIT128_GET(*a, bit)
#define BIT128_CLEAR_ALL_PTR(a) BIT128_CLEAR_ALL(*a)
#define BIT256_SET(a, bit) BIT128_SET(a, bit)
#define BIT256_CLEAR(a, bit) BIT128_CLEAR(a, bit)
#define BIT256_GET(a, bit) BIT128_GET(a, bit)
#define BIT256_CLEAR_ALL(a) BIT128_CLEAR_ALL(a)
#define BIT256_SET_PTR(a, bit) BIT256_SET(*a, bit)
#define BIT256_CLEAR_PTR(a, bit) BIT256_CLEAR(*a, bit)
#define BIT256_GET_PTR(a, bit) BIT256_GET(*a, bit)
#define BIT256_CLEAR_ALL_PTR(a) BIT256_CLEAR_ALL(*a)
#define BITS_COPY16_PTR(a,bits) \
{ \
BIT128_CLEAR_ALL_PTR(a); \
BITS_GET_ELEM_PTR(a, 0) = (bits) & 0xffff; \
}
#define BITS_COPY32_PTR(a,bits) \
{ \
BIT128_CLEAR_ALL_PTR(a); \
BITS_GET_ELEM_PTR(a, 0) = (bits); \
}
/* Helper macros and struct to keep track of many booleans. */
/* This struct has 256 bits. */
typedef struct
{
uint32_t data[8];
} retro_bits_t;
#ifdef _WIN32
# ifdef _WIN64
# define PRI_SIZET PRIu64
# else
# if _MSC_VER == 1800
# define PRI_SIZET PRIu32
# else
# define PRI_SIZET "u"
# endif
# endif
#elif PS2
# define PRI_SIZET "u"
#else
# if (SIZE_MAX == 0xFFFF)
# define PRI_SIZET "hu"
# elif (SIZE_MAX == 0xFFFFFFFF)
# define PRI_SIZET "u"
# elif (SIZE_MAX == 0xFFFFFFFFFFFFFFFF)
# define PRI_SIZET "lu"
# else
# error PRI_SIZET: unknown SIZE_MAX
# endif
#endif
#endif

View File

@@ -0,0 +1,116 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_timers.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_COMMON_TIMERS_H
#define __LIBRETRO_COMMON_TIMERS_H
#include <stdint.h>
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
#include <sys/timer.h>
#elif defined(XENON)
#include <time/time.h>
#elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__)
#include <unistd.h>
#elif defined(WIIU)
#include <wiiu/os/thread.h>
#elif defined(PSP)
#include <pspthreadman.h>
#elif defined(VITA)
#include <psp2/kernel/threadmgr.h>
#elif defined(PS2)
#include <SDL/SDL_timer.h>
#elif defined(_3DS)
#include <3ds.h>
#else
#include <time.h>
#endif
#if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(_WIN32) && defined(_XBOX)
#include <Xtl.h>
#endif
#include <limits.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
#include <retro_inline.h>
#ifdef DJGPP
#define timespec timeval
#define tv_nsec tv_usec
#include <unistd.h>
extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp)
{
usleep(1000000 * rqtp->tv_sec + rqtp->tv_nsec / 1000);
if (rmtp)
rmtp->tv_sec = rmtp->tv_nsec=0;
return 0;
}
#define nanosleep nanosleepDOS
#endif
/**
* retro_sleep:
* @msec : amount in milliseconds to sleep
*
* Sleeps for a specified amount of milliseconds (@msec).
**/
static INLINE void retro_sleep(unsigned msec)
{
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
sys_timer_usleep(1000 * msec);
#elif defined(PSP) || defined(VITA)
sceKernelDelayThread(1000 * msec);
#elif defined(PS2)
SDL_Delay(msec);
#elif defined(_3DS)
svcSleepThread(1000000 * (s64)msec);
#elif defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
SleepEx(msec, FALSE);
#elif defined(_WIN32)
Sleep(msec);
#elif defined(XENON)
udelay(1000 * msec);
#elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__)
usleep(1000 * msec);
#elif defined(WIIU)
OSSleepTicks(ms_to_ticks(msec));
#else
struct timespec tv = {0};
tv.tv_sec = msec / 1000;
tv.tv_nsec = (msec % 1000) * 1000000;
nanosleep(&tv, NULL);
#endif
}
#endif

View File

@@ -0,0 +1,111 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
#define __LIBRETRO_SDK_FILE_STREAM_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/types.h>
#include <libretro.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include <boolean.h>
#include <stdarg.h>
#define FILESTREAM_REQUIRED_VFS_VERSION 2
RETRO_BEGIN_DECLS
typedef struct RFILE RFILE;
#define FILESTREAM_REQUIRED_VFS_VERSION 2
void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info);
int64_t filestream_get_size(RFILE *stream);
int64_t filestream_truncate(RFILE *stream, int64_t length);
/**
* filestream_open:
* @path : path to file
* @mode : file mode to use when opening (read/write)
* @bufsize : optional buffer size (-1 or 0 to use default)
*
* Opens a file for reading or writing, depending on the requested mode.
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/
RFILE *filestream_open(const char *path, unsigned mode, unsigned hints);
int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position);
int64_t filestream_read(RFILE *stream, void *data, int64_t len);
int64_t filestream_write(RFILE *stream, const void *data, int64_t len);
int64_t filestream_tell(RFILE *stream);
void filestream_rewind(RFILE *stream);
int filestream_close(RFILE *stream);
int64_t filestream_read_file(const char *path, void **buf, int64_t *len);
char *filestream_gets(RFILE *stream, char *s, size_t len);
int filestream_getc(RFILE *stream);
int filestream_scanf(RFILE *stream, const char* format, ...);
int filestream_eof(RFILE *stream);
bool filestream_write_file(const char *path, const void *data, int64_t size);
int filestream_putc(RFILE *stream, int c);
int filestream_vprintf(RFILE *stream, const char* format, va_list args);
int filestream_printf(RFILE *stream, const char* format, ...);
int filestream_error(RFILE *stream);
int filestream_flush(RFILE *stream);
int filestream_delete(const char *path);
int filestream_rename(const char *old_path, const char *new_path);
const char *filestream_get_path(RFILE *stream);
bool filestream_exists(const char *path);
char *filestream_getline(RFILE *stream);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,134 @@
/* Copyright (C) 2010-2019 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (stdstring.h).
* ---------------------------------------------------------------------------------------
*
* 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.
*/
#ifndef __LIBRETRO_SDK_STDSTRING_H
#define __LIBRETRO_SDK_STDSTRING_H
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <string.h>
#include <boolean.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include <compat/strl.h>
RETRO_BEGIN_DECLS
static INLINE bool string_is_empty(const char *data)
{
return !data || (*data == '\0');
}
static INLINE bool string_is_equal(const char *a, const char *b)
{
return (a && b) ? !strcmp(a, b) : false;
}
#define STRLEN_CONST(x) ((sizeof((x))-1))
#define string_is_not_equal(a, b) !string_is_equal((a), (b))
#define string_add_pair_open(s, size) strlcat((s), " (", (size))
#define string_add_pair_close(s, size) strlcat((s), ")", (size))
#define string_add_bracket_open(s, size) strlcat((s), "{", (size))
#define string_add_bracket_close(s, size) strlcat((s), "}", (size))
#define string_add_single_quote(s, size) strlcat((s), "'", (size))
#define string_add_quote(s, size) strlcat((s), "\"", (size))
#define string_add_colon(s, size) strlcat((s), ":", (size))
#define string_add_glob_open(s, size) strlcat((s), "glob('*", (size))
#define string_add_glob_close(s, size) strlcat((s), "*')", (size))
#define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0)
#define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0)
static INLINE void string_add_between_pairs(char *s, const char *str,
size_t size)
{
string_add_pair_open(s, size);
strlcat(s, str, size);
string_add_pair_close(s, size);
}
static INLINE bool string_is_equal_case_insensitive(const char *a,
const char *b)
{
int result = 0;
const unsigned char *p1 = (const unsigned char*)a;
const unsigned char *p2 = (const unsigned char*)b;
if (!a || !b)
return false;
if (p1 == p2)
return true;
while ((result = tolower (*p1) - tolower (*p2++)) == 0)
if (*p1++ == '\0')
break;
return (result == 0);
}
static INLINE bool string_is_equal_noncase(const char *a, const char *b)
{
int result = 0;
const unsigned char *p1 = (const unsigned char*)a;
const unsigned char *p2 = (const unsigned char*)b;
if (!a || !b)
return false;
if (p1 == p2)
return false;
while ((result = tolower (*p1) - tolower (*p2++)) == 0)
if (*p1++ == '\0')
break;
return (result == 0);
}
char *string_to_upper(char *s);
char *string_to_lower(char *s);
char *string_ucwords(char *s);
char *string_replace_substring(const char *in, const char *pattern,
const char *by);
/* Remove leading whitespaces */
char *string_trim_whitespace_left(char *const s);
/* Remove trailing whitespaces */
char *string_trim_whitespace_right(char *const s);
/* Remove leading and trailing whitespaces */
char *string_trim_whitespace(char *const s);
/* max_lines == 0 means no limit */
char *word_wrap(char *buffer, const char *string,
int line_width, bool unicode, unsigned max_lines);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,18 @@
Copyright (c) 2013 Mikko Mononen memon@inside.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,685 @@
//
// Copyright (c) 2013 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef NANOVG_H
#define NANOVG_H
#ifdef __cplusplus
extern "C" {
#endif
#define NVG_PI 3.14159265358979323846264338327f
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
#endif
typedef struct NVGcontext NVGcontext;
struct NVGcolor {
union {
float rgba[4];
struct {
float r,g,b,a;
};
};
};
typedef struct NVGcolor NVGcolor;
struct NVGpaint {
float xform[6];
float extent[2];
float radius;
float feather;
NVGcolor innerColor;
NVGcolor outerColor;
int image;
};
typedef struct NVGpaint NVGpaint;
enum NVGwinding {
NVG_CCW = 1, // Winding for solid shapes
NVG_CW = 2, // Winding for holes
};
enum NVGsolidity {
NVG_SOLID = 1, // CCW
NVG_HOLE = 2, // CW
};
enum NVGlineCap {
NVG_BUTT,
NVG_ROUND,
NVG_SQUARE,
NVG_BEVEL,
NVG_MITER,
};
enum NVGalign {
// Horizontal align
NVG_ALIGN_LEFT = 1<<0, // Default, align text horizontally to left.
NVG_ALIGN_CENTER = 1<<1, // Align text horizontally to center.
NVG_ALIGN_RIGHT = 1<<2, // Align text horizontally to right.
// Vertical align
NVG_ALIGN_TOP = 1<<3, // Align text vertically to top.
NVG_ALIGN_MIDDLE = 1<<4, // Align text vertically to middle.
NVG_ALIGN_BOTTOM = 1<<5, // Align text vertically to bottom.
NVG_ALIGN_BASELINE = 1<<6, // Default, align text vertically to baseline.
};
enum NVGblendFactor {
NVG_ZERO = 1<<0,
NVG_ONE = 1<<1,
NVG_SRC_COLOR = 1<<2,
NVG_ONE_MINUS_SRC_COLOR = 1<<3,
NVG_DST_COLOR = 1<<4,
NVG_ONE_MINUS_DST_COLOR = 1<<5,
NVG_SRC_ALPHA = 1<<6,
NVG_ONE_MINUS_SRC_ALPHA = 1<<7,
NVG_DST_ALPHA = 1<<8,
NVG_ONE_MINUS_DST_ALPHA = 1<<9,
NVG_SRC_ALPHA_SATURATE = 1<<10,
};
enum NVGcompositeOperation {
NVG_SOURCE_OVER,
NVG_SOURCE_IN,
NVG_SOURCE_OUT,
NVG_ATOP,
NVG_DESTINATION_OVER,
NVG_DESTINATION_IN,
NVG_DESTINATION_OUT,
NVG_DESTINATION_ATOP,
NVG_LIGHTER,
NVG_COPY,
NVG_XOR,
};
struct NVGcompositeOperationState {
int srcRGB;
int dstRGB;
int srcAlpha;
int dstAlpha;
};
typedef struct NVGcompositeOperationState NVGcompositeOperationState;
struct NVGglyphPosition {
const char* str; // Position of the glyph in the input string.
float x; // The x-coordinate of the logical glyph position.
float minx, maxx; // The bounds of the glyph shape.
};
typedef struct NVGglyphPosition NVGglyphPosition;
struct NVGtextRow {
const char* start; // Pointer to the input text where the row starts.
const char* end; // Pointer to the input text where the row ends (one past the last character).
const char* next; // Pointer to the beginning of the next row.
float width; // Logical width of the row.
float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
};
typedef struct NVGtextRow NVGtextRow;
enum NVGimageFlags {
NVG_IMAGE_GENERATE_MIPMAPS = 1<<0, // Generate mipmaps during creation of the image.
NVG_IMAGE_REPEATX = 1<<1, // Repeat image in X direction.
NVG_IMAGE_REPEATY = 1<<2, // Repeat image in Y direction.
NVG_IMAGE_FLIPY = 1<<3, // Flips (inverses) image in Y direction when rendered.
NVG_IMAGE_PREMULTIPLIED = 1<<4, // Image data has premultiplied alpha.
NVG_IMAGE_NEAREST = 1<<5, // Image interpolation is Nearest instead Linear
};
// Begin drawing a new frame
// Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
// nvgBeginFrame() defines the size of the window to render to in relation currently
// set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
// control the rendering on Hi-DPI devices.
// For example, GLFW returns two dimension for an opened window: window size and
// frame buffer size. In that case you would set windowWidth/Height to the window size
// devicePixelRatio to: frameBufferWidth / windowWidth.
void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);
// Cancels drawing the current frame.
void nvgCancelFrame(NVGcontext* ctx);
// Ends drawing flushing remaining render state.
void nvgEndFrame(NVGcontext* ctx);
//
// Composite operation
//
// The composite operations in NanoVG are modeled after HTML Canvas API, and
// the blend func is based on OpenGL (see corresponding manuals for more info).
// The colors in the blending state have premultiplied alpha.
// Sets the composite operation. The op parameter should be one of NVGcompositeOperation.
void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);
// Sets the composite operation with custom pixel arithmetic. The parameters should be one of NVGblendFactor.
void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);
// Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of NVGblendFactor.
void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
//
// Color utils
//
// Colors in NanoVG are stored as unsigned ints in ABGR format.
// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
NVGcolor nvgRGBf(float r, float g, float b);
// Returns a color value from red, green, blue and alpha values.
NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
// Returns a color value from red, green, blue and alpha values.
NVGcolor nvgRGBAf(float r, float g, float b, float a);
// Linearly interpolates from color c0 to c1, and returns resulting color value.
NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
// Sets transparency of a color value.
NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
// Sets transparency of a color value.
NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
// Returns color value specified by hue, saturation and lightness.
// HSL values are all in range [0..1], alpha will be set to 255.
NVGcolor nvgHSL(float h, float s, float l);
// Returns color value specified by hue, saturation and lightness and alpha.
// HSL values are all in range [0..1], alpha in range [0..255]
NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
//
// State Handling
//
// NanoVG contains state which represents how paths will be rendered.
// The state contains transform, fill and stroke styles, text and font styles,
// and scissor clipping.
// Pushes and saves the current render state into a state stack.
// A matching nvgRestore() must be used to restore the state.
void nvgSave(NVGcontext* ctx);
// Pops and restores current render state.
void nvgRestore(NVGcontext* ctx);
// Resets current render state to default values. Does not affect the render state stack.
void nvgReset(NVGcontext* ctx);
//
// Render styles
//
// Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
// Solid color is simply defined as a color value, different kinds of paints can be created
// using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
//
// Current render style can be saved and restored using nvgSave() and nvgRestore().
// Sets whether to draw antialias for nvgStroke() and nvgFill(). It's enabled by default.
void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
// Sets current stroke style to a solid color.
void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
// Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
// Sets current fill style to a solid color.
void nvgFillColor(NVGcontext* ctx, NVGcolor color);
// Sets current fill style to a paint, which can be a one of the gradients or a pattern.
void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
// Sets the miter limit of the stroke style.
// Miter limit controls when a sharp corner is beveled.
void nvgMiterLimit(NVGcontext* ctx, float limit);
// Sets the stroke width of the stroke style.
void nvgStrokeWidth(NVGcontext* ctx, float size);
// Sets how the end of the line (cap) is drawn,
// Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
void nvgLineCap(NVGcontext* ctx, int cap);
// Sets how sharp path corners are drawn.
// Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
void nvgLineJoin(NVGcontext* ctx, int join);
// Sets the transparency applied to all rendered shapes.
// Already transparent paths will get proportionally more transparent as well.
void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
//
// Transforms
//
// The paths, gradients, patterns and scissor region are transformed by an transformation
// matrix at the time when they are passed to the API.
// The current transformation matrix is a affine matrix:
// [sx kx tx]
// [ky sy ty]
// [ 0 0 1]
// Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
// The last row is assumed to be 0,0,1 and is not stored.
//
// Apart from nvgResetTransform(), each transformation function first creates
// specific transformation matrix and pre-multiplies the current transformation by it.
//
// Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
// Resets current transform to a identity matrix.
void nvgResetTransform(NVGcontext* ctx);
// Premultiplies current coordinate system by specified matrix.
// The parameters are interpreted as matrix as follows:
// [a c e]
// [b d f]
// [0 0 1]
void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
// Translates current coordinate system.
void nvgTranslate(NVGcontext* ctx, float x, float y);
// Rotates current coordinate system. Angle is specified in radians.
void nvgRotate(NVGcontext* ctx, float angle);
// Skews the current coordinate system along X axis. Angle is specified in radians.
void nvgSkewX(NVGcontext* ctx, float angle);
// Skews the current coordinate system along Y axis. Angle is specified in radians.
void nvgSkewY(NVGcontext* ctx, float angle);
// Scales the current coordinate system.
void nvgScale(NVGcontext* ctx, float x, float y);
// Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
// [a c e]
// [b d f]
// [0 0 1]
// There should be space for 6 floats in the return buffer for the values a-f.
void nvgCurrentTransform(NVGcontext* ctx, float* xform);
// The following functions can be used to make calculations on 2x3 transformation matrices.
// A 2x3 matrix is represented as float[6].
// Sets the transform to identity matrix.
void nvgTransformIdentity(float* dst);
// Sets the transform to translation matrix matrix.
void nvgTransformTranslate(float* dst, float tx, float ty);
// Sets the transform to scale matrix.
void nvgTransformScale(float* dst, float sx, float sy);
// Sets the transform to rotate matrix. Angle is specified in radians.
void nvgTransformRotate(float* dst, float a);
// Sets the transform to skew-x matrix. Angle is specified in radians.
void nvgTransformSkewX(float* dst, float a);
// Sets the transform to skew-y matrix. Angle is specified in radians.
void nvgTransformSkewY(float* dst, float a);
// Sets the transform to the result of multiplication of two transforms, of A = A*B.
void nvgTransformMultiply(float* dst, const float* src);
// Sets the transform to the result of multiplication of two transforms, of A = B*A.
void nvgTransformPremultiply(float* dst, const float* src);
// Sets the destination to inverse of specified transform.
// Returns 1 if the inverse could be calculated, else 0.
int nvgTransformInverse(float* dst, const float* src);
// Transform a point by given transform.
void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
// Converts degrees to radians and vice versa.
float nvgDegToRad(float deg);
float nvgRadToDeg(float rad);
//
// Images
//
// NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
// In addition you can upload your own image. The image loading is provided by stb_image.
// The parameter imageFlags is combination of flags defined in NVGimageFlags.
// Creates image by loading it from the disk from specified file name.
// Returns handle to the image.
int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);
// Creates image by loading it from the specified chunk of memory.
// Returns handle to the image.
int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);
// Creates image from specified image data.
// Returns handle to the image.
int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);
// Updates image data specified by image handle.
void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
// Returns the dimensions of a created image.
void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
// Deletes created image.
void nvgDeleteImage(NVGcontext* ctx, int image);
//
// Paints
//
// NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
// These can be used as paints for strokes and fills.
// Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
// of the linear gradient, icol specifies the start color and ocol the end color.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey,
NVGcolor icol, NVGcolor ocol);
// Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
// drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
// (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
// the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h,
float r, float f, NVGcolor icol, NVGcolor ocol);
// Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
// the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr,
NVGcolor icol, NVGcolor ocol);
// Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern,
// (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey,
float angle, int image, float alpha);
//
// Scissoring
//
// Scissoring allows you to clip the rendering into a rectangle. This is useful for various
// user interface cases like rendering a text edit or a timeline.
// Sets the current scissor rectangle.
// The scissor rectangle is transformed by the current transform.
void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
// Intersects current scissor rectangle with the specified rectangle.
// The scissor rectangle is transformed by the current transform.
// Note: in case the rotation of previous scissor rect differs from
// the current one, the intersection will be done between the specified
// rectangle and the previous scissor rectangle transformed in the current
// transform space. The resulting shape is always rectangle.
void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
// Reset and disables scissoring.
void nvgResetScissor(NVGcontext* ctx);
//
// Paths
//
// Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
// Then you define one or more paths and sub-paths which describe the shape. The are functions
// to draw common shapes like rectangles and circles, and lower level step-by-step functions,
// which allow to define a path curve by curve.
//
// NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
// winding and holes should have counter clockwise order. To specify winding of a path you can
// call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
//
// Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
// with current stroke style by calling nvgStroke().
//
// The curve segments and sub-paths are transformed by the current transform.
// Clears the current path and sub-paths.
void nvgBeginPath(NVGcontext* ctx);
// Starts new sub-path with specified point as first point.
void nvgMoveTo(NVGcontext* ctx, float x, float y);
// Adds line segment from the last point in the path to the specified point.
void nvgLineTo(NVGcontext* ctx, float x, float y);
// Adds cubic bezier segment from last point in the path via two control points to the specified point.
void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
// Adds quadratic bezier segment from last point in the path via a control point to the specified point.
void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
// Adds an arc segment at the corner defined by the last path point, and two specified points.
void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
// Closes current sub-path with a line segment.
void nvgClosePath(NVGcontext* ctx);
// Sets the current sub-path winding, see NVGwinding and NVGsolidity.
void nvgPathWinding(NVGcontext* ctx, int dir);
// Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r,
// and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
// Angles are specified in radians.
void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
// Creates new rectangle shaped sub-path.
void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
// Creates new rounded rectangle shaped sub-path.
void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
// Creates new rounded rectangle shaped sub-path with varying radii for each corner.
void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft);
// Creates new ellipse shaped sub-path.
void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
// Creates new circle shaped sub-path.
void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
// Fills the current path with current fill style.
void nvgFill(NVGcontext* ctx);
// Fills the current path with current stroke style.
void nvgStroke(NVGcontext* ctx);
//
// Text
//
// NanoVG allows you to load .ttf files and use the font to render text.
//
// The appearance of the text can be defined by setting the current text style
// and by specifying the fill color. Common text and font settings such as
// font size, letter spacing and text align are supported. Font blur allows you
// to create simple text effects such as drop shadows.
//
// At render time the font face can be set based on the font handles or name.
//
// Font measure functions return values in local space, the calculations are
// carried in the same resolution as the final rendering. This is done because
// the text glyph positions are snapped to the nearest pixels sharp rendering.
//
// The local space means that values are not rotated or scale as per the current
// transformation. For example if you set font size to 12, which would mean that
// line height is 16, then regardless of the current scaling and rotation, the
// returned line height is always 16. Some measures may vary because of the scaling
// since aforementioned pixel snapping.
//
// While this may sound a little odd, the setup allows you to always render the
// same way regardless of scaling. I.e. following works regardless of scaling:
//
// const char* txt = "Text me up.";
// nvgTextBounds(vg, x,y, txt, NULL, bounds);
// nvgBeginPath(vg);
// nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
// nvgFill(vg);
//
// Note: currently only solid color fill is supported for text.
// Creates font by loading it from the disk from specified file name.
// Returns handle to the font.
int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);
// Creates font by loading it from the specified memory chunk.
// Returns handle to the font.
int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
// Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
int nvgFindFont(NVGcontext* ctx, const char* name);
// Adds a fallback font by handle.
int nvgAddFallbackFontId(NVGcontext* ctx, int baseFont, int fallbackFont);
// Adds a fallback font by name.
int nvgAddFallbackFont(NVGcontext* ctx, const char* baseFont, const char* fallbackFont);
// Sets the font size of current text style.
void nvgFontSize(NVGcontext* ctx, float size);
// Sets the blur of current text style.
void nvgFontBlur(NVGcontext* ctx, float blur);
// Sets the letter spacing of current text style.
void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
// Sets the proportional line height of current text style. The line height is specified as multiple of font size.
void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
// Sets the text align of current text style, see NVGalign for options.
void nvgTextAlign(NVGcontext* ctx, int align);
// Sets the font face based on specified id of current text style.
void nvgFontFaceId(NVGcontext* ctx, int font);
// Sets the font face based on specified name of current text style.
void nvgFontFace(NVGcontext* ctx, const char* font);
// Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end);
// Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn.
// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
// Measures the specified text string. Parameter bounds should be a pointer to float[4],
// if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
// Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
// Measured values are returned in local coordinate space.
float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
// Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
// if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
// Measured values are returned in local coordinate space.
void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
// Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
// Measured values are returned in local coordinate space.
int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions);
// Returns the vertical metrics based on the current text style.
// Measured values are returned in local coordinate space.
void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh);
// Breaks the specified text into lines. If end is specified only the sub-string will be used.
// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
//
// Internal Render API
//
enum NVGtexture {
NVG_TEXTURE_ALPHA = 0x01,
NVG_TEXTURE_RGBA = 0x02,
};
struct NVGscissor {
float xform[6];
float extent[2];
};
typedef struct NVGscissor NVGscissor;
struct NVGvertex {
float x,y,u,v;
};
typedef struct NVGvertex NVGvertex;
struct NVGpath {
int first;
int count;
unsigned char closed;
int nbevel;
NVGvertex* fill;
int nfill;
NVGvertex* stroke;
int nstroke;
int winding;
int convex;
};
typedef struct NVGpath NVGpath;
struct NVGparams {
void* userPtr;
int edgeAntiAlias;
int (*renderCreate)(void* uptr);
int (*renderCreateTexture)(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data);
int (*renderDeleteTexture)(void* uptr, int image);
int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
void (*renderViewport)(void* uptr, float width, float height, float devicePixelRatio);
void (*renderCancel)(void* uptr);
void (*renderFlush)(void* uptr);
void (*renderFill)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
void (*renderStroke)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths);
void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, const NVGvertex* verts, int nverts);
void (*renderDelete)(void* uptr);
};
typedef struct NVGparams NVGparams;
// Constructor and destructor, called by the render back-end.
NVGcontext* nvgCreateInternal(NVGparams* params);
void nvgDeleteInternal(NVGcontext* ctx);
NVGparams* nvgInternalParams(NVGcontext* ctx);
// Debug function to dump cached path data.
void nvgDebugDumpPathCache(NVGcontext* ctx);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#define NVG_NOTUSED(v) for (;;) { (void)(1 ? (void)0 : ( (void)(v) ) ); break; }
#ifdef __cplusplus
}
#endif
#endif // NANOVG_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,154 @@
//
// Copyright (c) 2009-2013 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef NANOVG_GL_UTILS_H
#define NANOVG_GL_UTILS_H
struct NVGLUframebuffer {
NVGcontext* ctx;
GLuint fbo;
GLuint rbo;
GLuint texture;
int image;
};
typedef struct NVGLUframebuffer NVGLUframebuffer;
// Helper function to create GL frame buffer to render to.
void nvgluBindFramebuffer(NVGLUframebuffer* fb);
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags);
void nvgluDeleteFramebuffer(NVGLUframebuffer* fb);
#endif // NANOVG_GL_UTILS_H
#ifdef NANOVG_GL_IMPLEMENTATION
#if defined(NANOVG_GL3) || defined(NANOVG_GLES2) || defined(NANOVG_GLES3)
// FBO is core in OpenGL 3>.
# define NANOVG_FBO_VALID 1
#elif defined(NANOVG_GL2)
// On OS X including glext defines FBO on GL2 too.
# ifdef __APPLE__
# include <OpenGL/glext.h>
# define NANOVG_FBO_VALID 1
# endif
#endif
static GLint defaultFBO = -1;
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags)
{
#ifdef NANOVG_FBO_VALID
GLint defaultFBO;
GLint defaultRBO;
NVGLUframebuffer* fb = NULL;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
glGetIntegerv(GL_RENDERBUFFER_BINDING, &defaultRBO);
fb = (NVGLUframebuffer*)malloc(sizeof(NVGLUframebuffer));
if (fb == NULL) goto error;
memset(fb, 0, sizeof(NVGLUframebuffer));
fb->image = nvgCreateImageRGBA(ctx, w, h, imageFlags | NVG_IMAGE_FLIPY | NVG_IMAGE_PREMULTIPLIED, NULL);
#if defined NANOVG_GL2
fb->texture = nvglImageHandleGL2(ctx, fb->image);
#elif defined NANOVG_GL3
fb->texture = nvglImageHandleGL3(ctx, fb->image);
#elif defined NANOVG_GLES2
fb->texture = nvglImageHandleGLES2(ctx, fb->image);
#elif defined NANOVG_GLES3
fb->texture = nvglImageHandleGLES3(ctx, fb->image);
#endif
fb->ctx = ctx;
// frame buffer object
glGenFramebuffers(1, &fb->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fb->fbo);
// render buffer object
glGenRenderbuffers(1, &fb->rbo);
glBindRenderbuffer(GL_RENDERBUFFER, fb->rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, w, h);
// combine all
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb->texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->rbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
#ifdef GL_DEPTH24_STENCIL8
// If GL_STENCIL_INDEX8 is not supported, try GL_DEPTH24_STENCIL8 as a fallback.
// Some graphics cards require a depth buffer along with a stencil.
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb->texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb->rbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
#endif // GL_DEPTH24_STENCIL8
goto error;
}
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glBindRenderbuffer(GL_RENDERBUFFER, defaultRBO);
return fb;
error:
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glBindRenderbuffer(GL_RENDERBUFFER, defaultRBO);
nvgluDeleteFramebuffer(fb);
return NULL;
#else
NVG_NOTUSED(ctx);
NVG_NOTUSED(w);
NVG_NOTUSED(h);
NVG_NOTUSED(imageFlags);
return NULL;
#endif
}
void nvgluBindFramebuffer(NVGLUframebuffer* fb)
{
#ifdef NANOVG_FBO_VALID
if (defaultFBO == -1) glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
glBindFramebuffer(GL_FRAMEBUFFER, fb != NULL ? fb->fbo : defaultFBO);
#else
NVG_NOTUSED(fb);
#endif
}
void nvgluDeleteFramebuffer(NVGLUframebuffer* fb)
{
#ifdef NANOVG_FBO_VALID
if (fb == NULL) return;
if (fb->fbo != 0)
glDeleteFramebuffers(1, &fb->fbo);
if (fb->rbo != 0)
glDeleteRenderbuffers(1, &fb->rbo);
if (fb->image >= 0)
nvgDeleteImage(fb->ctx, fb->image);
fb->ctx = NULL;
fb->fbo = 0;
fb->rbo = 0;
fb->texture = 0;
fb->image = -1;
free(fb);
#else
NVG_NOTUSED(fb);
#endif
}
#endif // NANOVG_GL_IMPLEMENTATION

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <nanovg.h>
#include <borealis/style.hpp>
#include <borealis/theme.hpp>
namespace brls
{
class FontStash
{
public:
int regular = 0;
int korean = 0;
int material = 0;
int sharedSymbols = 0;
};
class FrameContext
{
public:
NVGcontext* vg = nullptr;
float pixelRatio = 0.0;
FontStash* fontStash = nullptr;
ThemeValues* theme = nullptr;
};
} // namespace brls

View File

@@ -0,0 +1,42 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
namespace brls
{
// A simple header with text, a rectangle on the left
// and a separator
class Header : public View
{
private:
std::string label;
std::string sublabel;
bool separator;
public:
Header(std::string label, bool separator = true, std::string sublabel = "");
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
};
} // namespace brls

View File

@@ -0,0 +1,63 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2020 WerWolv
Copyright (C) 2020 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/box_layout.hpp>
#include <borealis/label.hpp>
#include <borealis/view.hpp>
namespace brls
{
// Displays button hints for the currently focused view
// Depending on the view's available actions
// there can only be one Hint visible at any time
class Hint : public BoxLayout
{
private:
bool animate;
GenericEvent::Subscription globalFocusEventSubscriptor;
VoidEvent::Subscription globalHintsUpdateEventSubscriptor;
static inline std::vector<Hint*> globalHintStack;
static void pushHint(Hint* hint);
static void popHint(Hint* hint);
static void animateHints();
static std::string getKeyIcon(Key key);
void rebuildHints();
public:
Hint(bool animate = true);
~Hint();
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
void setAnimate(bool animate)
{
this->animate = animate;
}
};
} // namespace brls

View File

@@ -0,0 +1,78 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 WerWolv
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/frame_context.hpp>
#include <borealis/view.hpp>
namespace brls
{
enum class ImageScaleType
{
NO_RESIZE = 0, // Nothing is resized
FIT, // The image is shrinked to fit the view boundaries
CROP, // The image is not resized but is cropped if bigger than the view
SCALE, // The image is stretched to match the view boundaries
VIEW_RESIZE // The view is resized to match the image
};
// An image
class Image : public View
{
public:
Image(std::string imagePath);
Image(unsigned char* buffer, size_t bufferSize);
~Image();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void setImage(unsigned char* buffer, size_t bufferSize);
void setImage(std::string imagePath);
void setScaleType(ImageScaleType imageScaleType);
void setOpacity(float opacity);
void setCornerRadius(float radius)
{
this->cornerRadius = radius;
}
private:
std::string imagePath;
unsigned char* imageBuffer = nullptr;
size_t imageBufferSize = 0;
int texture = -1;
NVGpaint imgPaint;
ImageScaleType imageScaleType = ImageScaleType::FIT;
float cornerRadius = 0;
int imageX = 0, imageY = 0;
int imageWidth = 0, imageHeight = 0;
int origViewWidth = 0, origViewHeight = 0;
void reloadTexture();
};
} // namespace brls

View File

@@ -0,0 +1,112 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
namespace brls
{
enum class LabelStyle
{
REGULAR = 0,
MEDIUM,
SMALL,
DESCRIPTION,
CRASH,
BUTTON_PLAIN,
BUTTON_PLAIN_DISABLED,
BUTTON_BORDERLESS,
LIST_ITEM,
NOTIFICATION,
DIALOG,
BUTTON_DIALOG,
HINT
};
// A Label, multiline or with a ticker
class Label : public View
{
private:
std::string text;
bool multiline;
unsigned fontSize;
float lineHeight;
LabelStyle labelStyle;
NVGalign horizontalAlign = NVG_ALIGN_LEFT;
NVGalign verticalAlign = NVG_ALIGN_MIDDLE;
NVGcolor customColor;
bool useCustomColor = false;
int customFont;
bool useCustomFont = false;
public:
Label(LabelStyle labelStyle, std::string text, bool multiline = false);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void setVerticalAlign(NVGalign align);
void setHorizontalAlign(NVGalign align);
void setText(std::string text);
void setStyle(LabelStyle style);
void setFontSize(unsigned size);
/**
* Sets the label color
*/
void setColor(NVGcolor color);
/**
* Unsets the label color - it
* will now use the default one
* for the label style
*/
void unsetColor();
/**
* Returns the effective label color
* = custom or the style default
*/
NVGcolor getColor(ThemeValues* theme);
/**
* Sets the font id
*/
void setFont(int fontId);
/**
* Unsets the font id - it
* will now use the regular one
*/
void unsetFont();
/**
* Returns the font used
* = custom or the regular font
*/
int getFont(FontStash* stash);
};
} // namespace brls

View File

@@ -0,0 +1,51 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 WerWolv
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
#include <vector>
namespace brls
{
// A view containing multiple children views with the ability to freely switch between these layers
class LayerView : public View
{
public:
LayerView();
~LayerView();
void addLayer(View* view);
void changeLayer(int index, bool focus = false);
int getLayerIndex();
View* getDefaultFocus() override;
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
private:
std::vector<View*> layers;
int selectedIndex = 0;
};
}

View File

@@ -0,0 +1,218 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/box_layout.hpp>
#include <borealis/image.hpp>
#include <borealis/label.hpp>
#include <borealis/rectangle.hpp>
#include <borealis/scroll_view.hpp>
#include <string>
namespace brls
{
// A list item
// TODO: Use a Label with integrated ticker
class ListItem : public View
{
private:
std::string label;
std::string subLabel;
std::string value;
bool valueFaint;
std::string oldValue;
bool oldValueFaint;
float valueAnimation = 0.0f;
bool checked = false; // check mark on the right
unsigned textSize;
bool drawTopSeparator = true;
Label* descriptionView = nullptr;
Image* thumbnailView = nullptr;
bool reduceDescriptionSpacing = false;
GenericEvent clickEvent;
bool indented = false;
void resetValueAnimation();
public:
ListItem(std::string label, std::string description = "", std::string subLabel = "");
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void getHighlightInsets(unsigned* top, unsigned* right, unsigned* bottom, unsigned* left) override;
virtual bool onClick();
View* getDefaultFocus() override;
void setThumbnail(Image* image);
void setThumbnail(std::string imagePath);
void setThumbnail(unsigned char* buffer, size_t bufferSize);
bool hasDescription();
void setDrawTopSeparator(bool draw);
bool getReduceDescriptionSpacing();
void setReduceDescriptionSpacing(bool value);
void setIndented(bool indented);
void setTextSize(unsigned textSize);
void setChecked(bool checked);
std::string getLabel();
/**
* Sets the value of this list item
* (the text on the right)
* Set faint to true to have the new value
* use a darker color (typically "OFF" labels)
*/
void setValue(std::string value, bool faint = false, bool animate = true);
std::string getValue();
GenericEvent* getClickEvent();
~ListItem();
};
// Some spacing (to make groups of ListItems)
class ListItemGroupSpacing : public Rectangle
{
public:
ListItemGroupSpacing(bool separator = false);
};
// A list item with mutliple choices for its value
// (will open a Dropdown)
// Fired when the user has selected a value
//
// Parameter is either the selected value index
// or -1 if the user cancelled
typedef Event<int> ValueSelectedEvent;
class SelectListItem : public ListItem
{
public:
SelectListItem(std::string label, std::vector<std::string> values, unsigned selectedValue = 0);
void setSelectedValue(unsigned value);
ValueSelectedEvent* getValueSelectedEvent();
private:
std::vector<std::string> values;
unsigned selectedValue;
ValueSelectedEvent valueEvent;
};
// A list item with a ON/OFF value
// that can be toggled
// Use the click event to detect when the value
// changes
class ToggleListItem : public ListItem
{
private:
bool toggleState;
std::string onValue, offValue;
void updateValue();
public:
ToggleListItem(std::string label, bool initialValue, std::string description = "", std::string onValue = "On", std::string offValue = "Off");
virtual bool onClick() override;
bool getToggleState();
};
// A list item which spawns the swkbd
// to input its value (string)
class InputListItem : public ListItem
{
protected:
std::string helpText;
int maxInputLength;
public:
InputListItem(std::string label, std::string initialValue, std::string helpText, std::string description = "", int maxInputLength = 32);
virtual bool onClick() override;
};
// A list item which spawns the swkbd
// to input its value (integer)
class IntegerInputListItem : public InputListItem
{
public:
IntegerInputListItem(std::string label, int initialValue, std::string helpText, std::string description = "", int maxInputLength = 32);
virtual bool onClick() override;
};
class List; // forward declaration for ListContentView::list
// The content view of lists (used internally)
class ListContentView : public BoxLayout
{
public:
ListContentView(List* list, size_t defaultFocus = 0);
protected:
void customSpacing(View* current, View* next, int* spacing) override;
private:
List* list;
};
// A vertical list of various widgets, with proper margins and spacing
// and a scroll bar
// In practice it's a ScrollView which content view is
// a ListContentView (BoxLayout)
class List : public ScrollView
{
private:
ListContentView* layout;
public:
List(size_t defaultFocus = 0);
~List();
// Wrapped BoxLayout methods
void addView(View* view, bool fill = false);
void clear(bool free = true);
void setMargins(unsigned top, unsigned right, unsigned bottom, unsigned left);
void setMarginBottom(unsigned bottom);
void setSpacing(unsigned spacing);
unsigned getSpacing();
virtual void customSpacing(View* current, View* next, int* spacing);
};
} // namespace brls

View File

@@ -0,0 +1,49 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdarg.h>
#include <string>
namespace brls
{
enum class LogLevel
{
ERROR = 0,
INFO,
DEBUG
};
class Logger
{
public:
static void setLogLevel(LogLevel logLevel);
static void error(const char* format, ...);
static void info(const char* format, ...);
static void debug(const char* format, ...);
protected:
static void log(LogLevel logLevel, const char* prefix, const char* color, const char* format, va_list ap);
};
} // namespace brls

View File

@@ -0,0 +1,40 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
namespace brls
{
// A Material icon (from the Material font)
class MaterialIcon : public View
{
private:
std::string icon;
unsigned middleX, middleY;
public:
MaterialIcon(std::string icon);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
};
} // namespace brls

View File

@@ -0,0 +1,64 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/animations.hpp>
#include <borealis/label.hpp>
#include <borealis/view.hpp>
#define BRLS_NOTIFICATIONS_MAX 8
// TODO: check in HOS that the animation duration + notification timeout are correct
namespace brls
{
class Notification : public View
{
public:
Notification(std::string text);
~Notification();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
menu_timer_t timeoutTimer;
private:
Label* label;
};
class NotificationManager : public View
{
private:
Notification* notifications[BRLS_NOTIFICATIONS_MAX];
void layoutNotification(size_t i);
public:
NotificationManager();
~NotificationManager();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void notify(std::string text);
};
}; // namespace brls

View File

@@ -0,0 +1,63 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 WerWolv
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/applet_frame.hpp>
#include <borealis/list.hpp>
#include <borealis/view.hpp>
#include <string>
namespace brls
{
class PopupFrame : public View
{
private:
PopupFrame(std::string title, unsigned char* imageBuffer, size_t imageBufferSize, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
PopupFrame(std::string title, std::string imagePath, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
PopupFrame(std::string title, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
AppletFrame* contentView = nullptr;
protected:
unsigned getShowAnimationDuration(ViewAnimation animation) override;
public:
~PopupFrame();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
View* getDefaultFocus() override;
virtual bool onCancel();
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
static void open(std::string title, unsigned char* imageBuffer, size_t imageBufferSize, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
static void open(std::string title, std::string imagePath, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
static void open(std::string title, AppletFrame* contentView, std::string subTitleLeft = "", std::string subTitleRight = "");
bool isTranslucent() override
{
return true;
}
};
} // namespace brls

View File

@@ -0,0 +1,58 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 Billy Laws
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/label.hpp>
#include <borealis/progress_spinner.hpp>
#include <borealis/view.hpp>
namespace brls
{
// TODO: Add the "ProgressDisplayFlags_" prefix to the members
enum ProgressDisplayFlags
{
SPINNER = 1u << 0,
PERCENTAGE = 1u << 1
};
inline constexpr ProgressDisplayFlags DEFAULT_PROGRESS_DISPLAY_FLAGS = (ProgressDisplayFlags)(ProgressDisplayFlags::SPINNER | ProgressDisplayFlags::PERCENTAGE);
// A progress bar with an optional spinner and percentage text.
class ProgressDisplay : public View
{
public:
ProgressDisplay(ProgressDisplayFlags progressFlags = DEFAULT_PROGRESS_DISPLAY_FLAGS);
~ProgressDisplay();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
void setProgress(int current, int max);
private:
float progressPercentage = 0.0f;
Label* label;
ProgressSpinner* spinner;
};
} // namespace brls

View File

@@ -0,0 +1,44 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 Billy Laws
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
namespace brls
{
// A progress spinner
class ProgressSpinner : public View
{
public:
ProgressSpinner();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
private:
float animationValue = 0.0f;
void restartAnimation();
};
} // namespace brls

View File

@@ -0,0 +1,47 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/frame_context.hpp>
#include <borealis/view.hpp>
namespace brls
{
// A solid color rectangle
class Rectangle : public View
{
protected:
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
public:
Rectangle(NVGcolor color);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void setColor(NVGcolor color);
~Rectangle() {}
private:
NVGcolor color = nvgRGB(0, 0, 255);
};
} // namespace brls

View File

@@ -0,0 +1,87 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <features/features_cpu.h>
namespace brls
{
// A task that is repeated at a given interval
// by the UI thread
class RepeatingTask
{
private:
retro_time_t interval;
retro_time_t lastRun = 0;
bool running = false;
bool stopRequested = false;
public:
RepeatingTask(retro_time_t interval);
virtual ~RepeatingTask();
/**
* Actual code to run by the task
* Must call RepeatingTask::run() !
*/
virtual void run(retro_time_t currentTime);
/**
* Fired when the task starts
*/
virtual void onStart() {};
/**
* Fired when the task stops
*/
virtual void onStop() {};
/**
* Starts the task
*/
void start();
/**
* Fires the task immediately and delays the
* next run
*/
void fireNow();
/**
* Pauses the task without deleting it
*/
void pause();
/**
* Stops and deletes the task
*/
void stop();
retro_time_t getInterval();
retro_time_t getLastRun();
bool isRunning();
bool isStopRequested();
};
} // namespace brls

View File

@@ -0,0 +1,65 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2020 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <borealis/view.hpp>
namespace brls
{
// TODO: horizontal scrolling, either in ScrollView or in a separate class (like Android has)
// A view that automatically scrolls vertically
// when one of its children gains focus
class ScrollView : public View
{
private:
View* contentView = nullptr;
bool ready = false; // has layout been called at least once?
unsigned middleY = 0; // y + height/2
unsigned bottomY = 0; // y + height
float scrollY = 0.0f; // from 0.0f to 1.0f, in % of content view height
bool updateScrollingOnNextLayout = false;
bool updateScrollingOnNextFrame = false;
unsigned getYCenter(View* view);
void prebakeScrolling();
bool updateScrolling(bool animated);
void startScrolling(bool animated, float newScroll);
void scrollAnimationTick();
public:
~ScrollView();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
void willAppear(bool resetState = false) override;
void willDisappear(bool resetState = false) override;
View* getDefaultFocus() override;
void onChildFocusGained(View* child) override;
void onWindowSizeChanged() override;
void setContentView(View* view);
View* getContentView();
};
} // namespace brls

View File

@@ -0,0 +1,94 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/box_layout.hpp>
#include <string>
#include <vector>
namespace brls
{
// A sidebar with multiple tabs
class SidebarSeparator : public View
{
public:
SidebarSeparator();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
};
class Sidebar;
// TODO: Use a Label view with integrated ticker for label and sublabel
// TODO: Have the label always tick when active
class SidebarItem : public View
{
private:
std::string label;
bool active = false;
Sidebar* sidebar = nullptr;
View* associatedView = nullptr;
public:
SidebarItem(std::string label, Sidebar* sidebar);
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
View* getDefaultFocus() override
{
return this;
}
virtual bool onClick();
void setActive(bool active);
bool isActive();
void onFocusGained() override;
void setAssociatedView(View* view);
View* getAssociatedView();
~SidebarItem();
};
// TODO: Add a style with icons, make it collapsible?
class Sidebar : public BoxLayout
{
private:
SidebarItem* currentActive = nullptr;
public:
Sidebar();
SidebarItem* addItem(std::string label, View* view);
void addSeparator();
void setActive(SidebarItem* item);
View* getDefaultFocus() override;
void onChildFocusGained(View* child) override;
size_t lastFocus = 0;
};
} // namespace brls

View File

@@ -0,0 +1,54 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 Billy Laws
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/applet_frame.hpp>
#include <borealis/sidebar.hpp>
#include <string>
#include <vector>
namespace brls
{
// An applet frame for implementing a stage based app with a progress display in top right
class StagedAppletFrame : public AppletFrame
{
public:
StagedAppletFrame();
~StagedAppletFrame();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void addStage(View* view);
void nextStage();
void previousStage();
unsigned getCurrentStage();
unsigned getStagesCount();
unsigned isLastStage();
private:
size_t currentStage = 0;
std::vector<View*> stageViews;
void enterStage(int index, bool requestFocus);
};
} // namespace brls

View File

@@ -0,0 +1,323 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 WerWolv
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
namespace brls
{
class Style
{
public:
// AppletFrame
struct
{
unsigned headerHeightRegular;
unsigned headerHeightPopup; // PopupFrame
unsigned footerHeight;
unsigned imageLeftPadding;
unsigned imageTopPadding;
unsigned imageSize;
unsigned separatorSpacing;
unsigned titleSize;
unsigned titleStart;
unsigned titleOffset;
unsigned footerTextSize;
unsigned footerTextSpacing;
unsigned slideAnimation;
} AppletFrame;
// Highlight
struct
{
unsigned strokeWidth;
float cornerRadius;
unsigned shadowWidth;
unsigned shadowOffset;
unsigned shadowFeather;
unsigned shadowOpacity;
unsigned animationDuration;
} Highlight;
// Background
struct
{
unsigned sidebarBorderHeight;
} Background;
// Sidebar
struct
{
unsigned width;
unsigned spacing;
unsigned marginLeft;
unsigned marginRight;
unsigned marginTop;
unsigned marginBottom;
struct
{
unsigned height;
unsigned textSize;
unsigned padding;
unsigned textOffsetX;
unsigned activeMarkerWidth;
unsigned highlight;
} Item;
struct
{
unsigned height;
} Separator;
} Sidebar;
// List
struct
{
unsigned marginLeftRight;
unsigned marginTopBottom;
unsigned spacing;
// Item
struct
{
unsigned height;
unsigned heightWithSubLabel;
unsigned valueSize;
unsigned padding;
unsigned thumbnailPadding;
unsigned descriptionIndent;
unsigned descriptionSpacing;
unsigned indent;
unsigned selectRadius;
} Item;
} List;
// Label
struct
{
unsigned regularFontSize;
unsigned mediumFontSize;
unsigned smallFontSize;
unsigned descriptionFontSize;
unsigned crashFontSize;
unsigned buttonFontSize;
unsigned listItemFontSize;
unsigned notificationFontSize;
unsigned dialogFontSize;
unsigned hintFontSize;
float lineHeight;
float notificationLineHeight;
} Label;
// CrashFrame
struct
{
float labelWidth; // proportional to frame width, from 0 to 1
unsigned boxStrokeWidth;
unsigned boxSize;
unsigned boxSpacing;
unsigned buttonWidth;
unsigned buttonHeight;
unsigned buttonSpacing;
} CrashFrame;
// Button
struct
{
float cornerRadius;
unsigned highlightInset;
float shadowWidth;
float shadowFeather;
float shadowOpacity;
float shadowOffset;
} Button;
// TableRow
struct
{
unsigned headerHeight;
unsigned headerTextSize;
unsigned bodyHeight;
unsigned bodyIndent;
unsigned bodyTextSize;
unsigned padding;
} TableRow;
// Dropdown
struct
{
unsigned listWidth;
unsigned listPadding;
unsigned listItemHeight;
unsigned listItemTextSize;
unsigned headerHeight;
unsigned headerFontSize;
unsigned headerPadding;
} Dropdown;
struct
{
unsigned edgePadding;
unsigned separatorSpacing;
unsigned footerHeight;
unsigned imageLeftPadding;
unsigned imageTopPadding;
unsigned imageSize;
unsigned contentWidth;
unsigned contentHeight;
unsigned headerTextLeftPadding;
unsigned headerTextTopPadding;
unsigned subTitleLeftPadding;
unsigned subTitleTopPadding;
unsigned subTitleSpacing;
unsigned subTitleSeparatorLeftPadding;
unsigned subTitleSeparatorTopPadding;
unsigned subTitleSeparatorHeight;
unsigned headerFontSize;
unsigned subTitleFontSize;
} PopupFrame;
// StagedAppletFrame
struct
{
unsigned progressIndicatorSpacing;
unsigned progressIndicatorRadiusUnselected;
unsigned progressIndicatorRadiusSelected;
unsigned progressIndicatorBorderWidth;
} StagedAppletFrame;
// ProgressSpinner
struct
{
float centerGapMultiplier;
float barWidthMultiplier;
unsigned animationDuration;
} ProgressSpinner;
// ProgressDisplay
struct
{
unsigned percentageLabelWidth;
} ProgressDisplay;
// Header
struct
{
unsigned height;
unsigned padding;
unsigned rectangleWidth;
unsigned fontSize;
} Header;
// FramerateCounter
struct
{
unsigned width;
unsigned height;
} FramerateCounter;
// ThumbnailSidebar
struct
{
unsigned marginLeftRight;
unsigned marginTopBottom;
unsigned buttonHeight;
unsigned buttonMargin;
} ThumbnailSidebar;
// AnimationDuration
struct
{
unsigned show;
unsigned showSlide;
unsigned highlight;
unsigned shake;
unsigned collapse;
unsigned progress;
unsigned notificationTimeout;
} AnimationDuration;
// Notification
struct
{
unsigned width;
unsigned padding;
unsigned slideAnimation;
} Notification;
// Dialog
struct
{
unsigned width;
unsigned height;
unsigned paddingTopBottom;
unsigned paddingLeftRight;
float cornerRadius;
unsigned buttonHeight;
unsigned buttonSeparatorHeight;
float shadowWidth;
float shadowFeather;
float shadowOpacity;
float shadowOffset;
} Dialog;
// As close to HOS as possible
static Style horizon();
// TODO: Make a condensed style
};
} // namespace brls

View File

@@ -0,0 +1,35 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 WerWolv
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <functional>
#include <string>
namespace brls
{
class Swkbd
{
public:
static bool openForText(std::function<void(std::string)> f, std::string headerText = "", std::string subText = "", int maxStringLength = 32, std::string initialText = "");
static bool openForNumber(std::function<void(int)> f, std::string headerText = "", std::string subText = "", int maxStringLength = 32, std::string initialText = "", std::string leftButton = "", std::string rightButton = "");
};
} // namespace brls

View File

@@ -0,0 +1,59 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/applet_frame.hpp>
#include <borealis/sidebar.hpp>
#include <string>
#include <vector>
namespace brls
{
// An applet frame containing a sidebar on the left with multiple tabs
class TabFrame : public AppletFrame
{
public:
TabFrame();
/**
* Adds a tab with given label and view
* All tabs and separators must be added
* before the TabFrame is itself added to
* the view hierarchy
*/
void addTab(std::string label, View* view);
void addSeparator();
View* getDefaultFocus() override;
virtual bool onCancel() override;
~TabFrame();
private:
Sidebar* sidebar;
BoxLayout* layout;
View* rightPane = nullptr;
void switchToView(View* view);
};
} // namespace brls

View File

@@ -0,0 +1,73 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/view.hpp>
#include <string>
#include <vector>
namespace brls
{
// The type of a Table Row
enum class TableRowType
{
HEADER = 0,
BODY
};
// A Table row
class TableRow
{
private:
TableRowType type;
std::string label;
std::string value;
public:
TableRow(TableRowType type, std::string label, std::string value = "");
std::string* getLabel();
std::string* getValue();
TableRowType getType();
void setValue(std::string value);
};
// A simple, static two-columns table, as seen in
// the Settings app (Internet connection details)
// All rows must be added before adding the view
// to a layout (it's static)
class Table : public View
{
private:
std::vector<TableRow*> rows;
public:
~Table();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
TableRow* addRow(TableRowType type, std::string label, std::string value = "");
};
} // namespace brls

View File

@@ -0,0 +1,43 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/repeating_task.hpp>
#include <vector>
namespace brls
{
class TaskManager
{
private:
std::vector<RepeatingTask*> repeatingTasks;
void stopRepeatingTask(RepeatingTask* task);
public:
void frame();
void registerRepeatingTask(RepeatingTask* task);
~TaskManager();
};
} // namespace brls

View File

@@ -0,0 +1,96 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <nanovg.h>
namespace brls
{
// Theme variants
// (used in Application)
//
// Not an enum class because it's used
// as an array index in Theme
enum ThemeVariant
{
ThemeVariant_LIGHT = 0,
ThemeVariant_DARK,
ThemeVariant_NUMBER_OF_VARIANTS
};
typedef struct
{
float backgroundColor[3]; // gl color
NVGcolor backgroundColorRGB;
NVGcolor textColor;
NVGcolor descriptionColor;
NVGcolor notificationTextColor;
NVGcolor backdropColor;
NVGcolor separatorColor;
NVGcolor sidebarColor;
NVGcolor activeTabColor;
NVGcolor sidebarSeparatorColor;
NVGcolor highlightBackgroundColor;
NVGcolor highlightColor1;
NVGcolor highlightColor2;
NVGcolor listItemSeparatorColor;
NVGcolor listItemValueColor;
NVGcolor listItemFaintValueColor;
NVGcolor tableEvenBackgroundColor;
NVGcolor tableBodyTextColor;
NVGcolor dropdownBackgroundColor;
NVGcolor nextStageBulletColor;
NVGcolor spinnerBarColor;
NVGcolor headerRectangleColor;
NVGcolor buttonPlainEnabledBackgroundColor;
NVGcolor buttonPlainDisabledBackgroundColor;
NVGcolor buttonPlainEnabledTextColor;
NVGcolor buttonPlainDisabledTextColor;
NVGcolor dialogColor;
NVGcolor dialogBackdrop;
NVGcolor dialogButtonColor;
NVGcolor dialogButtonSeparatorColor;
} ThemeValues;
// A theme contains colors for all variants
class Theme
{
public:
ThemeValues colors[ThemeVariant_NUMBER_OF_VARIANTS];
// As close to HOS as possible
static Theme horizon();
};
} // namespace brls

View File

@@ -0,0 +1,78 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019 natinusala
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <borealis/applet_frame.hpp>
#include <borealis/box_layout.hpp>
#include <borealis/button.hpp>
#include <borealis/image.hpp>
namespace brls
{
// The sidebar used in ThumbnailFrame
class ThumbnailSidebar : public View
{
private:
Image* image = nullptr;
Button* button = nullptr;
Label* title = nullptr;
Label* subTitle = nullptr;
public:
ThumbnailSidebar();
~ThumbnailSidebar();
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) override;
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
View* getDefaultFocus() override;
void setThumbnail(std::string imagePath);
void setThumbnail(unsigned char* buffer, size_t bufferSize);
void setTitle(std::string title);
void setSubtitle(std::string subTitle);
Button* getButton();
};
// An applet frame with a sidebar on the right, containing a thumbnail
// and a button (similar to the Wi-Fi settings in HOS)
class ThumbnailFrame : public AppletFrame
{
private:
ThumbnailSidebar* sidebar = nullptr;
BoxLayout* boxLayout = nullptr;
View* thumbnailContentView = nullptr;
public:
ThumbnailFrame();
~ThumbnailFrame();
void setContentView(View* view) override;
protected:
void layout(NVGcontext* vg, Style* style, FontStash* stash) override;
ThumbnailSidebar* getSidebar();
};
} // namespace brls

View File

@@ -0,0 +1,406 @@
/*
Borealis, a Nintendo Switch UI Library
Copyright (C) 2019-2020 natinusala
Copyright (C) 2019 p-sam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <features/features_cpu.h>
#include <stdio.h>
#include <borealis/actions.hpp>
#include <borealis/event.hpp>
#include <borealis/frame_context.hpp>
#include <functional>
#include <map>
#include <string>
#include <vector>
namespace brls
{
// The animation to play when
// pushing or popping a view
// (implemented in Application)
enum class ViewAnimation
{
FADE, // the old view fades away and the new one fades in
SLIDE_LEFT, // the old view slides out to the left and the new one slides in from the right
SLIDE_RIGHT // inverted SLIDE_LEFT
};
// Focus direction when navigating
enum class FocusDirection
{
UP,
DOWN,
LEFT,
RIGHT
};
// View background
enum class Background
{
NONE,
SIDEBAR,
DEBUG,
BACKDROP
};
extern NVGcolor transparent;
class View;
typedef Event<View*> GenericEvent;
typedef Event<> VoidEvent;
// Superclass for all the other views
// Lifecycle of a view is :
// new -> [willAppear -> willDisappear] -> delete
//
// Users have do to the new, the rest of the lifecycle is taken
// care of by the library
//
// willAppear and willDisappear can be called zero or multiple times
// before deletion (in case of a TabLayout for instance)
class View
{
private:
Background background = Background::NONE;
void drawBackground(NVGcontext* vg, FrameContext* ctx, Style* style);
void drawHighlight(NVGcontext* vg, ThemeValues* theme, float alpha, Style* style, bool background);
float highlightAlpha = 0.0f;
bool dirty = true;
bool highlightShaking = false;
retro_time_t highlightShakeStart;
FocusDirection highlightShakeDirection;
float highlightShakeAmplitude;
bool fadeIn = false; // is the fade in animation running?
bool forceTranslucent = false;
ThemeValues* themeOverride = nullptr;
bool hidden = false;
std::vector<Action> actions;
/**
* Parent user data, typically the index of the view
* in the internal layout structure
*/
void* parentUserdata = nullptr;
protected:
int x = 0;
int y = 0;
unsigned width = 0;
unsigned height = 0;
float collapseState = 1.0f;
bool focused = false;
View* parent = nullptr;
GenericEvent focusEvent;
virtual unsigned getShowAnimationDuration(ViewAnimation animation);
virtual void getHighlightInsets(unsigned* top, unsigned* right, unsigned* bottom, unsigned* left)
{
*top = 0;
*right = 0;
*bottom = 0;
*left = 0;
}
virtual void getHighlightMetrics(Style* style, float* cornerRadius)
{
*cornerRadius = style->Highlight.cornerRadius;
}
virtual bool isHighlightBackgroundEnabled()
{
return true;
}
// Helper functions to apply this view's alpha to a color
NVGcolor a(NVGcolor color);
NVGpaint a(NVGpaint paint);
NVGcolor RGB(unsigned r, unsigned g, unsigned b)
{
return this->a(nvgRGB(r, g, b));
}
NVGcolor RGBA(unsigned r, unsigned g, unsigned b, unsigned a)
{
return this->a(nvgRGBA(r, g, b, a));
}
NVGcolor RGBf(float r, float g, float b)
{
return this->a(nvgRGBf(r, g, b));
}
NVGcolor RGBAf(float r, float g, float b, float a)
{
return this->a(nvgRGBAf(r, g, b, a));
}
/**
* Should the hint alpha be animated when
* pushing the view?
*/
virtual bool animateHint()
{
return false;
}
public:
void setBoundaries(int x, int y, unsigned width, unsigned height);
void setBackground(Background background);
void setWidth(unsigned width);
void setHeight(unsigned height);
void shakeHighlight(FocusDirection direction);
int getX();
int getY();
unsigned getWidth();
unsigned getHeight(bool includeCollapse = true);
void setForceTranslucent(bool translucent);
void setParent(View* parent, void* parentUserdata = nullptr);
View* getParent();
bool hasParent();
void* getParentUserData();
void registerAction(std::string hintText, Key key, ActionListener actionListener, bool hidden = false);
void updateActionHint(Key key, std::string hintText);
void setActionAvailable(Key key, bool available);
std::string describe() const { return typeid(*this).name(); }
const std::vector<Action>& getActions()
{
return this->actions;
}
/**
* Called each frame
* Do not override it to draw your view,
* override draw() instead
*/
virtual void frame(FrameContext* ctx);
/**
* Called by frame() to draw
* the view onscreen
*/
virtual void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, Style* style, FrameContext* ctx) = 0;
/**
* Triggered when the view has been
* resized and needs to layout its
* children
*/
virtual void layout(NVGcontext* vg, Style* style, FontStash* stash)
{
// Nothing to do
}
/**
* Called when the view will appear
* on screen, before or after layout()
*
* Can be called if the view has
* already appeared, so be careful
*/
virtual void willAppear(bool resetState = false)
{
// Nothing to do
}
/**
* Called when the view will disappear
* from the screen
*
* Can be called if the view has
* already disappeared, so be careful
*/
virtual void willDisappear(bool resetState = false)
{
// Nothing to do
}
/**
* Called when the show() animation (fade in)
* ends
*/
virtual void onShowAnimationEnd() {};
/**
* Shows the view (fade in animation)
*
* Called once when the view is
* pushed to the view stack
*
* Not recursive
*/
virtual void show(std::function<void(void)> cb, bool animate = true, ViewAnimation animation = ViewAnimation::FADE);
/**
* Hides the view in a collapse animation
*/
void collapse(bool animated = true);
bool isCollapsed();
/**
* Shows the view in a expand animation (opposite
* of collapse)
*/
void expand(bool animated = true);
/**
* Hides the view (fade out animation)
*
* Called if another view is pushed
* on top of this one
*
* Not recursive
*/
virtual void hide(std::function<void(void)> cb, bool animated = true, ViewAnimation animation = ViewAnimation::FADE);
bool isHidden();
/**
* Calls layout() on next frame
* unless immediate is true in which case
* it's called immediately
*/
void invalidate(bool immediate = false);
/**
* Is this view translucent?
*
* If you override it please return
* <value> || View::isTranslucent()
* to keep the fadeIn transition
*/
virtual bool isTranslucent()
{
return fadeIn || forceTranslucent;
}
bool isFocused();
/**
* Returns the default view to focus when focusing this view
* Typically the view itself or one of its children
*
* Returning nullptr means that the view is not focusable
* (and neither are its children)
*
* When pressing a key, the flow is :
* 1. starting from the currently focused view's parent, traverse the tree upwards and
* repeatidly call getNextFocus() on every view until we find a next view to focus or meet the end of the tree
* 2. if a view is found, getNextFocus() will internally call getDefaultFocus() for the selected child
* 3. give focus to the result, if it exists
*/
virtual View* getDefaultFocus()
{
return nullptr;
}
/**
* Returns the next view to focus given the requested direction
* and the currently focused view (as parent user data)
*
* Returning nullptr means that there is no next view to focus
* in that direction - getNextFocus will then be called on our
* parent if any
*/
virtual View* getNextFocus(FocusDirection direction, void* parentUserdata)
{
return nullptr;
}
/**
* Fired when focus is gained
*/
virtual void onFocusGained();
/**
* Fired when focus is lost
*/
virtual void onFocusLost();
/**
* Fired when focus is gained on one of this view's children
*/
virtual void onChildFocusGained(View* child)
{
if (this->hasParent())
this->getParent()->onChildFocusGained(this);
}
/**
* Fired when focus is gained on one of this view's children
*/
virtual void onChildFocusLost(View* child)
{
if (this->hasParent())
this->getParent()->onChildFocusLost(this);
}
/**
* Fired when the window size changes
* Not guaranteed to be called before or after layout()
*/
virtual void onWindowSizeChanged()
{
// Nothing by default
}
GenericEvent* getFocusEvent();
float alpha = 1.0f;
virtual float getAlpha(bool child = false);
/**
* Forces this view and its children to use
* the specified theme variant
*/
void overrideThemeVariant(ThemeValues* newTheme);
virtual ~View();
};
} // namespace brls