00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SCROLLING_LABEL_H
00019 #define SCROLLING_LABEL_H
00020
00021 #include "../constants.h"
00022 #include "widget.h"
00023 #include "button.h"
00024 #include "window.h"
00025 #include "draganddrop.h"
00026 #include <vector>
00027
00028 using namespace std;
00029
00035 class WordClickedHandler {
00036 public:
00037 WordClickedHandler() {
00038 }
00039
00040 virtual ~WordClickedHandler() {
00041 }
00042
00043 virtual void wordClicked( char *word ) = 0;
00044 virtual void showingWord( char *word ) = 0;
00045 };
00046
00047 class ScrollingLabel : public Widget {
00048 protected:
00049 char text[3000];
00050 int lineWidth;
00051 vector<string> lines;
00052
00053
00054
00055
00056
00057 int value;
00058 int scrollerWidth, scrollerHeight;
00059 int listHeight;
00060 bool willSetScrollerHeight;
00061 float alpha, alphaInc;
00062 GLint lastTick;
00063 bool inside;
00064 int scrollerY;
00065 bool dragging;
00066 int dragX, dragY;
00067 int selectedLine;
00068
00069 bool innerDrag;
00070 int innerDragX, innerDragY;
00071
00072
00073 bool canGetFocusVar;
00074
00075 map<char, Color> coloring;
00076
00077 typedef struct _WordPos {
00078 int x, y, w, h;
00079 char word[255];
00080 } WordPos;
00081 WordPos wordPos[1000];
00082 int wordPosCount;
00083 WordClickedHandler *handler;
00084
00085 public:
00086
00087 bool debug;
00088
00089 ScrollingLabel(int x, int y, int w, int h, char *text );
00090 virtual ~ScrollingLabel();
00091
00092 inline void setWordClickedHandler( WordClickedHandler *handler ) { this->handler = handler; }
00093
00094 inline void addColoring( char c, Color color ) { coloring[c]=color; }
00095
00096 inline char *getText() { return text; }
00097 void setText(char *s);
00098
00099
00100
00101
00102
00103
00104
00105
00106 void drawWidget(Widget *parent);
00107
00113 bool handleEvent(Widget *parent, SDL_Event *event, int x, int y);
00114
00115 void removeEffects(Widget *parent);
00116
00117
00118 virtual inline bool hasSound() { return false; }
00119
00120 inline bool canGetFocus() { return canGetFocusVar; }
00121 inline void setCanGetFocus(bool b) { this->canGetFocusVar = b; }
00122
00123 private:
00124 char *printLine( Widget *parent, int x, int y, char *s );
00125 int getWordPos( int x, int y );
00126
00127
00128 };
00129
00130 #endif
00131