bool UiInv::checkFloorInvClick(int hx, int hy, int x, int y) { for (int n = 0; n != FINVPGSIZE; n++) { if (isInRect(floorinv[n]->a->p, hx, hy)) { if (isInRect(floorinv[n]->a->p, x, y)) { if (selecteditem) { engine.map->dropItem(selecteditem, engine.map->player->x, engine.map->player->y); engine.map->player->inventory->removeItem(selecteditem); selecteditem = NULL; } else if (finv) { Item* i = finv->items.getItem(n+page*FINVPGSIZE); if (i) { if (engine.map->player->inventory->addItem(i)) { finv->items.removeItem(n+page*FINVPGSIZE); finv->checkExistance(); } } } } return true; } } return false; }
void UiDashboard::checkUnclick(int hx, int hy, int x, int y) { for (Actor** a = atkbuttons; a != atkbuttons+6; a++) { if (isInRect((*a)->p, hx, hy)) { if (isInRect((*a)->p, x, y)) switch ((int) (a - atkbuttons)) { case AtkButtons::TARGETED: if (!engine.map->player->weapon) { engine.map->player->attack = engine.map->player->defaultattack; } case AtkButtons::AOE: case AtkButtons::QUIRKATK: if (engine.map->player->weapon) { engine.map->player->weapon->attacks[a-atkbuttons-3]->select(engine.map->player); } break; case AtkButtons::BLOCK: case AtkButtons::HEAL: case AtkButtons::QUIRKDEF: if (engine.map->player->weapon) { engine.map->player->weapon->defenses[a-atkbuttons]->select(engine.map->player); } break; default: break; } return; } } }
bool Slider::onMouseMove(int x, int y) { if (dragging) { float val = xToValue(x - left - dragOffsetX); if (val != value) { value = val; draw(); } return true; } bool in = isInRect(x, y, left, top, width, height); if (in) { int sliderX = valueToX(value); bool hl = isInRect(x, y, left + sliderX, top, height, height); if (hl != highlight) { highlight = hl; draw(); } } else if (highlight) { highlight = false; draw(); } return in; }
//if two points in the same rect bool isInSameRect(Point p1, Point p2, vector<MyPointCloud>& rect_clouds){ for(int i=0; i<rect_clouds.size(); i++){ if(isInRect(p1, rect_clouds.at(i))&&isInRect(p2, rect_clouds.at(i))){ return true; } } return false; }
void Prompt::unclick(const Pos hp, const Pos p) { if (isInRect(button1, p.x, p.y) && isInRect(button1, hp.x, hp.y)) { doOpt1(); } else if (isInRect(button2, p.x, p.y) && isInRect(button2, hp.x, hp.y)) { doOpt2(); } }
void Prompt::render(SDL_Surface* surface, const Pos* pos) { SDL_FillRect(surface, &promptwindow, PROMPTCOLOR); SDL_FillRect(surface, &button1, pos && isInRect(button1, pos->x, pos->y) ? CLICKEDBUTTONCOLOR : UNCLICKEDBUTTONCOLOR); SDL_FillRect(surface, &button2, pos && isInRect(button2, pos->x, pos->y) ? CLICKEDBUTTONCOLOR : UNCLICKEDBUTTONCOLOR); for (auto &line : text) { line.first->render(surface, engine.font->font, line.second.x, line.second.y); } opt1.first->render(surface, engine.font->font, opt1.second.x, opt1.second.y); opt2.first->render(surface, engine.font->font, opt2.second.x, opt2.second.y); }
bool UiInv::checkPlrInvClick(int hx, int hy, int x, int y) { for (InvActor** a = plrinv; a != plrinv+30; a++) { if (isInRect((*a)->a->p, hx, hy)) { if(isInRect((*a)->a->p, x, y)) { Item* i = engine.map->player->inventory->itemAtSlot(a-plrinv); if (i == selecteditem) selecteditem = NULL; else selecteditem = i; } return true; } } return false; }
bool Slider::onMouseButtonDown(int button, int x, int y) { bool in = isInRect(x, y, left, top, width, height); if (in) { int sliderX = valueToX(value); bool hl = isInRect(x, y, left + sliderX, top, height, height); if (hl) { dragging = true; dragOffsetX = x - left - sliderX; } } return in; }
void Tree::build( PolyArea* polys[] , int num , Vec2f const& bbMin , Vec2f const& bbMax ) { clear(); int numEdge = 0; for( int i = 0 ; i < num ; ++i ) { PolyArea* poly = polys[i]; numEdge += poly->getVertexNum(); int prev = poly->getVertexNum() - 1; for( int cur = 0 ;cur < poly->getVertexNum() ; ++cur ) { assert( isInRect( poly->getVertex( prev ) , bbMin , bbMax ) ); assert( isInRect( poly->getVertex( cur ) , bbMin , bbMax ) ); addEdge( poly->getVertex( prev ) , poly->getVertex( cur ) , i ); prev = cur; } } Vec2f edgeBB[2] = { Vec2f( bbMin.x , bbMax.y ) , Vec2f( bbMax.x , bbMin.y ) }; addEdge( bbMin , edgeBB[0] , -1 ); addEdge( edgeBB[0] , bbMax , -1 ); addEdge( bbMax , edgeBB[1] , -1 ); addEdge( edgeBB[1] , bbMin , -1 ); numEdge += 4; struct CountFun { CountFun(){ current = 0; } int current; int operator()() {return current++;} }; IndexVec idxEdges( numEdge ); std::generate_n( idxEdges.begin() , numEdge , CountFun() ); assert( mRoot == nullptr ); mRoot = contructTree_R( idxEdges ); mRoot->parent = nullptr; }
SDL_Surface* UiInv::render(bool clicked, int hx, int hy) { for (int i = 0; i != 30; i++) { SDL_FillRect(surface, &plrinv[i]->a->p, plrinv[i]->color - (clicked && isInRect(plrinv[i]->a->p, hx, hy) ? 0x101010 : 0) - (selecteditem && engine.map->player->inventory->getItem(i) == selecteditem ? 0x101010 : 0)); plrinv[i]->str->render(surface, engine.font->font, plrinv[i]->a->p.x + 2, plrinv[i]->a->p.y + 2); } for (InvActor** a = floorinv; a != floorinv+FINVPGSIZE; a++) { SDL_FillRect(surface, &(*a)->a->p, (*a)->color - (clicked && isInRect((*a)->a->p, hx, hy) ? 0x101010 : 0)); (*a)->str->render(surface, engine.font->font, (*a)->a->p.x + 2, (*a)->a->p.y + 2); } {int i = 0; for (auto a : slots) { SDL_FillRect(surface, &a->p, 0xDD8822- (clicked && isInRect(a->p, hx, hy) ? 0x101010 : 0)); SDL_Rect r = {a->p.x + 2, a->p.y + 2, 16, 16}; SDL_BlitSurface(engine.texture, &a->r, surface, &r); r.x += 8+2; slotnames[i]->render(surface, engine.font->font, r.x, r.y); r.x -= 8+2; r.y += 8+2; itemnames[i]->render(surface, engine.font->font, r.x, r.y); i++; } } SDL_Rect p = prevpage->p; SDL_FillRect(surface, &p, 0xDD8822- (clicked && isInRect(p, hx, hy) ? 0x101010 : 0)); p.x += 14; p.y += 3; prevname->render(surface, engine.font->font, p.x, p.y); p = nextpage->p; SDL_FillRect(surface, &p, 0xDD8822- (clicked && isInRect(p, hx, hy) ? 0x101010 : 0)); p.x += 15; p.y += 3; nextname->render(surface, engine.font->font, p.x, p.y); return surface; }
bool ProjectileList::checkRect(int index,char origin, float x1, float y1, float x2, float y2){ Projectile * toCheck = &(pVector.at(index)); if(toCheck->origin == origin) return false; else if(isInRect(toCheck->getX(),toCheck->getY(),x1,y1,x2,y2)) return true; }
_XBool _XSliderEx::canGetFocus(float x,float y) { if(!m_isInited) return XFalse; //如果没有初始化直接退出 if(!m_isActive) return XFalse; //没有激活的控件不接收控制 if(!m_isVisiable) return XFalse; //如果不可见直接退出 if(!m_isEnable) return XFalse; //如果无效则直接退出 return isInRect(x,y); }
void Enemy::onDieEnemy() { if (!isInRect(getPosition(), Vec4(0, 0, 1280, 960))) { SimpleAudioEngine::getInstance()->playEffect(die_fx_1); this->setPosition(Point(1280 / 2, 960 - 20)); this->getPhysicsBody()->setVelocity(Point(0, 0)); m_HP--; } }
bool Checkbox::onMouseMove(int x, int y) { bool in = isInRect(x, y, left, top, width, height); if (in != mouseInside) { mouseInside = in; draw(); } return false; }
void UiButtons::checkUnclick(int hx, int hy, int x, int y) { if (isInRect(invbutton->p, x, y)) { engine.enginestate = engine.enginestate == engine.inv ? engine.running : engine.inv; engine.ui->inv->page = 0; engine.ui->inv->selecteditem = NULL; engine.ui->inv->updateInventory(); } }
bool UiInv::checkOtherButtonsClick(int hx, int hy, int x, int y) { if (finv) { if (isInRect(prevpage->p, hx, hy) && isInRect(prevpage->p, x, y)) { if (page != 0) page--; return true; } if (isInRect(nextpage->p, hx, hy) && isInRect(nextpage->p, x, y)) { if ((page+1)*FINVPGSIZE <= (unsigned int) finv->items.itemNo()) page++; return true; } } if (selecteditem) { if (isInRect(slots[selecteditem->type]->p, hx, hy) && isInRect(slots[selecteditem->type]->p, x, y)) { if (selecteditem->use(engine.map->player)) { engine.map->player->inventory->removeItem(selecteditem); engine.doTick(engine.USEDFLAG); engine.ui->dashboard->refreshButtons(); if (selecteditem->type != Itemtype::USE) { itemnames[selecteditem->type]->setText(engine.font, selecteditem->name); } } } selecteditem = NULL; } else { for (int i = 1; i != 4; i++) { if (isInRect(slots[i]->p, hx, hy) && isInRect(slots[i]->p, x, y)) { switch (i) { case Itemtype::ARMOR: if (engine.map->player->destructible->armor) if (engine.map->player->destructible->armor->unequip(engine.map->player)) { engine.map->player->destructible->armor = NULL; itemnames[i]->setText(engine.font, "-"); } break; case Itemtype::WEAPON: if (engine.map->player->weapon) { if (engine.map->player->weapon->unequip(engine.map->player)) { engine.map->player->weapon = NULL; engine.ui->dashboard->refreshButtons(); itemnames[i]->setText(engine.font, "-"); } } break; default: break; } } } } return false; }
bool Button::onMouseButtonDown(int button, int x, int y) { if (isInRect(x, y, left, top, width, height)) { sound->play(L"click.wav"); if (command) command->doAction(); return true; } else return false; }
bool Checkbox::onMouseButtonDown(int button, int x, int y) { if (isInRect(x, y, left, top, width, height)) { sound->play(L"click.wav"); checked = ! checked; draw(); return true; } else return false; }
bool Enemy::isAboveFloor(Point pos) // 判断当前位置是否在地板上 { for (auto x : CommonUtil::getInstance()->groundRect) { if (isInRect(pos, x + Vec4(0, 0, 0, 20))) { return true; } } return false; }
void CreditsMenu::Update(sf::RenderWindow& window, InputHandler &input) { for(it = menuItems.begin(); it != menuItems.end(); it++) { if(isInRect(input.getMousePos(window),it->second) && input.clicked(window)) { menuValue = it->first; break; } } }
bool Enemy::isInGround(Sprite* sprite) { for (auto x : CommonUtil::getInstance()->groundRect) { if (isInRect(sprite->getPosition(), x + Vec4(0, 0, 0, 15))) { log("isInRect"); return true; } } return false; }
SDL_Surface* UiDashboard::render(bool clicked, int hx, int hy) { for (int i = 0; i != 6; i++) { SDL_Rect p = atkbuttons[i]->p; SDL_Rect iconp = {p.x + 1, p.y + 1, 8, 8}; SDL_FillRect(surface, &p, clicked && isInRect(p, hx, hy) ? 0x885512 : 0xDDAA22); atknames[i]->render(surface, engine.font->font, p.x+1+8+1, p.y+1); SDL_BlitSurface(engine.texture, atkicons+i, surface, &iconp); } return surface; }
void UiXP::checkClick(int mb, int hx, int hy) { for (int i = 0; i != 10; i++) { if (isInRect(holder->bars[i]->bar->barmax, hx, hy)) { if (mb == SDL_BUTTON_LEFT) { holder->setFocus(i); } else if (mb == SDL_BUTTON_RIGHT) { holder->log(*engine.ui->log, i); } break; } } }
bool Enemy::isBoxHere() // 判断箱子是否出现在屏幕 { auto size = Director::getInstance()->getWinSize(); auto boxPos = getBoxSprite()->getPosition(); log("box.x = %f, box.y = %f", boxPos.x, boxPos.y); if (isInRect(boxPos, Vec4(0, 0, size.width, size.height))) { return true; } return false; }
SDL_Surface* UiButtons::render(bool clicked, int hx, int hy) { hpbar->render(surface); hpbar->renderName(surface); mpbar->render(surface); mpbar->renderName(surface); SDL_Rect p = invbutton->p; SDL_FillRect(surface, &p, clicked && isInRect(p, hx, hy) ? 0x885512 : 0xDDAA22); p.x += 5; p.y += 3; SDL_BlitSurface(engine.texture, &invbutton->r, surface, &p); p.x += 8 + 2; invtext->render(surface, engine.font->font, p.x, p.y); return surface; }
/*! * @brief 画面入力の読み込み(MAPの入力切り離した版) * @param [x,y] クリック時のマウスポインタの座標 * @retval MAP入力待ちのときは最近傍のCP,CS,CHを返す。 * 入力待ちのボタンが押されているときはMAP入力に優先してボタンの番号を返す。 * どちらでもない時はBUT_ENDを返す。 */ static CatanInput ActC_inputButton(int _x,int _y) { CatanInput input={ me_player,TYPE_OBJ_END,-1, BUT_END,false }; int cur_player=Act_GetWaitPlayer(); bool waitMapFlg=Act_GetWaitMapFlg(); bool isWaitingForMe = Act_IsMeWaited(input.player); /* マップ入力待ち かつ 自分待ちもしくは全員待ち 2013.02.17 */ /* マップ入力待ち かつ 自分待ちもしくは3人待ち 2013.03.03 */ if(isWaitingForMe && waitMapFlg) //(me_player==cur_player||/* 自分のみ待ち */ //( ( cur_player < 0 ) && (- cur_player != me_player) )))/* 3人待ち */ { input.obj = Dsp_GetNNObj( _x, _y); input.isInput=true; //input.but_num=BUT_MAP;//BUT_ENDのまま } /* ボタンの入力があるときはMAP入力に優先してボタンの番号を返す */ /* 後の処理で優先するように、という話 2013.02.17 */ for(int i = 0; i < BUT_END ; i++) { //if(i==BUT_MAP)continue; bool waitFlg_i=Act_GetWaitFlg(i); if(/*waitFlg[i]*/isWaitingForMe && waitFlg_i) //(me_player==cur_player||/* 自分のみ待ち */ //( ( cur_player < 0 ) && ((-cur_player) - 1 != me_player) )))/* 3人待ち */ { if(isInRect( _x, _y, i)) { //printf("input %d\n",i); input.but_num = i; input.isInput = true; break;/* 押されるボタンは同時に一つまでなのですぐbreakする */ } } } return input; }
bool HitTest(SDL_Rect rectFirst, SDL_Rect rectSecond) { bool isHit = false; if (isInRect(rectFirst.x, rectFirst.y, rectSecond)) isHit = true; if (isInRect(rectFirst.x + rectFirst.w, rectFirst.y, rectSecond)) isHit = true; if (isInRect(rectFirst.x, rectFirst.y + rectFirst.h, rectSecond)) isHit = true; if (isInRect(rectFirst.x + rectFirst.w, rectFirst.y + rectFirst.h, rectSecond)) isHit = true; if (isInRect(rectSecond.x, rectSecond.y, rectFirst)) isHit = true; if (isInRect(rectSecond.x + rectSecond.w, rectSecond.y, rectFirst)) isHit = true; if (isInRect(rectSecond.x, rectSecond.y + rectSecond.h, rectFirst)) isHit = true; if (isInRect(rectSecond.x + rectSecond.w, rectSecond.y + rectSecond.h, rectFirst)) isHit = true; return isHit; }
bool isInOption(int x, int y, int option) { return isInRect(x, y, 170, 95 + 25 * option, 150, 25); }
// // Process function of caption bar // LRESULT DockingCont::runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { static ToolTip toolTip; switch (Message) { case WM_LBUTTONDOWN: { _isMouseDown = TRUE; if (isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)) == posClose) { _isMouseClose = TRUE; _isMouseOver = TRUE; // start hooking hWndServer = _hCaption; winVer ver = (NppParameters::getInstance())->getWinVersion(); hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0); if (!hookMouse) { DWORD dwError = ::GetLastError(); TCHAR str[128]; ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError); ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed"), MB_OK | MB_ICONERROR); } ::RedrawWindow(hwnd, NULL, NULL, TRUE); } focusClient(); return TRUE; } case WM_LBUTTONUP: { _isMouseDown = FALSE; if (_isMouseClose == TRUE) { // end hooking ::UnhookWindowsHookEx(hookMouse); if (_isMouseOver == TRUE) { doClose(); } _isMouseClose = FALSE; _isMouseOver = FALSE; } focusClient(); return TRUE; } case WM_LBUTTONDBLCLK: { if (isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)) == posCaption) ::SendMessage(_hParent, DMM_FLOATALL, 0, (LPARAM)this); focusClient(); return TRUE; } case WM_MOUSEMOVE: { POINT pt = {0}; // get correct cursor position ::GetCursorPos(&pt); ::ScreenToClient(_hCaption, &pt); if (_isMouseDown == TRUE) { if (_isMouseClose == FALSE) { // keep sure that button is still down and within caption if ((wParam == MK_LBUTTON) && (isInRect(hwnd, pt.x, pt.y) == posCaption)) { _dragFromTab = FALSE; NotifyParent(DMM_MOVE); _isMouseDown = FALSE; } else { _isMouseDown = FALSE; } } else { BOOL isMouseOver = _isMouseOver; _isMouseOver = (isInRect(hwnd, pt.x, pt.y) == posClose ? TRUE : FALSE); // if state is changed draw new if (_isMouseOver != isMouseOver) { ::SetFocus(NULL); ::RedrawWindow(hwnd, NULL, NULL, TRUE); } } } else if (_bCapTTHover == FALSE) { _hoverMPos = isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)); if ((_bCaptionTT == TRUE) || (_hoverMPos == posClose)) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.hwndTrack = hwnd; tme.dwFlags = TME_LEAVE | TME_HOVER; tme.dwHoverTime = 1000; _bCapTTHover = _TrackMouseEvent(&tme); } } else if ((_bCapTTHover == TRUE) && (_hoverMPos != isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)))) { toolTip.destroy(); _bCapTTHover = FALSE; } return TRUE; } case WM_MOUSEHOVER: { RECT rc = {0}; POINT pt = {0}; // get mouse position ::GetCursorPos(&pt); toolTip.init(_hInst, hwnd); if (_hoverMPos == posCaption) { toolTip.Show(rc, _pszCaption.c_str(), pt.x, pt.y + 20); } else { toolTip.Show(rc, TEXT("Close"), pt.x, pt.y + 20); } return TRUE; } case WM_MOUSELEAVE: { toolTip.destroy(); _bCapTTHover = FALSE; return TRUE; } case WM_SIZE: { ::GetWindowRect(hwnd, &_rcCaption); ScreenRectToClientRect(hwnd, &_rcCaption); break; } case WM_SETTEXT: { ::RedrawWindow(hwnd, NULL, NULL, TRUE); return TRUE; } default: break; } return ::CallWindowProc(_hDefaultCaptionProc, hwnd, Message, wParam, lParam); }
bool MenuState::handleEvent(const sf::Event& event) { // Check and activate based on the mouse button click location MousePosition mPos = sf::Mouse::getPosition(*getContext().window); sf::Rect<float> startrect = sf::Rect<float>(mStartButton.getPosition().x, mStartButton.getPosition().y, 230.f, 50.f); sf::Rect<float> endrect = sf::Rect<float>(mExitButton.getPosition().x, mExitButton.getPosition().y, 230.f, 50.f); if (event.type == sf::Event::MouseButtonReleased) { if (isInRect(mPos, startrect)) { requestStackPop(); requestStackPush(States::Loading); } if (isInRect(mPos, endrect)) { requestStackPop(); } } if (event.type == sf::Event::MouseMoved) { if (isInRect(mPos, startrect)) { mStartButton.setColor(sf::Color(255, 255, 255, 255)); } else { mStartButton.setColor(sf::Color(200, 200, 200, 255)); } if (isInRect(mPos, endrect)) { mExitButton.setColor(sf::Color(255, 255, 255, 255)); } else { mExitButton.setColor(sf::Color(200, 200, 200, 255)); } } // Only handle an event if the keyboard is used if (event.type != sf::Event::KeyPressed) { return false; } if (event.key.code == sf::Keyboard::Return) { if (mOptionIndex == Play) { requestStackPop(); requestStackPush(States::Loading); } else if (mOptionIndex == Exit) { // Pop the last element off the stack (itself) requestStackPop(); } } else if (event.key.code == sf::Keyboard::Down) { // Increment and wrap around if (mOptionIndex < mOptions.size() - 1) { mOptionIndex++; } else { mOptionIndex = 0; } updateOptionText(); } else if (event.key.code == sf::Keyboard::Up) { // Decrement if (mOptionIndex > 0) { mOptionIndex--; } else { mOptionIndex = mOptions.size() - 1; } updateOptionText(); } return true; }