bool RadioButton::OnLButtonUp(int mouse_x, int mouse_y) { if (IsOver(mouse_x, mouse_y) == true) { Component* parent = GetParent(); Layout* layout = parent->GetLayout(); // Update all the other radio buttons. Component* child = layout->GetFirst(); while (child != 0) { if (child != this && child->GetType() == Component::kRadiobutton) { RadioButton* button = (RadioButton*)child; button->SetPressed(false); } child = layout->GetNext(); } SetPressed(true); Click(true); } else { // Go back to previous state. switch(GetState()) { case kReleasing: SetState(kPressed); break; case kPressing: SetState(kReleased); break; default: break; } } ReleaseMouseFocus(); return true; }
bool ActiveWidget::PointerMove(const Pos& p, int btn_no) { bool result=false; if (!_is_dragging[btn_no] && _was_touched[btn_no] ) { Pos r = _touch_pos[btn_no]-p; if ( ( r.x*r.x + r.y*r.y ) > _drag_radius ) { _is_dragging[btn_no] = true; OnCatch[btn_no].Schedule_1( _touch_pos[btn_no] ); DBG_Text("Drag"); } } if ( _was_touched[btn_no] && !_was_over && IsOver(p) ) { result |= OnMoveIn[btn_no].Schedule_1(p); DBG_Text("-----}"); InputIncEager(this); DBG_Text("MoveIn"); _unsent_outside = false; } else if ( _was_touched[btn_no] && _was_over && !IsOver(p) ) { result |= OnMoveOut[btn_no].Schedule_1(p); DBG_Text("{-----"); InputDecEager(this); DBG_Text("MoveOut"); _unsent_outside = true; } else if ( _was_touched[btn_no] ) { return true; } return result; }
void KalahContainers::KeepMoving() { while (true) { int Num; int RetVal; do { Output(); INPUT: cout << "Determine the house number(1 ~ 6): "; string StrNum; cin >> StrNum; try { Num = std::stoi(StrNum); } catch (const exception &e) { cout << "Non-numeric characters detected!\n"; goto INPUT; } RetVal = PlayerMove(Num); if (RetVal == INVALID_INPUT) cout << "Invalid number detected! Do it again!\n"<<endl; else{ cout << "The player has chosen the " << Num << "th house" <<endl; Output(); } if (RetVal == GOOD_LUCK){ cout << "Good Job, You have an extra move!\n"<<endl; } } while (RetVal == GOOD_LUCK || RetVal == INVALID_INPUT); if (IsOver(PlayerHouses)) return; do { cout << "############################################" << endl<<endl; cout << "Computer is thinking ......."<<endl<<endl; cout << "############################################" << endl<<endl; // Num = ComputerThinking(); Num = ComputerStrategy() + 1; cout << "Computer takes the " <<Length - Num + 1 << "th house!\n"<<endl; RetVal = ComputerMove(Num); if (RetVal == GOOD_LUCK){ Output(); cout << "Computer have an extra move!\n"<<endl; } } while (RetVal == GOOD_LUCK || RetVal == INVALID_INPUT); if (IsOver(ComputerHouses)) return; } }
CThread::~CThread() { if (!IsOver()) Kill(); safe_del(_t); }
bool cChoiceManager::ButtonClicked(int x, int y) { if (!IsActive()) { return false; } if (!IsOver(x, y) && !g_UpArrow && !g_DownArrow && !g_EnterKey) { return false; } if (g_EnterKey) { if (m_callback) { m_callback(m_ActiveChoice->m_CurrChoice); m_callback = 0; } m_ActiveChoice = 0; return true; } if (g_UpArrow) { g_UpArrow = false; m_ActiveChoice->m_CurrChoice--; if (m_ActiveChoice->m_CurrChoice < 0) m_ActiveChoice->m_CurrChoice = m_ActiveChoice->m_NumChoices - 1; return true; } if (g_DownArrow) { g_DownArrow = false; m_ActiveChoice->m_CurrChoice++; if (m_ActiveChoice->m_CurrChoice > m_ActiveChoice->m_NumChoices - 1) m_ActiveChoice->m_CurrChoice = 0; return true; } if (m_ActiveChoice->m_ScrollDisabled) { bool bv = find_active(x, y); return bv; } if (m_CurrUp == m_UpOn) { if (m_ActiveChoice->m_Position - 1 >= 0) m_ActiveChoice->m_Position--; return true; } if (m_CurrDown == m_DownOn) { if (m_ActiveChoice->m_Position + m_ActiveChoice->m_NumDrawnElements < m_ActiveChoice->m_NumChoices) m_ActiveChoice->m_Position++; return true; } return find_active(x, y); }
bool cButton::ButtonClicked(int x, int y) { if (m_Disabled || m_Hidden) return false; if (IsOver(x, y)) { g_InterfaceEvents.AddEvent(EVENT_BUTTONCLICKED, m_ID); return true; } return false; }
bool ActiveWidget::PointerIdle(const Pos& p, bool drag) { bool result=false; if ( IsOver(p) && !_was_over ) { DBG_Text("----->"); if ( !IsActive() ) { ShowHint(); } else if (!drag) { result |= OnMoveOver.Schedule_1(p); ShowHint(); } InputIncEager(this); if (!drag) DBG_Text("MoveOver"); } else if( _was_over && !IsOver(p) || _unsent_outside ) { DBG_Text("<-----"); if ( !IsActive() ) { HideHint(); } else if (!drag) { result |= OnMoveOutside.Schedule_1(p); HideHint(); } InputDecEager(this); if (!drag) DBG_Text("MoveSide"); _unsent_outside = false; } return result; }
bool cScrollBar::MouseDown(int x, int y) { // this function is needed to initiate dragging of the bar if(m_Disabled || m_Hidden) return true; m_DragInitYPos = y - m_YPos; // mouse Y position within entire bar section // make sure they clicked within the scroll bar itself, not just anywhere in the overall scrollbar section if( IsOver(x,y) && (m_DragInitYPos > m_BarTop + m_ImgButtonUp->h) && (m_DragInitYPos < m_BarTop + m_ImgButtonUp->h + m_BarHeight) ) { g_DragScrollBar = this; // g_DragScrollBar is used in main.cpp to reference whichever bar is being dragged (if any) m_DragInitYPos -= m_BarTop; // update to mouse Y position, within scroll bar itself } return true; }
void ActiveWidget::Idle() { if ( IsActive() ) { Timer actual_time; int i; for (i=0; i!=NUM_BUTTONS; ++i) { if ( _was_touched[i] && ( actual_time - _last_time[i] >= _current_dt[i]*0.001 ) ) { _current_dt[i] = _period; _last_time[i] = actual_time; if ( IsOver(_cursor) ) { WhileHold[i].Schedule_1(_cursor); } WhileDrag[i].Schedule_1(_cursor); //DBG_Info_0("WhileDrag"); } } } }
void EBox::Draw() { #ifdef DEBUG if (Mouse.MiddleState() && IsOver()) { Coord p1,p2; p1 = GetPos(); p2 = p1 + GetSize(); bg->drawRect(p1.x,p1.y,p2.x,p2.y,1,1,1,0.2); p1 = p1 + GetLeftTopMargin(); p2 = p2 - GetRightBottomMargin(); bg->drawRect(p1.x,p1.y,p2.x,p2.y,1,1,1,0.2); } #endif for (int i=0; i<_vChilds.size(); i++) { _vChilds[i]->Draw(); } }
bool cScrollBar::ButtonClicked(int x, int y, bool mouseWheelDown, bool mouseWheelUp) { if(m_Disabled || m_Hidden || !ParentPosition) return false; if(IsOver(x,y)) { int newpos = m_ItemTop; if (mouseWheelUp) newpos -= m_ScrollAmount; else if (mouseWheelDown) newpos += m_ScrollAmount; // clicked on "up" button; scroll up small amount else if (y <= m_YPos + m_ImgButtonUp->h) newpos -= m_ScrollAmount; // clicked on "down" button; scroll down small amount else if (y >= m_YPos + m_Height - m_ImgButtonUp->h) newpos += m_ScrollAmount; // clicked in bar space above actual scroll bar; scroll up large amount else if (y < m_YPos + m_BarTop + m_ImgButtonUp->h) newpos -= m_PageAmount; // clicked in bar space below actual scroll bar; scroll down large amount else if (y > m_YPos + m_BarTop + m_BarHeight + m_ImgButtonUp->h) newpos += m_PageAmount; if(newpos != m_ItemTop) { if(newpos > m_ItemsTotal - m_ItemsVisible) newpos = m_ItemsTotal - m_ItemsVisible; else if(newpos < 0) newpos = 0; *ParentPosition = newpos; if(m_UpdateSelf) SetTopValue(newpos); } return true; } return false; }
bool ActiveWidget::PointerDown(const Pos& p, int btn_no) { if ( IsOver(p) ) { _touch_pos[btn_no] = p; _was_touched[btn_no]=true; OnPress[btn_no].Schedule_1(p); DBG_Text(">>><<<"); InputIncEager(this); // increase for press InputIncEager(this); // increase for move-in DBG_Text("Press"); _last_time[btn_no] = Timer(); _current_dt[btn_no] = _delay; return true; } else { DBG_Text("> . <"); OffPress[btn_no].Schedule_1(p); _was_touched[btn_no]=false; } return false; }
void UIObject::Update(int x, int y) { hovered = IsOver(x, y); }
void cListBox::OnClicked(int x, int y, bool mouseWheelDown, bool mouseWheelUp) { cListItem* current = 0; if (m_NumElements == 0) // it doesn't matter if there are no items in the list return; // if user clicked on "un-sort" header, do that if (m_ShowHeaders && m_HeaderClicksSort && x > m_XPos + m_eWidth - 16 && x <= m_XPos + m_eWidth && y > m_YPos + m_BorderSize && y <= m_YPos + m_BorderSize + LISTBOX_ITEMHEIGHT ) { UnSortList(); return; } if (IsOver(x, y)) { if (mouseWheelDown) { ScrollDown(); return; } if (mouseWheelUp) { ScrollUp(); return; } if (m_EnableEvents) g_InterfaceEvents.AddEvent(EVENT_SELECTIONCHANGE, m_ID); // See if a header was clicked m_HeaderClicked = ""; if (m_ShowHeaders && y > m_YPos + m_BorderSize && y <= m_YPos + m_BorderSize + LISTBOX_ITEMHEIGHT) { int x_start = 0, x_end = 0; for (int i = 0; i < m_ColumnCount; i++) { if (m_SkipColumn[i]) continue; x_start = m_ColumnOffset[i] - 3; if (i < m_ColumnCount - 1) x_end = m_ColumnOffset[i + 1] - 3; else x_end = m_eWidth; if (x >= m_XPos + x_start && x <= m_XPos + x_end) { // then set it as clicked m_HeaderClicked = m_ColumnName[i]; // should we re-sort list based on header? if (m_HeaderClicksSort) { if (m_SortedColumn == m_ColumnName[i]) m_SortedDescending = !m_SortedDescending; else { m_SortedColumn = m_ColumnName[i]; m_SortedDescending = false; } ReSortList(); } return; } } } bool deselect = false; if (m_MultiSelect == true) { if (g_ShiftDown == false && g_CTRLDown == false) { m_HasMultiSelect = false; deselect = true; } else m_HasMultiSelect = true; } else deselect = true; // first unselect any currently selected items if (deselect) { m_LastSelected = 0; current = m_Items; while (current) { current->m_Selected = false; current = current->m_Next; } } bool singleSelect = true; if (m_MultiSelect == true) { if (g_ShiftDown == true) singleSelect = false; } else singleSelect = true; if (singleSelect) // find the first element displayed { current = m_Items; int count = 0; while (current) { if (count == m_Position) break; count++; current = current->m_Next; } // Check each element to see if mouse is over it int temp = 0; while (current) { if ((count - m_Position) >= m_NumDrawnElements) // stop if running past the visible list break; int cX = m_XPos + m_BorderSize; int cY = (m_YPos + m_BorderSize) + (LISTBOX_ITEMHEIGHT*temp); if (m_ShowHeaders) // Account for headers if shown cY += LISTBOX_ITEMHEIGHT; // Check if over the item if (x > cX && y > cY && x < cX + m_eWidth && y <= cY + m_eHeight) { // then select it current->m_Selected = !current->m_Selected; m_LastSelected = current; // update info for tracking double-clicks m_LastClickTime = m_CurrentClickTime; m_LastClickX = m_CurrentClickX; m_LastClickY = m_CurrentClickY; m_CurrentClickTime = SDL_GetTicks(); m_CurrentClickX = x; m_CurrentClickY = y; break; } count++; temp++; current = current->m_Next; } } else { if (g_ShiftDown == true) // select from first to last { current = m_Items; cListItem* select_first = 0; cListItem* select_last = 0; int count = 0; // scan through to find both last-clicked-on item and currently-clicked-on item while (current) { if (select_first && select_last) // if we have both now, we're done here break; // was this the last item the user clicked on earlier? if (current == m_LastSelected) { if (!select_first) select_first = current; else select_last = current; } // is this the current item the user just clicked on? if (count >= m_Position && count - m_Position < m_NumDrawnElements) { int cX = m_XPos + m_BorderSize; int cY = (m_YPos + m_BorderSize) + (LISTBOX_ITEMHEIGHT*(count - m_Position)); if (m_ShowHeaders) // Account for headers if shown cY += LISTBOX_ITEMHEIGHT; // Check if over the item if (x > cX && y > cY && x < cX + m_eWidth && y <= cY + m_eHeight) { if (!select_first) select_first = current; else select_last = current; } } count++; current = current->m_Next; } current = select_first; while (current) // now simply select each one ranging from first to last { current->m_Selected = true; // select the item if (current == select_last) { m_LastSelected = current; break; } current = current->m_Next; } } } } }
bool ActiveWidget::AcceptInputCursor( const InputCursor &cur) { DBG_AcceptC int i; _cursor=cur.Position(); _result=false; bool drag = false; bool was_over = IsOver(_cursor); if ( !IsActive() ) { PointerIdle( _cursor, false ); _was_over = was_over; } else if ( !IsOver(_cursor) || cur.Cond()==Widget::NORMAL ) { for (i=0; i!=NUM_BUTTONS; ++i) { if (_mb_down[i]) { _result |= PointerMove(_cursor,i); drag=true; } if (_is_dragging[i]) { _result |= OnDrag[i].Send_3(_cursor,cur.Move(),_touch_pos[i]); } } if (!drag) { _result |= PointerIdle(_cursor, drag); _result |= WhileMoving.Schedule_3(_cursor,cur.Move(),_was_over); } _was_over = was_over; // prevent from changing shape "on-events" } else { if ( _was_over ) { DBG_Text("------"); for (i=0; i!=NUM_BUTTONS; ++i) { if (_mb_down[i] && cur.Cond()==Widget::OFFSIDE ) { _result |= OnMoveOut[i].Schedule_1(_cursor); InputDecEager(this); DBG_Text("MoveOut+"); } else if ( cur.Cond()==Widget::INACTIVE ) { if (_mb_down[i]) InputDecEager(this); _is_dragging[i] = _mb_down[i] = false; DBG_Text("ForceOut"); } } _result |= OnMoveOutside.Schedule_1(_cursor); HideHint(); InputDecEager(this); _was_over = false; DBG_Text("OffSide"); } if ( cur.Cond()==Widget::OFFSIDE ) { _result |= WhileMoving.Schedule_3( _cursor, cur.Move(), _was_over); } } return ( _result = _was_over && (cur.Cond()==Widget::NORMAL) ); }