00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(__INCLUDE_GLWListViewh_INCLUDE__)
00023 #define __INCLUDE_GLWListViewh_INCLUDE__
00024
00025 #include <GLW/GLWidget.h>
00026 #include <GLW/GLWScrollW.h>
00027 #include <XML/XMLNode.h>
00028 #include <common/Vector.h>
00029 #include <vector>
00030 #include <string>
00031 #include <map>
00032
00033 class GLWListViewI
00034 {
00035 public:
00036 virtual void url(const char *url) = 0;
00037 virtual void event(std::map<std::string, std::string> &event) = 0;
00038 };
00039
00040 class GLWListView :
00041 public GLWidget
00042 {
00043 public:
00044 GLWListView(float x = 0.0f, float y = 0.0f,
00045 float w = 0.0f, float h = 0.0f,
00046 int maxLen = -1, float textSize = 10.0f,
00047 float scrollSpeed = 0.0f);
00048 virtual ~GLWListView();
00049
00050 void setHandler(GLWListViewI *handler) { handler_ = handler; }
00051 void setColor(Vector &color) { color_ = color; }
00052
00053 bool addXML(XMLNode *node);
00054 void addLine(const std::string &text);
00055 void clear();
00056 void resetPosition();
00057 void endPosition();
00058
00059 virtual void draw();
00060 virtual void simulate(float frameTime);
00061 virtual void mouseDown(int button, float x, float y, bool &skipRest);
00062 virtual void mouseUp(int button, float x, float y, bool &skipRest);
00063 virtual void mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest);
00064 virtual void mouseWheel(float x, float y, float z, bool &skipRest);
00065
00066 virtual void setX(float x) { x_ = x; scroll_.setX(x_ + w_ - 17); }
00067 virtual void setY(float y) { y_ = y; scroll_.setY(y_); }
00068 virtual void setW(float w) { w_ = w; scroll_.setX(x_ + w_ - 17); }
00069 virtual void setH(float h) { h_ = h; scroll_.setH(h_ - 1); }
00070
00071 REGISTER_CLASS_HEADER(GLWListView);
00072
00073 protected:
00074 struct WordEntry
00075 {
00076 WordEntry(const char *word, Vector &color) :
00077 word_(word), color_(color), wordRef_(0) { }
00078
00079 unsigned wordRef_;
00080 static unsigned wordRefCount_;
00081
00082 Vector color_;
00083 std::string href_;
00084 std::string word_;
00085 std::map<std::string, std::string> event_;
00086 };
00087 struct LineEntry
00088 {
00089 std::vector<WordEntry> words_;
00090 };
00091 struct UrlEntry
00092 {
00093 float x_, y_;
00094 float w_, h_;
00095 WordEntry *entry_;
00096 };
00097
00098 GLWListViewI *handler_;
00099 float currentPosition_;
00100 float scrollSpeed_;
00101 float textSize_;
00102 int maxLen_;
00103 Vector color_;
00104 GLWScrollW scroll_;
00105 std::vector<LineEntry> lines_;
00106 std::vector<UrlEntry> urls_;
00107
00108 void setScroll();
00109 bool addWordEntry(std::list<WordEntry> &words,
00110 std::string &word, XMLNode *parentNode);
00111 bool getLines(std::list<WordEntry> &words, float &lineLen);
00112 bool getWords(XMLNode *node, std::list<WordEntry> &words);
00113 void drawUrl(WordEntry &entry, int drawChars, float x, float y);
00114 };
00115
00116 #endif