00001 #pragma once
00002 #ifndef WIN32_LEAN_AND_MEAN
00003 #define WIN32_LEAN_AND_MEAN
00004 #endif
00005
00006 #define WINDLL
00007 #define MSG_USER_PAINT 0x0410
00008
00009
00010
00011
00012 #include <windows.h>
00013 #include <ddraw.h>
00014 #include <winuserm.h>
00015 #include <sipapi.h>
00016 #include <shellapi.h>
00017 #include <string>
00018 #include <sstream>
00019 #include <map>
00020
00021 #include <vector>
00022 #include <aygshell.h>
00023 #include <imaging.h>
00024
00025 using namespace std;
00026
00027 class MouseCtrl;
00028 class EventHandler;
00029 class DirectDrawWarp;
00030 class MessageBoxSense;
00031 class Section;
00032
00033 #define MANILA_SDK_VERSION 1.53
00034 #define DRAWING_GDI
00035
00036
00037
00038
00039 #ifdef DRAWING_GDI
00040 #define RGB555(r,g,b) (((0x001F&(WORD)r) << 10) |((0x1F&(WORD)g) << 5) |((0x1F&(WORD)b)))///< RGB565 : RRRR RGGG GGGB BBBB (31,63,31)
00041 #define RGB16(r,g,b) (((0x001F&(WORD)r) << 11) |((0x3F&(WORD)g) << 5) |((0x1F&(WORD)b)))///< RGB565 : RRRR RGGG GGGB BBBB (31,63,31)
00042 #define RGB565to32(r,g,b) (((0x000000FF&(DWORD)r) << 19) |((0x000000FF&(DWORD)g) << 10) |((0xFF000000|(DWORD)((uchar)b))<<3))///< RGB 565 to RGB32 (false 16Bit)
00043 #define RGB555to32(r,g,b) (((0x000000FF&(DWORD)r) << 19) |((0x000000FF&(DWORD)g) << 11) |((0xFF000000|(DWORD)((uchar)b))<<3))///< RGB 555 to RGB32 (false 16Bit)
00044 #define RGBA555to32(alpha,color) ((DWORD)alpha|(((DWORD)(0x7C00&color)) << 9) |(((DWORD)(0x03E0&color)) << 6) |(((DWORD)(0x001F&color)) <<3))///< RGB 555 to RGB32 with alpha (false 16Bit)
00045 #else
00046 #define RGB565to32(r,g,b) (((WORD)r << 11) |(0x3F&(WORD)g) << 5) |((0x1F&(WORD)b))// RGB565 : RRRR RGGG GGGB BBBB (31,63,31)
00047
00048 #endif
00049
00050 #ifdef _DEBUG
00051 #define MyASSERT(condition) ASSERT(condition)
00052 #else
00053 #define MyASSERT(condition)
00054 #endif
00055
00057 typedef struct DIRECTDRAW_GDI
00058 {
00059 IDirectDrawSurface* directDrawSurf;
00060 HDC deviceInterface;
00061 HBITMAP bitmap;
00062 HGDIOBJ oldObj;
00063 BYTE nbBPP;
00064 int width,height;
00065 DIRECTDRAW_GDI(){directDrawSurf=NULL;deviceInterface=0;bitmap=0;nbBPP=0;};
00066 }DIRECTDRAW_GDI;
00068 typedef struct GDI_OVERLAY
00069 {
00070 IDirectDrawSurface* directDrawSurf;
00071 HDC deviceInterface;
00072 HBITMAP bitmap;
00073 int width,height;
00074 HWND windowOverlay;
00075 RECT positionOut;
00076 bool visible;
00077 GDI_OVERLAY(){directDrawSurf=NULL;deviceInterface=0;bitmap=0;visible=false;};
00078 }GDI_OVERLAY;
00079
00080
00082 typedef struct
00083 {
00084 BYTE bWidth;
00085 BYTE bHeight;
00086 BYTE bColorCount;
00087 BYTE bReserved;
00088 WORD wPlanes;
00089 WORD wBitCount;
00090 DWORD dwBytesInRes;
00091 DWORD dwImageOffset;
00092 } ICONDIRENTRY, *LPICONDIRENTRY;
00093
00095 typedef struct
00096 {
00097 WORD idReserved;
00098 WORD idType;
00099 WORD idCount;
00100 ICONDIRENTRY idEntries[1];
00101 } ICONDIR, *LPICONDIR;
00102
00104 typedef struct
00105 {
00106 BITMAPINFOHEADER icHeader;
00107 RGBQUAD icColors[1];
00108 BYTE icXOR[1];
00109 BYTE icAND[1];
00110 } ICONIMAGE, *LPICONIMAGE;
00111
00116
00117 class WINDLL GlobalInformations
00118 {
00119 GlobalInformations(wstring name);
00120 ~GlobalInformations(void);
00121
00123 static GlobalInformations* resources;
00126 wstring appName;
00128 void releaseLoadedVar();
00131 static wstring findUserDirectory(GlobalInformations* gi);
00133 static void loadResources(GlobalInformations* gi,wstring myDirectory);
00134 public:
00137 static void setName(wstring newName);
00139 static GlobalInformations* getInstance();
00141 static bool alreadyInitialized(){return resources!=NULL;};
00142
00143 wstring *bg_common_titlebar;
00144 wstring *bg_common_divider_section;
00145 wstring *btn_common_msgbox_large;
00146 wstring *btn_common_msgbox_small;
00147 wstring *btn_common_normal;
00148 wstring *btn_switch_thirdState;
00149 wstring *btn_checkbox_thirdState;
00150 wstring *btn_common_switch;
00151 wstring *btn_common_checkbox;
00152 wstring *btn_common_slider;
00153 wstring *btn_slider;
00154 wstring *btn_common_input;
00155 wstring *btn_common_listitem;
00156 wstring *pivot_leftarrow;
00157 wstring *pivot_rightarrow;
00158 wstring *btn_common_combo_down;
00159 wstring *btn_common_listitem_bottom;
00160 wstring *btn_common_listitem_middle;
00161 wstring *bg_common_dotline;
00162 wstring *bg_msg_box;
00163 wstring *bg_dark;
00164
00169 DirectDrawWarp* window;
00171 bool cantBeClosed;
00173 HINSTANCE m_hInstance;
00175 HWND m_hWnd;
00177 LPDIRECTDRAW *ldDDraw;
00179 DIRECTDRAW_GDI *primaryBuffer;
00181 DIRECTDRAW_GDI *backBuffer;
00185 DIRECTDRAW_GDI *background;
00188 bool isActiv;
00191 bool mustRender;
00193 bool mustRedraw;
00195 HANDLE waitForMSG;
00197 double percentOfVGA;
00199 bool isLandscape;
00201 CRITICAL_SECTION criticPaint;
00202 CRITICAL_SECTION criticAddBufPaint;
00204 wstring userDirectory;
00206 bool hasMenuBar;
00207
00209 HFONT hFontTitle;
00210
00211
00212 RECT rs;
00213 RECT rcUpdateRegion;
00214 RECT rcVisibleDesktopTOP;
00215 RECT rcVisibleDesktopBOTTOM;
00216
00217 DWORD lastTick1;
00218 DWORD lastTick2;
00219 DWORD lenght1;
00220 DWORD lenght2;
00221 };
00222
00223
00228
00229 class WINDLL LocalisedString{
00230 public:
00234 static TCHAR* windowCreationError;
00235 static TCHAR* LoadImageError;
00236 static TCHAR* SizeImageError;
00237 static TCHAR* AddElemError;
00238 static TCHAR* ResourceError;
00239 static TCHAR* szDDrawError;
00240 static TCHAR* szDDrawFailedMsg;
00241 static TCHAR* szSetCooperativeFailMsg;
00242 static TCHAR* szNoOverlaysMsg;
00243 static TCHAR* szCreateOverlayFailMsg;
00244 static TCHAR* szLoadOverlayFailMsg;
00245 static TCHAR* szShowOverlayFailMsg;
00246 static TCHAR* szNoFlipSurfacesMsg;
00247 static TCHAR* szEnumAttachedSurfacesFailMsg;
00248 static TCHAR* szCreateSurfaceFailMsg;
00249 static TCHAR* szSetTimerFailMsg;
00250 static TCHAR* szGetCapsFailMsg;
00251 static TCHAR* szNoBackBufferMsg;
00252 static TCHAR* szSurfaceLost;
00253 static TCHAR* szGetDC;
00254 static TCHAR* szCreateInputText;
00255 static TCHAR* szShowKbrd;
00256 static TCHAR* szCreateMyItem;
00257
00258
00260 static void explainFail(LPCTSTR error,LPCTSTR title,int quit=1);
00262 static void explainFailDirectDraw(int hRet,wstring info);
00264 static void explainFailIImage(HRESULT hRet,wstring info);
00266 static void explainFailWinAPI(wstring info);
00267
00268 };
00269
00270 #define TYPE_CHILD_SECTION 1
00271 #define TYPE_EDIT_CTRL 2
00272 #define TYPE_ITEM 3
00273 #define TYPE_LABEL 4
00274 #define TYPE_PANEL 5
00275 #define TYPE_PICTURE 6
00276 #define TYPE_SELECTOR 7
00277 #define TYPE_SECTION 8
00278 #define TYPE_SLIDER 9
00279
00284
00285 class WINDLL Element
00286 {
00287 static vector<Element*> listElements;
00288 static IImagingFactory *pImgFactory;
00289 static map<DWORD,IImagingFactory*> runningThread;
00290 static EventHandler* gestEvent;
00291 protected:
00292 RECT position;
00293 RECT positionAbsolute;
00294 bool isActivated;
00295 MouseCtrl* mouseEvent;
00296 int idElement;
00297 int paddingSup;
00298 int typeElement;
00299
00301 virtual void loadSurf(){};
00302 public:
00304 static void reloadAllSurface();
00305 Element* owner;
00306
00307 Element(int idElement,int &x,int &y,int typeElement,bool realPos=false);
00308 virtual ~Element(void);
00309
00310 friend class MessageBoxSense;
00312 virtual void setMustRedraw();
00313
00314
00315
00316
00317
00324 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y)=0;
00325
00332 virtual Element* isClicked(int x,int y)=0;
00333
00334
00335
00336
00337
00338
00344 virtual bool run(bool isRightClick=false);
00346 virtual void add(Element* e,int minHeight=-1,int pos=-1,bool mixWithOther=true);
00352 virtual int mouseGesture(){return 0;};
00353
00354
00355
00356
00357
00359 static bool noError;
00361 GlobalInformations* gi;
00363 static IImage* getImgFromBuffer(BitmapData* dataBuffer);
00365 static DIRECTDRAW_GDI *fromIImageToGDI(IImage** src,bool force32bits=false);
00367 static DIRECTDRAW_GDI * loadImageWithAlpha(wstring name,bool rescall);
00369 static DIRECTDRAW_GDI * loadImage(wstring *name,bool rescall=false,bool transparent=false);
00370
00377 static DIRECTDRAW_GDI* CreateBitmapMask(DIRECTDRAW_GDI *hbmColour, COLORREF crTransparent);
00379 static IImage * loadIImage(wstring *name);
00381 static void resizeIImage(wstring *name);
00382 static RECT patchImage(DIRECTDRAW_GDI * bkg,wstring *name,int nbPatch,int posX,int posY);
00383 static EventHandler* getGestEvent() { return gestEvent; }
00384 static void setGestEvent(EventHandler* val) { gestEvent = val; }
00385
00386 static IImagingFactory* getIImagingFactory();
00387
00389 inline int getWidth(){return position.right-position.left;};
00391 inline int getHeight(){return position.bottom-position.top;};
00393 inline int getTop(){return position.top;};
00395 inline int getLeft(){return position.left;};
00397 inline int getBottom(){return position.bottom;};
00399 inline int getRight(){return position.right;};
00401 inline int getId(){return idElement;};
00403 inline int getType(){return typeElement;};
00404
00405 inline void setWidth(int t){position.right=position.left+t;};
00406 inline void setHeight(int t){position.bottom=position.top+t;};
00407 inline void setTop(int t){position.top=t*gi->percentOfVGA;};
00408 inline void setBottom(int t){position.bottom=t;};
00409 inline void setRight(int t){position.right=t;};
00410 inline void setLeft(int t){position.left=t;};
00411 inline void recopiePosition(RECT &dest){dest=position;};
00412
00413 static void redraw();
00414
00415 virtual void unClick(){isActivated=false;};
00416
00421 static Element* getElementByID(int id,int typeExpected=-1);
00423 virtual void sizeChanged(Element* src,int width,int height);
00427 void WriteBMPFile(HBITMAP bitmap, LPTSTR filename, HDC hDC);
00429 static bool saveIcon(HICON myIcon,wstring fileDst);
00435 static HICON loadIcon(wstring fileDst,wstring link);
00437 static void sendMsg(int wParam,void* lParam);
00439 static bool ConvertToDIB(HBITMAP& hBitmap);
00440 };
00441
00446
00447 class WINDLL MyPictureBox :
00448 public Element
00449 {
00450 DIRECTDRAW_GDI *pImage;
00451 RECT clipping;
00452 int numImage;
00453 int nbMaxImage;
00454 int widthImg;
00455 bool canScal;
00457 virtual void loadSurf();
00458 public:
00468 MyPictureBox(int idElement, int x,int y,wstring img,int nbImg=1,bool rescall=false);
00469
00479 MyPictureBox(int idElement, int x,int y,DIRECTDRAW_GDI *i,int nbImg=1);
00480 ~MyPictureBox(void);
00481
00488 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
00495 virtual Element* isClicked(int x,int y);
00496
00501 inline void setNumImage(int i){numImage=i<nbMaxImage?i:0;};
00502
00507 inline void changeImg(DIRECTDRAW_GDI *surf){pImage=surf;};
00512 inline void setScallingAbility(bool canScal){this->canScal=canScal;};
00513
00514 };
00515
00516 #define LABEL_STATE_NORMAL 0
00517 #define LABEL_STATE_HOVER 1
00518 #define LABEL_STATE_DSBL 2
00519 #define LABEL_STATE_SELECTED 3
00520
00521 #define TEXT_NORMAL 0
00522 #define TEXT_BIG 1
00523 #define TEXT_ITALIC 2
00524 #define TEXT_SMALL 3
00525
00532
00533 class WINDLL MyLabel :
00534 public Element
00535 {
00536 HFONT myFont;
00537
00538 DIRECTDRAW_GDI *render;
00539 wstring myText;
00540 RECT clipping;
00541 RECT sizeSurface;
00542 DWORD previousColor;
00543 DWORD myColor[4];
00544 DWORD backColor;
00545 DDCOLORKEY ddck;
00546
00547 int state;
00548 bool mustErase;
00549 bool isVisible;
00550 bool isCenterV;
00551 bool isCenterH;
00552 int lastWidth;
00553 int paddingTop;
00554 int paddingLeft;
00555
00556 MyPictureBox *backGrnd;
00557 void initComponnents(int type,DWORD color);
00559 virtual void loadSurf();
00560
00561 void computeRealAlpha( COLORREF color ) ;
00562 public:
00563 static HFONT fontTitle;
00564 static HFONT fontNormal;
00565 static HFONT fontItalic;
00566 static HFONT fontSmall;
00567
00580 MyLabel(int idElement, int x,int y,int width,int height,wstring text,int fontType=0,bool centered=true,DWORD color=0);
00592 MyLabel(int idElement, int x,int y,wstring text,int fontType=0,DWORD color=0,bool realPos=false,DWORD backColor=1);
00603 MyLabel(int idElement, int x,int y,wstring text,DIRECTDRAW_GDI *bkgHover,int fontType=0,DWORD color=0);
00615 MyLabel(int idElement, int x,int y,wstring text,MyPictureBox* image,int paddingText,int fontType=0,DWORD color=0);
00616 ~MyLabel(void);
00617
00624 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
00631 virtual Element* isClicked(int x,int y);
00637 bool run(bool isRightClicked=false);
00641 void unClick();
00642
00650 virtual void paintColor(DIRECTDRAW_GDI* lpDDraw,int x,int y,COLORREF color,COLORREF background);
00651
00657 void setText(wstring nT,bool redraw=true);
00662 wstring getText(){return myText;};
00663
00665 int getState(){return state;};
00667 void changeState(int newState){state=newState;};
00668
00669 bool isClickable;
00670
00672 void center();
00678 void centerV(int top=-1,int bottom=-1);
00684 void centerH(int left,int right);
00686 void setPaddingTop(int t){paddingTop=t;};
00688 void setPaddingLeft(int l){paddingLeft=l;};
00689
00691 int getPaddingTop(){return paddingTop;};
00693 int getPaddingLeft(){return paddingLeft;};
00694
00700 void setBkg(DIRECTDRAW_GDI *surf);
00706 void changeColor(DWORD color,int state=LABEL_STATE_NORMAL);
00707
00713 void changeVisibility(bool vis,bool eraseBckground=true);
00714
00715 };
00716
00717
00718
00719
00720
00721
00722
00723 #define NB_MOUSE_HISTORY 3
00724 #define DBL_CLICK_LENGTH 0 //to activate dbc, set to 200
00725 #define VEL_INERTIE 100.0
00726
00727
00733 class WINDLL MouseCtrl
00734 {
00735
00736 int mouseOldXPos, mouseOldYPos;
00737 int mouseClickXPos, mouseClickYPos;
00738 int mouseNewXPos, mouseNewYPos;
00739 int lastMouseXPos, lastMouseYPos;
00740 bool hasInfoAboutClick;
00741 bool rightClick;
00742 bool splClick;
00743 bool mouseDown;
00744 bool clickSelected;
00745 bool dblClick;
00746 bool scrolling;
00747 bool somethingAppend;
00748 bool clickPosGet;
00749 bool slideLeft;
00750
00751 DWORD lastTickMouse;
00752 DWORD clickEvent;
00753 DWORD startScrolling;
00754 DWORD lastScroll;
00755 double userXVel[NB_MOUSE_HISTORY], userYVel[NB_MOUSE_HISTORY];
00756 int idPos;
00757
00758 static CRITICAL_SECTION mouseUpdate;
00759
00760 Element* gestMouse;
00761 static GlobalInformations* gi;
00762
00764 MouseCtrl(void);
00765 static MouseCtrl* instance;
00766 bool cantSlideLeft;
00767 public:
00768 ~MouseCtrl(void);
00769
00774 static MouseCtrl* getInstance();
00779 int updateElement();
00784 Element* giveControlBack(){
00785 if (gestMouse!=NULL){
00786 Element* out=gestMouse;
00787 gestMouse->unClick();
00788 return out;
00789 };
00790 return NULL;
00791 };
00792
00793
00794
00795
00796
00797
00798
00800 void rightBtnDown(int x,int y);
00802 void leftBtnDown(int x,int y);
00804 void leftBtnUp(int x,int y);
00806 void leftBtnMove(int x,int y);
00808 void setClickSelected(bool val){clickSelected=val;};
00810 bool setMouseAnalyse(Element* e);
00816 Element* changeMouseAnalyse(Element* e);
00818 void stopScroll();
00823 bool pickChange(){bool out=somethingAppend||scrolling;somethingAppend=false;return out;};
00824
00825
00826
00827
00828
00829
00831 int getMouseDY();
00833 int getMouseDX();
00835 double getMouseDXMean();
00840 bool isMouseDown();
00845 bool isSelected();
00850 bool isSlidingLeft();
00855 bool isClicked();
00860 bool isRightClicked() const { return rightClick; };
00865 bool isDblClicked();
00870 bool sthgHasChange();
00871
00873 void getMousePosition(int &x,int &y);
00874 };
00875
00876
00877
00878
00879
00880
00881 #define VIS_SLIDE_NORMAL 0
00882 #define VIS_SLIDE_DISABLED 2
00883
00889 class MySlider :
00890 public Element
00891 {
00892 protected:
00893
00894 static DIRECTDRAW_GDI *slideSurf;
00895 static DIRECTDRAW_GDI *btnSurf;
00896
00897 RECT clipping;
00898 static int widthSlide;
00899 static int heightSlide;
00900 static int widthBtn;
00901 static int heightBtn;
00902 Section* container;
00903
00904 int state;
00905 int position;
00906 int minVal,maxVal;
00907 bool sliderAnim;
00908 bool isSliding;
00909 void loadSurf();
00910 public:
00921 MySlider(int idElement, int x,int y,int width,bool visible,int minVal=0,int maxVal=100);
00931 MySlider(int idElement, int x,int y,int width,bool visible, double lengthAnim);
00932 ~MySlider(void);
00933
00935 void updatePosition(int newPos=-1);
00936
00943 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
00950 virtual Element* isClicked(int x,int y);
00956 bool run(bool isRightClicked=false);
00960 void unClick();
00961
00967 int mouseGesture();
00968
00973 void changeVisibility(int state){this->state=state;};
00975 int getValue(){return position;};
00976 static MySlider* slideRunning;
00977 int mySpeed;
00978 };
00979
00980
00981
00982
00983
00984
00985
00986 #define PADDING_SECT_H 5
00987 #define SCROLL_WIDTH 5
00988
00994 class WINDLL Section :
00995 public Element
00996 {
00997 protected:
00998
00999 wstring title;
01000 static DIRECTDRAW_GDI *bkgSurface;
01001 RECT rcTitle;
01002 RECT clipping;
01003
01004
01005
01006
01007
01008 int posOverlay;
01009 static LPCRITICAL_SECTION criticAdd;
01010
01011 vector<Element*> components;
01012
01013 Element* mouseAnalysePrev;
01014 Element* drawingHook;
01015 int prevPos;
01016 int prevOverlay;
01017 static int TITLE_SECTION_HEIGHT;
01018 static int TITLE_SECTION_WIDTH;
01019
01020 bool canScroll;
01021
01022
01023 void printScrollBar(DIRECTDRAW_GDI* lpDDraw);
01024 void computeBkgSurface();
01025
01026 virtual void loadSurf();
01027 public:
01036 Section(int idElement, int x,int y,int width,wstring title=L"");
01037 ~Section(void);
01038
01039 Element* selectedElement;
01040 static bool scrollVisible;
01041
01047 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01054 virtual Element* isClicked(int x,int y);
01060 virtual int mouseGesture();
01061
01069 void add(Element* e,int minHeight=-1,int pos=-1,bool mixWithOther=false);
01074 void remove(unsigned int pos);
01075
01077 void setDrawingHook(Element* e);
01078
01080 inline void slideOverlay(int dY){posOverlay+=dY;};
01082 void updateScreen();
01084 void overlayVisibility(bool visib);
01085
01087 inline void unselect(){selectedElement=NULL;}
01089 void sizeChanged(Element* src,int w,int h);
01090
01095 void scrollingAbility( bool canScroll ){this->canScroll=canScroll;}
01096
01098 void goToTop();
01099
01106 int verifScrollingRange(int dy,bool isDragged);
01107
01108 static GDI_OVERLAY *scrollBar;
01109 };
01110
01111
01112
01113
01114
01115 #define ID_EDITCHILD 102
01116 #define IDM_EDITMENU 103
01117
01118 #define VIS_NORMAL 0
01119 #define VIS_HOVER 1
01120 #define VIS_DISABLED 2
01121
01122
01123 using namespace std;
01124
01130 class WINDLL MyEditControl :
01131 public Element
01132 {
01133 static DIRECTDRAW_GDI *inputDDraw;
01134 static unsigned char widthCorner;
01135 static unsigned short int widthItem;
01136
01137 MyLabel* text;
01138 bool slideToTop;
01139 DWORD startAnim;
01140 DWORD startPos;
01141
01142 int state;
01143
01144 RECT clipping;
01145 Section* container;
01146
01147 void show();
01149 virtual void loadSurf();
01150 public:
01158 MyEditControl(int idElement, int x,int y,int width);
01159 ~MyEditControl(void);
01160
01167 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01174 virtual Element* isClicked(int x,int y);
01180 bool run(bool isRightClicked=false);
01184 void unClick();
01190 int mouseGesture();
01191
01193 wstring getText(){return text->getText();}
01195 void setText( LPCWSTR param1 );
01197 void sizeChanged(Element* src,int width,int height);
01198 static int EDIT_MENU_HEIGHT;
01199
01200 static HWND input;
01201
01202 void showSIP();
01203 static MyEditControl* pEditCtrl;
01204 };
01205
01206
01207
01208
01209
01210 #define ITEM_IS_CHECKBOX 1
01211 #define ITEM_IS_SWITCH 2
01212 #define ITEM_IS_BUTTON_NORMAL 3
01213 #define ITEM_IS_BUTTON_BIG 4
01214 #define ITEM_IS_BUTTON_SHORT 5
01215
01216 #define ITEM_STATE_EBL_EMPTY 0
01217 #define ITEM_STATE_EBL_SELECTED 1
01218 #define ITEM_STATE_DSBL_EMPTY 2
01219 #define ITEM_STATE_DSBL_SELECTED 3
01220 #define ITEM_STATE_HOVER_EMPTY 4
01221 #define ITEM_STATE_HOVER_SELECTED 5
01222 #define ITEM_THIRD_STATE 6
01223 #define ITEM_THIRD_STATE_DSBL 7
01224
01225 #define ITEM_COLOR_HOVER 0
01226 #define ITEM_COLOR_DISABLED 1
01227 #define ITEM_COLOR_NORMAL 2
01228
01233 class WINDLL MyItem :
01234 public Element
01235 {
01236 static DIRECTDRAW_GDI *checkBoxThrd;
01237 static DIRECTDRAW_GDI *switchThrd;
01238 static DIRECTDRAW_GDI *checkBoxes;
01239 static DIRECTDRAW_GDI *switches;
01240 static DIRECTDRAW_GDI *button_normal;
01241 static DIRECTDRAW_GDI *button_big;
01242 static DIRECTDRAW_GDI *button_short;
01243
01244 static int checkBoxesWidth;
01245 static int checkBoxesHeight;
01246 static int switchesWidth;
01247 static int switchesHeight;
01248 static int button_normalWidth;
01249 static int button_normalHeight;
01250 static int button_bigWidth;
01251 static int button_bigHeight;
01252 static int button_shortWidth;
01253 static int button_shortHeight;
01254 static int button_ckThrdWidth;
01255 static int button_ckThrdHeight;
01256 static int button_swThrdWidth;
01257 static int button_swThrdHeight;
01258
01259 DIRECTDRAW_GDI *mySurface;
01260 RECT clipping;
01261 RECT positionElement;
01262 RECT positionText;
01263 int elementHeight;
01264 int elementWidth;
01265 unsigned char state;
01266 unsigned char type;
01267
01268 DWORD colorHover,colorDsbl,colorNrmal;
01269 DWORD colorBackHover,colorBackDsbl,colorBackNrmal;
01270
01271 MyLabel* text;
01272 bool isCentered;
01273 bool forceErase;
01275 void setMustRedraw();
01277 virtual void loadSurf();
01278 public:
01288 MyItem(int idElement, int x,int y,unsigned char type,unsigned char state,wstring text=L"");
01289 ~MyItem(void);
01290
01297 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01304 virtual Element* isClicked(int x,int y);
01310 bool run(bool isRightClicked=false);
01314 void unClick();
01319 unsigned char isEnabled(){return state!=ITEM_STATE_DSBL_EMPTY&&state!=ITEM_STATE_DSBL_SELECTED&&state!=ITEM_THIRD_STATE_DSBL;};
01323 unsigned char isSelected(){return state==ITEM_STATE_HOVER_SELECTED||state==ITEM_STATE_EBL_SELECTED;};
01324
01329 void changeText(wstring text);
01330
01331
01334 inline void switchVisibility(){
01335 if(state==ITEM_STATE_DSBL_EMPTY||state==ITEM_STATE_DSBL_SELECTED) state-=2;
01336 else if(state==ITEM_STATE_EBL_EMPTY||state==ITEM_STATE_EBL_SELECTED) state+=2;
01337 else if(state==ITEM_THIRD_STATE) state++;
01338 else if(state==ITEM_THIRD_STATE_DSBL) state--;
01339 else state-=2;
01340 setMustRedraw();
01341 }
01343 void sizeChanged(Element* src,int width,int height);
01350 void changeColorTxt(DWORD color,DWORD backColor,int type);
01352 void centerH();
01354 void hasBackgroundTransparent(bool val){forceErase=val;};
01355 };
01356
01357
01358
01359
01360
01361
01362
01363 #define PADDING_PANEL_H 0//was set to 5 but padding should be manually set...
01364
01369 class WINDLL MyPanel :
01370 public Element
01371 {
01372 wstring title;
01373 static DIRECTDRAW_GDI *bkgSurfaceSrc;
01374 DIRECTDRAW_GDI *bkgSurface;
01375 static int bkgSurfaceSrcWidth;
01376 static DIRECTDRAW_GDI *separator;
01377 static int separatorWidth;
01378 static LPCRITICAL_SECTION criticAdd;
01379
01380 RECT rcTitle;
01381 RECT clipping;
01382
01383
01385
01387
01388 bool hasTitle,hasSeparator;
01389
01390 vector<Element*> components;
01391 vector<int> heightComp;
01392 vector<bool> isAlone;
01393
01394 void computeSurface();
01395
01396 virtual void loadSurf();
01397 public:
01408 MyPanel(int idElement, int x,int y,int width,wstring title,bool hasTitle=true,bool hasSeparator=true);
01409 ~MyPanel(void);
01410
01417 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01424 virtual Element* isClicked(int x,int y);
01425
01433 void add(Element* e,int minHeight=-1,int pos=-1,bool mixWithOther=true);
01439 Element* remove(int pos,int nb=1);
01440
01445 void changeTitle(wstring title);
01446
01448
01450
01452 Element* getElement(int pos){if((unsigned int)pos<components.size()&&pos>=0)return components[pos];else return NULL;};
01454 int getSize(){return components.size();};
01456 void sizeChanged(Element* src,int width,int height);
01457 static int TITLE_PANEL_HEIGHT;
01458 };
01459
01460
01461
01462
01463
01464
01465 #define SELECT_STATE_NORMAL 0
01466 #define SELECT_STATE_HOVER 1
01467 #define SELECT_STATE_DSBL 2
01468 #define SELECT_STATE_SELECTED 3
01469
01474 class WINDLL MySelector :
01475 public Element
01476 {
01477 static DIRECTDRAW_GDI *header;
01478 static int elementWidth;
01479 static int elementHeight;
01480 static int elementListWidth;
01481 static DIRECTDRAW_GDI *listMiddle;
01482 static DIRECTDRAW_GDI *listBottom;
01483
01484 MyPanel *values;
01485 MyLabel* selected;
01486 RECT clipping;
01487 int state;
01488
01489 Section* container;
01490 MyLabel* title;
01491 bool animation;
01492 bool animToVisibility;
01493 bool hasPaintingHook;
01494 int lastY;
01495 int animIndex;
01496 bool isOpen;
01497 DWORD startSlide;
01498 int itemChoose;
01499 int listDY;
01500 DIRECTDRAW_GDI* backgroundBuff;
01501 bool backgroundIsCaptured;
01502
01503 virtual void loadSurf();
01504 public:
01512 MySelector(int idElement, int x,int y,wstring nameOfChoice);
01513 ~MySelector(void);
01514
01521 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01528 virtual Element* isClicked(int x,int y);
01534 bool run(bool isRightClicked=false);
01538 void unClick();
01544 int mouseGesture();
01545
01547
01549
01551 void addItem(wstring word);
01556 int getSelection();
01558 void setSelection(int idSelect);
01561 MyLabel* getItemSelected(){return selected;};
01571 MyLabel* operator[] (unsigned int i);
01577 void updateTitle(wstring wantedTitle=L"");
01578 };
01579
01580
01581
01582
01583
01584 #define PADDING_ARROW 15
01585
01586 #define STATE_NORMAL 0
01587 #define STATE_HOVER 1
01588 #define STATE_DSBL 2
01589 #define STATE_SELECTED 3
01590
01595 class WINDLL ChildSection :
01596 public Element
01597 {
01598
01599 void slideScreen(DIRECTDRAW_GDI* lpDDraw);
01600 protected:
01601 static DIRECTDRAW_GDI *backgroundLeft;
01602 static DIRECTDRAW_GDI *backgroundRight;
01603
01604 static int arrowWidth;
01605 static int arrowHeight;
01606 static int backgroundHeight;
01607 static int backgroundWidth;
01608
01609 Section* container;
01610 Section* ourSection;
01611 wstring savTitle;
01612 int savPaddingTopTitle;
01613 MyLabel* title;
01614 MyLabel* subTitle;
01615
01616
01617 double durationSlide;
01618 bool sliding;
01619 bool slidToLeft;
01620 bool isInOurSection;
01621 unsigned char state;
01622 RECT clipping;
01623
01624 virtual void loadSurf();
01625 public:
01634 ChildSection(int idElement,int x,int y,wstring title,wstring subtitle=L"");
01635 ~ChildSection(void);
01636
01643 virtual void paint(DIRECTDRAW_GDI* lpDDraw,int x,int y);
01650 virtual Element* isClicked(int x,int y);
01656 bool run(bool isRightClicked=false);
01660 void unClick();
01661
01667 int mouseGesture();
01668
01676 void add(Element *e,int minH=-1,int pos=-1,bool mixWithOther=false){ourSection->add(e,minH,pos,mixWithOther);};
01681 void remove(int pos){ourSection->remove(pos);};
01682
01685 void changeSpeed(double newLength=200){durationSlide=newLength;};
01686 };
01687
01688
01689
01690
01691
01692
01693
01694 #define MESSAGE_ALERT 1
01695 #define MESSAGE_YESNO 2
01696 #define MESSAGE_OKCANCEL 3
01697 #define MESSAGE_ABORTRETRY 4
01698
01699 #define MSG_REP_NO 0
01700 #define MSG_REP_YES 1
01701 #define MSG_REP_CANCEL 0
01702 #define MSG_REP_OK 1
01703 #define MSG_REP_ABORT 0
01704 #define MSG_REP_RETRY 1
01705
01706 #define MESSAGE_REP 0x0500
01707
01712 class MessageBoxSense{
01713 MessageBoxSense(wstring title,wstring message,int type);
01714
01715 static DIRECTDRAW_GDI *msgBox;
01716 static RECT rectBox;
01717 static int answer;
01718 static HANDLE threadMSG;
01719 static bool standAlone;
01720
01721 static long FAR PASCAL messageDispatch(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
01722 long messageAnalysis(UINT message, WPARAM wParam, LPARAM lParam);
01723
01724 RECT posAbsolute;
01725 bool isInit;
01726 bool isActive;
01727 bool isAlreadyComputed;
01728 Element* selectedButton;
01729 int type;
01730 int heightMsg;
01731 int widthTitle;
01732 wstring title;
01733 wstring message;
01734 MyItem** button;
01735
01736 bool repaintButton;
01737
01738 static GlobalInformations* gi;
01739 public:
01740 ~MessageBoxSense();
01741 HWND hWnd;
01742
01750 static int show(wstring title,wstring message,int type);
01755 void updateFrame(DIRECTDRAW_GDI* screen);
01757 virtual void loadSurf();
01758 };
01759
01760
01761
01762
01763
01764
01765 #define EVENT_CLICK 1
01766 #define EVENT_VALUE_CHANGED 2
01767 #define EVENT_RIGHT_CLICK 3
01768
01773
01795 class WINDLL EventHandler
01796 {
01797 HANDLE hThread;
01798 DWORD idThread;
01799 static DWORD WINAPI launchApp( LPVOID lpParameter );
01800 protected:
01802 HINSTANCE gInstance;
01806 virtual void initApplication()=0;
01807
01808 public:
01816 EventHandler(HINSTANCE hInstance,wstring windowName,bool topmost=false,HMENU menu=NULL);
01817 ~EventHandler(void);
01818
01826 virtual void messageTreatment(Element* src,int idEvent,void* lParam=NULL)=0;
01828 void messageProc(void* src,UINT msg=EVENT_CLICK);
01830 void runApp();
01832 static void msgExecute(MSG msg);
01835 void showWindow(bool isVisible);
01836 };
01837
01838
01839
01840
01841
01842 #define SW_MINIMIZED 6
01843 #define MS_PER_FRAME 25
01844 #define NB_FRAME_ANIM 1
01845
01850 class WINDLL DirectDrawWarp
01851 {
01852 private:
01853
01854
01855
01856
01857
01858 DWORD previousFrame;
01859 bool isTopMost;
01860
01861 static GlobalInformations* gi;
01862
01863 const TCHAR* name;
01864
01865 MouseCtrl* mouse;
01866 MessageBoxSense* messageBox;
01867
01868
01869
01870
01871
01872 wstring imgBkgFile;
01873 wstring imgBkgFileLand;
01874 vector<Section*> section;
01875 int sectionActiv;
01876 int numRefreash;
01877 vector<RECT> bufferPaint;
01878 vector<bool> bufferPaintBack;
01879
01880 bool isWindowInitialized;
01881 bool hasBackground;
01882 HWND g_hWndMenuBar;
01883
01884
01885
01886
01887
01888 static long FAR PASCAL StaticWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
01889 long WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
01890 int renderProc();
01891
01892 int UpdateFramePriv(bool eraseBack=false);
01893
01894 public:
01902 DirectDrawWarp(HINSTANCE hInstance,const TCHAR* name,bool topmost=false,HMENU menuBottom=NULL);
01906 DirectDrawWarp();
01907 ~DirectDrawWarp(void);
01908
01912 void UpdateFrame(bool eraseBack=false);
01914 void updateElements(){this->mouse->updateElement();};
01915
01917 void add(Section* e);
01918
01920 void changeControl(MessageBoxSense* mb);
01921
01923 void initWindow();
01927 void addToRedraw(RECT &rc,bool backErase);
01930 void doRepaintBuffered(int dy);
01940 HRESULT BltFast(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur, RECT *src,DWORD flag,LPDDBLTFX param);
01949 HRESULT BltMask(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur,DIRECTDRAW_GDI* maskBlt, RECT *src);
01958 void BltMix(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur, RECT *src,DWORD constantAlpha);
01963 static void deleteSurf(DIRECTDRAW_GDI** surf);
01969 static HRESULT createSurf(DDSURFACEDESC* desc,DIRECTDRAW_GDI* surf);
01974 static GDI_OVERLAY* createOverlay(DDSURFACEDESC* desc);
01976 static void beginPaint();
01978 static void endPaint();
01979
01985 void setBackgroundImg( LPCWSTR imgSrc=NULL,bool forLandscape=false);
01986
01992 void setMenu( HMENU hMenu );
01993
02001 void changeMenu( UINT message,int idMenu, LPARAM info ) ;
02006 void setBackgroundColor( COLORREF newColor);
02007
02008 static int background_color;
02009 RECT hMenuArea;
02010 HMENU myHMenu;
02011 };