00001 #include "../../Library/SDK_Manila_Sense.h"
00002
00003 DIRECTDRAW_GDI *MyItem::checkBoxes=NULL;
00004 DIRECTDRAW_GDI *MyItem::switches=NULL;
00005 DIRECTDRAW_GDI *MyItem::button_normal=NULL;
00006 DIRECTDRAW_GDI *MyItem::button_big=NULL;
00007 DIRECTDRAW_GDI *MyItem::button_short=NULL;
00008 DIRECTDRAW_GDI *MyItem::checkBoxThrd=NULL;
00009 DIRECTDRAW_GDI *MyItem::switchThrd=NULL;
00010
00011 int MyItem::checkBoxesWidth;
00012 int MyItem::checkBoxesHeight;
00013 int MyItem::switchesWidth;
00014 int MyItem::switchesHeight;
00015 int MyItem::button_normalWidth;
00016 int MyItem::button_normalHeight;
00017 int MyItem::button_bigWidth;
00018 int MyItem::button_bigHeight;
00019 int MyItem::button_shortWidth;
00020 int MyItem::button_shortHeight;
00021 int MyItem::button_ckThrdWidth;
00022 int MyItem::button_swThrdWidth;
00023 int MyItem::button_ckThrdHeight;
00024 int MyItem::button_swThrdHeight;
00025
00026 void MyItem::loadSurf(){
00027 if(switchThrd==NULL&&type==ITEM_IS_SWITCH){
00028 switchThrd=loadImage(gi->btn_switch_thirdState);
00029 button_swThrdWidth=switchThrd->width/2;
00030 button_swThrdHeight=switchThrd->height;
00031 }
00032 if(checkBoxThrd==NULL&&type==ITEM_IS_CHECKBOX){
00033 checkBoxThrd=loadImage(gi->btn_checkbox_thirdState);
00034 button_ckThrdWidth=checkBoxThrd->width/2;
00035 button_ckThrdHeight=checkBoxThrd->height;
00036 }
00037 if(button_big==NULL&&type==ITEM_IS_BUTTON_BIG){
00038 button_big=loadImage(gi->btn_common_msgbox_large);
00039 button_bigWidth=button_big->width/4;
00040 button_bigHeight=button_big->height;
00041 }
00042 if(button_short==NULL&&type==ITEM_IS_BUTTON_SHORT){
00043 button_short=loadImage(gi->btn_common_msgbox_small);
00044 button_shortWidth=button_short->width/4;
00045 button_shortHeight=button_short->height;
00046 }
00047 if(button_normal==NULL&&type==ITEM_IS_BUTTON_NORMAL){
00048 button_normal=loadImage(gi->btn_common_normal);
00049 button_normalWidth=button_normal->width/4;
00050 button_normalHeight=button_normal->height;
00051 }
00052 if(switches==NULL&&type==ITEM_IS_SWITCH){
00053 switches=loadImage(gi->btn_common_switch);
00054 switchesWidth=switches->width/7;
00055 switchesHeight=switches->height;
00056 }
00057 if(checkBoxes==NULL&&type==ITEM_IS_CHECKBOX){
00058 checkBoxes=loadImage(gi->btn_common_checkbox);
00059 checkBoxesWidth=checkBoxes->width/6;
00060 checkBoxesHeight=checkBoxes->height;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 if(isCentered){
00086 centerH();
00087 }
00088
00089 }
00090 void MyItem::centerH(){
00091 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00092 int myWidth=this->getWidth();
00093 this->setLeft((dwWidth-myWidth)/2);
00094 this->setWidth(myWidth);
00095 isCentered=true;
00096 }
00097
00098 MyItem::MyItem(int idElement, int x,int y,unsigned char t,unsigned char s,wstring tex):Element(idElement, x,y,TYPE_ITEM)
00099 {
00100 isCentered=false;
00101 this->text=NULL;
00102 this->type=t;
00103 this->state=s;
00104
00105 wstring primaryText;
00106 wstring secondaryText;
00107
00108 loadSurf();
00109
00110 switch(type){
00111 case ITEM_IS_CHECKBOX:
00112 elementHeight=checkBoxesHeight;
00113 elementWidth=checkBoxesWidth;
00114 mySurface=checkBoxes;
00115 break;
00116 case ITEM_IS_SWITCH:
00117 elementHeight=switchesHeight;
00118 elementWidth=switchesWidth;
00119 mySurface=switches;
00120 break;
00121 case ITEM_IS_BUTTON_NORMAL:
00122 elementHeight=button_normalHeight;
00123 elementWidth=button_normalWidth;
00124 mySurface=button_normal;
00125 break;
00126 case ITEM_IS_BUTTON_BIG:
00127 elementHeight=button_bigHeight;
00128 elementWidth=button_bigWidth;
00129 mySurface=button_big;
00130 break;
00131 case ITEM_IS_BUTTON_SHORT:
00132 elementHeight=button_shortHeight;
00133 elementWidth=button_shortWidth;
00134 mySurface=button_short;
00135 break;
00136 default:
00137 LocalisedString::explainFail( LocalisedString::szCreateMyItem,L"Wrong parameter");
00138 }
00139
00140
00141 this->setHeight(elementHeight);
00142 this->setWidth(elementWidth);
00143
00144
00145 if(tex!=L""){
00146 changeText(tex);
00147 }else
00148 text=NULL;
00149 positionAbsolute.left=0;
00150 positionAbsolute.top=0;
00151 positionAbsolute.right=0;
00152 positionAbsolute.bottom=0;
00153
00154 colorHover=RGB(196,196,196);
00155 colorDsbl=RGB(128,128,128);
00156 colorNrmal=RGB(5,5,5);
00157 colorBackHover=RGB565to32(6,12,6);
00158 colorBackDsbl=RGB565to32(28,56,28);
00159 colorBackNrmal=RGB565to32(28,56,28);
00160 }
00161
00162 MyItem::~MyItem(void)
00163 {
00164
00165 delete text;
00166 }
00167
00168
00169 void MyItem::sizeChanged(Element* src,int width,int height){
00170 if(src!=text)
00171 return;
00172 switch(type){
00173 case ITEM_IS_BUTTON_NORMAL:
00174 case ITEM_IS_BUTTON_BIG:
00175 case ITEM_IS_BUTTON_SHORT:
00176 if(width>getWidth()){
00177 text->setWidth(getWidth());
00178 }
00179 if(height>getHeight()){
00180 text->setHeight(getHeight());
00181 }
00182 }
00183 }
00184
00185 bool MyItem::run(bool isRightClicked){
00186 if(!(this->state==ITEM_STATE_DSBL_EMPTY||this->state==ITEM_STATE_DSBL_SELECTED||this->state==ITEM_THIRD_STATE_DSBL))
00187 Element::run(isRightClicked);
00188
00189
00190 if(this->state==ITEM_STATE_HOVER_EMPTY){
00191 this->state=ITEM_STATE_EBL_SELECTED;
00192 setMustRedraw();
00193 return false;
00194 }
00195 if(this->state==ITEM_STATE_HOVER_SELECTED){
00196 this->state=ITEM_STATE_EBL_EMPTY;
00197 setMustRedraw();
00198 return false;
00199 }
00200 if(this->state==ITEM_THIRD_STATE){
00201 this->state=ITEM_STATE_EBL_SELECTED;
00202 setMustRedraw();
00203 return false;
00204 }
00205 return false;
00206 }
00207
00208
00209 void MyItem::unClick(){
00210 if(this->state==ITEM_STATE_HOVER_EMPTY){
00211 this->state=ITEM_STATE_EBL_EMPTY;
00212 setMustRedraw();
00213 return;
00214 }
00215
00216 if(this->state==ITEM_STATE_HOVER_SELECTED){
00217 this->state=ITEM_STATE_EBL_SELECTED;
00218 setMustRedraw();
00219 return;
00220 }
00221 };
00222
00223 Element* MyItem::isClicked(int x,int y){
00224 if(positionAbsolute.right==positionAbsolute.bottom&&
00225 positionAbsolute.bottom==0)
00226 return NULL;
00227
00228 int width=this->getWidth();
00229 if(text!=NULL&&width<text->getRight())
00230 width=text->getRight();
00231 if(x>positionAbsolute.left-5&&x<positionAbsolute.left+width+5&&y>positionAbsolute.top-10-gi->rcVisibleDesktopTOP.top&&
00232 y<positionAbsolute.top+this->getHeight()-gi->rcVisibleDesktopTOP.top){
00233 this->isActivated=true;
00234 if(this->state==ITEM_STATE_EBL_EMPTY){
00235 this->state=ITEM_STATE_HOVER_EMPTY;
00236 setMustRedraw();
00237 }else
00238 if(this->state==ITEM_STATE_EBL_SELECTED){
00239 this->state=ITEM_STATE_HOVER_SELECTED;
00240 setMustRedraw();
00241 }
00242 return this;
00243 }
00244 return NULL;
00245 };
00246
00247 void MyItem::paint(DIRECTDRAW_GDI* lpDDraw,int x,int y){
00248 int posReal;
00249 switch(type){
00250 case ITEM_IS_CHECKBOX:
00251 elementHeight=checkBoxesHeight;
00252 elementWidth=checkBoxesWidth;
00253 mySurface=checkBoxes;
00254 if(state==ITEM_THIRD_STATE||state==ITEM_THIRD_STATE_DSBL){
00255 mySurface=checkBoxThrd;
00256 elementHeight=button_ckThrdHeight;
00257 elementWidth=button_ckThrdWidth;
00258 posReal=state-ITEM_THIRD_STATE;
00259 }else
00260 posReal=state;
00261 break;
00262 case ITEM_IS_SWITCH:
00263 elementHeight=switchesHeight;
00264 elementWidth=switchesWidth;
00265 mySurface=switches;
00266 mySurface=switches;
00267 if(state==ITEM_STATE_HOVER_EMPTY||state==ITEM_STATE_HOVER_SELECTED)
00268 posReal=6;
00269 else{
00270 if(state==ITEM_THIRD_STATE||state==ITEM_THIRD_STATE_DSBL){
00271 elementHeight=button_swThrdHeight;
00272 elementWidth=button_swThrdWidth;
00273 mySurface=switchThrd;
00274 posReal=state-ITEM_THIRD_STATE;
00275 }else
00276 posReal=state;
00277 }
00278
00279 break;
00280 case ITEM_IS_BUTTON_NORMAL:
00281 case ITEM_IS_BUTTON_BIG:
00282 case ITEM_IS_BUTTON_SHORT:
00283 switch(state){
00284 case ITEM_STATE_EBL_EMPTY:
00285 case ITEM_STATE_EBL_SELECTED:
00286 posReal=0;
00287 break;
00288 case ITEM_STATE_DSBL_EMPTY:
00289 case ITEM_STATE_DSBL_SELECTED:
00290 posReal=2;
00291 break;
00292 case ITEM_STATE_HOVER_EMPTY:
00293 case ITEM_STATE_HOVER_SELECTED:
00294 posReal=1;
00295 break;
00296 }
00297 break;
00298 }
00299
00300 positionAbsolute.top=this->getTop()+y;
00301 positionAbsolute.bottom=positionAbsolute.top+elementHeight;
00302 positionAbsolute.left=this->getLeft()+x;
00303 positionAbsolute.right=positionAbsolute.left+elementWidth;
00304
00305
00306
00307 if(!(positionAbsolute.top>=gi->rcUpdateRegion.bottom||positionAbsolute.bottom<=gi->rcUpdateRegion.top||
00308 positionAbsolute.left>=gi->rcUpdateRegion.right||positionAbsolute.right<=gi->rcUpdateRegion.left)){
00309
00310 if(positionAbsolute.top<gi->rcUpdateRegion.top){
00311 clipping.top=gi->rcUpdateRegion.top-positionAbsolute.top;
00312 positionAbsolute.top=gi->rcUpdateRegion.top;
00313 }else{
00314 clipping.top=0;
00315 }
00316 if(positionAbsolute.bottom>gi->rcUpdateRegion.bottom){
00317 clipping.bottom=this->getHeight()-(positionAbsolute.bottom-gi->rcUpdateRegion.bottom);
00318 positionAbsolute.bottom=gi->rcUpdateRegion.bottom;
00319 }else{
00320 clipping.bottom=this->getHeight();
00321 }
00322 if(positionAbsolute.left<gi->rcUpdateRegion.left){
00323 clipping.left=posReal*elementWidth+gi->rcUpdateRegion.left-positionAbsolute.left;
00324 positionAbsolute.left=gi->rcUpdateRegion.left;
00325 }else{
00326 clipping.left=posReal*elementWidth;
00327 }
00328 if(positionAbsolute.right>gi->rcUpdateRegion.right){
00329 clipping.right=(posReal+1)*elementWidth-(positionAbsolute.right-gi->rcUpdateRegion.right);
00330 positionAbsolute.right=gi->rcUpdateRegion.right;
00331 }else{
00332 clipping.right=(posReal+1)*elementWidth;
00333 }
00334
00335 HRESULT hres;
00336
00337 if(positionAbsolute.bottom>positionAbsolute.top&&positionAbsolute.right>positionAbsolute.left){
00338
00339 hres= gi->window->BltFast(lpDDraw,&positionAbsolute, mySurface,&clipping, DDBLT_WAITNOTBUSY|DDBLT_KEYSRC,NULL);
00340
00341 if (hres != DD_OK)
00342 LocalisedString::explainFailDirectDraw(hres,L"MyItem Blt(mySurface);");
00343 }
00344 }
00345
00346 positionAbsolute.top=this->getTop()+y;
00347 positionAbsolute.left=this->getLeft()+x;
00348
00349
00350 if(this->text!=NULL){
00351 if((state==ITEM_STATE_HOVER_EMPTY||state==ITEM_STATE_HOVER_SELECTED)&&(type==ITEM_IS_BUTTON_NORMAL||type==ITEM_IS_BUTTON_BIG||type==ITEM_IS_BUTTON_SHORT))
00352 this->text->paintColor(lpDDraw,positionAbsolute.left,positionAbsolute.top,colorHover,colorBackHover);
00353 else
00354 if(state==ITEM_STATE_DSBL_EMPTY||state==ITEM_STATE_DSBL_SELECTED||state==ITEM_THIRD_STATE_DSBL)
00355 this->text->paintColor(lpDDraw,positionAbsolute.left,positionAbsolute.top,colorDsbl,colorBackDsbl);
00356 else
00357 this->text->paintColor(lpDDraw,positionAbsolute.left,positionAbsolute.top,colorNrmal,colorBackNrmal);
00358 }
00359
00360 };
00361
00362
00363
00364
00365 void MyItem::setMustRedraw(){
00366 if(positionAbsolute.right==positionAbsolute.bottom&&
00367 positionAbsolute.bottom==0)
00368 return;
00369
00370 if(text!=NULL&&(type==ITEM_IS_CHECKBOX||type==ITEM_IS_SWITCH))
00371 positionAbsolute.right=positionAbsolute.left+this->getWidth()+text->getRight();
00372 else
00373 positionAbsolute.right=positionAbsolute.left+this->getWidth();
00374
00375 if(positionAbsolute.right>GetSystemMetrics(SM_CXSCREEN))
00376 positionAbsolute.right=GetSystemMetrics(SM_CXSCREEN);
00377 if(positionAbsolute.left<0)
00378 positionAbsolute.left=0;
00379 positionAbsolute.bottom=positionAbsolute.top+this->getHeight();
00380 if(positionAbsolute.bottom>GetSystemMetrics(SM_CYSCREEN))
00381 positionAbsolute.bottom=GetSystemMetrics(SM_CYSCREEN);
00382 if(positionAbsolute.top<gi->rs.top)
00383 positionAbsolute.top=gi->rs.top;
00384
00385 if(positionAbsolute.bottom-positionAbsolute.top>0&&
00386 positionAbsolute.right-positionAbsolute.left>0){
00387 gi->window->addToRedraw(positionAbsolute,type==ITEM_IS_CHECKBOX||type==ITEM_IS_SWITCH||forceErase);
00388 }
00389 }
00390
00391
00392 void MyItem::changeText(wstring t){
00393 if(text!=NULL){
00394 switch(type){
00395 case ITEM_IS_BUTTON_NORMAL:
00396 case ITEM_IS_BUTTON_BIG:
00397 case ITEM_IS_BUTTON_SHORT:
00398 text->setText(t);
00399 text->centerH(0,this->getWidth());
00400 break;
00401 default:
00402 text->setRight(gi->rs.right);
00403 text->setText(t);
00404 }
00405 }else{
00406 switch(type){
00407 case ITEM_IS_CHECKBOX:
00408 case ITEM_IS_SWITCH:
00409 text=new MyLabel(-1,elementWidth+6*gi->percentOfVGA,0,t,0,(DWORD)0,true);
00410 break;
00411 case ITEM_IS_BUTTON_BIG:
00412 text=new MyLabel(-1,0,0,t,TEXT_BIG,(DWORD)0,true);
00413 text->centerH(0,this->getWidth());
00414 break;
00415 case ITEM_IS_BUTTON_NORMAL:
00416 case ITEM_IS_BUTTON_SHORT:
00417 text=new MyLabel(-1,0,0,t,0,(DWORD)0,true);
00418 text->centerH(0,this->getWidth());
00419 break;
00420 }
00421 }
00422 text->centerV(0,this->getHeight());
00423 text->isClickable=true;
00424 text->owner=this;
00425 this->setMustRedraw();
00426 }
00427
00428 void MyItem::changeColorTxt(DWORD color,DWORD backColor,int type){
00429 switch(type){
00430 case ITEM_COLOR_HOVER:
00431 colorHover=color;
00432 colorBackHover=backColor;
00433 break;
00434 case ITEM_COLOR_DISABLED:
00435 colorDsbl=color;
00436 colorBackDsbl=backColor;
00437 break;
00438 case ITEM_COLOR_NORMAL:
00439 colorNrmal=color;
00440 colorBackNrmal=backColor;
00441 break;
00442 }
00443 }