mirror of
https://github.com/XorTroll/hb-appstore.git
synced 2025-03-01 14:57:31 +00:00
more sdl2 stuff for switch
This commit is contained in:
parent
a5a644ac68
commit
807dffc932
2
Makefile
2
Makefile
@ -55,7 +55,7 @@ CFLAGS := -g -Wall -O2 \
|
||||
-ffast-math \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DSWITCH -D__LIBNX__ -DNOSTYLUS -DUSE_FILE32API -DNOCURL
|
||||
CFLAGS += $(INCLUDE) -DSWITCH -D__LIBNX__ -DNOSTYLUS -DUSE_FILE32API -DNOCURL -DNOGUI
|
||||
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
@ -21,13 +21,12 @@ A quick summary of how to run it on 3.0.0 is also included below. For newer firm
|
||||
- when you're done hit home to exit (and album again to go back to hbmenu)
|
||||
|
||||
### Building with libnx
|
||||
1. Install [devkitA64](http://switchbrew.org/index.php?title=Setting_up_Development_Environment)
|
||||
2. Install [dkp-pacman](https://devkitpro.org/viewtopic.php?f=13&t=8702)
|
||||
3. Install needed Switch dependencies via dkp-pacman:
|
||||
1. Install [dkp-pacman](https://devkitpro.org/viewtopic.php?f=13&t=8702)
|
||||
3. Install devkitA64 and needed Switch dependencies via dkp-pacman:
|
||||
```
|
||||
sudo dkp-pacman -S libnx switch-bzip2 switch-curl switch-freetype switch-libjpeg-turbo switch-sdl2 switch-sdl2_gfx switch-sdl2_image switch-sdl2_ttf switch-zlib
|
||||
sudo dkp-pacman -S devkitA64 libnx switch-tools switch-curl switch-bzip2 switch-curl switch-freetype switch-libjpeg-turbo switch-sdl2 switch-sdl2_gfx switch-sdl2_image switch-sdl2_ttf switch-zlib switch-libpng
|
||||
```
|
||||
4. Once it's all setup, recursively clone the repo and run make:
|
||||
3. Once it's all setup, recursively clone the repo and run make:
|
||||
```
|
||||
git clone --recursive https://github.com/vgmoose/appstorenx.git
|
||||
cd appstorenx
|
||||
|
@ -7,71 +7,71 @@ int console_main()
|
||||
{
|
||||
// initialize text console
|
||||
Console* console = new Console();
|
||||
|
||||
|
||||
init_networking();
|
||||
|
||||
|
||||
// create "get" object with default repo
|
||||
Get* get = new Get("./.get/", "http://switchbru.com/appstore");
|
||||
Input* input = new Input();
|
||||
|
||||
|
||||
// create main menu object
|
||||
Menu* menu = new Menu(console, get);
|
||||
|
||||
|
||||
bool running = true;
|
||||
|
||||
|
||||
while(running)
|
||||
{
|
||||
console->background(42, 37, 39);
|
||||
|
||||
|
||||
// show the current menu screen
|
||||
menu->display();
|
||||
SDL_Delay(16);
|
||||
|
||||
|
||||
// update pressed buttons in input object
|
||||
input->updateButtons();
|
||||
|
||||
|
||||
// if we're on the install screen, perform an install
|
||||
if (menu->screen == INSTALLING || menu->screen == REMOVING)
|
||||
{
|
||||
Package* target = get->packages[menu->position];
|
||||
|
||||
|
||||
// install package
|
||||
bool succeeded = false;
|
||||
|
||||
|
||||
if (menu->screen == INSTALLING)
|
||||
succeeded = get->install(target);
|
||||
else if (menu->screen == REMOVING)
|
||||
succeeded = get->remove(target);
|
||||
|
||||
|
||||
// change screen accordingly
|
||||
if (succeeded)
|
||||
menu->screen = INSTALL_SUCCESS;
|
||||
else
|
||||
menu->screen = INSTALL_FAILED;
|
||||
}
|
||||
|
||||
|
||||
// send either A or B to the menu object, if held
|
||||
if (input->held(BUTTON_A) || input->held(BUTTON_B))
|
||||
menu->advanceScreen(input->held(BUTTON_A));
|
||||
|
||||
|
||||
if (menu->screen == INSTALL_SCREEN && input->held(BUTTON_X))
|
||||
menu->screen = REMOVING;
|
||||
|
||||
|
||||
// if minus is pressed, exit
|
||||
if (input->held(BUTTON_MINUS))
|
||||
running = false;
|
||||
|
||||
|
||||
// if B is pressed on the splash screen, exit
|
||||
// if (menu->screen == SPLASH && input->held(BUTTON_B))
|
||||
// running = false;
|
||||
|
||||
|
||||
// move cursor up or down depending on input
|
||||
menu->moveCursor(-1*(input->held(BUTTON_UP)) + (input->held(BUTTON_DOWN)));
|
||||
|
||||
|
||||
// move page PAGE_SIZE forward/backward depending on input
|
||||
menu->moveCursor(-1*PAGE_SIZE*input->held(BUTTON_LEFT) + PAGE_SIZE*input->held(BUTTON_RIGHT));
|
||||
}
|
||||
|
||||
|
||||
console->close();
|
||||
input->close();
|
||||
|
||||
|
BIN
gui/.DS_Store
vendored
Normal file
BIN
gui/.DS_Store
vendored
Normal file
Binary file not shown.
@ -37,13 +37,16 @@ void AppCard::update()
|
||||
this->elements.push_back(status);
|
||||
|
||||
// app name
|
||||
int w, h;
|
||||
TextElement* appname = new TextElement(package->title.c_str(), size+3, &black);
|
||||
appname->position(this->x + 255 - appname->textSurface->w, this->y + 165);
|
||||
SDL_QueryTexture(appname->textSurface, NULL, NULL, &w, &h);
|
||||
appname->position(this->x + 255 - w, this->y + 165);
|
||||
this->elements.push_back(appname);
|
||||
|
||||
// author
|
||||
TextElement* author = new TextElement(package->author.c_str(), size, &gray);
|
||||
author->position(this->x + 255 - author->textSurface->w, this->y + 185);
|
||||
SDL_QueryTexture(author->textSurface, NULL, NULL, &w, &h);
|
||||
author->position(this->x + 255 - w, this->y + 185);
|
||||
this->elements.push_back(author);
|
||||
|
||||
// download status icon
|
||||
|
@ -147,8 +147,8 @@ void AppList::render(Element* parent)
|
||||
SDL_Rect dimens = { 0, 0, 920, 720 };
|
||||
dimens.x = this->x - 35;
|
||||
|
||||
SDL_FillRect(parent->renderer, &dimens, SDL_MapRGBA(parent->window_surface->format, 0xFF, 0xFF, 0xFF, 0xFF));
|
||||
this->window_surface = parent->window_surface;
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderFillRect(parent->renderer, &dimens);
|
||||
this->renderer = parent->renderer;
|
||||
|
||||
// draw the cursor at the highlighted position, if appropriate
|
||||
|
@ -64,8 +64,10 @@ AppPopup::AppPopup(Package* package)
|
||||
title2->position(550, 345);
|
||||
this->elements.push_back(title2);
|
||||
|
||||
int w, h;
|
||||
SDL_QueryTexture(title2->textSurface, NULL, NULL, &w, &h);
|
||||
TextElement* author = new TextElement(("- " + package->author).c_str(), 20, &gray);
|
||||
author->position(550 + title2->textSurface->w + 5, 345);
|
||||
author->position(550 + w + 5, 345);
|
||||
this->elements.push_back(author);
|
||||
|
||||
TextElement* subtitle = new TextElement(package->short_desc.c_str(), 20, &gray);
|
||||
@ -179,8 +181,8 @@ bool AppPopup::process(SDL_Event* event)
|
||||
|
||||
void AppPopup::render(Element* parent)
|
||||
{
|
||||
if (this->window_surface == NULL)
|
||||
this->window_surface = parent->window_surface;
|
||||
if (this->renderer == NULL)
|
||||
this->renderer = parent->renderer;
|
||||
|
||||
if (this->parent == NULL)
|
||||
this->parent = parent;
|
||||
@ -220,9 +222,9 @@ void AppPopup::updateCurrentlyDisplayedPopup(float amount)
|
||||
popup->parent->parent->render(NULL);
|
||||
|
||||
// force update the main screen
|
||||
if (popup->window_surface != NULL)
|
||||
if (popup->renderer != NULL)
|
||||
{
|
||||
SDL_blit(popup->window_surface);
|
||||
SDL_blit(popup->renderer);
|
||||
|
||||
// must call poll event here to allow SDL to redraw the screen
|
||||
SDL_Event event;
|
||||
|
@ -26,7 +26,6 @@ public:
|
||||
void wipeElements();
|
||||
|
||||
// SDL main graphics variables
|
||||
SDL_Surface* window_surface = NULL;
|
||||
SDL_Window* window = NULL;
|
||||
SDL_Renderer* renderer = NULL;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
std::unordered_map<std::string, SDL_Surface> ImageCache::cache;
|
||||
std::unordered_map<std::string, SDL_Texture*> ImageCache::cache;
|
||||
std::string ImageCache::cache_path;
|
||||
|
||||
ImageCache::ImageCache(const char* tmp_path)
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
static std::string cache_path;
|
||||
|
||||
// a map of all SDL surfaces that have been displayed
|
||||
static std::unordered_map<std::string, SDL_Surface> cache;
|
||||
static std::unordered_map<std::string, SDL_Texture*> cache;
|
||||
|
||||
// a map of pkg_names to version strings to know when icons are outdated
|
||||
std::unordered_map<std::string, std::string> version_cache;
|
||||
|
@ -9,20 +9,20 @@ ImageElement::ImageElement(const char* path)
|
||||
// try to find it in the cache first
|
||||
if (ImageCache::cache.count(key))
|
||||
{
|
||||
this->imgSurface = &ImageCache::cache[key];
|
||||
this->imgSurface = ImageCache::cache[key];
|
||||
return;
|
||||
}
|
||||
|
||||
// not found, create it
|
||||
|
||||
if (this->imgSurface != NULL)
|
||||
SDL_FreeSurface(this->imgSurface);
|
||||
SDL_DestroyTexture(this->imgSurface);
|
||||
|
||||
this->imgSurface = IMG_Load( path );
|
||||
this->imgSurface = IMG_LoadTexture(this->renderer, path );
|
||||
|
||||
// add to cache for next time
|
||||
if (this->imgSurface != NULL)
|
||||
ImageCache::cache[key] = *(this->imgSurface);
|
||||
ImageCache::cache[key] = (this->imgSurface);
|
||||
}
|
||||
|
||||
void ImageElement::render(Element* parent)
|
||||
@ -31,18 +31,21 @@ void ImageElement::render(Element* parent)
|
||||
imgLocation.x = this->x + parent->x;
|
||||
imgLocation.y = this->y + parent->y;
|
||||
|
||||
SDL_BlitSurface(this->imgSurface, NULL, parent->window_surface, &imgLocation);
|
||||
SDL_RenderCopy(parent->renderer, this->imgSurface, NULL, &imgLocation);
|
||||
}
|
||||
|
||||
void ImageElement::resize(int width, int height)
|
||||
{
|
||||
if (width == this->imgSurface->w && height == this->imgSurface->h)
|
||||
int w, h;
|
||||
SDL_QueryTexture(this->imgSurface, NULL, NULL, &w, &h);
|
||||
|
||||
if (width == w && height == h)
|
||||
return; // already the right size
|
||||
|
||||
SDL_Surface* delme = this->imgSurface;
|
||||
SDL_Texture* delme = this->imgSurface;
|
||||
|
||||
// this->imgSurface = rotozoomSurfaceXY(this->imgSurface, 0, ((double)width)/this->imgSurface->w, ((double)height)/this->imgSurface->h, 1);
|
||||
|
||||
// delete the old surface, and update the cache
|
||||
ImageCache::cache[this->path] = *(this->imgSurface);
|
||||
ImageCache::cache[this->path] = (this->imgSurface);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public:
|
||||
ImageElement(const char* path);
|
||||
void render(Element* parent);
|
||||
|
||||
SDL_Surface* imgSurface = NULL;
|
||||
SDL_Texture* imgSurface = NULL;
|
||||
const char* path;
|
||||
|
||||
void resize(int width, int height);
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "AppCard.hpp"
|
||||
#include "../libs/get/src/Utils.hpp"
|
||||
|
||||
SDL_Renderer* MainDisplay::mainRenderer = NULL;
|
||||
|
||||
MainDisplay::MainDisplay(Get* get)
|
||||
{
|
||||
this->get = get;
|
||||
@ -33,6 +35,8 @@ MainDisplay::MainDisplay(Get* get)
|
||||
|
||||
this->window = SDL_CreateWindow("n/a", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
|
||||
this->renderer = SDL_CreateRenderer(this->window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE);
|
||||
|
||||
MainDisplay::mainRenderer = this->renderer;
|
||||
|
||||
#if defined(SWITCH)
|
||||
// hide cursor for switch
|
||||
@ -160,7 +164,8 @@ void MainDisplay::render(Element* parent)
|
||||
|
||||
void MainDisplay::background(int r, int g, int b)
|
||||
{
|
||||
SDL_FillRect(this->window_surface, NULL, SDL_MapRGBA(this->window_surface->format, r, g, b, 0xFF));
|
||||
SDL_SetRenderDrawColor(this->renderer, r, g, b, 0xFF);
|
||||
SDL_RenderFillRect(this->renderer, NULL);
|
||||
}
|
||||
|
||||
void MainDisplay::update()
|
||||
|
@ -14,6 +14,8 @@ public:
|
||||
void background(int r, int g, int b);
|
||||
void update();
|
||||
|
||||
static SDL_Renderer* mainRenderer;
|
||||
|
||||
Get* get = NULL;
|
||||
ImageCache* imageCache = NULL;
|
||||
|
||||
|
@ -16,8 +16,6 @@ void ProgressBar::render(Element* parent)
|
||||
|
||||
int blue = this->color;
|
||||
int gray = 0x989898ff;
|
||||
int blue2 = SDL_MapRGB(parent->window_surface->format, (blue >> 24) & 0xff, (blue >> 16) & 0xff, (blue >> 8) & 0xff);
|
||||
int gray2 = SDL_MapRGB(parent->window_surface->format, 0x98, 0x98, 0x98);
|
||||
|
||||
// draw full grayed out bar first
|
||||
SDL_Rect gray_rect;
|
||||
@ -26,7 +24,8 @@ void ProgressBar::render(Element* parent)
|
||||
gray_rect.w = width;
|
||||
gray_rect.h = 9;
|
||||
|
||||
SDL_FillRect(parent->window_surface, &gray_rect, gray2);
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x98, 0x98, 0x98, 0xff); //gray2
|
||||
SDL_RenderFillRect(parent->renderer, &gray_rect);
|
||||
|
||||
// draw ending "circle"
|
||||
filledCircleColor(parent->renderer, x + this->width, y, 5, gray);
|
||||
@ -41,7 +40,8 @@ void ProgressBar::render(Element* parent)
|
||||
blue_rect.w = width*this->percent;
|
||||
blue_rect.h = 9;
|
||||
|
||||
SDL_FillRect(parent->window_surface, &blue_rect, blue2);
|
||||
SDL_SetRenderDrawColor(parent->renderer, (blue >> 24) & 0xff, (blue >> 16) & 0xff, (blue >> 8) & 0xff, 0xff); // blue2
|
||||
SDL_RenderFillRect(parent->renderer, &blue_rect);
|
||||
|
||||
// draw right "circle" (rounded part of bar, and ending)
|
||||
filledCircleColor(parent->renderer, x + width*this->percent, y, 5, blue);
|
||||
|
@ -105,7 +105,8 @@ void Sidebar::render(Element* parent)
|
||||
SDL_Rect dimens = { 0, 0, 400, 60 };
|
||||
dimens.y = 150+this->curCategory*70 - 15; // TODO: extract formula into method
|
||||
|
||||
SDL_FillRect(parent->window_surface, &dimens, SDL_MapRGBA(parent->window_surface->format, 0x67, 0x6a, 0x6d, 0xFF));
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x67, 0x6a, 0x6d, 0xFF);
|
||||
SDL_RenderFillRect(parent->renderer, &dimens);
|
||||
|
||||
// draw the selected category, if one should be highlighted
|
||||
if (this->highlighted >= 0)
|
||||
|
@ -22,28 +22,29 @@ void TextElement::render(Element* parent)
|
||||
textLocation.x = this->x + parent->x;
|
||||
textLocation.y = this->y + parent->y;
|
||||
|
||||
SDL_BlitSurface(this->textSurface, NULL, parent->window_surface, &textLocation);
|
||||
SDL_RenderCopy(parent->renderer, this->textSurface, NULL, &textLocation);
|
||||
}
|
||||
|
||||
SDL_Surface* TextElement::renderText(std::string& message, int size)
|
||||
SDL_Texture* TextElement::renderText(std::string& message, int size)
|
||||
{
|
||||
std::string key = message + std::to_string(size);
|
||||
|
||||
// try to find it in the cache first
|
||||
if (ImageCache::cache.count(key))
|
||||
return &ImageCache::cache[key];
|
||||
return ImageCache::cache[key];
|
||||
|
||||
// not found, make/render it
|
||||
|
||||
TTF_Font *font = TTF_OpenFont("./res/productsans.ttf", size);
|
||||
|
||||
SDL_Surface *surf = TTF_RenderText_Blended(font, message.c_str(), this->color);
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(MainDisplay::mainRenderer, surf);
|
||||
|
||||
// SDL_FreeSurface(surf);
|
||||
TTF_CloseFont(font);
|
||||
|
||||
// save it to the cache for later
|
||||
ImageCache::cache[key] = *surf;
|
||||
ImageCache::cache[key] = texture;
|
||||
|
||||
return surf;
|
||||
return texture;
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ class TextElement : public Element
|
||||
public:
|
||||
TextElement(const char* text, int size, SDL_Color* color = 0);
|
||||
void render(Element* parent);
|
||||
SDL_Surface* renderText(std::string& message, int size);
|
||||
SDL_Texture* renderText(std::string& message, int size);
|
||||
|
||||
SDL_Surface* textSurface;
|
||||
SDL_Texture* textSurface;
|
||||
SDL_Color color;
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user