diff --git a/kandinsky/include/kandinsky/context.h b/kandinsky/include/kandinsky/context.h index 9113644b0..673e4d737 100644 --- a/kandinsky/include/kandinsky/context.h +++ b/kandinsky/include/kandinsky/context.h @@ -16,7 +16,7 @@ public: // Text void drawChar(char character, KDPoint p, KDText::FontSize size = KDText::FontSize::Large, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); - void drawString(const char * text, KDPoint p, KDText::FontSize size = KDText::FontSize::Large, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); + void drawString(const char * text, KDPoint p, KDText::FontSize size = KDText::FontSize::Large, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite, int maxLength = -1); void blendChar(char character, KDPoint p, KDText::FontSize size, KDColor textColor = KDColorBlack); void blendString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor = KDColorBlack); diff --git a/kandinsky/src/context_text.cpp b/kandinsky/src/context_text.cpp index a4a9111bd..965443702 100644 --- a/kandinsky/src/context_text.cpp +++ b/kandinsky/src/context_text.cpp @@ -27,11 +27,13 @@ void KDContext::drawChar(char character, KDPoint p, KDText::FontSize size, KDCol characterBuffer); } -void KDContext::drawString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor) { +void KDContext::drawString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, int maxLength) { KDPoint position = p; int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH; KDPoint characterSize(characterWidth, 0); - while(*text != 0) { + + const char * end = text+maxLength; + while(*text != 0 && text != end) { drawChar(*text, position, size, textColor, backgroundColor); text++; position = position.translatedBy(characterSize);