64 lines
No EOL
1.3 KiB
C++
64 lines
No EOL
1.3 KiB
C++
#include "textviewer.h"
|
|
|
|
void TextViewer::Draw(TextEngine* t) {
|
|
t->renderText(8.0f, 8.0f, 0.5f, 0.5f, false, std::string("Current File:" + path).c_str());
|
|
|
|
for(int i = textoffset; i < lineEntries.size(); i++) {
|
|
if(i == currentindex) {
|
|
t->renderText(8.0f, (16.0f * i) - (textoffset * 16.0f) + 16.0f, 0.5f, 0.5f, false, std::string(">" + lineEntries[i]).c_str());
|
|
} else {
|
|
t->renderText(8.0f, (16.0f * i) - (textoffset * 16.0f) + 16.0f, 0.5f, 0.5f, false, lineEntries[i].c_str());
|
|
}
|
|
}
|
|
|
|
if(lineEntries.size() <= 0) {
|
|
t->renderText(8.0f, 32.0f, 0.5f, 0.5f, false, "File is empty!");
|
|
}
|
|
}
|
|
|
|
bool TextViewer::Update(u32 key) {
|
|
//Exit viewer
|
|
if(key & KEY_B) {
|
|
return false;
|
|
}
|
|
|
|
if(key & KEY_UP) {
|
|
//Easy fix until i'm bothered to fix the issue
|
|
if(currentindex < 0 | textoffset < 0) {
|
|
currentindex = 0;
|
|
textoffset = 0;
|
|
}
|
|
|
|
if(textoffset != 0) {
|
|
textoffset -= 1;
|
|
currentindex -= 1;
|
|
}
|
|
|
|
if(currentindex != 0) {
|
|
currentindex -= 1;
|
|
}
|
|
}
|
|
|
|
if(key & KEY_DOWN) {
|
|
if(currentindex == 13 + textoffset) {
|
|
textoffset += 1;
|
|
}
|
|
|
|
if(currentindex != lineEntries.size() - 1) {
|
|
currentindex += 1;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TextViewer::Init() {
|
|
std::ifstream input( path );
|
|
for( std::string line; getline( input, line ); )
|
|
{
|
|
lineEntries.push_back(line);
|
|
}
|
|
}
|
|
|
|
void TextViewer::Cleanup() {
|
|
lineEntries.clear();
|
|
} |