mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 23:42:58 +02:00
CComponentsText: add member to use file as text source
This commit is contained in:
@@ -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(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(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 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);
|
virtual void removeLineBreaks(std::string& str);
|
||||||
|
|
||||||
//get a Text Box object, so it's possible to get access directly to its methods
|
//get a Text Box object, so it's possible to get access directly to its methods
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
#include <neutrino.h>
|
#include <neutrino.h>
|
||||||
#include "cc.h"
|
#include "cc.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ void CComponentsText::initCCText()
|
|||||||
string new_text = static_cast <string> (ct_text);
|
string new_text = static_cast <string> (ct_text);
|
||||||
ct_text_sent = ct_textbox->setText(&new_text, ct_box->iWidth);
|
ct_text_sent = ct_textbox->setText(&new_text, ct_box->iWidth);
|
||||||
#ifdef DEBUG_CC
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* fon
|
|||||||
ct_text_mode = mode;
|
ct_text_mode = mode;
|
||||||
ct_font = font_text;
|
ct_font = font_text;
|
||||||
#ifdef DEBUG_CC
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +191,27 @@ void CComponentsText::setText(const int digit, const int mode, Font* font_text)
|
|||||||
#endif
|
#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)
|
void CComponentsText::paintText(bool do_save_bg)
|
||||||
{
|
{
|
||||||
paintInit(do_save_bg);
|
paintInit(do_save_bg);
|
||||||
|
Reference in New Issue
Block a user