/*
ILI9341_due_gText.cpp - Used for rendering GLCD fonts on Arduino Due
Copyright (c) 2014 Marek Buriak
The library is based on GLCD library by Bill Perry and Michael Margolis:
https://code.google.com/p/glcd-arduino
This file is part of the Arduino ILI9341_due library.
Sources for this library can be found at https://github.com/marekburiak/ILI9341_Due.
Fonts .h files can be created with GLCDFontCreator2 (not the one MikroElektronika):
https://code.google.com/p/glcd-arduino/downloads/detail?name=GLCDFontCreator2.zip&can=2&q=
ILI9341_due is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
ILI9341_due is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ILI9341_due. If not, see .
*/
#ifndef ILI9341_GTEXT_H
#define ILI9341_GTEXT_H
//#include "WString.h"
//#include "../Streaming/Streaming.h"
#include "ILI9341_due.h"
#define INCLUDE_NOT_WORKING_YET 0
#define GTEXT_VERSION 1 // software version of this code
// Font Indices
#define GTEXT_FONT_LENGTH 0
#define GTEXT_FONT_FIXED_WIDTH 2
#define GTEXT_FONT_HEIGHT 3
#define GTEXT_FONT_FIRST_CHAR 4
#define GTEXT_FONT_CHAR_COUNT 5
#define GTEXT_FONT_WIDTH_TABLE 6
#define GTEXT_DRAW_DIRECTION_RIGHT 0
#define GTEXT_DRAW_DIRECTION_DOWN 1
#define GTEXT_DRAW_DIRECTION_LEFT 2
#define GTEXT_DRAW_DIRECTION_UP 3
typedef enum {
gTextFontMode_Solid = 0,
gTextFontMode_Transparent = 1
} gTextFontMode;
// the following returns true if the given font is fixed width
// zero length is flag indicating fixed width font (array does not contain width data entries)
#define isFixedWidthFont(font) (pgm_read_byte(font+GTEXT_FONT_LENGTH) == 0 && pgm_read_byte(font+GTEXT_FONT_LENGTH+1) == 0))
/*
* Coodinates for predefined areas are compressed into a single 32 bit token.
*
* This works as the coordinates are cuurenly only 8 bit values.
*
* This allows the creatation of an unlmited number of predefined areas with zero code or
* data space overhead.
*
* A macro is used to create the tokens from a set of x1,y1 x2,y2 coordinates.
*
* A union is used to extract the coordinates from the 32 bit token.
*
* WARNING:
* This is non portable code in that it will only work on little endian processors.
* If you use big endian you have to switch the byte ordering in the union.
*/
#define MK_TareaToken(x1, y1, x2, y2) \
(uint32_t) (((uint32_t) (x1) << 24) | ((uint32_t)(y1) << 16) | ((uint32_t)(x2) << 8) | (uint32_t)(y2))
/// @cond hide_from_doxygen
typedef union
{
struct
{
uint8_t y2;
uint8_t x2;
uint8_t y1;
uint8_t x1;
}coord;
uint32_t token; // swap byte order above for big endian
}TareaToken;
/// @endcond
typedef uint8_t textMode; // type holding mode for scrolling and future attributes like padding etc.
// the only textMode supported in the current release is scrolling
const textMode SCROLL_UP = 0;
const textMode SCROLL_DOWN = 1; // this was changed from -1 so it can used in a bitmask
const textMode DEFAULT_SCROLLDIR = SCROLL_UP;
/**
* @defgroup glcd_enum GLCD enumerations
*/
/**
* @ingroup glcd_enum
* @hideinitializer
* @brief Pre Defined Text areas
*
* These enumerations are used to easily define text areas
* using predefined display areas.\n
* They are used with the
* \ref gText::DefineArea(predefinedArea selection, textMode mode) "DefineArea()" function call.
*/
typedef enum {
//textAreaFULL = MK_TareaToken( 0, 0, DISPLAY_WIDTH -1, DISPLAY_HEIGHT -1 ),
///**= firstChar && c < (firstChar+charCount)) {
c -= firstChar;
width = pgm_read_byte(font+GTEXT_FONT_WIDTH_TABLE+c);
}
}
return width;
};
static uint16_t stringWidth(const char* str, gTextFont font, uint8_t letterSpacing)
{
uint16_t width = 0;
while(*str != 0) {
width += ILI9341_due_gText::charWidth(*str++, font) + letterSpacing;
}
if(width > 0)
width -= letterSpacing;
return width;
};
//#ifndef USE_ARDUINO_FLASHSTR
// // when the following function is supported in arduino it will be removed from this library
// void printFlash(FLASHSTRING str); //this overrides the Arduino print function to implicilty store the string in flash (progmem)
// void printFlashln(FLASHSTRING str);
//#endif
/*@}*/
};
#endif