//-----------------------------------------------. void guiTypeTextDropDown::updateGui(float x, float y, bool firstHit, bool isRelative) { if( value.getNumValues() == 0 ){ return; } if(!firstHit)return; if( state == SG_STATE_SELECTED){ float relX = x - hitArea.x; float relY = y - hitArea.y; if(bShowDropDown) { for(unsigned int i = 0; i < vecDropList.size(); i++){ ofRectangle tmpRect(0, i * (boxHeight), boundingBox.width, boxHeight); if( isInsideRect(relX, relY, tmpRect) ){ value.setValue(i, 0); bShowDropDown = false; //CB notify(); break; } } } else { ofRectangle tmpRect(0, 0, boundingBox.width, boxHeight); if( isInsideRect(relX, relY, tmpRect) ){ bShowDropDown = true; } } } }
// Listens for SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP // events only. Based on the processed event the Button's state may change. void Button::HandleEvents(SDL_Event* event) { if (current_state_ != NORMAL) { current_state_ = NORMAL; } switch (event->type) { case SDL_MOUSEMOTION: // onHover if (isInsideRect(label_texbb_.dimensions, event->motion.x, event->motion.y)) { current_state_ = HOVERING; } break; case SDL_MOUSEBUTTONDOWN: // onClick if (isInsideRect(label_texbb_.dimensions, event->button.x, event->button.y)) { current_state_ = CLICKED; #ifndef DEBUG cout << "Button Clicked" << endl; #endif } break; case SDL_MOUSEBUTTONUP: // onRelease if (isInsideRect(label_texbb_.dimensions, event->button.x, event->button.y)) { current_state_ = RELEASED; #ifndef DEBUG cout << "Button Released" << endl; #endif } } }
//-----------------------------------------------. void guiTypeButtonSlider::updateGui(float x, float y, bool firstHit, bool isRelative){ if(state != SG_STATE_SELECTED)return; if(this->readOnly) return; if( firstHit ){ if( isInsideRect(x, y, slider->hitArea) ){ slider->state = SG_STATE_SELECTED; slider->setSelected(); slider->updateGui(x,y,firstHit,isRelative); prevMouse.set(x, y); } }else{ slider->state = SG_STATE_SELECTED; slider->setSelected(); slider->updateGui(x,y,firstHit,isRelative); prevMouse.set(x, y); } if( isInsideRect(x, y, leftButton->hitArea) ){ if(!firstHit) return; leftButton->state = SG_STATE_SELECTED; leftButton->setSelected(); leftButton->updateGui(x,y,firstHit,isRelative); slider->setSelected(); float pct = slider->value.getPct(); pct = pct - INCREMENT; slider->value.setValueAsPct( pct ); prevMouse.set(x, y); timeThen = timeNow; } if( isInsideRect(x, y, rightButton->hitArea) ){ if(!firstHit) return; leftButton->state = SG_STATE_SELECTED; rightButton->setSelected(); rightButton->updateGui(x,y,firstHit,isRelative); slider->setSelected(); float pct = slider->value.getPct(); pct = pct + INCREMENT; slider->value.setValueAsPct( pct ); prevMouse.set(x, y); timeThen = timeNow; } value.setValue(slider->value.getValueF()); // for xml settings saving //CB notify(); }
//------------------------------- void ofxLabGui::mousePressed(float x, float y, int button){ if( hidden ) return; bool tabButtonPressed = false; if( bCollapsible && isInsideRect(x, y, minimizeButton)){ if( bCollapsible ) minimize = !minimize; }else if( isInsideRect(x, y, topBar) && bDraggable){ dragging = true; mouseDownPoint.set(x - boundingBox.x, y-boundingBox.y, 0); }else if(!minimize){ bool bPanelClicked = false; bool bTextEnterSet = false; //check panel tabs for(int i = 0; i < panels.size(); i++){ if ( !panels[i]->enabled ) continue; ofRectangle scaledTabRect = panels[i]->getTabRect(); scaledTabRect.x += panels[i]->getPosX(); scaledTabRect.y += getPosY(); if( isInsideRect(x, y, scaledTabRect) && !bPanelClicked){ selectedPanel = i; panels[i]->bSelected = true; tabButtonPressed = true; bPanelClicked = true; //break; } else { panels[i]->bSelected = false; } } if (!bPanelClicked) panels[selectedPanel]->bSelected = true; } if(minimize == false && tabButtonPressed == false && isInsideRect(x, y, boundingBox) ){ for(int i = 0; i < panels.size(); i++){ if( i == selectedPanel )panels[i]->checkHit( x - hitArea.x, y - hitArea.y, button); } saveAsButton->checkHit(x, y, button); saveAsButton->updateGui(x, y, false, true); loadButton->checkHit(x, y, button); loadButton->updateGui(x, y, false, true); saveButton->checkHit(x, y, button); saveButton->updateGui(x, y, false, true); restoreButton->checkHit(x, y, button); restoreButton->updateGui(x, y, false, true); } prevMouse.set(x, y); }
fz_rect getContainingRect( fz_node *node, fz_rect maxRect ) { fz_rect rect = fz_emptyrect; if (node) { switch(node->kind) { case FZ_NTEXT: case FZ_NIMAGE: case FZ_NPATH: if (isInsideRect(maxRect, node->bbox)) rect = fz_mergerects(rect, node->bbox); break; default: break; } // Recurse for (fz_node *child = node->first; child; child = child->next) rect = fz_mergerects(rect, getContainingRect(child, maxRect)); } return rect; }
//------------------------------- bool ofxControlPanel::mouseDragged(float x, float y, int button){ if( hidden ) return false; //we do this so people can check if mouse is interacting with panel bool isDragging = dragging; if( !isDragging ){ ofRectangle checkRect = boundingBox; if( minimize ){ checkRect.height = topBar.height; } if( isInsideRect(x, y, checkRect) ){ isDragging = true; } } if(dragging)setPosition( MAX(0, x - mouseDownPoint.x), MAX(0, y -mouseDownPoint.y)); else if(!minimize){ for(int i = 0; i < (int) panels.size(); i++){ if( i == selectedPanel ){ if(button){ panels[i]->updateGui( x - prevMouse.x, y - prevMouse.y, false, true); }else{ panels[i]->updateGui( x - hitArea.x, y - hitArea.y, false, false); } } } } prevMouse.set(x, y); return isDragging; }
bool ofxControlPanel::isMouseInPanel(int x, int y){ ofRectangle nowBounding = boundingBox; if(minimize) nowBounding.height = 20; if( isInsideRect(x, y, nowBounding) ) return true; else return false; }
//------------------------------- bool ofxControlPanel::mousePressed(float x, float y, int button){ if( hidden ) return false; hitSomething = false; bool tabButtonPressed = false; ofRectangle checkRect = boundingBox; if( minimize ){ checkRect.height = topBar.height; } //we do this so people can check if mouse is interacting with panel if( isInsideRect(x, y, checkRect) ){ hitSomething = true; } if( isInsideRect(x, y, minimizeButton)){ minimize = !minimize; }else if( usingXml && isInsideRect(x, y, saveButton) ){ saveSettings(); saveDown = true; printf("saving settings!\n"); }else if( usingXml && isInsideRect(x, y, restoreButton) ){ printf("restoring settings!\n"); reloadSettings(); restoreDown = true; }else if( isInsideRect(x, y, topBar) && bDraggable){ dragging = true; mouseDownPoint.set(x - boundingBox.x, y-boundingBox.y, 0); }else if(!minimize){ int lastSelectedPanel = selectedPanel; for(int i = 0; i < (int) panels.size(); i++){ if( isInsideRect(x, y, panelTabs[i]) ){ selectedPanel = i; if( lastSelectedPanel != selectedPanel ){ bNewPanelSelected = true; }else{ bNewPanelSelected = false; } tabButtonPressed = true; break; } } } if(minimize == false && tabButtonPressed == false && isInsideRect(x, y, boundingBox) ){ for(int i = 0; i < (int) panels.size(); i++){ if( i == selectedPanel ){ elementSelected = panels[i]->checkHit( x - hitArea.x, y - hitArea.y, button); } } } prevMouse.set(x, y); return hitSomething; }
//------------------------------- void ofxControlPanel::mousePressed(float x, float y, int button){ if( hidden ) return; bool tabButtonPressed = false; if( isInsideRect(x, y, minimizeButton)){ minimize = !minimize; }else if( usingXml && isInsideRect(x, y, saveButton) ){ saveSettings(); saveDown = true; }else if( usingXml && isInsideRect(x, y, restoreButton) ){ reloadSettings(); restoreDown = true; }else if( isInsideRect(x, y, topBar) && bDraggable){ dragging = true; mouseDownPoint.set(x - boundingBox.x, y-boundingBox.y, 0); }else if(!minimize){ for(int i = 0; i < (int) panels.size(); i++){ if( isInsideRect(x, y, panelTabs[i]) ){ selectedPanel = i; tabButtonPressed = true; break; } } } if(minimize == false && tabButtonPressed == false && isInsideRect(x, y, boundingBox) ){ for(int i = 0; i < (int) panels.size(); i++){ if( i == selectedPanel )panels[i]->checkHit( x - hitArea.x, y - hitArea.y, button); } } prevMouse.set(x, y); }
//--------------------------------------------------------------------------- void ofxTSPSPeopleTracker::mousePressed( ofMouseEventArgs &e ) { if (isInsideRect(e.x, e.y, cameraView)){ activeViewIndex = CAMERA_SOURCE_VIEW; cameraView.setActive(); adjustedView.setActive(false); bgView.setActive(false); processedView.setActive(false); dataView.setActive(false); } else if (isInsideRect(e.x, e.y, adjustedView)){ activeViewIndex = ADJUSTED_CAMERA_VIEW; adjustedView.setActive(); cameraView.setActive(false); bgView.setActive(false); processedView.setActive(false); dataView.setActive(false); } else if (isInsideRect(e.x, e.y, bgView)){ activeViewIndex = REFERENCE_BACKGROUND_VIEW; bgView.setActive(); cameraView.setActive(false); adjustedView.setActive(false); processedView.setActive(false); dataView.setActive(false); } else if (isInsideRect(e.x, e.y, processedView)){ activeViewIndex = PROCESSED_VIEW; processedView.setActive(); cameraView.setActive(false); adjustedView.setActive(false); bgView.setActive(false); dataView.setActive(false); } else if (isInsideRect(e.x, e.y, dataView)){ activeViewIndex = DATA_VIEW; dataView.setActive(); cameraView.setActive(false); adjustedView.setActive(false); bgView.setActive(false); processedView.setActive(false); } }
//should be called on mousedown //------------------------------------------- bool guiBaseObject::checkHit(float x, float y, bool isRelative){ if(readOnly)return false; if( isInsideRect(x, y, hitArea) ){ state = SG_STATE_SELECTED; setSelected(); updateGui(x, y, true, isRelative); float offsetX = x - hitArea.x; float offsetY = y - hitArea.y; for(unsigned int i = 0; i < children.size(); i++){ children[i]->checkHit(offsetX, offsetY, isRelative); } return true; } return false; }
//-----------------------------------------------. void guiTypeMultiToggle::updateGui(float x, float y, bool firstHit, bool isRelative){ if(!firstHit)return; if( state == SG_STATE_SELECTED){ float relX = x - hitArea.x; float relY = y - hitArea.y; for(unsigned int i = 0; i < bNames.size(); i++){ ofRectangle tmpRect(0, i * (boxSize+boxSpacing), boxSize, boxSize); if( isInsideRect(relX, relY, tmpRect) ){ value.setValue(i, 0); break; } } //CB notify(); } }
//------------------------------- void ofxControlPanel::mouseDragged(float x, float y, int button){ if( hidden ) return; if(dragging)setPosition( MAX(0, x - mouseDownPoint.x), MAX(0, y -mouseDownPoint.y)); else if(!minimize){ for(int i = 0; i < panels.size(); i++){ if( i == selectedPanel ){ if(button){ panels[i]->updateGui( x - prevMouse.x, y - prevMouse.y, false, true); }else{ panels[i]->updateGui( x - hitArea.x, y - hitArea.y, false, false); } } } } if( isInsideRect(x, y, boundingBox) ) bMouseInPanel = true; else bMouseInPanel = false; prevMouse.set(x, y); }
int menu(SDL_Renderer* Renderer){ SDL_Event event; SDL_Texture* cursor_texture = getTextureFromPath("BMPimages/Cursor/1.bmp", Renderer); ButtonMenu* startButton = malloc(sizeof(ButtonMenu)); ButtonMenu* exitButton = malloc(sizeof(ButtonMenu)); VolumeMenu* volumeButton = malloc(sizeof(VolumeMenu)); TTF_Font* Font = TTF_OpenFont("TTFtext/GOST-type-B-Standard.ttf", 1000); Mix_Music* musicMenu = Mix_LoadMUS("MIXmusic/space.flac"); GameStates state = IN_MENU; int x, y; int volumeOn = 1; SDL_Rect menuRect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}; SDL_Texture* array_menu_bg[BG_SPRITES]; size_t displace_menu_bg_2 = 0; size_t displace_menu_bg_3 = 0; size_t displace_menu_bg_4 = 0; Mix_PlayMusic(musicMenu, -1); initButtons(Renderer, Font, startButton, exitButton, volumeButton); initMenuBgSprites(Renderer, array_menu_bg); while(state == IN_MENU){ while(SDL_PollEvent(&event)) { if (event.type == SDL_QUIT){ state = EXIT; } if (event.type == SDL_MOUSEMOTION){ SDL_GetMouseState(&x, &y); if (isInsideRect(x, y, startButton->Rect)) startButton->cur_texture = startButton->mouseInside; else startButton->cur_texture = startButton->mouseOutside; if (isInsideRect(x, y, exitButton->Rect)) exitButton->cur_texture = exitButton->mouseInside; else exitButton->cur_texture = exitButton->mouseOutside; if (isInsideRect(x, y, volumeButton->Rect)){ if (volumeOn) volumeButton->cur_texture = volumeButton->mouseInside_volOn; else volumeButton->cur_texture = volumeButton->mouseInside_volOff; } else{ if (volumeOn) volumeButton->cur_texture = volumeButton->mouseOutside_volOn; else volumeButton->cur_texture = volumeButton->mouseOutside_volOff; } } if (event.type == SDL_MOUSEBUTTONDOWN){ SDL_GetMouseState(&x, &y); if (isInsideRect(x, y, startButton->Rect)) state = START; if (isInsideRect(x, y, exitButton->Rect)) state = EXIT; if (isInsideRect(x, y, volumeButton->Rect)){ if (volumeOn){ volumeOn = 0; Mix_PauseMusic(); volumeButton->cur_texture = volumeButton->mouseInside_volOff; } else{ volumeOn = 1; Mix_ResumeMusic(); volumeButton->cur_texture = volumeButton->mouseInside_volOn; } } } } SDL_SetRenderDrawColor(Renderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(Renderer); SDL_RenderCopy(Renderer, array_menu_bg[0], NULL, &menuRect); renderInfinityText(Renderer, array_menu_bg[1], &displace_menu_bg_2, 544, 2, 1); renderInfinityText(Renderer, array_menu_bg[2], &displace_menu_bg_3, 544, 2, 2); renderInfinityText(Renderer, array_menu_bg[3], &displace_menu_bg_4, 544, 2, 3); SDL_RenderCopy(Renderer, startButton->cur_texture, NULL, &startButton->Rect); SDL_RenderCopy(Renderer, volumeButton->cur_texture, NULL, &volumeButton->Rect); SDL_RenderCopy(Renderer, exitButton->cur_texture, NULL, &exitButton->Rect); showCursor(Renderer, cursor_texture); SDL_RenderPresent(Renderer); getFps(); waitForFps(35); } return state; }
static void CB_MouseUp(s32 x,s32 y) { TRomSetState *pCurRomSetState=&RomSetState; if(isInsideRect(menurect11,x,y)==true) { } if(isInsideRect(menurect12,x,y)==true) { } if(isInsideRect(menurect13,x,y)==true) { } if(isInsideRect(menurect14,x,y)==true) { } if(isInsideRect(menurect16,x,y)==true) { if(pCurRomSetState->CheatState) { isPressRect16=false; DSIdx=dsi(); strcpy(CheatRomInfo.FullPathAlias,RomSetInfo.FullPathAlias); memcpy(&RomSetStateTmp,&RomSetState,sizeof(TRomSetState)); SetFlag(); { strcpy(pNDSAlis,CheatRomInfo.FullPathAlias); if(isHomeBrew() == true) { //do nothing } else {//商业ROM启动代码 //打开金手指窗口 if(isUserCheatDataExits()) { NDSCheatInfo *pInfo=FindSelectNDSCheatHeadInfo(); if(pInfo) { safefree(pInfo); isPressRect16=false; SetNextProc(ENP_Cheat,EPFE_CrossFade); } } else isPressRect16=true; } } } } if(isInsideRect(menurect00,x,y)==true) { isPressA=false; CloseRomData(); CB_CancelBtn_Click(NULL); } if(isInsideRect(menurect01,x,y)==true) { isPressB=false; CB_CancelBtn_Click(NULL); } }
static void CB_MouseDown(s32 x,s32 y) { TRomSetState *pCurRomSetState=&RomSetState; if(isInsideRect(menurect11,x,y)==true) { { if(pCurRomSetState->SoftReset) pCurRomSetState->SoftReset=false; else pCurRomSetState->SoftReset=true; ItemIdx=0; } } if(isInsideRect(menurect12,x,y)==true) { { if(pCurRomSetState->RealtimeSave) pCurRomSetState->RealtimeSave=false; else pCurRomSetState->RealtimeSave=true; ItemIdx=1; } } if(isInsideRect(menurect13,x,y)==true) { { if(pCurRomSetState->GameGuide) pCurRomSetState->GameGuide=false; else pCurRomSetState->GameGuide=true; ItemIdx=2; } } if(isInsideRect(menurect14,x,y)==true) { { if(pCurRomSetState->CheatState) pCurRomSetState->CheatState=false; else pCurRomSetState->CheatState=true; ItemIdx=3; } } if(isInsideRect(menurect15,x,y)==true) { { if(pCurRomSetState->DownloadPlayState) pCurRomSetState->DownloadPlayState=false; else pCurRomSetState->DownloadPlayState=true; ItemIdx=4; } } if(isInsideRect(menurect16,x,y)==true) { if(pCurRomSetState->CheatState) { isPressRect16=false; } } if(isInsideRect(menurect17,x,y)==true) { { if(pCurRomSetState->SpeciaMode) pCurRomSetState->SpeciaMode=false; else pCurRomSetState->SpeciaMode=true; ItemIdx=5; } } if(isInsideRect(menurect18,x,y)==true) { { if(pCurRomSetState->SpeciaMode) { pCurRomSetState->Speed += 1; if(pCurRomSetState->Speed == 11) pCurRomSetState->Speed = 0; } } } if(isInsideRect(menurect00,x,y)==true) { isPressA=true; } if(isInsideRect(menurect01,x,y)==true) { isPressB=true; } }