diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 20fe1a886..892038ee3 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -213,6 +213,7 @@ class CComponentsText : public CComponentsItem virtual void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); + virtual void setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void removeLineBreaks(std::string& str); //get a Text Box object, so it's possible to get access directly to its methods diff --git a/src/gui/components/cc_item_text.cpp b/src/gui/components/cc_item_text.cpp index cd87db762..916a67231 100644 --- a/src/gui/components/cc_item_text.cpp +++ b/src/gui/components/cc_item_text.cpp @@ -32,6 +32,8 @@ #include #include "cc.h" #include +#include +#include using namespace std; @@ -137,7 +139,7 @@ void CComponentsText::initCCText() string new_text = static_cast (ct_text); ct_text_sent = ct_textbox->setText(&new_text, ct_box->iWidth); #ifdef DEBUG_CC - printf(" [CComponentsText] [%s - %d] init text: %s [x %d, y %d, h %d, w %d]\n", __FUNCTION__, __LINE__, ct_text, ct_box->iX, ct_box->iY, height, width); + printf(" [CComponentsText] [%s - %d] init text: %s [x %d, y %d, h %d, w %d]\n", __FUNCTION__, __LINE__, ct_text.c_str(), ct_box->iX, ct_box->iY, height, width); #endif } @@ -158,7 +160,7 @@ void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* fon ct_text_mode = mode; ct_font = font_text; #ifdef DEBUG_CC - printf(" [CComponentsText] [%s - %d] ct_text: %s \n", __FUNCTION__, __LINE__, ct_text); + printf(" [CComponentsText] [%s - %d] ct_text: %s \n", __FUNCTION__, __LINE__, ct_text.c_str()); #endif } @@ -189,6 +191,27 @@ void CComponentsText::setText(const int digit, const int mode, Font* font_text) #endif } +//set text lines directly from a file +void CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text) +{ + string file = path_to_textfile; + string txt = ""; + + ifstream in (file.c_str(), ios::in); + if (!in){ + printf("[CComponentsText] [%s - %d] error while open %s -> %s\n", __FUNCTION__, __LINE__, file.c_str(), strerror(errno)); + return; + } + string line; + + while(getline(in, line)){ + txt += line + '\n'; + } + in.close(); + + setText(txt, mode, font_text); +} + void CComponentsText::paintText(bool do_save_bg) { paintInit(do_save_bg);