Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

TextSelection.cpp

00001 //Licence: LGPL 00002 //Copyright: Visti Andresen 00003 00004 #include "TextSelection.h" 00005 00006 TextSelection::TextSelection(const string &label, const string &name, vector<string> &choices, Font *font) 00007 { 00008 label_ = label; 00009 name_ = name; 00010 choices_ = choices; 00011 font_ = font; 00012 currentSelection_ = 0; 00013 } 00014 00015 TextSelection::~TextSelection() 00016 { 00017 } 00018 00019 void TextSelection::load(ifstream &file) 00020 { 00021 if (findLoadPosition(name_, file)){ 00022 file >> currentSelection_ ; 00023 } 00024 } 00025 00026 void TextSelection::save(ofstream &file) 00027 { 00028 file << name_ << "="<<currentSelection_<<endl; 00029 } 00030 00031 void TextSelection::draw(float x, float y, float zoom) 00032 { 00033 font_->printString(label_+ choices_[currentSelection_], x, y, zoom); 00034 } 00035 00036 float TextSelection::getWidth(float zoom) 00037 { 00038 return font_->getWidth(label_+ choices_[currentSelection_], zoom); 00039 } 00040 00041 float TextSelection::getHeight(float zoom) 00042 { 00043 return font_->getHeight(zoom); 00044 } 00045 00046 bool TextSelection::handleKeyEvent(SDL_Event *event) 00047 { 00048 if (event->type != SDL_KEYDOWN) return false; 00049 if (event->key.keysym.sym == SDLK_RIGHT) { 00050 currentSelection_++; 00051 if (currentSelection_ >= choices_.size()) currentSelection_ = 0; 00052 return true; 00053 } 00054 if (event->key.keysym.sym == SDLK_LEFT) { 00055 if (currentSelection_==0) currentSelection_= choices_.size()-1; 00056 else currentSelection_--; 00057 00058 return true; 00059 } 00060 return false; 00061 }

Generated on Wed Sep 1 14:46:57 2004 by doxygen 1.3.7