mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[Kandinsky] Create a KDText class for text measurement
Change-Id: Ie3ecd402b5476f41a2f8694a276f62495fbcdbd1
This commit is contained in:
@@ -17,7 +17,7 @@ void TextView::setText(const char * text) {
|
||||
}
|
||||
|
||||
void TextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
KDSize textSize = ctx->stringSize(m_text);
|
||||
KDSize textSize = KDText::stringSize(m_text);
|
||||
KDPoint origin = {
|
||||
(KDCoordinate)(m_horizontalAlignment*(m_frame.width() - textSize.width())),
|
||||
(KDCoordinate)(m_verticalAlignment*(m_frame.height() - textSize.height()))
|
||||
|
||||
@@ -13,6 +13,7 @@ objs += $(addprefix kandinsky/src/,\
|
||||
point.o\
|
||||
rect.o\
|
||||
size.o\
|
||||
text.o\
|
||||
)
|
||||
tests += $(addprefix kandinsky/test/,\
|
||||
color.cpp\
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
#include <kandinsky/point.h>
|
||||
#include <kandinsky/rect.h>
|
||||
#include <kandinsky/size.h>
|
||||
#include <kandinsky/text.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,6 @@ public:
|
||||
// Text
|
||||
void drawChar(char character, KDPoint p, uint8_t inverse);
|
||||
void drawString(const char * text, KDPoint p, uint8_t inverse);
|
||||
KDSize stringSize(const char * text);
|
||||
|
||||
// Line. Not anti-aliased.
|
||||
void drawLine(KDPoint p1, KDPoint p2, KDColor c);
|
||||
|
||||
11
kandinsky/include/kandinsky/text.h
Normal file
11
kandinsky/include/kandinsky/text.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef KANDINSKY_TEXT_H
|
||||
#define KANDINSKY_TEXT_H
|
||||
|
||||
#include <kandinsky/size.h>
|
||||
|
||||
class KDText {
|
||||
public:
|
||||
static KDSize stringSize(const char * text);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <kandinsky/context.h>
|
||||
#include <string.h>
|
||||
#include "font.h"
|
||||
|
||||
void KDContext::drawChar(char character, KDPoint p, uint8_t inverse) {
|
||||
@@ -24,7 +23,3 @@ void KDContext::drawString(const char * text, KDPoint p, uint8_t inverse) {
|
||||
position = position.translatedBy(characterSize);
|
||||
}
|
||||
}
|
||||
|
||||
KDSize KDContext::stringSize(const char * text) {
|
||||
return KDSize(BITMAP_FONT_CHARACTER_WIDTH*strlen(text), BITMAP_FONT_CHARACTER_HEIGHT);
|
||||
}
|
||||
|
||||
7
kandinsky/src/text.cpp
Normal file
7
kandinsky/src/text.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <kandinsky/text.h>
|
||||
#include <string.h>
|
||||
#include "font.h"
|
||||
|
||||
KDSize KDText::stringSize(const char * text) {
|
||||
return KDSize(BITMAP_FONT_CHARACTER_WIDTH*strlen(text), BITMAP_FONT_CHARACTER_HEIGHT);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ extern "C" {
|
||||
void print(const char * message) {
|
||||
static int line_y = 0;
|
||||
KDContext * ctx = KDIonContext::sharedContext();
|
||||
int line_height = ctx->stringSize("M").height();
|
||||
int line_height = KDText::stringSize("M").height();
|
||||
ctx->drawString(message, KDPoint(0, line_y), 0);
|
||||
line_y += line_height;
|
||||
if (line_y > ION_SCREEN_HEIGHT) {
|
||||
|
||||
Reference in New Issue
Block a user