void IngameWindow::MouseLeftDown(const MouseCoords& mc) { // Maus muss sich auf der Titelleiste befinden Rect title_rect( static_cast<unsigned short>(pos_.x + LOADER.GetImageN("resource", 36)->getWidth()), pos_.y, static_cast<unsigned short>(width_ - LOADER.GetImageN("resource", 36)->getWidth() - LOADER.GetImageN("resource", 37)->getWidth()), LOADER.GetImageN("resource", 43)->getHeight() ); if(Coll(mc.x, mc.y, title_rect)) { // Start mit Bewegung isMoving = true; lastMousePos = DrawPoint(mc.x, mc.y); } // beiden Buttons oben links und rechts prfen const Rect rec[2] = { GetLeftButtonRect(), GetRightButtonRect() }; for(unsigned char i = 0; i < 2; ++i) { if(Coll(mc.x, mc.y, rec[i])) button_state[i] = BUTTON_PRESSED; } }
bool ctrlScrollBar::Msg_LeftDown(const MouseCoords& mc) { if (Coll(mc.x, mc.y, GetX(), GetY() + button_height + scrollbar_pos, width_, scrollbar_height)) { // Maus auf dem Scrollbutton move = true; return true; } else if (Coll(mc.x, mc.y, GetX(), GetY(), width_, button_height) || Coll(mc.x, mc.y, GetX(), GetY() + height_ - button_height, width_, button_height)) { // Maus auf einer Schaltflaeche return RelayMouseMessage(&Window::Msg_LeftDown, mc); } else { // Maus auf der Leiste unsigned short diff = scrollbar_height / 2; if (Coll(mc.x, mc.y, GetX(), GetY() + button_height, width_, scrollbar_pos)) { if (scrollbar_pos < diff) scrollbar_pos = 0; else scrollbar_pos -= diff; CalculatePosition(); parent_->Msg_ScrollChange(id_, scroll_pos); return true; } else { unsigned short sbb = button_height + scrollbar_pos + scrollbar_height; if (Coll(mc.x, mc.y, GetX(), GetY() + sbb, width_, height_ - (sbb + button_height))) { scrollbar_pos += diff; if (scrollbar_pos > (scroll_height - scrollbar_height)) scrollbar_pos = scroll_height - scrollbar_height; CalculatePosition(); parent_->Msg_ScrollChange(id_, scroll_pos); return true; } } } return false; }
bool CollEdges(const Rect& rect1, const Rect& rect2) { return ( Coll(rect1.left, rect1.top, rect2) || Coll(rect1.right, rect1.top, rect2) || Coll(rect1.left, rect1.bottom, rect2) || Coll(rect1.right, rect1.bottom, rect2) || Coll(rect2.left, rect2.top, rect1) || Coll(rect2.right, rect2.top, rect1) || Coll(rect2.left, rect2.bottom, rect1) || Coll(rect2.right, rect2.bottom, rect1) ); }
void IngameWindow::MouseLeftUp(const MouseCoords& mc) { // Bewegung stoppen move = false; // beiden Buttons oben links und rechts prfen const Rect rec[2] = { GetLeftButtonRect(), GetRightButtonRect() }; for(unsigned char i = 0; i < 2; ++i) { button_state[i] = BUTTON_UP; if(Coll(mc.x, mc.y, rec[i])) { if(i) { SetMinimized(!GetMinimized()); LOADER.GetSoundN("sound", 113)->Play(255, false); } else if(!modal) Close(); } } }
void IngameWindow::MouseLeftUp(const MouseCoords& mc) { // Bewegung stoppen isMoving = false; // beiden Buttons oben links und rechts prfen const Rect rec[2] = { GetLeftButtonRect(), GetRightButtonRect() }; for(unsigned i = 0; i < 2; ++i) { button_state[i] = BUTTON_UP; if(Coll(mc.x, mc.y, rec[i])) { if(i == 0 && (!IsModal() || closeOnRightClick_)) Close(); else if(i==1 && !IsModal()) { SetMinimized(!IsMinimized()); LOADER.GetSoundN("sound", 113)->Play(255, false); } } } }
void IngameWindow::MouseMove(const MouseCoords& mc) { // Fenster bewegen, wenn die Bewegung aktiviert wurde if(isMoving) { DrawPoint newMousePos(mc.x, mc.y); DrawPoint newPos = pos_ + newMousePos - lastMousePos; if(newPos.x < 0) { newMousePos.x -= newPos.x; newPos.x = 0; } if(newPos.y < 0) { newMousePos.y -= newPos.y; newPos.y = 0; } if(newPos.x > VIDEODRIVER.GetScreenWidth() - width_) { newMousePos.x -= newPos.x - (VIDEODRIVER.GetScreenWidth() - width_); newPos.x = VIDEODRIVER.GetScreenWidth() - width_; } if(newPos.y > VIDEODRIVER.GetScreenHeight() - height_) { newMousePos.y -= newPos.y - (VIDEODRIVER.GetScreenHeight() - height_); newPos.y = VIDEODRIVER.GetScreenHeight() - height_; } // Fix mouse position if moved too far if(newMousePos.x - mc.x || newMousePos.y - mc.y) VIDEODRIVER.SetMousePos(newMousePos); pos_ = newPos; lastMousePos = DrawPoint(mc.x, mc.y); } // beiden Buttons oben links und rechts prfen const Rect rec[2] = { GetLeftButtonRect(), GetRightButtonRect() }; for(unsigned char i = 0; i < 2; ++i) { if(Coll(mc.x, mc.y, rec[i])) { if(mc.ldown) button_state[i] = BUTTON_PRESSED; else button_state[i] = BUTTON_HOVER; } else button_state[i] = BUTTON_UP; } }
/** * * * @author Divan */ bool ctrlProgress::Msg_WheelDown(const MouseCoords& mc) { // If mouse is over the controls, simulate button click if(Coll(mc.x, mc.y, GetX(), GetY(), width_, height_)) { Msg_ButtonClick(0); return true; } return false; }
/** * * * @author OLiver */ bool ctrlButton::Msg_LeftDown(const MouseCoords& mc) { if(enabled && Coll(mc.x, mc.y, GetX(), GetY(), width, height)) { state = BUTTON_PRESSED; return true; } return false; }
// Prüfen, ob bei gehighlighteten Button die Maus auch noch über dem Button ist void ctrlButton::TestMouseOver() { if(state == BUTTON_HOVER || state == BUTTON_PRESSED) { if(!Coll(VideoDriverWrapper::inst().GetMouseX(), VideoDriverWrapper::inst().GetMouseY(), GetX(), GetY(), width, height)) // Nicht mehr drauf --> wieder normalen Zustand state = BUTTON_UP; } }
/** * prüft ob Mauskoordinaten in einer gesperrten Region liegt. * * @param[in] window das Fenster, welches die Region sperrt. * @param[in] mc Mauskoordinaten. * * @return @p true falls Mausposition innerhalb der gesperrten Region, * @p false falls außerhalb * * @author OLiver */ bool Window::TestWindowInRegion(Window *window, const MouseCoords& mc) { for(list<LockedRegion>::iterator it = locked_areas.begin(); it.valid(); ++it) { if(it->window != window && Coll(mc.x + GetX(), mc.y + GetY(), it->rect)) return true; } return false; }
bool ctrlCheck::Msg_LeftDown(const MouseCoords& mc) { if(!readonly && Coll(mc.x, mc.y, GetX(), GetY(), width_, height_)) { check = !check; parent_->Msg_CheckboxChange(GetID(), check); return true; } return false; }
bool ctrlComboBox::Msg_WheelDown(const MouseCoords& mc) { ctrlList* list = GetCtrl<ctrlList>(0); if(!readonly && Coll(mc.x, mc.y, GetX(), GetY() + height_, width_, height_ + list->GetHeight()) && list->GetVisible()) { // Scrolled in opened list -> return RelayMouseMessage(&Window::Msg_WheelDown, mc); } if(!readonly && Coll(mc.x, mc.y, GetX(), GetY(), width_, height_)) { // Scrolled without list opened if (list->GetSelection() + 1 < list->GetLineCount()) Msg_ListSelectItem(GetID(), list->GetSelection() + 1); return true; } return false; }
/** * prüft ob Mauskoordinaten in einer gesperrten Region liegt. * * @param[in] window das Fenster, welches die Region sperrt. * @param[in] mc Mauskoordinaten. * * @return @p true falls Mausposition innerhalb der gesperrten Region, * @p false falls außerhalb * * @author OLiver */ bool Window::TestWindowInRegion(Window* window, const MouseCoords& mc) const { for(std::map<Window*, Rect>::const_iterator it = locked_areas.begin(); it != locked_areas.end(); ++it) { if(it->first == window) continue; // Locking window can always access its locked regions // All others cannot: if(Coll(mc.x + GetX(), mc.y + GetY(), it->second)) return true; } return false; }
bool ctrlScrollBar::Msg_LeftDown(const MouseCoords& mc) { if (Coll(mc.x, mc.y, GetX(), GetY() + button_height + sliderPos, width_, sliderHeight)) { // Maus auf dem Scrollbutton isMouseScrolling = true; return true; } else if (Coll(mc.x, mc.y, GetX(), GetY() + button_height, width_, sliderPos)) { // Clicked above slider -> Move half a slider height up if (sliderPos < sliderHeight / 2) sliderPos = 0; else sliderPos -= sliderHeight / 2; UpdatePosFromSlider(); return true; } else { unsigned short bottomSliderPos = button_height + sliderPos + sliderHeight; if (Coll(mc.x, mc.y, GetX(), GetY() + bottomSliderPos, width_, height_ - (bottomSliderPos + button_height))) { // Clicked below slider -> Move half a slider height down sliderPos += sliderHeight / 2; if(sliderPos + sliderHeight > scroll_height) { RTTR_Assert(scroll_height > sliderHeight); // Otherwise the scrollbar should be hidden sliderPos = scroll_height - sliderHeight; } UpdatePosFromSlider(); return true; } } return RelayMouseMessage(&Window::Msg_LeftDown, mc); }
bool ctrlComboBox::Msg_LeftDown(const MouseCoords& mc) { ctrlList* list = GetCtrl<ctrlList>(0); // Irgendwo anders hingeklickt --> Liste ausblenden if(!readonly && !Coll(mc.x, mc.y, GetX(), GetY(), width_, height_ + list->GetHeight())) { // Liste wieder ausblenden ShowList(false); return false; } if(!readonly && Coll(mc.x, mc.y, GetX(), GetY(), width_, height_)) { // Liste wieder ein/ausblenden ShowList(!list->GetVisible()); return true; } // Für Button und Liste weiterleiten return RelayMouseMessage(&Window::Msg_LeftDown, mc); }
/** * * * @author OLiver */ bool ctrlTable::Msg_RightDown(const MouseCoords& mc) { if(Coll(mc.x, mc.y, GetX(), GetY()+header_height, width-20, height)) { SetSelection((mc.y - header_height - GetY()) / font->getHeight() + GetCtrl<ctrlScrollBar>(0)->GetPos(), false); if(parent) parent->Msg_TableRightButton(this->id,row_r_selection); return true; } else return RelayMouseMessage(&Window::Msg_RightDown, mc); }
bool ctrlImage::Msg_MouseMove(const MouseCoords& mc) { // gültiges Bildz? if(image) { // Jeweils Tooltip ein- und ausblenden, wenn die Maus über dem Bild ist if(Coll(mc.x, mc.y, GetX() - image->getNx(), GetY() - image->getNy(), image->getWidth(), image->getHeight())) WINDOWMANAGER.SetToolTip(this, tooltip_); else WINDOWMANAGER.SetToolTip(this, ""); } return false; }
IngameWindow* WindowManager::FindWindowUnderMouse(const MouseCoords& mc) const{ // Fenster durchgehen ( von hinten nach vorn, da die vordersten ja zuerst geprüft werden müssen !! ) for(std::list<IngameWindow*>::const_reverse_iterator it = windows.rbegin(); it != windows.rend(); ++it) { // FensterRect für Kollisionsabfrage Rect window_rect = (*it)->GetRect(); // trifft die Maus auf ein Fenster? if(Coll(mc.x, mc.y, window_rect)){ return *it; } } return NULL; }
bool ctrlList::Msg_WheelUp(const MouseCoords& mc) { // Forward to ScrollBar ctrlScrollBar* scrollbar = GetCtrl<ctrlScrollBar>(0); // If mouse in list or scrollbar if(Coll(mc.x, mc.y, GetX() + 2, GetY() + 2, width_ - /*2*/2, height_ - 4)) { // Simulate Button Click scrollbar->Msg_ButtonClick(0); return true; } return false; }
bool ctrlTable::Msg_WheelDown(const MouseCoords& mc) { // Forward to ScrollBar ctrlScrollBar *scrollbar = GetCtrl<ctrlScrollBar>(0); // If mouse in list if(Coll(mc.x, mc.y, GetX() + 2, GetY() + 2, width - /*2*/2, height - 4)) { // Simulate Button Click scrollbar->Msg_ButtonClick(1); return true; } else return false; }
/** * * * @author OLiver */ bool ctrlButton::Msg_LeftUp(const MouseCoords& mc) { if(state == BUTTON_PRESSED) { state = BUTTON_UP; if(enabled && Coll(mc.x, mc.y, GetX(), GetY(), width, height)) { parent->Msg_ButtonClick(GetID()); return true; } } return false; }
/** * * * @author OLiver */ bool ctrlTable::Msg_LeftDown(const MouseCoords& mc) { if(Coll(mc.x, mc.y, GetX(), GetY() + header_height, width - 20, height - header_height)) { SetSelection((mc.y - header_height - GetY()) / font->getHeight() + GetCtrl<ctrlScrollBar>(0)->GetPos()); if(parent) parent->Msg_TableLeftButton(this->id, row_l_selection); // Doppelklick? Dann noch einen extra Eventhandler aufrufen if(mc.dbl_click && parent) parent->Msg_TableChooseItem(this->id,row_l_selection); return true; } else return RelayMouseMessage(&Window::Msg_LeftDown, mc); }
bool ctrlComboBox::Msg_RightDown(const MouseCoords& mc) { ctrlList* list = GetCtrl<ctrlList>(0); // Für Button und Liste weiterleiten (und danach erst schließen) bool ret = RelayMouseMessage(&Window::Msg_RightDown, mc); // Clicked on list -> close it if(!readonly && Coll(mc.x, mc.y, GetX(), GetY() + height_, width_, height_ + list->GetHeight())) { // Liste wieder ausblenden ShowList(false); } return ret; }
/** * * * @author OLiver */ bool ctrlProgress::Msg_MouseMove(const MouseCoords& mc) { // an Buttons weiterleiten RelayMouseMessage(&Window::Msg_MouseMove, mc); if(Coll(mc.x, mc.y, GetX() + height_ + x_padding, GetY(), width_ - height_ * 2 - x_padding * 2, height_)) { WINDOWMANAGER.SetToolTip(this, tooltip_); return true; } else { WINDOWMANAGER.SetToolTip(this, ""); return false; } }
bool ctrlList::Msg_LeftUp(const MouseCoords& mc) { ctrlScrollBar* scrollbar = GetCtrl<ctrlScrollBar>(0); // Wenn Maus in der Liste if(Coll(mc.x, mc.y, GetX() + 2, GetY() + 2, width_ - 22, height_ - 4)) { // Doppelklick? Dann noch einen extra Eventhandler aufrufen if(mc.dbl_click && parent_ && selection_ >= 0) parent_->Msg_ListChooseItem(id_, selection_); return true; } // Für die Scrollbar weiterleiten return scrollbar->Msg_LeftUp(mc); }
IngameWindow* WindowManager::FindWindowUnderMouse(const MouseCoords& mc) const{ // Fenster durchgehen ( von hinten nach vorn, da die vordersten ja zuerst geprüft werden müssen !! ) for(std::list<IngameWindow*>::const_reverse_iterator it = windows.rbegin(); it != windows.rend(); ++it) { // FensterRect für Kollisionsabfrage Rect window_rect = (*it)->GetRect(); // trifft die Maus auf ein Fenster? if(Coll(mc.x, mc.y, window_rect)){ return *it; } // Check also if we are in the locked area of a window (e.g. dropdown extends outside of window) if((*it)->TestWindowInRegion(NULL, mc)) return *it; } return NULL; }
bool ctrlList::Msg_RightDown(const MouseCoords& mc) { ctrlScrollBar* scrollbar = GetCtrl<ctrlScrollBar>(0); // Wenn Maus in der Liste if(Coll(mc.x, mc.y, GetX() + 2, GetY() + 2, width_ - 22, height_ - 4)) { // Tooltip löschen, sonst bleibt er ewig WINDOWMANAGER.SetToolTip(this, ""); // aktuellen Eintrag selektieren selection_ = mouseover + scrollbar->GetPos(); parent_->Msg_ListSelectItem(id_, selection_); return true; } // Für die Scrollbar weiterleiten return scrollbar->Msg_RightDown(mc); }
/** * * * @author OLiver */ bool ctrlProgress::Msg_LeftDown(const MouseCoords& mc) { // Test if clicked on progress bar if(Coll(mc.x, mc.y, GetX() + height_ + 2 + x_padding, GetY() + 4 + y_padding, width_ - height_ * 2 - 4 - 2 * x_padding, height_ - 8 - 2 * y_padding)) { // The additional check for (position > maximum) is // mathematically redundant here; if there was more code than // it in SetPosition() we had to call it here instead of simply: position = ( mc.x - (GetX() + height_ + 2 + x_padding) + /*rounding:*/ (width_ - height_ * 2 - 4 - 2 * x_padding) / maximum / 2) * maximum / (width_ - height_ * 2 - 4 - 2 * x_padding); if(parent_) parent_->Msg_ProgressChange(GetID(), position); return true; } else return RelayMouseMessage(&Window::Msg_LeftDown, mc); }
/** * * * @author OLiver */ bool ctrlButton::Msg_MouseMove(const MouseCoords& mc) { if(enabled && Coll(mc.x, mc.y, GetX(), GetY(), width, height)) { if(mc.ldown) state = BUTTON_PRESSED; else state = BUTTON_HOVER; WindowManager::inst().SetToolTip(this, tooltip); return true; } else { state = BUTTON_UP; WindowManager::inst().SetToolTip(this, ""); return false; } }
bool ctrlList::Msg_MouseMove(const MouseCoords& mc) { ctrlScrollBar* scrollbar = GetCtrl<ctrlScrollBar>(0); // Wenn Maus in der Liste if(Coll(mc.x, mc.y, GetX() + 2, GetY() + 2, width_ - 22, height_ - 4)) { // Neue Selektierung mouseover = (mc.y - (GetY() + 2) ) / font->getHeight(); WINDOWMANAGER.SetToolTip(this, ((font->getWidth(GetItemText(mouseover)) > width_ - 22) ? GetItemText(mouseover) : "")); return true; } // Mouse-Over deaktivieren und Tooltip entfernen mouseover = -1; WINDOWMANAGER.SetToolTip(this, ""); // Für die Scrollbar weiterleiten return scrollbar->Msg_MouseMove(mc); }