00001 #include "../../Library/SDK_Manila_Sense.h"
00002
00003 DIRECTDRAW_GDI *MySelector::header=NULL;
00004 DIRECTDRAW_GDI *MySelector::listBottom=NULL;
00005 DIRECTDRAW_GDI *MySelector::listMiddle=NULL;
00006 int MySelector::elementListWidth=0;
00007 int MySelector::elementWidth=0;
00008 int MySelector::elementHeight=0;
00009
00010 void MySelector::loadSurf(){
00011
00012 if(header==NULL){
00013 header=loadImage(gi->btn_common_combo_down);
00014 elementWidth=header->width/4;
00015 elementHeight=header->height;
00016
00017 }
00018 if(listBottom==NULL){
00019 listBottom=loadImage(gi->btn_common_listitem_bottom);
00020
00021 }
00022 if(listMiddle==NULL){
00023 listMiddle=loadImage(gi->btn_common_listitem_middle);
00024 elementListWidth=listMiddle->width/4;
00025
00026 }
00027
00028 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00029 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00030
00031 if(dwWidth > dwHeight){
00032 if(paddingSup==0){
00033 double diff=dwWidth- dwHeight;
00034 paddingSup=diff/2;
00035 if(this->getRight()+paddingSup<dwWidth){
00036 this->setRight(this->getRight()+paddingSup);
00037 this->setLeft(this->getLeft()+paddingSup);
00038 }else{
00039 paddingSup=0;
00040 }
00041 }
00042 }else{
00043 if(paddingSup!=0){
00044 this->setRight(this->getRight()-paddingSup);
00045 this->setLeft(this->getLeft()-paddingSup);
00046 paddingSup=0;
00047 }
00048 }
00049
00050 }
00051 MySelector::MySelector(int idElement, int x,int y,wstring nameOfChoice):Element(idElement, x,y,TYPE_SELECTOR)
00052 {
00053 backgroundIsCaptured=true;
00054 backgroundBuff=NULL;
00055 loadSurf();
00056 itemChoose=-1;
00057
00058 this->setHeight(header->height);
00059 this->setWidth(elementWidth);
00060 positionAbsolute.left=0;
00061 positionAbsolute.top=0;
00062 positionAbsolute.right=0;
00063 positionAbsolute.bottom=0;
00064
00065 values=new MyPanel(-1,5,0,elementListWidth-10,L"",false,true);
00066
00067 title=new MyLabel(-1,5,0,(elementListWidth-30)/gi->percentOfVGA,elementHeight/gi->percentOfVGA,nameOfChoice);
00068 title->isClickable=true;
00069 title->center();
00070
00071 container=NULL;
00072 animation=false;
00073 isOpen=false;
00074 hasPaintingHook=false;
00075 animToVisibility=false;
00076 state=SELECT_STATE_NORMAL;
00077 selected=NULL;
00078 animIndex=0;
00079 }
00080
00081 MySelector::~MySelector(void)
00082 {
00083 }
00084
00085 bool MySelector::run(bool isRightClicked){
00086 Element::run(isRightClicked);
00087
00088 if(state!=SELECT_STATE_HOVER){
00089 return false;
00090 }
00091 if(values->getSize()==0)
00092 return false;
00093
00094 container=(Section*)this->mouseEvent->changeMouseAnalyse(this);
00095 this->state=SELECT_STATE_SELECTED;
00096 this->setMustRedraw();
00097
00098 animToVisibility=true;
00099 animation=false;
00100 isOpen=false;
00101 animIndex=0;
00102 if(backgroundBuff!=NULL)
00103 DirectDrawWarp::deleteSurf(&backgroundBuff);
00104
00105
00106 DDSURFACEDESC DDSurfDesc;
00107 memset(&DDSurfDesc, 0, sizeof(DDSurfDesc));
00108 DDSurfDesc.dwSize = sizeof(DDSurfDesc);
00109 DDSurfDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
00110 DDSurfDesc.dwWidth = gi->rs.right;
00111 DDSurfDesc.dwHeight = gi->rs.bottom;
00112
00113 backgroundBuff=new DIRECTDRAW_GDI;
00114
00115 HRESULT hret=DirectDrawWarp::createSurf(&DDSurfDesc, backgroundBuff);
00116 if (hret != DD_OK)
00117 LocalisedString::explainFailDirectDraw(hret,L"MySelector CreateSurface");
00118 backgroundIsCaptured=true;
00119
00120
00121 SetTimer(gi->m_hWnd, 1, MS_PER_FRAME, NULL);
00122 startSlide=GetTickCount();
00123
00124 return true;
00125 }
00126 void MySelector::unClick(){
00127 if(this->state==SELECT_STATE_HOVER){
00128 this->state=SELECT_STATE_NORMAL;
00129 setMustRedraw();
00130 }
00131
00132 if(container!=NULL){
00133 state=SELECT_STATE_NORMAL;
00134 if(backgroundBuff!=NULL)
00135 DirectDrawWarp::deleteSurf(&backgroundBuff);
00136 isOpen=false;
00137 gi->rcUpdateRegion=gi->rs;
00138 container->setDrawingHook(NULL);
00139 container->verifScrollingRange(0,false);
00140 hasPaintingHook=false;
00141 this->mouseEvent->changeMouseAnalyse(container);
00142 mouseEvent->setClickSelected(false);
00143
00144 animation=false;
00145 isOpen=false;
00146 gi->window->addToRedraw(gi->rs,true);
00147 }
00148
00149 };
00150
00151 Element* MySelector::isClicked(int x,int y){
00152 if(state==SELECT_STATE_DSBL){
00153 return NULL;
00154 }
00155 if(positionAbsolute.right==positionAbsolute.bottom&&
00156 positionAbsolute.bottom==0)
00157 return NULL;
00158
00159 if(x>positionAbsolute.left&&x<positionAbsolute.left+getWidth()&&
00160 y>positionAbsolute.top-gi->rcVisibleDesktopTOP.top&&y<positionAbsolute.top-gi->rcVisibleDesktopTOP.top+this->getHeight()){
00161 this->isActivated=true;
00162 if(this->state==SELECT_STATE_NORMAL){
00163 this->state=SELECT_STATE_HOVER;
00164 setMustRedraw();
00165 }
00166 return this;
00167 }
00168 return NULL;
00169 };
00170
00171 void MySelector::paint(DIRECTDRAW_GDI* lpDDraw,int x,int y){
00172
00173 if(hasPaintingHook){
00174 y=lastY;
00175 if(!backgroundIsCaptured){
00176 backgroundIsCaptured=true;
00177 gi->window->BltFast(backgroundBuff,&gi->rs,gi->primaryBuffer,&gi->rs,NULL,NULL);
00178 }
00179 }else
00180 lastY=y;
00181 HRESULT hres;
00182
00183
00184 positionAbsolute.top=this->getTop()+y;
00185 positionAbsolute.bottom=positionAbsolute.top+this->getHeight();
00186 positionAbsolute.left=this->getLeft()+x;
00187 positionAbsolute.right=positionAbsolute.left+getWidth();
00188
00189 if(animation){
00190
00191 DWORD timeL=(GetTickCount()-startSlide);
00192
00193 double accel=((double)values->getHeight())/(300.0*50.0);
00194
00195 int dist=(accel*(timeL*timeL))/2.0;
00196 if(dist<values->getHeight()){
00197 animIndex=dist;
00198 }else{
00199 animIndex=values->getHeight();
00200 animation=false;
00201 isOpen=true;
00202
00203 KillTimer(gi->m_hWnd, 1);
00204 }
00205 if(animIndex>0){
00206 gi->rcUpdateRegion=positionAbsolute;
00207 gi->rcUpdateRegion.top=this->getTop()+y+this->getHeight();
00208 gi->rcUpdateRegion.bottom=gi->rcUpdateRegion.top+animIndex;
00209 if(gi->rcUpdateRegion.bottom>gi->rs.bottom)
00210 gi->rcUpdateRegion.bottom=gi->rs.bottom;
00211
00212 if(backgroundBuff!=NULL)
00213 gi->window->BltFast(lpDDraw,&gi->rcUpdateRegion,backgroundBuff,&gi->rcUpdateRegion,NULL,NULL);
00214
00215
00216 this->values->paint(lpDDraw,
00217 positionAbsolute.left,this->getTop()+y+this->getHeight()-4+animIndex-values->getHeight());
00218 }
00219 }else{
00220 if(isOpen){
00221
00222
00223 if(backgroundBuff!=NULL)
00224 gi->window->BltFast(lpDDraw,&gi->rcUpdateRegion,backgroundBuff,&gi->rcUpdateRegion,NULL,NULL);
00225
00226 this->values->paint(lpDDraw,positionAbsolute.left,this->getTop()+y+this->getHeight()-4+listDY);
00227 gi->mustRedraw=false;
00228 };
00229 }
00230
00231
00232
00233
00234 if(!(positionAbsolute.top>=gi->rcUpdateRegion.bottom||positionAbsolute.bottom<=gi->rcUpdateRegion.top||
00235 positionAbsolute.left>=gi->rcUpdateRegion.right||positionAbsolute.right<=gi->rcUpdateRegion.left)){
00236
00237 int top=gi->rcUpdateRegion.top;
00238 if(top<gi->rs.top)
00239 top=gi->rs.top;
00240 if(positionAbsolute.top<top){
00241 clipping.top=top-positionAbsolute.top;
00242 positionAbsolute.top=top;
00243 }else{
00244 clipping.top=0;
00245 }
00246 if(positionAbsolute.bottom>gi->rcUpdateRegion.bottom){
00247 clipping.bottom=this->getHeight()-(positionAbsolute.bottom-gi->rcUpdateRegion.bottom);
00248 positionAbsolute.bottom=gi->rcUpdateRegion.bottom;
00249 }else{
00250 clipping.bottom=this->getHeight();
00251 }
00252 if(positionAbsolute.left<gi->rcUpdateRegion.left){
00253 clipping.left=state*elementWidth+gi->rcUpdateRegion.left-positionAbsolute.left;
00254 positionAbsolute.left=gi->rcUpdateRegion.left;
00255 }else{
00256 clipping.left=state*elementWidth;
00257 }
00258 if(positionAbsolute.right>gi->rcUpdateRegion.right){
00259 clipping.right=(state+1)*elementWidth-(positionAbsolute.right-gi->rcUpdateRegion.right);
00260 positionAbsolute.right=gi->rcUpdateRegion.right;
00261 }else{
00262 clipping.right=(state+1)*elementWidth;
00263 }
00264
00265 if (positionAbsolute.bottom-positionAbsolute.top>0)
00266 {
00267 hres= gi->window->BltFast(lpDDraw,&positionAbsolute, header,&clipping, NULL,NULL);
00268 if (hres != DD_OK)
00269 LocalisedString::explainFailDirectDraw(hres,L"MySelector Blt(header);");
00270 }
00271
00272
00273 if(title!=NULL){
00274 if(state==SELECT_STATE_NORMAL||state==SELECT_STATE_SELECTED)
00275 this->title->paintColor(lpDDraw,this->getLeft()+x,this->getTop()+y,RGB(5,5,5),RGB565to32(28,56,28));
00276 else
00277 if(state==SELECT_STATE_HOVER)
00278 this->title->paintColor(lpDDraw,this->getLeft()+x,this->getTop()+y,RGB(160,160,160),RGB565to32(6,12,6));
00279 else
00280 title->paintColor(lpDDraw,this->getLeft()+x,this->getTop()+y,RGB(160,160,160),RGB565to32(28,56,28));
00281 }
00282 }
00283
00284 if(!hasPaintingHook){
00285
00286 positionAbsolute.top=this->getTop()+y;
00287 positionAbsolute.left=this->getLeft()+x;
00288 }
00289 };
00290
00291
00292 int MySelector::mouseGesture(){
00293 if(animToVisibility){
00294 listDY=0;
00295 bool slideUp=(values->getHeight()+getHeight()>gi->rs.bottom);
00296 double lengthSlide=0;
00297 if(slideUp){
00298 lengthSlide=positionAbsolute.top-gi->rs.top;
00299 if(lengthSlide<1)
00300 lengthSlide=0;
00301 }else{
00302
00303 slideUp=(positionAbsolute.bottom+values->getHeight()>gi->rs.bottom);
00304 lengthSlide=positionAbsolute.bottom+values->getHeight()-gi->rs.bottom;
00305 }
00306 if(slideUp&&lengthSlide!=0){
00307 DWORD timeL=GetTickCount()-startSlide;
00308 double accel=lengthSlide/(300.0*50.0);
00309
00310 int dist=-(accel*(timeL*timeL))/2.0;
00311 if(lengthSlide+dist<0||dist>0)
00312 dist=-lengthSlide;
00313 container->slideOverlay(dist);
00314 gi->mustRedraw=false;
00315 lengthSlide=dist;
00316 }
00317 if(lengthSlide==0){
00318 mouseEvent->stopScroll();
00319 startSlide=GetTickCount();
00320 animToVisibility=false;
00321 animation=true;
00322 container->setDrawingHook(this);
00323 hasPaintingHook=true;
00324 gi->mustRedraw=true;
00325 backgroundIsCaptured=false;
00326 }
00327 return lengthSlide;
00328 }
00329
00330 if(!mouseEvent->pickChange())
00331 return 0;
00332
00333 if(mouseEvent->isClicked()||mouseEvent->isDblClicked()){
00334 if(selected!=NULL){
00335
00336 int nbElem=values->getSize();
00337 for(int i=0;i<nbElem;i++){
00338
00339 if(values->getElement(i)==selected)
00340 itemChoose=i;
00341 else
00342 values->getElement(i)->unClick();
00343 }
00344 selected->run();
00345 setSelection(itemChoose);
00346 }
00347 selected=NULL;
00348 this->unClick();
00349 return 0;
00350 }
00351
00352 if(mouseEvent->isSelected()){
00353 if(this->selected!=NULL){
00354 this->selected->unClick();
00355 this->selected=NULL;
00356 }
00357 int posX,posY;
00358 this->mouseEvent->getMousePosition(posX,posY);
00359 this->selected=(MyLabel*)values->isClicked(posX,posY);
00360 if(selected==NULL)
00361 this->unClick();
00362 }
00363
00364 if(!mouseEvent->isSelected()&&this->selected!=NULL){
00365 this->selected->unClick();
00366 this->selected=NULL;
00367 }
00368
00369
00370
00371
00372 int dY=this->mouseEvent->getMouseDY();
00373 int yBottom=dY;
00374 if(yBottom<listDY)
00375 yBottom=listDY;
00376 yBottom=positionAbsolute.bottom+yBottom+values->getHeight();
00377 if (yBottom<gi->rs.bottom)
00378 {
00379 yBottom=gi->rs.bottom;
00380 }
00381 RECT updateR={positionAbsolute.left,positionAbsolute.bottom,
00382 positionAbsolute.right,yBottom};
00383 gi->window->addToRedraw(updateR,false);
00384 listDY+=dY;
00385 int minHeight=gi->rs.bottom/4;
00386 if(minHeight>values->getHeight())
00387 listDY=0;
00388 else
00389 if(listDY < -values->getHeight()+minHeight)
00390 listDY = -values->getHeight()+minHeight;
00391 if(listDY>0)
00392 listDY=0;
00393
00394 return 0;
00395 };
00396
00397
00398 void MySelector::addItem(wstring word){
00399
00400 int nbElem=values->getSize();
00401
00402 MyLabel* lab;
00403 if(nbElem==0){
00404 lab=new MyLabel(-1,0,0,word,listBottom);
00405 }else{
00406 lab=new MyLabel(-1,0,0,word,listBottom);
00407 ((MyLabel*)values->getElement(nbElem-1))->setBkg(listMiddle);
00408 }
00409 lab->center();
00410 values->add(lab);
00411 };
00412 int MySelector::getSelection(){
00413 if(itemChoose>=0)
00414 return itemChoose;
00415 int nbElem=values->getSize();
00416 for(int i=0;i<nbElem;i++){
00417 if(values->getElement(i)==selected){
00418 itemChoose=i;
00419 return i;
00420 }
00421 }
00422 return -1;
00423 };
00424 MyLabel* MySelector::operator[] (unsigned int i){
00425 int nbElem=values->getSize();
00426 if(i<nbElem&&i>0)
00427 return (MyLabel*)values->getElement(i);
00428 return NULL;
00429 }
00430 void MySelector::updateTitle(wstring wantedTitle){
00431 if(selected==NULL&&(itemChoose<0||itemChoose>=values->getSize())){
00432 title->setText(wantedTitle);
00433 }else{
00434 if(selected==NULL)
00435 selected=(MyLabel*)values->getElement(itemChoose);
00436 title->setText(selected->getText());
00437 }
00438 title->center();
00439 setMustRedraw();
00440 }
00441 void MySelector::setSelection(int idSelect){
00442 if(idSelect<0||idSelect>=values->getSize())
00443 return;
00444 itemChoose=idSelect;
00445 selected=(MyLabel*)values->getElement(itemChoose);
00446 if(selected!=NULL){
00447 selected->run();
00448 updateTitle();
00449 }
00450 getGestEvent()->messageProc(this,EVENT_VALUE_CHANGED);
00451 };