Add initConstResources
This commit is contained in:
parent
abd67fe8b7
commit
14f7effb2c
8
Makefile
8
Makefile
@ -11,7 +11,7 @@ FLAGS = -pipe
|
|||||||
CFLAGS = -Wall
|
CFLAGS = -Wall
|
||||||
CFLAGS += -Ofast
|
CFLAGS += -Ofast
|
||||||
CFLAGS += -std=c++17
|
CFLAGS += -std=c++17
|
||||||
#CFLAGS += -g
|
CFLAGS += -g
|
||||||
#CFLAGS += -pg
|
#CFLAGS += -pg
|
||||||
|
|
||||||
#required for rss-cli
|
#required for rss-cli
|
||||||
@ -34,9 +34,9 @@ TARGET = dashboard.out
|
|||||||
|
|
||||||
MAKEFLAGS += --jobs=4
|
MAKEFLAGS += --jobs=4
|
||||||
|
|
||||||
DEFINITIONS = -DDATA='"$(DATA)"'
|
DEFINITIONS = -DDATA_='"$(DATA)"'
|
||||||
DEFINITIONS += -DDATA_IMG='"$(DATA_IMG)"'
|
DEFINITIONS += -DDATA_IMG_='"$(DATA_IMG)"'
|
||||||
DEFINITIONS += -DDATA_FONT='"$(DATA_FONT)"'
|
DEFINITIONS += -DDATA_FONT_='"$(DATA_FONT)"'
|
||||||
|
|
||||||
all : $(OBJ)
|
all : $(OBJ)
|
||||||
@echo LD $@
|
@echo LD $@
|
||||||
|
@ -255,6 +255,10 @@ board::~board(){
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Board init functions ///////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int board::init(){
|
int board::init(){
|
||||||
SDL_Log("Init SDL...\n");
|
SDL_Log("Init SDL...\n");
|
||||||
|
|
||||||
@ -315,13 +319,68 @@ int board::init(){
|
|||||||
// This is called to start the main loop.
|
// This is called to start the main loop.
|
||||||
// This is where most of the logic lives
|
// This is where most of the logic lives
|
||||||
void board::start(){
|
void board::start(){
|
||||||
|
initConstResources();
|
||||||
|
|
||||||
|
SDL_Log("Starting main loop...\n");
|
||||||
for(;;){
|
for(;;){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Grab all constant resources from
|
||||||
|
// the configuration file, as well as
|
||||||
|
// all panel's configurations
|
||||||
|
void board::initConstResources(){
|
||||||
|
//load all resrouces declared in config.hpp
|
||||||
|
std::string fullPath = DATA_DIR;
|
||||||
|
|
||||||
|
SDL_Log("Base path: %s", fullPath.c_str());
|
||||||
|
|
||||||
|
//load images into memory
|
||||||
|
fullPath = DATA_IMG;
|
||||||
|
fullPath += "/";
|
||||||
|
SDL_Log("Static images directory prefix: %s\n", fullPath.c_str());
|
||||||
|
SDL_Log("Loading static images into working memory...\n");
|
||||||
|
for(unsigned int i = 0;
|
||||||
|
i < (sizeof(IMAGE_LOCATIONS)/sizeof(IMAGE_LOCATIONS[0])); ++i){
|
||||||
|
|
||||||
|
SDL_Log("Loaded image %s at memory location %p\n",
|
||||||
|
IMAGE_LOCATIONS[i],
|
||||||
|
setImage(fullPath + IMAGE_LOCATIONS[0]));
|
||||||
|
}
|
||||||
|
SDL_Log("Loaded static images into working memory\n");
|
||||||
|
|
||||||
|
//load fonts into memory
|
||||||
|
fullPath = DATA_FONT;
|
||||||
|
fullPath += "/";
|
||||||
|
SDL_Log("Loading fonts into working memory...\n");
|
||||||
|
for(unsigned int i = 0;
|
||||||
|
i < (sizeof(FONT_LOCATIONS)/sizeof(FONT_LOCATIONS[0])); ++i){
|
||||||
|
|
||||||
|
SDL_Log("Loaded font %s %lu at memory location %p\n",
|
||||||
|
FONT_LOCATIONS[i]._name,
|
||||||
|
FONT_LOCATIONS[i]._size,
|
||||||
|
setFont({FONT_LOCATIONS[i]._name, FONT_LOCATIONS[i]._size}));
|
||||||
|
}
|
||||||
|
SDL_Log("Loaded fonts into working memory\n");
|
||||||
|
|
||||||
|
SDL_Log("Loading static strings into working memory...\n");
|
||||||
|
for(unsigned int i = 0;
|
||||||
|
i < (sizeof(CONST_STRINGS)/sizeof(CONST_STRINGS[0])); ++i){
|
||||||
|
SDL_Log("Loaded string (\"%s\") with font %s %lu at memory location %p\n",
|
||||||
|
CONST_STRINGS[i]._text,
|
||||||
|
CONST_STRINGS[i]._font_size._name,
|
||||||
|
CONST_STRINGS[i]._font_size._size,
|
||||||
|
setString(CONST_STRINGS[i]._text,
|
||||||
|
{ CONST_STRINGS[i]._font_size._name,
|
||||||
|
CONST_STRINGS[i]._font_size._size }));
|
||||||
|
}
|
||||||
|
SDL_Log("Loaded static strings into working memory\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Memory Functions ///////////////////////////////////////////////////////////
|
// Memory Functions ///////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -350,7 +409,7 @@ TTF_Font* board::getFont(const font_and_size& fs){
|
|||||||
if(_fonts.find(fs) != _fonts.end())
|
if(_fonts.find(fs) != _fonts.end())
|
||||||
return _fonts.find(fs)->second.font();
|
return _fonts.find(fs)->second.font();
|
||||||
|
|
||||||
//Dynamic Fonts? Is the needed?
|
//TODO: Dynamic Fonts? Is the needed?
|
||||||
//not found, return null
|
//not found, return null
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ namespace dashboard {
|
|||||||
SDL_Texture_Wrapper, string_and_font_hash> _dynamic_strings;
|
SDL_Texture_Wrapper, string_and_font_hash> _dynamic_strings;
|
||||||
|
|
||||||
//TODO: Dynamic images?
|
//TODO: Dynamic images?
|
||||||
|
//TODO: Dynamic Fonts?
|
||||||
|
|
||||||
//local pointers to the globals
|
//local pointers to the globals
|
||||||
SDL_Window* _window;
|
SDL_Window* _window;
|
||||||
|
@ -74,7 +74,15 @@ constexpr int IMG_FLAGS = 0
|
|||||||
// DATA_DIR
|
// DATA_DIR
|
||||||
// Where all resources will be
|
// Where all resources will be
|
||||||
// Keep this as DATA to use the install dir set in the makefile
|
// Keep this as DATA to use the install dir set in the makefile
|
||||||
constexpr char DATA_DIR[] = DATA;
|
constexpr char DATA_DIR[] = DATA_ ;
|
||||||
|
|
||||||
|
// IMG_DIR
|
||||||
|
// Where all images are
|
||||||
|
// Keep this a DATA_IMG_ to use the DATA_IMG dir defined in the makefile
|
||||||
|
constexpr char DATA_IMG[] = DATA_IMG_;
|
||||||
|
|
||||||
|
//TODO: Add directory prefix for each of these, and change it so it doesnt use
|
||||||
|
//that whole path as the key for the file
|
||||||
|
|
||||||
// IMAGE_LOCATIONS
|
// IMAGE_LOCATIONS
|
||||||
// Locations of all static images used
|
// Locations of all static images used
|
||||||
@ -82,14 +90,27 @@ static const char* IMAGE_LOCATIONS[] = {
|
|||||||
"img/bmp_24.png",
|
"img/bmp_24.png",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FONT_DIR
|
||||||
|
// Where all fonts are kept
|
||||||
|
// Keep this as FONT_DIR_ to use the DATA_FONT dir defined in the makefile
|
||||||
|
constexpr char DATA_FONT[] = DATA_FONT_;
|
||||||
|
|
||||||
// FONT_LOCATIONS
|
// FONT_LOCATIONS
|
||||||
// Locations of all fonts used
|
// Locations of all fonts used
|
||||||
static const char* FONT_LOCATIONS[] = {
|
struct FONT_SIZE {
|
||||||
"font/ielianto-normal.ttf",
|
const char* _name;
|
||||||
|
const size_t _size;
|
||||||
|
};
|
||||||
|
static const FONT_SIZE FONT_LOCATIONS[] = {
|
||||||
|
{ "elianto-normal.ttf", 24 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// CONST_STRINGS
|
// CONST_STRINGS
|
||||||
// All constant strings
|
// All constant strings
|
||||||
static const char* CONST_STRINGS[] = {
|
struct FONT_SIZE_STRING {
|
||||||
|
const char* _text;
|
||||||
|
const FONT_SIZE _font_size;
|
||||||
|
};
|
||||||
|
static const FONT_SIZE_STRING CONST_STRINGS[] = {
|
||||||
|
{ "Test string 12345", FONT_LOCATIONS[1] },
|
||||||
};
|
};
|
||||||
|
10
src/main.cpp
10
src/main.cpp
@ -8,13 +8,19 @@
|
|||||||
#include "handler/handler.hpp"
|
#include "handler/handler.hpp"
|
||||||
#include "board.hpp"
|
#include "board.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
dashboard::handlers::setHandlers();
|
dashboard::handlers::setHandlers();
|
||||||
|
|
||||||
dashboard::board _board;
|
dashboard::board _board(false);
|
||||||
|
|
||||||
|
if(_board.init() != 0){
|
||||||
|
std::cerr << "Due to errors, " << argv[0]
|
||||||
|
<< " was unable to start, quitting!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
_board.start();
|
_board.start();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user