public override bool OnMessage(GUIMessage message) { if (base.OnMessage(message)) { if (!Focus) { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; } else if (message.Param1 == (int)SpinSelect.SPIN_BUTTON_UP) { _spinSelect = SpinSelect.SPIN_BUTTON_UP; } else { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; } return true; } if (message.TargetControlId == GetID) { switch (message.Message) { case GUIMessage.MessageType.GUI_MSG_ITEM_SELECT: Value = (int)message.Param1; return true; case GUIMessage.MessageType.GUI_MSG_LABEL_RESET: { _listLabels.DisposeAndClearList(); _listValues.DisposeAndClearList(); Value = 0; return true; } case GUIMessage.MessageType.GUI_MSG_SHOWRANGE: if (message.Param1 != 0) { _showRange = true; } else { _showRange = false; } break; case GUIMessage.MessageType.GUI_MSG_LABEL_ADD: { AddLabel(message.Label, (int)message.Param1); return true; } case GUIMessage.MessageType.GUI_MSG_ITEM_SELECTED: { message.Param1 = (int)Value; message.Param2 = (int)_spinSelect; if (_spinType == SpinType.SPIN_CONTROL_TYPE_TEXT || _spinType == SpinType.SPIN_CONTROL_TYPE_DISC_NUMBER) { if (_intValue >= 0 && _intValue < _listLabels.Count) { message.Label = (string)_listLabels[_intValue]; } if (_intValue >= 0 && _intValue < _listValues.Count) { message.Param1 = (int)_listValues[_intValue]; } } return true; } } } return false; }
public override void Render(float timePassed) { if (GUIGraphicsContext.EditMode == false) { if (!IsVisible) { _typed = string.Empty; base.Render(timePassed); return; } } if (!Focus) { _typed = string.Empty; } int dwPosX = _positionX; string wszText; if (_spinType == SpinType.SPIN_CONTROL_TYPE_INT) { string strValue = _intValue.ToString(); if (_digits > 1) { while (strValue.Length < _digits) { strValue = "0" + strValue; } } if (_showRange) { wszText = strValue + "/" + _endInt.ToString(); } else { wszText = strValue.ToString(); } if (_prefixText.Length > 0) { wszText = _prefixText + " " + wszText; } if (_suffixText.Length > 0) { wszText = wszText + " " + _suffixText; } } else if (_spinType == SpinType.SPIN_CONTROL_TYPE_FLOAT) { wszText = String.Format("{0:2}/{1:2}", _floatValue, _endFloat); if (_prefixText.Length > 0) { wszText = _prefixText + " " + wszText; } if (_suffixText.Length > 0) { wszText = wszText + " " + _suffixText; } } else { wszText = ""; if (_intValue >= 0 && _intValue < _listLabels.Count) { if (_showRange) { wszText = String.Format("({0}/{1}) {2}", _intValue + 1, (int)_listLabels.Count, _listLabels[_intValue]); } else { wszText = (string)_listLabels[_intValue]; } } else { String.Format("?{0}?", _intValue); } } int iTextXPos = _positionX; int iTextYPos = _positionY; if (_alignment == Alignment.ALIGN_LEFT) { if (_font != null) { if (wszText != null && wszText.Length > 0) { float fTextHeight = 0, fTextWidth = 0; _font.GetTextExtent(wszText, ref fTextWidth, ref fTextHeight); if (Orientation == eOrientation.Horizontal) { _imageSpinUpFocus.SetPosition((int)fTextWidth + 5 + dwPosX + _imageSpinDown.Width, _positionY); _imageSpinUp.SetPosition((int)fTextWidth + 5 + dwPosX + _imageSpinDown.Width, _positionY); _imageSpinDownFocus.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY); _imageSpinDown.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY); } else { _imageSpinUpFocus.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY - (Height / 2)); _imageSpinUp.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY - (Height / 2)); _imageSpinDownFocus.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY + (Height / 2)); _imageSpinDown.SetPosition((int)fTextWidth + 5 + dwPosX, _positionY + (Height / 2)); } } } } if (_alignment == Alignment.ALIGN_CENTER) { if (_font != null) { float fTextHeight = 1, fTextWidth = 1; if (wszText != null && wszText.Length > 0) { _font.GetTextExtent(wszText, ref fTextWidth, ref fTextHeight); } if (Orientation == eOrientation.Horizontal) { iTextXPos = dwPosX + _imageSpinUp.Width; iTextYPos = _positionY; _imageSpinDownFocus.SetPosition((int)dwPosX, _positionY); _imageSpinDown.SetPosition((int)dwPosX, _positionY); _imageSpinUpFocus.SetPosition((int)fTextWidth + _imageSpinUp.Width + dwPosX, _positionY); _imageSpinUp.SetPosition((int)fTextWidth + _imageSpinUp.Width + dwPosX, _positionY); fTextHeight /= 2.0f; float fPosY = ((float)_height) / 2.0f; fPosY -= fTextHeight; fPosY += (float)iTextYPos; iTextYPos = (int)fPosY; } else { iTextXPos = dwPosX; iTextYPos = _positionY + Height; _imageSpinUpFocus.SetPosition((int)+dwPosX, _positionY - (Height + (int)fTextHeight) / 2); _imageSpinUp.SetPosition((int)dwPosX, _positionY - (Height + (int)fTextHeight) / 2); _imageSpinDownFocus.SetPosition((int)dwPosX, _positionY + (Height + (int)fTextHeight) / 2); _imageSpinDown.SetPosition((int)dwPosX, _positionY + (Height + (int)fTextHeight) / 2); } } } if (_spinSelect == SpinSelect.SPIN_BUTTON_UP) { if (_reverse) { if (!CanMoveDown()) { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; } } else { if (!CanMoveUp()) { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; } } } if (_spinSelect == SpinSelect.SPIN_BUTTON_DOWN) { if (_reverse) { if (!CanMoveUp()) { _spinSelect = SpinSelect.SPIN_BUTTON_UP; } } else { if (!CanMoveDown()) { _spinSelect = SpinSelect.SPIN_BUTTON_UP; } } } if (Focus) { bool bShow = CanMoveUp(); if (_reverse) { bShow = CanMoveDown(); } if (_spinSelect == SpinSelect.SPIN_BUTTON_UP && bShow) { _imageSpinUpFocus.Render(timePassed); } else { _imageSpinUp.Render(timePassed); } bShow = CanMoveDown(); if (_reverse) { bShow = CanMoveUp(); } if (_spinSelect == SpinSelect.SPIN_BUTTON_DOWN && bShow) { _imageSpinDownFocus.Render(timePassed); } else { _imageSpinDown.Render(timePassed); } } else { _imageSpinUp.Render(timePassed); _imageSpinDown.Render(timePassed); } if (_font != null) { _labelControl.FontName = _fontName; _labelControl.TextColor = _textColor; _labelControl.Label = wszText; if (Disabled) { _labelControl.TextColor &= 0x80ffffff; } if (_alignment != Alignment.ALIGN_CENTER) { if (wszText != null && wszText.Length > 0) { _labelControl.TextAlignment = _alignment; float fHeight = (float)_labelControl.TextHeight; fHeight /= 2.0f; float fPosY = ((float)_height) / 2.0f; fPosY -= fHeight; fPosY += (float)_positionY; // This offset positioning preserves the legacy behavior of a (hardcoded) 3 pixel offset. int sign = 1; if (_alignment == Alignment.ALIGN_RIGHT) { sign = -1; } _labelControl.SetPosition(_positionX - 3 + (_textOffsetX * sign), (int)fPosY + _textOffsetY); } } else { _labelControl.SetPosition(iTextXPos + _textOffsetX, iTextYPos + _textOffsetY); _labelControl.TextAlignment = Alignment.ALIGN_LEFT; } _labelControl.Render(timePassed); } base.Render(timePassed); }
public override void OnAction(Action action) { _actionHandled = false; switch (action.wID) { case Action.ActionType.REMOTE_0: case Action.ActionType.REMOTE_1: case Action.ActionType.REMOTE_2: case Action.ActionType.REMOTE_3: case Action.ActionType.REMOTE_4: case Action.ActionType.REMOTE_5: case Action.ActionType.REMOTE_6: case Action.ActionType.REMOTE_7: case Action.ActionType.REMOTE_8: case Action.ActionType.REMOTE_9: { if (((_digits == -1) && (_typed.Length >= 3)) || ((_digits != -1) && (_typed.Length >= _digits))) { _typed = ""; } int iNumber = action.wID - Action.ActionType.REMOTE_0; _typed += (char)(iNumber + '0'); int iValue; iValue = Int32.Parse(_typed); switch (_spinType) { case SpinType.SPIN_CONTROL_TYPE_INT: { // Value entered if (((_digits == -1) && (_typed.Length >= 3)) || ((_digits != -1) && (_typed.Length >= _digits))) { // Check value if (iValue < _startInt) { iValue = _startInt; } _typed = iValue.ToString(); } if (iValue > _endInt) { _typed = ""; _typed += (char)(iNumber + '0'); iValue = Int32.Parse(_typed); } _intValue = iValue; if (_intValue >= _startInt && _intValue <= _endInt) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null); GUIGraphicsContext.SendMessage(msg); } } break; case SpinType.SPIN_CONTROL_TYPE_TEXT: { if (iValue < 0 || iValue >= _listLabels.Count) { iValue = 0; } _intValue = iValue; if (_intValue >= 0 && _intValue < _listLabels.Count) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null); msg.Label = (string)_listLabels[_intValue]; GUIGraphicsContext.SendMessage(msg); } } break; case SpinType.SPIN_CONTROL_TYPE_DISC_NUMBER: { if (iValue < 0 || iValue >= _listLabels.Count) { iValue = 0; } _intValue = iValue + 1; if (_intValue >= 1 && _intValue < _listLabels.Count) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_CLICKED, WindowId, GetID, ParentID, 0, 0, null); msg.Label = (string)_listLabels[_intValue]; GUIGraphicsContext.SendMessage(msg); } } break; } } break; } if (action.wID == Action.ActionType.ACTION_PAGE_UP) { if (!_reverse) { PageDown(); } else { PageUp(); } _actionHandled = true; return; } if (action.wID == Action.ActionType.ACTION_PAGE_DOWN) { if (!_reverse) { PageUp(); } else { PageDown(); } _actionHandled = true; return; } if (action.wID == Action.ActionType.ACTION_MOVE_UP || action.wID == Action.ActionType.ACTION_MOVE_DOWN || action.wID == Action.ActionType.ACTION_MOVE_LEFT || action.wID == Action.ActionType.ACTION_MOVE_RIGHT) { bool bUp = false; bool bDown = false; if (Orientation == eOrientation.Horizontal && action.wID == Action.ActionType.ACTION_MOVE_LEFT) { bUp = true; } if (Orientation == eOrientation.Vertical && action.wID == Action.ActionType.ACTION_MOVE_DOWN) { bUp = true; } if (bUp) { if (_spinSelect == SpinSelect.SPIN_BUTTON_UP) { if (_reverse) { if (CanMoveUp()) { // Only a change in _spinSelect state defines a handled action. _actionHandled = _spinSelect != SpinSelect.SPIN_BUTTON_DOWN; _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; return; } } else { if (CanMoveDown()) { // Only a change in _spinSelect state defines a handled action. _actionHandled = _spinSelect != SpinSelect.SPIN_BUTTON_DOWN; _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; return; } } } } if (Orientation == eOrientation.Horizontal && action.wID == Action.ActionType.ACTION_MOVE_RIGHT) { bDown = true; } if (Orientation == eOrientation.Vertical && action.wID == Action.ActionType.ACTION_MOVE_UP) { bDown = true; } if (bDown) { if (_spinSelect == SpinSelect.SPIN_BUTTON_DOWN) { if (_reverse) { if (CanMoveDown()) { // Only a change in _spinSelect state defines a handled action. _actionHandled = _spinSelect != SpinSelect.SPIN_BUTTON_UP; _spinSelect = SpinSelect.SPIN_BUTTON_UP; return; } } else { if (CanMoveUp()) { // Only a change in _spinSelect state defines a handled action. _actionHandled = _spinSelect != SpinSelect.SPIN_BUTTON_UP; _spinSelect = SpinSelect.SPIN_BUTTON_UP; return; } } } } // causes issues with tvguide date control // Focus = false; // if not handeled before -> loose focus to go back to main list } if (Focus) { if (action.wID == Action.ActionType.ACTION_MOUSE_CLICK || action.wID == Action.ActionType.ACTION_SELECT_ITEM) { if (_spinSelect == SpinSelect.SPIN_BUTTON_UP) { if (_reverse) { MoveDown(); } else { MoveUp(); } action.wID = Action.ActionType.ACTION_INVALID; _actionHandled = true; return; } if (_spinSelect == SpinSelect.SPIN_BUTTON_DOWN) { if (_reverse) { MoveUp(); } else { MoveDown(); } action.wID = Action.ActionType.ACTION_INVALID; _actionHandled = true; return; } } } base.OnAction(action); }
public override bool HitTest(int x, int y, out int controlID, out bool focused) { controlID = GetID; focused = Focus; if (x >= _imageSpinUp.XPosition && x <= _imageSpinUp.XPosition + _imageSpinUp.RenderWidth) { if (y >= _imageSpinUp.YPosition && y <= _imageSpinUp.YPosition + _imageSpinUp.RenderHeight) { if (_reverse) { if (CanMoveDown()) { _spinSelect = SpinSelect.SPIN_BUTTON_UP; return true; } } else { if (CanMoveUp()) { _spinSelect = SpinSelect.SPIN_BUTTON_UP; return true; } } } } if (x >= _imageSpinDown.XPosition && x <= _imageSpinDown.XPosition + _imageSpinDown.RenderWidth) { if (y >= _imageSpinDown.YPosition && y <= _imageSpinDown.YPosition + _imageSpinDown.RenderHeight) { if (_reverse) { if (CanMoveUp()) { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; return true; } } else { if (CanMoveDown()) { _spinSelect = SpinSelect.SPIN_BUTTON_DOWN; return true; } } } } Focus = false; return false; }