mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-28 00:39:30 +00:00
Added missing dependicies
This commit is contained in:
parent
03baa21c10
commit
ebcd9f00ed
47 changed files with 18405 additions and 0 deletions
21
libs/sftdlib/LICENSE
Normal file
21
libs/sftdlib/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Sergi Granell (xerpi), xerpi.g.12@gmail.com
|
||||
|
||||
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.
|
||||
11
libs/sftdlib/README.md
Normal file
11
libs/sftdlib/README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
## SFTDLIB
|
||||
|
||||
Simple and Fast Text Drawing library for the Nintendo 3DS (using sf2dlib and ctrulib)
|
||||
|
||||
### Prerequisites
|
||||
|
||||
ctrulib: https://github.com/smealum/ctrulib
|
||||
|
||||
SF2D: https://github.com/xerpi/sf2dlib
|
||||
|
||||
FreeType2 (portlib): https://github.com/xerpi/3ds_portlibs
|
||||
2303
libs/sftdlib/libsftd/Doxyfile
Normal file
2303
libs/sftdlib/libsftd/Doxyfile
Normal file
File diff suppressed because it is too large
Load diff
141
libs/sftdlib/libsftd/Makefile
Normal file
141
libs/sftdlib/libsftd/Makefile
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/3ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := sftd
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(CTRULIB) $(PORTLIBS) \
|
||||
$(CURDIR)/../../3ds_portlibs/build \
|
||||
$(CURDIR)/../../sf2dlib/libsf2d
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
$(foreach dir,$(PORTLIBS),-I$(dir)/include/freetype2) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
$(BUILD): lib
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) lib latex html
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
install: $(BUILD)
|
||||
@cp $(OUTPUT) $(CTRULIB)/lib
|
||||
@cp include/sftd.h $(CTRULIB)/include
|
||||
@echo "Installed!"
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
# WARNING: This is not the right way to do this! TODO: Do it right!
|
||||
#---------------------------------------------------------------------------------
|
||||
%_vsh.h %.vsh.o : %.vsh
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
|
||||
@bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@rm ../$(notdir $<).shbin
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
113
libs/sftdlib/libsftd/include/sftd.h
Normal file
113
libs/sftdlib/libsftd/include/sftd.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/**
|
||||
* @file sftd.h
|
||||
* @author Sergi Granell (xerpi)
|
||||
* @date 2 April 2015
|
||||
* @brief sftdlib header
|
||||
*/
|
||||
|
||||
#ifndef SFTD_H
|
||||
#define SFTD_H
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Structs
|
||||
|
||||
/**
|
||||
* @brief Represents a font
|
||||
*/
|
||||
typedef struct sftd_font sftd_font;
|
||||
|
||||
// Basic functions
|
||||
|
||||
/**
|
||||
* @brief Initializates the library
|
||||
* @return Whether the initialization has been successful or not
|
||||
*/
|
||||
int sftd_init();
|
||||
|
||||
/**
|
||||
* @brief Finishes the library
|
||||
* @return Whether the finalization has been successful or not
|
||||
*/
|
||||
int sftd_fini();
|
||||
|
||||
/**
|
||||
* @brief Loads a font from a file
|
||||
* @param filename the path to the font
|
||||
* @return a pointer to the loaded font (NULL on error)
|
||||
*/
|
||||
sftd_font *sftd_load_font_file(const char *filename);
|
||||
|
||||
/**
|
||||
* @brief Loads a font from memory
|
||||
* @param buffer the address of the font
|
||||
* @param size the size of the font buffer
|
||||
* @return a pointer to the loaded font (NULL on error)
|
||||
*/
|
||||
sftd_font *sftd_load_font_mem(const void *buffer, unsigned int size);
|
||||
|
||||
/**
|
||||
* @brief Frees a font
|
||||
* @param font pointer to the font to freeze
|
||||
*/
|
||||
void sftd_free_font(sftd_font *font);
|
||||
|
||||
// Draw functions
|
||||
|
||||
/**
|
||||
* @brief Draws text using a font
|
||||
* @param font the font to use
|
||||
* @param x the x coordinate to draw the text to
|
||||
* @param y the y coordinate to draw the text to
|
||||
* @param color the color to draw the font
|
||||
* @param size the font size
|
||||
* @param text a pointer to the text to draw
|
||||
*/
|
||||
void sftd_draw_text(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text);
|
||||
|
||||
/**
|
||||
* @brief Draws formatted text using a font
|
||||
* @param font the font to use
|
||||
* @param x the x coordinate to draw the text to
|
||||
* @param y the y coordinate to draw the text to
|
||||
* @param color the color to draw the font
|
||||
* @param size the font size
|
||||
* @param text a pointer to the text to draw
|
||||
* @param ... variable arguments
|
||||
*/
|
||||
void sftd_draw_textf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text, ...);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Draws wide text using a font
|
||||
* @param font the font to use
|
||||
* @param x the x coordinate to draw the text to
|
||||
* @param y the y coordinate to draw the text to
|
||||
* @param color the color to draw the font
|
||||
* @param size the font size
|
||||
* @param text a pointer to the wide text to draw
|
||||
*/
|
||||
void sftd_draw_wtext(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text);
|
||||
|
||||
/**
|
||||
* @brief Draws formatted wide text using a font
|
||||
* @param font the font to use
|
||||
* @param x the x coordinate to draw the text to
|
||||
* @param y the y coordinate to draw the text to
|
||||
* @param color the color to draw the font
|
||||
* @param size the font size
|
||||
* @param text a pointer to the wide text to draw
|
||||
* @param ... variable arguments
|
||||
*/
|
||||
void sftd_draw_wtextf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text, ...);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
269
libs/sftdlib/libsftd/source/sftd.c
Normal file
269
libs/sftdlib/libsftd/source/sftd.c
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
#include "sftd.h"
|
||||
#include <wchar.h>
|
||||
#include <sf2d.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_CACHE_H
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
static int sftd_initialized = 0;
|
||||
static FT_Library ftlibrary;
|
||||
static FTC_Manager ftcmanager;
|
||||
|
||||
typedef enum {
|
||||
SFTD_LOAD_FROM_FILE,
|
||||
SFTD_LOAD_FROM_MEM
|
||||
} sftd_font_load_from;
|
||||
|
||||
struct sftd_font {
|
||||
sftd_font_load_from from;
|
||||
union {
|
||||
char *filename;
|
||||
struct {
|
||||
const void *font_buffer;
|
||||
unsigned int buffer_size;
|
||||
};
|
||||
};
|
||||
FTC_CMapCache cmapcache;
|
||||
FTC_ImageCache imagecache;
|
||||
};
|
||||
|
||||
static FT_Error ftc_face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face)
|
||||
{
|
||||
sftd_font *font = (sftd_font *)face_id;
|
||||
|
||||
FT_Error error = FT_Err_Cannot_Open_Resource;
|
||||
|
||||
if (font->from == SFTD_LOAD_FROM_FILE) {
|
||||
error = FT_New_Face(
|
||||
library,
|
||||
font->filename,
|
||||
0,
|
||||
face);
|
||||
} else if (font->from == SFTD_LOAD_FROM_MEM) {
|
||||
error = FT_New_Memory_Face(
|
||||
library,
|
||||
font->font_buffer,
|
||||
font->buffer_size,
|
||||
0,
|
||||
face);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
int sftd_init()
|
||||
{
|
||||
if (sftd_initialized) return 2;
|
||||
|
||||
FT_Error error = FT_Init_FreeType(&ftlibrary);
|
||||
if (error != FT_Err_Ok) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
error = FTC_Manager_New(
|
||||
ftlibrary,
|
||||
0, /* use default */
|
||||
0, /* use default */
|
||||
0, /* use default */
|
||||
&ftc_face_requester, /* use our requester */
|
||||
NULL, /* user data */
|
||||
&ftcmanager);
|
||||
|
||||
if (error != FT_Err_Ok) {
|
||||
FT_Done_FreeType(ftlibrary);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sftd_initialized = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sftd_fini()
|
||||
{
|
||||
if (!sftd_initialized) return 2;
|
||||
|
||||
FT_Error error = FT_Done_FreeType(ftlibrary);
|
||||
if (error != FT_Err_Ok) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FTC_Manager_Done(ftcmanager);
|
||||
|
||||
sftd_initialized = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sftd_font *sftd_load_font_file(const char *filename)
|
||||
{
|
||||
sftd_font *font = malloc(sizeof(*font));
|
||||
|
||||
size_t len = strlen(filename);
|
||||
|
||||
font->filename = malloc(len + 1);
|
||||
strcpy(font->filename, filename);
|
||||
font->filename[len] = '\0';
|
||||
|
||||
FTC_CMapCache_New(ftcmanager, &font->cmapcache);
|
||||
FTC_ImageCache_New(ftcmanager, &font->imagecache);
|
||||
|
||||
font->from = SFTD_LOAD_FROM_FILE;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
sftd_font *sftd_load_font_mem(const void *buffer, unsigned int size)
|
||||
{
|
||||
sftd_font *font = malloc(sizeof(*font));
|
||||
font->font_buffer = buffer;
|
||||
font->buffer_size = size;
|
||||
|
||||
FTC_CMapCache_New(ftcmanager, &font->cmapcache);
|
||||
FTC_ImageCache_New(ftcmanager, &font->imagecache);
|
||||
|
||||
font->from = SFTD_LOAD_FROM_MEM;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
void sftd_free_font(sftd_font *font)
|
||||
{
|
||||
if (font) {
|
||||
FTC_FaceID face_id = (FTC_FaceID)font;
|
||||
FTC_Manager_RemoveFaceID(ftcmanager, face_id);
|
||||
if (font->from == SFTD_LOAD_FROM_FILE) {
|
||||
free(font->filename);
|
||||
}
|
||||
free(font);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_bitmap(FT_Bitmap *bitmap, int x, int y, unsigned int color)
|
||||
{
|
||||
//This is too ugly
|
||||
sf2d_texture *tex = sf2d_create_texture(bitmap->width, bitmap->rows, GPU_RGBA8, SF2D_PLACE_TEMP);
|
||||
|
||||
int j, k;
|
||||
for (j = 0; j < bitmap->rows; j++) {
|
||||
for (k = 0; k < bitmap->width; k++) {
|
||||
((u32 *)tex->data)[j*tex->pow2_w + k] = __builtin_bswap32((color & ~0xFF) | bitmap->buffer[j*bitmap->width + k]);
|
||||
}
|
||||
}
|
||||
|
||||
sf2d_texture_tile32(tex);
|
||||
sf2d_draw_texture(tex, x, y);
|
||||
sf2d_free_texture(tex);
|
||||
}
|
||||
|
||||
void sftd_draw_text(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text)
|
||||
{
|
||||
FTC_FaceID face_id = (FTC_FaceID)font;
|
||||
FT_Face face;
|
||||
FTC_Manager_LookupFace(ftcmanager, face_id, &face);
|
||||
|
||||
FT_Int charmap_index;
|
||||
charmap_index = FT_Get_Charmap_Index(face->charmap);
|
||||
|
||||
FT_Glyph glyph;
|
||||
FT_Bool use_kerning = FT_HAS_KERNING(face);
|
||||
FT_UInt glyph_index, previous = 0;
|
||||
int pen_x = x;
|
||||
int pen_y = y;
|
||||
|
||||
FTC_ScalerRec scaler;
|
||||
scaler.face_id = face_id;
|
||||
scaler.width = size;
|
||||
scaler.height = size;
|
||||
scaler.pixel = 1;
|
||||
|
||||
FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL;
|
||||
|
||||
while (*text) {
|
||||
glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text);
|
||||
|
||||
if (use_kerning && previous && glyph_index) {
|
||||
FT_Vector delta;
|
||||
FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
|
||||
pen_x += delta.x >> 6;
|
||||
}
|
||||
|
||||
FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL);
|
||||
if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
|
||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
|
||||
|
||||
draw_bitmap(&bitmap_glyph->bitmap, pen_x + bitmap_glyph->left + x, pen_y - bitmap_glyph->top + y, color);
|
||||
|
||||
pen_x += bitmap_glyph->root.advance.x >> 16;
|
||||
pen_y += bitmap_glyph->root.advance.y >> 16;
|
||||
}
|
||||
|
||||
previous = glyph_index;
|
||||
text++;
|
||||
}
|
||||
}
|
||||
|
||||
void sftd_draw_textf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text, ...)
|
||||
{
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(buffer, 256, text, args);
|
||||
sftd_draw_text(font, x, y, color, size, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void sftd_draw_wtext(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text)
|
||||
{
|
||||
FTC_FaceID face_id = (FTC_FaceID)font;
|
||||
FT_Face face;
|
||||
FTC_Manager_LookupFace(ftcmanager, face_id, &face);
|
||||
|
||||
FT_Int charmap_index;
|
||||
charmap_index = FT_Get_Charmap_Index(face->charmap);
|
||||
|
||||
FT_Glyph glyph;
|
||||
FT_Bool use_kerning = FT_HAS_KERNING(face);
|
||||
FT_UInt glyph_index, previous = 0;
|
||||
int pen_x = x;
|
||||
int pen_y = y;
|
||||
|
||||
FTC_ScalerRec scaler;
|
||||
scaler.face_id = face_id;
|
||||
scaler.width = size;
|
||||
scaler.height = size;
|
||||
scaler.pixel = 1;
|
||||
|
||||
FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL;
|
||||
|
||||
while (*text) {
|
||||
glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text);
|
||||
|
||||
if (use_kerning && previous && glyph_index) {
|
||||
FT_Vector delta;
|
||||
FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
|
||||
pen_x += delta.x >> 6;
|
||||
}
|
||||
|
||||
FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL);
|
||||
if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
|
||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
|
||||
|
||||
draw_bitmap(&bitmap_glyph->bitmap, pen_x + bitmap_glyph->left + x, pen_y - bitmap_glyph->top + y, color);
|
||||
|
||||
pen_x += bitmap_glyph->root.advance.x >> 16;
|
||||
pen_y += bitmap_glyph->root.advance.y >> 16;
|
||||
}
|
||||
|
||||
previous = glyph_index;
|
||||
text++;
|
||||
}
|
||||
}
|
||||
|
||||
void sftd_draw_wtextf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text, ...)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vswprintf(buffer, 256, text, args);
|
||||
sftd_draw_wtext(font, x, y, color, size, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
201
libs/sftdlib/sample/Makefile
Normal file
201
libs/sftdlib/sample/Makefile
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITARM)/3ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#
|
||||
# NO_SMDH: if set to anything, no SMDH file is generated.
|
||||
# APP_TITLE is the name of the app stored in the SMDH file (Optional)
|
||||
# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
|
||||
# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
|
||||
# ICON is the filename of the icon (.png), relative to the project folder.
|
||||
# If not set, it attempts to use one of the following (in this order):
|
||||
# - <Project name>.png
|
||||
# - icon.png
|
||||
# - <libctru folder>/default_icon.png
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := sftd_sample
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
APP_TITLE := SFFTLIB sample
|
||||
APP_DESCRIPTION := SFFTLIB sample
|
||||
APP_AUTHOR := xerpi
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
|
||||
|
||||
CFLAGS := -g -Wall -O2 -mword-relocations \
|
||||
-fomit-frame-pointer -ffast-math \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lsftd -lfreetype -lpng -lz -lsf2d -lctru -lm
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(CTRULIB) $(PORTLIBS)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
ifeq ($(strip $(ICON)),)
|
||||
icons := $(wildcard *.png)
|
||||
ifneq (,$(findstring $(TARGET).png,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/$(TARGET).png
|
||||
else
|
||||
ifneq (,$(findstring icon.png,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/icon.png
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_ICON := $(TOPDIR)/$(ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_SMDH)),)
|
||||
export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
|
||||
endif
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET)-strip.elf $(TARGET).cia $(TARGET).3ds
|
||||
#---------------------------------------------------------------------------------
|
||||
$(TARGET)-strip.elf: $(BUILD)
|
||||
@$(STRIP) $(TARGET).elf -o $(TARGET)-strip.elf
|
||||
#---------------------------------------------------------------------------------
|
||||
cci: $(TARGET)-strip.elf
|
||||
@makerom -f cci -rsf resources/$(TARGET).rsf -target d -exefslogo -elf $(TARGET)-strip.elf -o $(TARGET).3ds
|
||||
@echo "built ... sf2d_sample.3ds"
|
||||
#---------------------------------------------------------------------------------
|
||||
cia: $(TARGET)-strip.elf
|
||||
@makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf resources/$(TARGET).rsf -exefslogo -target t
|
||||
@echo "built ... sf2d_sample.cia"
|
||||
#---------------------------------------------------------------------------------
|
||||
send: $(BUILD)
|
||||
@3dslink $(TARGET).3dsx
|
||||
#---------------------------------------------------------------------------------
|
||||
run: $(BUILD)
|
||||
@citra $(TARGET).3dsx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(NO_SMDH)),)
|
||||
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
|
||||
else
|
||||
$(OUTPUT).3dsx : $(OUTPUT).elf
|
||||
endif
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ttf.o : %.ttf
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
# WARNING: This is not the right way to do this! TODO: Do it right!
|
||||
#---------------------------------------------------------------------------------
|
||||
%.vsh.o : %.vsh
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
|
||||
@bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@rm ../$(notdir $<).shbin
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
BIN
libs/sftdlib/sample/data/airstrike.ttf
Normal file
BIN
libs/sftdlib/sample/data/airstrike.ttf
Normal file
Binary file not shown.
236
libs/sftdlib/sample/resources/sftd_sample.rsf
Normal file
236
libs/sftdlib/sample/resources/sftd_sample.rsf
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
BasicInfo:
|
||||
Title : "SFTDLIB sample"
|
||||
CompanyCode : "00"
|
||||
ProductCode : "sftd-sample"
|
||||
ContentType : Application # Application / SystemUpdate / Manual / Child / Trial
|
||||
Logo : Nintendo # Nintendo / Licensed / Distributed / iQue / iQueForSystem
|
||||
|
||||
#Rom:
|
||||
# Specifies the root path of the file system to include in the ROM.
|
||||
# HostRoot : "$(ROMFS_ROOT)"
|
||||
|
||||
|
||||
TitleInfo:
|
||||
UniqueId : 0xf0024 # This was/is the first real homebrew app. I hope this TID range is not used by any retail game/app.
|
||||
Category : Application # Application / SystemApplication / Applet / Firmware / Base / DlpChild / Demo / Contents / SystemContents / SharedContents / AddOnContents / Patch / AutoUpdateContents
|
||||
|
||||
CardInfo:
|
||||
MediaSize : 512MB # 128MB / 256MB / 512MB / 1GB / 2GB / 4GB / 8GB / 16GB / 32GB
|
||||
MediaType : Card1 # Card1 / Card2
|
||||
CardDevice : NorFlash # NorFlash(Pick this if you use savedata) / None
|
||||
|
||||
|
||||
Option:
|
||||
UseOnSD : true # true if App is to be installed to SD
|
||||
EnableCompress : true # Compresses exefs code
|
||||
FreeProductCode : true # Removes limitations on ProductCode
|
||||
EnableCrypt : false # Enables encryption for NCCH and CIA
|
||||
MediaFootPadding : false # If true CCI files are created with padding
|
||||
|
||||
ExeFs: # these are the program segments from the ELF, check your elf for the appropriate segment names
|
||||
ReadOnly:
|
||||
- .rodata
|
||||
- RO
|
||||
ReadWrite:
|
||||
- .data
|
||||
- RO
|
||||
Text:
|
||||
- .init
|
||||
- .text
|
||||
- STUP_ENTRY
|
||||
|
||||
PlainRegion: # only used with SDK ELFs
|
||||
# - .module_id
|
||||
|
||||
AccessControlInfo:
|
||||
# UseOtherVariationSaveData : true
|
||||
# UseExtSaveData : true
|
||||
# ExtSaveDataId: 0xffffffff
|
||||
# SystemSaveDataId1: 0x220
|
||||
# SystemSaveDataId2: 0x00040010
|
||||
# OtherUserSaveDataId1: 0x220
|
||||
# OtherUserSaveDataId2: 0x330
|
||||
# OtherUserSaveDataId3: 0x440
|
||||
# UseExtendedSaveDataAccessControl: true
|
||||
# AccessibleSaveDataIds: [0x101, 0x202, 0x303, 0x404, 0x505, 0x606]
|
||||
FileSystemAccess:
|
||||
# - CategorySystemApplication
|
||||
# - CategoryHardwareCheck
|
||||
# - CategoryFileSystemTool
|
||||
- Debug
|
||||
# - TwlCardBackup
|
||||
# - TwlNandData
|
||||
# - Boss
|
||||
- DirectSdmc
|
||||
# - Core
|
||||
# - CtrNandRo
|
||||
# - CtrNandRw
|
||||
# - CtrNandRoWrite
|
||||
# - CategorySystemSettings
|
||||
# - CardBoard
|
||||
# - ExportImportIvs
|
||||
# - DirectSdmcWrite
|
||||
# - SwitchCleanup
|
||||
# - SaveDataMove
|
||||
# - Shop
|
||||
# - Shell
|
||||
# - CategoryHomeMenu
|
||||
IoAccessControl:
|
||||
# - FsMountNand
|
||||
# - FsMountNandRoWrite
|
||||
# - FsMountTwln
|
||||
# - FsMountWnand
|
||||
# - FsMountCardSpi
|
||||
# - UseSdif3
|
||||
# - CreateSeed
|
||||
# - UseCardSpi
|
||||
|
||||
IdealProcessor : 0
|
||||
AffinityMask : 1
|
||||
|
||||
Priority : 16
|
||||
|
||||
MaxCpu : 0x9E # Default
|
||||
|
||||
DisableDebug : true
|
||||
EnableForceDebug : false
|
||||
CanWriteSharedPage : true
|
||||
CanUsePrivilegedPriority : false
|
||||
CanUseNonAlphabetAndNumber : true
|
||||
PermitMainFunctionArgument : true
|
||||
CanShareDeviceMemory : true
|
||||
RunnableOnSleep : false
|
||||
SpecialMemoryArrange : true
|
||||
|
||||
CoreVersion : 2
|
||||
DescVersion : 2
|
||||
|
||||
ReleaseKernelMajor : "02"
|
||||
ReleaseKernelMinor : "33"
|
||||
MemoryType : Application # Application / System / Base
|
||||
HandleTableSize: 512
|
||||
IORegisterMapping:
|
||||
- 1ff50000-1ff57fff
|
||||
- 1ff70000-1ff77fff
|
||||
MemoryMapping:
|
||||
- 1f000000-1f5fffff:r
|
||||
SystemCallAccess:
|
||||
ArbitrateAddress: 34
|
||||
Break: 60
|
||||
CancelTimer: 28
|
||||
ClearEvent: 25
|
||||
ClearTimer: 29
|
||||
CloseHandle: 35
|
||||
ConnectToPort: 45
|
||||
ControlMemory: 1
|
||||
CreateAddressArbiter: 33
|
||||
CreateEvent: 23
|
||||
CreateMemoryBlock: 30
|
||||
CreateMutex: 19
|
||||
CreateSemaphore: 21
|
||||
CreateThread: 8
|
||||
CreateTimer: 26
|
||||
DuplicateHandle: 39
|
||||
ExitProcess: 3
|
||||
ExitThread: 9
|
||||
GetCurrentProcessorNumber: 17
|
||||
GetHandleInfo: 41
|
||||
GetProcessId: 53
|
||||
GetProcessIdOfThread: 54
|
||||
GetProcessIdealProcessor: 6
|
||||
GetProcessInfo: 43
|
||||
GetResourceLimit: 56
|
||||
GetResourceLimitCurrentValues: 58
|
||||
GetResourceLimitLimitValues: 57
|
||||
GetSystemInfo: 42
|
||||
GetSystemTick: 40
|
||||
GetThreadContext: 59
|
||||
GetThreadId: 55
|
||||
GetThreadIdealProcessor: 15
|
||||
GetThreadInfo: 44
|
||||
GetThreadPriority: 11
|
||||
MapMemoryBlock: 31
|
||||
OutputDebugString: 61
|
||||
QueryMemory: 2
|
||||
ReleaseMutex: 20
|
||||
ReleaseSemaphore: 22
|
||||
SendSyncRequest1: 46
|
||||
SendSyncRequest2: 47
|
||||
SendSyncRequest3: 48
|
||||
SendSyncRequest4: 49
|
||||
SendSyncRequest: 50
|
||||
SetThreadPriority: 12
|
||||
SetTimer: 27
|
||||
SignalEvent: 24
|
||||
SleepThread: 10
|
||||
UnmapMemoryBlock: 32
|
||||
WaitSynchronization1: 36
|
||||
WaitSynchronizationN: 37
|
||||
InterruptNumbers:
|
||||
ServiceAccessControl:
|
||||
- APT:U
|
||||
- $hioFIO
|
||||
- $hostio0
|
||||
- $hostio1
|
||||
- ac:u
|
||||
- boss:U
|
||||
- cam:u
|
||||
- cecd:u
|
||||
- cfg:u
|
||||
- dlp:FKCL
|
||||
- dlp:SRVR
|
||||
- dsp::DSP
|
||||
- frd:u
|
||||
- fs:USER
|
||||
- gsp::Gpu
|
||||
- hid:USER
|
||||
- http:C
|
||||
- mic:u
|
||||
- ndm:u
|
||||
- news:u
|
||||
- nwm::UDS
|
||||
- ptm:u
|
||||
- pxi:dev
|
||||
- soc:U
|
||||
- ssl:C
|
||||
- y2r:u
|
||||
- ldr:ro
|
||||
- ir:USER
|
||||
|
||||
|
||||
SystemControlInfo:
|
||||
SaveDataSize: 0KB # It doesn't use any save data.
|
||||
RemasterVersion: 2
|
||||
StackSize: 0x40000
|
||||
# JumpId: 0
|
||||
Dependency:
|
||||
ac: 0x0004013000002402L
|
||||
am: 0x0004013000001502L
|
||||
boss: 0x0004013000003402L
|
||||
camera: 0x0004013000001602L
|
||||
cecd: 0x0004013000002602L
|
||||
cfg: 0x0004013000001702L
|
||||
codec: 0x0004013000001802L
|
||||
csnd: 0x0004013000002702L
|
||||
dlp: 0x0004013000002802L
|
||||
dsp: 0x0004013000001a02L
|
||||
friends: 0x0004013000003202L
|
||||
gpio: 0x0004013000001b02L
|
||||
gsp: 0x0004013000001c02L
|
||||
hid: 0x0004013000001d02L
|
||||
http: 0x0004013000002902L
|
||||
i2c: 0x0004013000001e02L
|
||||
ir: 0x0004013000003302L
|
||||
mcu: 0x0004013000001f02L
|
||||
mic: 0x0004013000002002L
|
||||
ndm: 0x0004013000002b02L
|
||||
news: 0x0004013000003502L
|
||||
nim: 0x0004013000002c02L
|
||||
nwm: 0x0004013000002d02L
|
||||
pdn: 0x0004013000002102L
|
||||
ps: 0x0004013000003102L
|
||||
ptm: 0x0004013000002202L
|
||||
ro: 0x0004013000003702L
|
||||
socket: 0x0004013000002e02L
|
||||
spi: 0x0004013000002302L
|
||||
ssl: 0x0004013000002f02L
|
||||
41
libs/sftdlib/sample/source/main.c
Normal file
41
libs/sftdlib/sample/source/main.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <3ds.h>
|
||||
#include <sf2d.h>
|
||||
#include <sftd.h>
|
||||
#include "airstrike_ttf.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
sf2d_init();
|
||||
sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));
|
||||
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
printf("sftd sample\n");
|
||||
|
||||
// Font loading
|
||||
sftd_init();
|
||||
sftd_font *font = sftd_load_font_mem(airstrike_ttf, airstrike_ttf_size);
|
||||
|
||||
while (aptMainLoop()) {
|
||||
|
||||
hidScanInput();
|
||||
if (hidKeysDown() & KEY_START) break;
|
||||
|
||||
sf2d_start_frame(GFX_TOP, GFX_LEFT);
|
||||
|
||||
sftd_draw_text(font, 10, 10, RGBA8(255, 0, 0, 255), 20, "Font drawing on the top screen!");
|
||||
sftd_draw_textf(font, 10, 40, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
|
||||
|
||||
sf2d_end_frame();
|
||||
|
||||
sf2d_swapbuffers();
|
||||
}
|
||||
|
||||
sftd_free_font(font);
|
||||
sftd_fini();
|
||||
|
||||
sf2d_fini();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue