Comments (1)
#define TEXT_ALIGN_CENTER 0
#define TEXT_ALIGN_RIGHT 1
#define TEXT_ALIGN_LEFT 2
const uint8_t fontDepartureBoard[96][10] = {{3,0,0,0,0,0,0,0,0,0},{1,1,1,1,1,1,0,1,0,0},{3,5,5,5,0,0,0,0,0,0},{5,10,10,31,10,31,10,10,0,0},{5,0,0,0,0,0,0,0,0,0},{5,0,0,0,0,0,0,0,0,0},{5,6,9,6,21,9,9,22,0,0},{1,1,1,0,0,0,0,0,0,0},{3,4,2,1,1,1,2,4,0,0},{3,1,2,4,4,4,2,1,0,0},{5,0,0,0,0,0,0,0,0,0},{5,0,0,4,4,31,4,4,0,0},{2,0,0,0,0,0,0,2,2,1},{4,0,0,0,15,0,0,0,0,0},{1,0,0,0,0,0,0,1,0,0},{4,8,12,4,6,2,3,1,0,0},{4,6,9,9,9,9,9,6,0,0},{4,2,3,2,2,2,2,7,0,0},{4,6,9,8,4,2,1,15,0,0},{4,6,9,8,4,8,9,6,0,0},{4,8,12,10,9,15,8,8,0,0},{4,15,1,7,8,8,9,6,0,0},{4,6,9,1,7,9,9,6,0,0},{4,15,8,4,2,2,2,2,0,0},{4,6,9,9,6,9,9,6,0,0},{4,6,9,9,14,8,9,6,0,0},{1,0,0,1,0,0,1,0,0,0},{1,0,0,1,0,0,1,1,0,0},{4,8,4,2,1,2,4,8,0,0},{4,0,0,15,0,15,0,0,0,0},{4,1,2,4,8,4,2,1,0,0},{5,14,17,16,8,4,0,4,0,0},{5,0,0,0,0,0,0,0,0,0},{4,6,9,9,15,9,9,9,0,0},{4,7,9,9,7,9,9,7,0,0},{4,6,9,1,1,1,9,6,0,0},{4,7,9,9,9,9,9,7,0,0},{4,15,1,1,7,1,1,15,0,0},{4,15,1,1,7,1,1,1,0,0},{4,6,9,1,13,9,9,6,0,0},{4,9,9,9,15,9,9,9,0,0},{3,7,2,2,2,2,2,7,0,0},{4,15,4,4,4,4,5,2,0,0},{4,9,9,5,3,5,9,9,0,0},{4,1,1,1,1,1,1,15,0,0},{5,17,27,21,17,17,17,17,0,0},{4,9,11,13,9,9,9,9,0,0},{4,6,9,9,9,9,9,6,0,0},{4,7,9,9,7,1,1,1,0,0},{4,6,9,9,9,9,6,12,0,0},{4,7,9,9,7,5,9,9,0,0},{4,6,9,1,6,8,9,6,0,0},{5,31,4,4,4,4,4,4,0,0},{4,9,9,9,9,9,9,6,0,0},{5,17,17,17,17,17,10,4,0,0},{5,17,17,17,21,21,27,17,0,0},{5,17,10,4,4,4,10,17,0,0},{5,17,17,10,4,4,4,4,0,0},{5,31,16,8,4,2,1,31,0,0},{3,7,1,1,1,1,1,7,0,0},{4,1,3,2,6,4,12,8,0,0},{3,7,4,4,4,4,4,7,0,0},{5,4,10,17,0,0,0,0,0,0},{5,0,0,0,0,0,0,31,0,0},{5,0,0,0,0,0,0,0,0,0},{4,0,0,6,8,14,9,14,0,0},{4,1,1,7,9,9,9,7,0,0},{4,0,0,14,1,1,1,14,0,0},{4,8,8,14,9,9,9,14,0,0},{4,0,0,6,9,7,1,14,0,0},{4,4,10,2,7,2,2,2,0,0},{4,0,0,6,9,9,9,14,8,7},{4,1,1,5,11,9,9,9,0,0},{1,1,0,1,1,1,1,1,0,0},{3,4,0,4,4,4,4,4,5,2},{4,1,1,9,5,3,5,9,0,0},{2,2,2,2,2,2,2,2,0,0},{5,0,0,11,21,21,17,17,0,0},{4,0,0,5,11,9,9,9,0,0},{4,0,0,6,9,9,9,6,0,0},{4,0,0,7,9,9,9,7,1,1},{4,0,0,14,9,9,9,14,8,8},{4,0,0,5,11,1,1,1,0,0},{4,0,0,14,1,6,8,7,0,0},{4,2,2,7,2,2,2,12,0,0},{4,0,0,9,9,9,9,6,0,0},{5,0,0,17,17,17,10,4,0,0},{5,0,0,17,17,21,21,10,0,0},{5,0,0,17,10,4,10,17,0,0},{4,0,0,9,9,9,9,14,8,7},{5,0,0,31,8,4,2,31,0,0},{5,0,0,0,0,0,0,0,0,0},{1,1,1,1,1,1,1,1,0,0},{5,0,0,0,0,0,0,0,0,0},{5,0,0,2,21,8,0,0,0,0},{5,0,0,0,0,0,0,0,0,0}};
void drawStringAligned(uint8_t x, uint8_t y, uint8_t width, uint8_t charWidth, uint8_t alignment, rgb24 colour, const char* str){
uint8_t xPos = 0;
uint8_t strLen = strlen(str);
uint8_t strWidth = (strLen * charWidth);
// set position of text within container
switch(alignment){
case TEXT_ALIGN_LEFT:
xPos=0;
break;
case TEXT_ALIGN_RIGHT:
xPos = (width-strWidth);
break;
case TEXT_ALIGN_CENTER:
xPos = (width-strWidth)/2;
break;
}
backgroundLayer.drawString(xPos, y, colour, str);
}
/*******************************************************
* drawString
* IN
* int x x position of text
* int y y position of text
* uint8_t width of text container (only needed for text align right/center)
* uint16_t vertical mask (useful when scrolling text up/down without over writing graphics above/below)
* uint8_t text alignment within its container (TEXT_ALIGN_CENTER,TEXT_ALIGN_RIGHT,TEXT_ALIGN_LEFT)
* rgb24 text colour
* String text to be displayed
*
* int length in pixels of drawn text
********************************************************/
int drawString(int x, int y, uint8_t width, uint16_t mask, uint8_t alignment, rgb24 colour, String str){
uint8_t xPos = 0;
uint8_t len = 0;
uint8_t w;
// pre calculate text width
for(uint8_t i=0; str[i]!='\0'; ++i)
len += fontDepartureBoard[ str[i]-32 ][0]+1;
xPos = len-1;
// check text is actually within the display canvas, if not DONT draw it! (but still return the length of the string in pixels)
if((x>=kMatrixWidth) || (x+len<=0))
return len;
// set position of text within container
switch(alignment){
case TEXT_ALIGN_LEFT:
xPos=0;
break;
case TEXT_ALIGN_RIGHT:
xPos = (width-xPos);
break;
case TEXT_ALIGN_CENTER:
xPos = (width-xPos)/2;
break;
}
for(uint8_t i=0; str[i]!='\0'; ++i){
w = drawChar(x+xPos,y,mask,colour,str[i]);
xPos+=(1+w);
if(xPos>width && width!=0)
break;
}
return len;
}
uint8_t drawChar(int xPos, int yPos, uint16_t mask, rgb24 colour, char character){
uint8_t width = fontDepartureBoard[character-32][0];
// each font row
for(uint8_t y=0; y<9; y++){
if(mask & 0x1){
uint8_t fontRowData = fontDepartureBoard[character-32][y+1];
// for each font row pixel
for(uint8_t x=0; x<width; x++){
if(fontRowData & 0x1)
backgroundLayer.drawPixel(x+xPos,y+yPos,colour);
fontRowData>>=1;
}
}
mask>>=1;
}
return width;
}
from smartmatrix.
Related Issues (20)
- Using a custom font misplaces the text with GFX enabled HOT 1
- Add more MultiRowRefreshMappings HOT 1
- ESP32-S2 Support
- Teensy 4: Default FlexIO clock configuration is invalid HOT 6
- How do I best make 30 independent lines manageable with the Raspberry Pi HOT 2
- Support for Custom ScrollModes HOT 2
- ESP32 call to draw the ellipse function is bound to die problem HOT 7
- Faster integers?
- Update to arduino-esp32 v2.0.3 HOT 3
- Weird /4 scan HUB75 matrix HOT 3
- ESP32 S3 Support HOT 2
- scroll with offset
- Can't compile to ESP32 HOT 3
- Can't seem to increase brightness. HOT 2
- Wiring a Teensy 4.1 without SmartLED Shield HOT 2
- add single track 128x64 support
- Slight tearing on 64x64 screen HOT 1
- Apparent v4.0.3 Arduino Library Content Mismatch HOT 1
- create ability to check scrolling layer's position and possibly be able to pause/resume it HOT 2
- Wy i can't compile ?! Thanks for help HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smartmatrix.