set text font

master
wgroeneveld 4 years ago
parent feaa1b6054
commit be7492a4b6
  1. 1
      .travis.yml
  2. 7
      README.md
  3. 5
      engine/include/libgba-sprite-engine/background/text_stream.h
  4. 15
      engine/src/background/text_stream.cpp

@ -26,6 +26,7 @@ before_install:
- mkdir build
- cp libgtest_main.so build/libgtest_main.a
- cp libgtest.so build/libgtest.a
# still needed to actually execute the binary
- sudo cp -a include/gtest /usr/include
- sudo cp -a libgtest_main.so libgtest.so /usr/lib/

@ -1,7 +1,7 @@
## A high-level object-oriented Gameboy Advance sprite engine library
![travis build status](https://travis-ci.org/wgroeneveld/gba-sprite-engine.svg?branch=master)
[![Build Status](https://travis-ci.org/wgroeneveld/gba-sprite-engine.svg?branch=master)](https://travis-ci.org/wgroeneveld/gba-sprite-engine)
That's a mouthful - let's break that down:
@ -160,7 +160,10 @@ Useful text manipulation:
* `setText(txt, row, col)`
* `<< text` or `<< int` etc: append to text stream for debugging purposes.
* `setTextColor(COLOR)`: changes default color palette (white).
* `setFontColor(COLOR)`: changes default color palette (white).
* `setFontStyle(const void* data, int size)` if you prefer your own font face.
Changing the font style assumes a tile width of 32 and the same symbol indexes! It also resets the font color and map so call this before doing anything else.
#### Error logging

@ -35,7 +35,10 @@ public:
void clear();
void setText(std::string text, int row, int col);
void setText(const char* text, int row, int col);
void setTextColor(COLOR color);
void setFontColor(COLOR color);
void setFontStyle(const void *data, int size);
static TextStream& instance();
void persist() override;

@ -21,7 +21,7 @@ TextStream::TextStream() : Background(0, text_data, sizeof(text_data), nullptr,
this->palette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager());
persist();
clearMap();
clear();
}
void log_text(const char* text) {
@ -94,12 +94,21 @@ TextStream& TextStream::operator<<(const char * s) {
return *this;
}
void TextStream::setTextColor(COLOR color) {
// WARNING: resets map and font color. Assumes a fixed tile width of TILE_WIDTH
void TextStream::setFontStyle(const void *data, int size) {
this->data = data;
this->size = size;
persist();
clear();
}
void TextStream::setFontColor(COLOR color) {
palette.get()->change(PALETTE_TEXT_BANK, PALETTE_COLOR_INDEX, color);
}
void TextStream::persist() {
Background::persist();
// WARNING: stream hijacks last bg palette bank, last index, no matter what.
setTextColor(PaletteManager::color(31, 31, 31));
setFontColor(PaletteManager::color(31, 31, 31));
}

Loading…
Cancel
Save