00001
00002
00003
00004 #ifndef CSGRAFIK_ELEMENT_h
00005 #define CSGRAFIK_ELEMENT_h
00006
00007 #ifdef WIN32
00008 #pragma warning(disable : 4786 )
00009 #endif
00010
00011 const int BORDER_STATE_VISIBLE = 1;
00012 const int BORDER_STATE_PRESSED = 2;
00013 const int BORDER_STATE_HOVERING = 4;
00014 const int BORDER_STATE_FOCUSED = 8;
00015 const int BORDER_STATE_ACTIVATED = 16;
00016 const int BORDER_STATE_ENABLED = 32;
00017
00018 const int BORDER_STATE_DEFAULT = BORDER_STATE_VISIBLE;
00019
00020
00021 const int BUTTON_VISIBLE = BORDER_STATE_VISIBLE;
00022 const int BUTTON_PRESSED = BORDER_STATE_PRESSED;
00023 const int BUTTON_HOVERING = BORDER_STATE_HOVERING;
00024 const int BUTTON_FOCUSED = BORDER_STATE_FOCUSED;
00025 const int BUTTON_ACTIVATED = BORDER_STATE_ACTIVATED;
00026 const int BUTTON_ENABLED = BORDER_STATE_ENABLED;
00027
00028 const int BUTTON_DEFAULT = BUTTON_VISIBLE + BUTTON_ENABLED;
00029
00030 const int POSITION_NOT_SET = -1;
00031 const int POSITION_NORTH = 0;
00032 const int POSITION_SOUTH = 1;
00033 const int POSITION_EAST = 2;
00034 const int POSITION_WEST = 3;
00035 const int POSITION_CENTER = 4;
00036 const int POSITION_ABSOLUT = 5;
00037
00038
00039 const int POSITION_ORDER_TOP = POSITION_NORTH;
00040 const int POSITION_ORDER_BOTTOM = POSITION_SOUTH;
00041 const int POSITION_ORDER_LEFT = POSITION_WEST;
00042 const int POSITION_ORDER_RIGHT = POSITION_EAST;
00043
00044 const int TYPE_HORIZONTAL = 0;
00045 const int TYPE_VERTICAL = 1;
00046
00047 const int TYPE_CHANGE_UP = 1;
00048 const int TYPE_CHANGE_INIT = 2;
00049 const int TYPE_CHANGE_DOWN = -1;
00050 const int TYPE_CHANGE_ONLY_ME = -2;
00051
00052 const int LAYOUT_ELEMENT = 1;
00053 const int LAYOUT_INTERNAL = 8;
00054 const int LAYOUT_LAYOUT = 16;
00055 const int LAYOUT_MOVE = 2;
00056 const int LAYOUT_SIZE = 4;
00057 const int LAYOUT_NOT = 0;
00058
00059 #include <vector>
00060 #include <string>
00061
00062 #include "SDLMain.h"
00063 #include "CSMessageListener.h"
00064 #include "CSLAF.h"
00065 #include "CSLog.h"
00066 #include "CSLayoutManager.h "
00067 #include "CSInset.h"
00068
00069 class CSGrafikElement;
00070 class CSFont;
00071 class CSBorder;
00072 class CSDesktop;
00073 class CSWindow;
00074 class CSScrollbar;
00075 class CSArea;
00076 class CSLayoutManager;
00077
00078 typedef std::vector<CSGrafikElement *> CSGrafikElements;
00079
00080 const int MOUSE_CURSOR_TYPE_DEFAULT = 0;
00081 const int MOUSE_CURSOR_TYPE_SIZING = 1;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 class CSGrafikElement : public CSMessageDispatchable, public CSMessageListener
00168 {
00169 friend CSDesktop;
00170 friend CSLayoutManager;
00171 friend CSWindow;
00172 private:
00173 CSLayoutManager *mLayoutManager;
00174 CSLayoutData mLayoutData;
00175 bool mFrontElement;
00176 bool mLayoutChanged;
00177
00178 CSGrafikElement *mMainElement;
00179 int mX;
00180 int mY;
00181 int mViewportX;
00182 int mViewportY;
00183 int mViewportHeight;
00184 int mViewportWidth;
00185 int mViewportOffsetX;
00186 int mViewportOffsetY;
00187 SDL_Rect mElementArea;
00188 SDL_Rect mViewportArea;
00189 int getElementMaxX();
00190 int getElementMaxY();
00191
00192 void removeMainAllElements() {mElements.clear(); }
00193 CSGrafikElement *getElement(int x, int y, SDL_Rect *parentViewport, int &receiverX, int &receiverY);
00194 CSGrafikElements *getElements() {return &mElements; }
00195
00196 bool mFocusable;
00197
00198 bool mFocused;
00199 bool mModal;
00200 bool mEnabled;
00201 bool mActivated;
00202 bool mActive;
00203
00204 bool mBackGroundColorSet;
00205 int mBackgroundColor;
00206 bool mTextColorSet;
00207 int mTextColor;
00208 bool mHorizontalElementSpacingSet;
00209 int mHorizontalElementSpacing;
00210 bool mVerticalElementSpacingSet;
00211 int mVerticalElementSpacing;
00212
00213 int mCurrentLAFId;
00214 int mCursorType;
00215
00216 CSBorder *mBorder;
00217 CSArea *mArea;
00218 CSFont *mFont;
00219 int mStyle;
00220 std::string mType;
00221
00222 protected:
00223 bool mVisible;
00224 CSInset mInset;
00225 CSInset *getInsetInternal() {return &mInset;}
00226 CSLayoutData *getLayoutDataInternal() {return &mLayoutData;}
00227
00228 void deleteElements();
00229 virtual int getViewportWidth() {return mViewportWidth;}
00230 virtual int getViewportHeight() {return mViewportHeight;}
00231 virtual int getViewportX() {return mViewportX;}
00232 virtual int getViewportY() {return mViewportY;}
00233
00234
00235 int mBorderState;
00236 bool mHeightSet;
00237 bool mWidthSet;
00238 int mHeight;
00239 int mWidth;
00240 int mMinWidth;
00241 int mMinHeight;
00242
00243 int mActionId;
00244
00245
00246 CSGrafikElements mElements;
00247 CSGrafikElement *mParent;
00248
00249 std::string mTooltipText;
00250
00251 GuiMessage MESSAGE_FOCUS_GAINED;
00252 GuiMessage MESSAGE_FOCUS_LOST;
00253 GuiMessage MESSAGE_KEY_PRESSED;
00254 GuiMessage MESSAGE_KEY_RELEASED;
00255 GuiMessage MESSAGE_MOUSE_PRESSED;
00256 GuiMessage MESSAGE_MOUSE_RELEASED;
00257 GuiMessage MESSAGE_MOUSE_MOTION;
00258 GuiMessage MESSAGE_MOUSE_MOTION_LOST;
00259
00260 SDL_Rect getElementArea() {return mElementArea;}
00261
00262
00263
00264 virtual void setParent(CSGrafikElement *parent);
00265 void init(int height, int width);
00266
00267 void translateToDesktop(int &x, int &y);
00268
00269
00270 virtual void CSGrafikElement::paintArea(SDL_Surface *destination, SDL_Rect *parentArea)
00271 {
00272 paintAreaStandard(destination, parentArea);
00273 }
00274 void paintBorder(SDL_Surface *destination, SDL_Rect *parentArea);
00275 void paintAreaStandard(SDL_Surface *destination, SDL_Rect *parentArea);
00276 void paintChildren(SDL_Surface *destination, SDL_Rect *parentViewport);
00277 CSGrafikElement *removeMainElement(CSGrafikElement *element);
00278 CSLayoutManager *getMainLayoutManager()
00279 {
00280 return mLayoutManager;
00281 }
00282
00283 void setMainLayoutManager(CSLayoutManager *manager)
00284 {
00285 if (mLayoutManager != 0)
00286 {
00287 delete mLayoutManager;
00288 mLayoutManager = 0;
00289 }
00290 mLayoutManager = manager;
00291 if (mLayoutManager != 0)
00292 {
00293 mLayoutManager->setHostingElement(this);
00294 }
00295 }
00296
00297 virtual void rebuildElement() {}
00298
00299
00300 void doLayout();
00301 void setMainElement(CSGrafikElement *element) {mMainElement = element;}
00302
00303 public:
00304 static const char *CLASS;
00305 virtual std::string getType() {return (std::string) CLASS;}
00306
00307 CSGrafikElement(int height, int width);
00308 ~CSGrafikElement(void);
00309 CSGrafikElement *getUppermostAncestor();
00310 CSWindow *getParentWindow();
00311 CSDesktop *getDesktop(void);
00312 CSGrafikElement *getParent(void) {return mParent;}
00313 virtual void paint(SDL_Surface *destination, SDL_Rect *parentViewport)
00314 {
00315 paintChildren(destination, parentViewport);
00316 }
00317 void setPosition(int x, int y);
00318 bool isFrontElement() {return mFrontElement;}
00319 void toFront(CSGrafikElement *element);
00320 void setGUIType(std::string type) {mType = type;}
00321 std::string getGUIType() {if (mType.size() == 0) return getType(); return mType;}
00322 int getX() {return mX;}
00323 int getY() {return mY;}
00324
00325
00326 bool isIn(int x, int y, SDL_Rect *parentViewport);
00327 void reactOnMessageGrafikElement(CSMessage *message) {}
00328 virtual void reactOnMessage(CSMessage *message) {reactOnMessageGrafikElement(message);}
00329 virtual bool isTransparent(int x, int y, SDL_Rect *parentViewport) {return false;}
00330 virtual void putString(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, const std::string &string);
00331 virtual void putString(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, int color, const std::string &string);
00332
00333 void line(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, int x2, int y2, Uint32 color);
00334 void setActionId(int id) {mActionId=id;};
00335
00336 virtual void lafChanged(int id);
00337 bool isChild(CSGrafikElement *element);
00338 virtual void cursorDefault();
00339 virtual void cursorSizing();
00340 virtual CSMouseCursor *getCursor();
00341 void setCurrentLAFId(int id) {mCurrentLAFId = id;}
00342 int getCurrentLAFId(void) {return mCurrentLAFId;}
00343 virtual void setTooltipText(const std::string &s) {mTooltipText = s;}
00344 virtual std::string getTooltipText() {return mTooltipText;}
00345
00346 virtual void layoutSetup(){}
00347 virtual bool getActive(){return mActive;}
00348 virtual void setActive(bool b){mActive = b;}
00349 virtual void setEnabled(bool b){mEnabled = b;}
00350 virtual bool getEnabled(){return mEnabled;}
00351 virtual void setActivated(bool b){mActivated = b;}
00352 virtual bool getActivated(){return mActivated;}
00353 virtual bool getModal() {return mModal;}
00354 virtual void setModal(bool m) {mModal = m;}
00355 virtual bool getVisible() {return mVisible;}
00356 virtual void setVisible(bool v);
00357 virtual void setFocusable(bool b);
00358 virtual bool getFocusable() {return mFocusable;}
00359 bool getFocused() {return mFocused;}
00360 void setFocused(bool b) {mFocused = b;}
00361 virtual SDL_Rect getViewportArea() {return mViewportArea;}
00362
00363 int getHeight() {if (mHeight<mMinHeight) return mMinHeight; return mHeight;}
00364 int getWidth() {if (mWidth<mMinWidth) return mMinWidth; return mWidth;}
00365 void setHeight(int h);
00366 void setWidth(int w);
00367 virtual CSFont *getFont();
00368
00369
00370
00371 virtual void setFont(CSFont *font)
00372 {
00373 if (mFont != font)
00374 {
00375 mFont = font;
00376 layoutChanged();
00377 }
00378 }
00379
00380 virtual void setInset(const CSInset &inset) {mInset = inset;}
00381 virtual CSInset getInset() {return mInset;}
00382 virtual void setBorder(CSBorder *border, bool deleteOldBorder = false);
00383 virtual CSBorder *getBorder();
00384
00385 virtual void setArea(CSArea *area, bool deleteOldArea = false);
00386 virtual CSArea *getArea();
00387
00388 int getBackgroundColor();
00389 void setBackgroundColor(int backgroundColor);
00390 int getTextColor();
00391 void setTextColor(int textColor);
00392 void setStyle(int style) {mStyle = style;}
00393 int getHorizontalElementSpacing();
00394 void setHorizontalElementSpacing(int horizontalElementSpacing);
00395 int getVerticalElementSpacing();
00396 void setVerticalElementSpacing(int verticalElementSpacing);
00397 void setBorderState(int state){mBorderState = state;}
00398
00399 CSLayoutManager *getLayoutManager()
00400 {
00401 if (mMainElement == this)
00402 {
00403 return getMainLayoutManager();
00404 }
00405 else
00406 {
00407 return mMainElement->getLayoutManager();
00408 }
00409 }
00410 void setLayoutManager(CSLayoutManager *manager)
00411 {
00412 if (mMainElement == this)
00413 {
00414 setMainLayoutManager(manager);
00415 }
00416 else
00417 {
00418 mMainElement->setLayoutManager(manager);
00419 }
00420 }
00421 CSLayoutData getLayoutData() {return mLayoutData;}
00422 void setLayoutData(const CSLayoutData &layoutData)
00423 {
00424 mLayoutData = layoutData;
00425 setPosition(mLayoutData.getX(), mLayoutData.getY());
00426 mLayoutManager->buildArea(this);
00427
00428
00429 layoutChanged();
00430 }
00431
00432
00433 void addMainElement(CSGrafikElement *element, int position);
00434 void addMainElement(CSGrafikElement *element, int x, int y);
00435 void addMainElement(CSGrafikElement *element);
00436 void addElement(CSGrafikElement *element, int position);
00437 void addElement(CSGrafikElement *element, int x, int y);
00438 void addFrontElement(CSGrafikElement *element, int x, int y);
00439 void addFrontElementCenter(CSGrafikElement *element);
00440 void addElement(CSGrafikElement *element);
00441
00442 int getMinWidth() {if (getVisible()) return mMinWidth; return 0;}
00443 void setMinWidth(int w) {mMinWidth = w;}
00444 int getMinHeight() {if (getVisible()) return mMinHeight; return 0;}
00445 void setMinHeight(int h) {mMinHeight = h;}
00446 void removeFrontElement(CSGrafikElement *element);
00447 CSGrafikElement *removeElement(CSGrafikElement *element);
00448
00449 void setViewportOffset(int x, int y)
00450 {
00451 mViewportOffsetX = x;
00452 mViewportOffsetY = y;
00453 }
00454
00455 void getViewportOffset(int &x, int &y)
00456 {
00457 x = 0;
00458 y = 0;
00459 if (mParent)
00460 {
00461
00462 }
00463 x += mViewportOffsetX;
00464 y += mViewportOffsetY;
00465 }
00466 void getViewportOffsetParent(int &x, int &y)
00467 {
00468 x = 0;
00469 y = 0;
00470 if (mParent)
00471 {
00472 mParent->getViewportOffsetParent(x, y);
00473 }
00474 x += mViewportOffsetX;
00475 y += mViewportOffsetY;
00476 }
00477
00478 void removeAllElements()
00479 {
00480 if (mMainElement == this)
00481 {
00482 removeMainAllElements();
00483 }
00484 else
00485 {
00486 mMainElement->removeAllElements();
00487 }
00488 }
00489
00490
00491
00492 void layoutChanged(bool sizing = false);
00493 };
00494 #endif // CSGRAFIK_ELEMENT_h
00495
00496
00497
00498