Added font library. Changed Image to use File Service. Small fixes to File Service. Added Point and Size structs.

main
Nichole Mattera 3 years ago
parent 94ac0e0924
commit 734b1235bf
  1. 5011
      Libs/stb_truetype.h
  2. 3
      Makefile
  3. 14
      Source/Draw.cpp
  4. 16
      Source/Draw.hpp
  5. 24
      Source/Image.cpp
  6. 6
      Source/Image.hpp
  7. 14
      Source/Main.cpp
  8. 4
      Source/Scenes/Root.cpp
  9. 2
      Source/Services/File.cpp
  10. 1
      Source/Services/File.hpp

File diff suppressed because it is too large Load Diff

@ -39,7 +39,8 @@ include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
TARGET := HekateUpdater
BUILD := build
SOURCES := Source Source/Managers Source/Scenes Source/Views
SOURCES := Source Source/Managers Source/Scenes Source/Services Source/Views
INCLUDES := Libs
ROMFS := RomFS
APP_TITLE := Hekate Updater

@ -21,8 +21,8 @@
#include "Draw.hpp"
namespace HekateUpdater {
void Draw::pixel(u16 x, u16 y, Colour colour) {
u32 position = y * Application::Stride + x * sizeof(u32);
void Draw::pixel(Point point, Colour colour) {
u32 position = point.y * Application::Stride + point.x * sizeof(u32);
u8 * framebuffer = Application::CurrentFramebuffer;
framebuffer[position] = Draw::_blend(framebuffer[position], colour.red, colour.alpha);
@ -34,19 +34,19 @@ namespace HekateUpdater {
void Draw::fill(Rect rect, Colour colour) {
for (u16 x = rect.x; x < rect.x + rect.width; x++) {
for (u16 y = rect.y; y < rect.y + rect.height; y++) {
Draw::pixel(x, y, colour);
Draw::pixel(Point(x, y), colour);
}
}
}
void Draw::image(u16 x, u16 y, std::shared_ptr<Image> image) {
void Draw::image(Point point, std::shared_ptr<Image> image) {
if (!image->imageLoaded || image->rawImage == nullptr)
return;
for (u16 x2 = x; x2 < x + image->width; x2++) {
for (u16 y2 = y; y2 < y + image->height; y2++) {
for (u16 x2 = point.x; x2 < point.x + image->width; x2++) {
for (u16 y2 = point.y; y2 < point.y + image->height; y2++) {
int pos = ((y2 * image->width) + x2) * 3;
Draw::pixel(x2, y2, Colour(image->rawImage[pos], image->rawImage[pos + 1], image->rawImage[pos + 2], 255));
Draw::pixel(Point(x2, y2), Colour(image->rawImage[pos], image->rawImage[pos + 1], image->rawImage[pos + 2], 255));
}
}
}

@ -22,12 +22,24 @@
#include "Image.hpp"
#define Point(x, y) { x, y }
#define Size(w, h) { w, h }
#define Rect(x, y, w, h) { x, y, w, h }
#define Colour(r, g, b, a) { r, g, b, a }
#pragma once
namespace HekateUpdater {
struct Point {
u16 x;
u16 y;
};
struct Size {
u16 width;
u16 height;
};
struct Rect {
u16 x;
u16 y;
@ -44,9 +56,9 @@ namespace HekateUpdater {
class Draw {
public:
static void pixel(u16 x, u16 y, Colour Colour);
static void pixel(Point point, Colour Colour);
static void fill(Rect rect, Colour Colour);
static void image(u16 x, u16 y, std::shared_ptr<Image> image);
static void image(Point point, std::shared_ptr<Image> image);
private:
static u8 _blend(u32 source, u32 destination, u8 alpha);

@ -18,17 +18,14 @@
*/
#include <cstring>
#include <fstream>
#include <png.h>
#include <sstream>
#include <vector>
#include "Image.hpp"
#include <png.h>
#include "Services/File.hpp"
namespace HekateUpdater {
Image::Image(std::string filePath) {
std::string file = this->_readFile(filePath);
this->imageLoaded = this->_readPNG(file);
Image::Image(std::string path) {
auto data = Services::File::read(path);
this->imageLoaded = this->_readPNG(data);
}
Image::~Image() {
@ -37,20 +34,13 @@ namespace HekateUpdater {
}
}
std::string Image::_readFile(std::string filePath) {
std::ifstream file(filePath);
std::ostringstream ss;
ss << file.rdbuf();
return ss.str();
}
bool Image::_readPNG(std::string file) {
bool Image::_readPNG(std::vector<char> file) {
png_image image;
memset(&image, 0, sizeof(image));
image.version = PNG_IMAGE_VERSION;
if (png_image_begin_read_from_memory(&image, file.c_str(), file.length()) == 0) {
if (png_image_begin_read_from_memory(&image, &file[0], file.size()) == 0) {
return false;
}

@ -19,6 +19,7 @@
#include <string>
#include <switch.h>
#include <vector>
#pragma once
@ -30,12 +31,11 @@ namespace HekateUpdater {
u16 width = 0;
u16 height = 0;
Image(std::string filePath);
Image(std::string path);
~Image();
private:
std::string _readFile(std::string filePath);
bool _readPNG(std::string file);
bool _readPNG(std::vector<char> file);
};
}

@ -40,9 +40,8 @@ void userAppInit(void) {
nxlinkStdio();
#endif
// res = nifmInitialize(NifmServiceType_User);
// if (R_FAILED(res))
// fatalThrow(res);
if (R_FAILED(nifmInitialize(NifmServiceType_User)))
fatalThrow(0x9003);
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
fatalThrow(0x9004);
@ -50,16 +49,15 @@ void userAppInit(void) {
if (R_FAILED(romfsInit()))
fatalThrow(0x9005);
// rc = plInitialize();
// if (R_FAILED(res))
// fatalThrow(res);
if (R_FAILED(plInitialize(PlServiceType_User)))
fatalThrow(0x9006);
}
void userAppExit(void) {
// plExit();
plExit();
romfsExit();
curl_global_cleanup();
// nifmExit();
nifmExit();
socketExit();
setsysExit();
}

@ -27,7 +27,7 @@ namespace HekateUpdater::Scenes {
auto theme = Managers::Theme::Instance();
this->background = theme->background;
// this->icon = std::make_unique<Image>("romfs:/icon.png");
this->icon = std::make_unique<Image>("romfs:/images/0_icon.png");
}
void Root::buttonsDown(u32 buttons) {
@ -37,6 +37,6 @@ namespace HekateUpdater::Scenes {
}
void Root::render(Rect rect) {
// Draw::image(0, 0, this->icon);
Draw::image(Point(0, 0), this->icon);
}
}

@ -65,7 +65,7 @@ namespace HekateUpdater::Services {
void File::unlink(std::string path) {
if (File::exists(path)) {
remove(path.c_str()) == 0;
remove(path.c_str());
}
}

@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <string>
#include <vector>
#pragma once

Loading…
Cancel
Save