bool CGUIDialog::Load(const CStdString& strFileName, bool bContainsPath) { m_renderOrder = 1; if (!CGUIWindow::Load(strFileName, bContainsPath)) { return false; } // Clip labels to extents if (m_vecControls.size()) { CGUIControl* pBase = m_vecControls[0]; for (ivecControls p = m_vecControls.begin() + 1; p != m_vecControls.end(); ++p) { if ((*p)->GetControlType() == CGUIControl::GUICONTROL_LABEL) { CGUILabelControl* pLabel = (CGUILabelControl*)(*p); if (!pLabel->GetWidth()) { float spacing = (pLabel->GetXPosition() - pBase->GetXPosition()) * 2; pLabel->SetWidth(pBase->GetWidth() - spacing); pLabel->SetTruncate(true); } } } } return true; }
void CGUIDialogVisualisationSettings::SetupPage() { // cleanup first, if necessary FreeControls(); m_pOriginalSpin = (CGUISpinControlEx*)GetControl(CONTROL_DEFAULT_SPIN); m_pOriginalRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_DEFAULT_RADIOBUTTON); m_pOriginalSettingsButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_BUTTON); if (!m_pOriginalSpin || !m_pOriginalRadioButton || !m_pOriginalSettingsButton) return; m_pOriginalSpin->SetVisible(false); m_pOriginalRadioButton->SetVisible(false); m_pOriginalSettingsButton->SetVisible(false); // update our settings label CStdString strSettings; strSettings.Format("%s %s", g_infoManager.GetLabel(402).c_str(), g_localizeStrings.Get(5)); SET_CONTROL_LABEL(CONTROL_SETTINGS_LABEL, strSettings); CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CONTROL_GROUP_LIST); #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY if (!group || group->GetControlType() != CGUIControl::GUICONTROL_GROUPLIST) { // our controls for layout... CGUIControl *pArea = (CGUIControl *)GetControl(CONTROL_AREA); const CGUIControl *pGap = GetControl(CONTROL_GAP); if (!pArea || !pGap) return; Remove(CONTROL_AREA); group = new CGUIControlGroupList(GetID(), CONTROL_GROUP_LIST, pArea->GetXPosition(), pArea->GetYPosition(), pArea->GetWidth(), pArea->GetHeight(), pGap->GetHeight() - m_pOriginalSettingsButton->GetHeight(), 0, VERTICAL, false); group->SetNavigation(CONTROL_GROUP_LIST, CONTROL_GROUP_LIST, CONTROL_GROUP_LIST, CONTROL_GROUP_LIST); Insert(group, pGap); pArea->FreeResources(); delete pArea; SET_CONTROL_HIDDEN(CONTROL_PAGE); } #endif if (!group) return; if (!m_pSettings || !m_pSettings->size()) { // no settings available SET_CONTROL_VISIBLE(CONTROL_NONE_AVAILABLE); return; } else { SET_CONTROL_HIDDEN(CONTROL_NONE_AVAILABLE); } // run through and create our controls for (unsigned int i = 0; i < m_pSettings->size(); i++) { VisSetting &setting = m_pSettings->at(i); AddSetting(setting, group->GetWidth(), CONTROL_START + i); } UpdateSettings(); }
void CGUIWindow::LoadControl(TiXmlElement* pControl, CGUIControlGroup *pGroup) { // get control type CGUIControlFactory factory; CRect rect(0, 0, (float)m_coordsRes.iWidth, (float)m_coordsRes.iHeight); if (pGroup) { rect.x1 = pGroup->GetXPosition(); rect.y1 = pGroup->GetYPosition(); rect.x2 = rect.x1 + pGroup->GetWidth(); rect.y2 = rect.y1 + pGroup->GetHeight(); } CGUIControl* pGUIControl = factory.Create(GetID(), rect, pControl); if (pGUIControl) { float maxX = pGUIControl->GetXPosition() + pGUIControl->GetWidth(); if (maxX > m_width) { m_width = maxX; } float maxY = pGUIControl->GetYPosition() + pGUIControl->GetHeight(); if (maxY > m_height) { m_height = maxY; } // if we are in a group, add to the group, else add to our window if (pGroup) pGroup->AddControl(pGUIControl); else AddControl(pGUIControl); // if the new control is a group, then add it's controls if (pGUIControl->IsGroup()) { TiXmlElement *pSubControl = pControl->FirstChildElement("control"); while (pSubControl) { LoadControl(pSubControl, (CGUIControlGroup *)pGUIControl); pSubControl = pSubControl->NextSiblingElement("control"); } } } }
// OnMouseAction - called by OnAction() EVENT_RESULT CGUIWindow::OnMouseAction(const CAction &action) { g_graphicsContext.SetScalingResolution(m_coordsRes, m_needsScaling); CPoint mousePoint(action.GetAmount(0), action.GetAmount(1)); g_graphicsContext.InvertFinalCoords(mousePoint.x, mousePoint.y); // create the mouse event CMouseEvent event(action.GetID(), action.GetHoldTime(), action.GetAmount(2), action.GetAmount(3)); if (m_exclusiveMouseControl) { CGUIControl *child = (CGUIControl *)GetControl(m_exclusiveMouseControl); if (child) { CPoint renderPos = child->GetRenderPosition() - CPoint(child->GetXPosition(), child->GetYPosition()); return child->OnMouseEvent(mousePoint - renderPos, event); } } UnfocusFromPoint(mousePoint); return SendMouseEvent(mousePoint, event); }
void CGUIWindow::LoadControl(TiXmlElement* pControl, CGUIControlGroup *pGroup, const CRect &rect) { // get control type CGUIControlFactory factory; CGUIControl* pGUIControl = factory.Create(GetID(), rect, pControl); if (pGUIControl) { float maxX = pGUIControl->GetXPosition() + pGUIControl->GetWidth(); if (maxX > m_width) { m_width = maxX; } float maxY = pGUIControl->GetYPosition() + pGUIControl->GetHeight(); if (maxY > m_height) { m_height = maxY; } // if we are in a group, add to the group, else add to our window if (pGroup) pGroup->AddControl(pGUIControl); else AddControl(pGUIControl); // if the new control is a group, then add it's controls if (pGUIControl->IsGroup()) { CGUIControlGroup *grp = (CGUIControlGroup *)pGUIControl; TiXmlElement *pSubControl = pControl->FirstChildElement("control"); CRect grpRect(grp->GetXPosition(), grp->GetYPosition(), grp->GetXPosition() + grp->GetWidth(), grp->GetYPosition() + grp->GetHeight()); while (pSubControl) { LoadControl(pSubControl, grp, grpRect); pSubControl = pSubControl->NextSiblingElement("control"); } } } }
void CGUIDialog::OnWindowLoaded() { CGUIWindow::OnWindowLoaded(); // Clip labels to extents if (m_children.size()) { CGUIControl* pBase = m_children[0]; for (iControls p = m_children.begin() + 1; p != m_children.end(); ++p) { if ((*p)->GetControlType() == CGUIControl::GUICONTROL_LABEL) { CGUILabelControl* pLabel = (CGUILabelControl*)(*p); if (!pLabel->GetWidth()) { float spacing = (pLabel->GetXPosition() - pBase->GetXPosition()) * 2; pLabel->SetWidth(pBase->GetWidth() - spacing); } } } } }
/* Searches for a control in Window->vecControls * If we can't find any but the window has the controlId (in case of a not python window) * we create a new control with basic functionality */ Control* Window_GetControlById(Window* self, int iControlId) { Control* pControl = NULL; // find in window vector first!!! // this saves us from creating a complete new control vector<Control*>::iterator it = self->vecControls.begin(); while (it != self->vecControls.end()) { Control* control = *it; if (control->iControlId == iControlId) { Py_INCREF(control); return control; } else ++it; } // lock xbmc GUI before accessing data from it GilSafeSingleLock lock(g_graphicsContext); // check if control exists CGUIControl* pGUIControl = (CGUIControl*)self->pWindow->GetControl(iControlId); if (!pGUIControl) { // control does not exist. CStdString error; error.Format("Non-Existent Control %d",iControlId); PyErr_SetString(PyExc_TypeError, error.c_str()); return NULL; } // allocate a new control with a new reference CLabelInfo li; switch(pGUIControl->GetControlType()) { case CGUIControl::GUICONTROL_BUTTON: pControl = (Control*)ControlButton_Type.tp_alloc(&ControlButton_Type, 0); new(&((ControlButton*)pControl)->strFont) string(); new(&((ControlButton*)pControl)->strText) string(); new(&((ControlButton*)pControl)->strText2) string(); new(&((ControlButton*)pControl)->strTextureFocus) string(); new(&((ControlButton*)pControl)->strTextureNoFocus) string(); li = ((CGUIButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlButton*)pControl)->disabledColor = li.disabledColor; ((ControlButton*)pControl)->focusedColor = li.focusedColor; ((ControlButton*)pControl)->textColor = li.textColor; ((ControlButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlButton*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_CHECKMARK: pControl = (Control*)ControlCheckMark_Type.tp_alloc(&ControlCheckMark_Type, 0); new(&((ControlCheckMark*)pControl)->strFont) string(); new(&((ControlCheckMark*)pControl)->strText) string(); new(&((ControlCheckMark*)pControl)->strTextureFocus) string(); new(&((ControlCheckMark*)pControl)->strTextureNoFocus) string(); li = ((CGUICheckMarkControl *)pGUIControl)->GetLabelInfo(); // note: conversion to plain colors from infocolors. ((ControlCheckMark*)pControl)->disabledColor = li.disabledColor; //((ControlCheckMark*)pControl)->shadowColor = li.shadowColor; ((ControlCheckMark*)pControl)->textColor = li.textColor; if (li.font) ((ControlCheckMark*)pControl)->strFont = li.font->GetFontName(); ((ControlCheckMark*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_LABEL: pControl = (Control*)ControlLabel_Type.tp_alloc(&ControlLabel_Type, 0); new(&((ControlLabel*)pControl)->strText) string(); new(&((ControlLabel*)pControl)->strFont) string(); break; case CGUIControl::GUICONTROL_SPIN: pControl = (Control*)ControlSpin_Type.tp_alloc(&ControlSpin_Type, 0); new(&((ControlSpin*)pControl)->strTextureUp) string(); new(&((ControlSpin*)pControl)->strTextureDown) string(); new(&((ControlSpin*)pControl)->strTextureUpFocus) string(); new(&((ControlSpin*)pControl)->strTextureDownFocus) string(); break; case CGUIControl::GUICONTROL_FADELABEL: pControl = (Control*)ControlFadeLabel_Type.tp_alloc(&ControlFadeLabel_Type, 0); new(&((ControlFadeLabel*)pControl)->strFont) string(); new(&((ControlFadeLabel*)pControl)->vecLabels) std::vector<string>(); break; case CGUIControl::GUICONTROL_TEXTBOX: pControl = (Control*)ControlTextBox_Type.tp_alloc(&ControlTextBox_Type, 0); new(&((ControlTextBox*)pControl)->strFont) string(); break; case CGUIControl::GUICONTROL_IMAGE: pControl = (Control*)ControlImage_Type.tp_alloc(&ControlImage_Type, 0); new(&((ControlImage*)pControl)->strFileName) string(); break; case CGUIControl::GUICONTROL_PROGRESS: pControl = (Control*)ControlProgress_Type.tp_alloc(&ControlProgress_Type, 0); new(&((ControlProgress*)pControl)->strTextureLeft) string(); new(&((ControlProgress*)pControl)->strTextureMid) string(); new(&((ControlProgress*)pControl)->strTextureRight) string(); new(&((ControlProgress*)pControl)->strTextureBg) string(); new(&((ControlProgress*)pControl)->strTextureOverlay) string(); break; case CGUIControl::GUICONTROL_SLIDER: pControl = (Control*)ControlSlider_Type.tp_alloc(&ControlSlider_Type, 0); new(&((ControlSlider*)pControl)->strTextureBack) string(); new(&((ControlSlider*)pControl)->strTexture) string(); new(&((ControlSlider*)pControl)->strTextureFoc) string(); break; case CGUIControl::GUICONTAINER_LIST: case CGUIControl::GUICONTAINER_WRAPLIST: case CGUIControl::GUICONTAINER_FIXEDLIST: case CGUIControl::GUICONTAINER_PANEL: pControl = (Control*)ControlList_Type.tp_alloc(&ControlList_Type, 0); new(&((ControlList*)pControl)->strFont) string(); new(&((ControlList*)pControl)->strTextureButton) string(); new(&((ControlList*)pControl)->strTextureButtonFocus) string(); new(&((ControlList*)pControl)->vecItems) std::vector<PYXBMC::ListItem*>(); // create a python spin control ((ControlList*)pControl)->pControlSpin = (ControlSpin*)ControlSpin_New(); break; case CGUIControl::GUICONTROL_GROUP: pControl = (Control*)ControlGroup_Type.tp_alloc(&ControlGroup_Type, 0); break; case CGUIControl::GUICONTROL_RADIO: pControl = (Control*)ControlRadioButton_Type.tp_alloc(&ControlRadioButton_Type, 0); new(&((ControlRadioButton*)pControl)->strFont) string(); new(&((ControlRadioButton*)pControl)->strText) string(); new(&((ControlRadioButton*)pControl)->strTextureFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureNoFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureRadioFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureRadioNoFocus) string(); li = ((CGUIRadioButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlRadioButton*)pControl)->disabledColor = li.disabledColor; ((ControlRadioButton*)pControl)->focusedColor = li.focusedColor; ((ControlRadioButton*)pControl)->textColor = li.textColor; ((ControlRadioButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlRadioButton*)pControl)->strFont = li.font->GetFontName(); ((ControlRadioButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_EDIT: pControl = (Control*)ControlEdit_Type.tp_alloc(&ControlEdit_Type, 0); new(&((ControlEdit*)pControl)->strFont) string(); new(&((ControlEdit*)pControl)->strText) string(); new(&((ControlEdit*)pControl)->strTextureFocus) string(); new(&((ControlEdit*)pControl)->strTextureNoFocus) string(); li = ((CGUIEditControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlEdit*)pControl)->disabledColor = li.disabledColor; ((ControlEdit*)pControl)->textColor = li.textColor; if (li.font) ((ControlEdit*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; default: break; } if (!pControl) { // throw an exeption PyErr_SetString(PyExc_Exception, "Unknown control type for python"); return NULL; } Py_INCREF(pControl); // we have a valid control here, fill in all the 'Control' data pControl->pGUIControl = pGUIControl; pControl->iControlId = pGUIControl->GetID(); pControl->iParentId = self->iWindowId; pControl->dwHeight = (int)pGUIControl->GetHeight(); pControl->dwWidth = (int)pGUIControl->GetWidth(); pControl->dwPosX = (int)pGUIControl->GetXPosition(); pControl->dwPosY = (int)pGUIControl->GetYPosition(); pControl->iControlUp = pGUIControl->GetControlIdUp(); pControl->iControlDown = pGUIControl->GetControlIdDown(); pControl->iControlLeft = pGUIControl->GetControlIdLeft(); pControl->iControlRight = pGUIControl->GetControlIdRight(); // It got this far so means the control isn't actually in the vector of controls // so lets add it to save doing all that next time self->vecControls.push_back(pControl); // return the control with increased reference (+1) return pControl; }
/* Searches for a control in Window->vecControls * If we can't find any but the window has the controlId (in case of a not python window) * we create a new control with basic functionality */ Control* Window::GetControlById(int iControlId) throw (WindowException) { TRACE; // find in window vector first!!! // this saves us from creating a complete new control std::vector<AddonClass::Ref<Control> >::iterator it = vecControls.begin(); while (it != vecControls.end()) { AddonClass::Ref<Control> control = (*it); if (control->iControlId == iControlId) { return control.get(); } else ++it; } // lock xbmc GUI before accessing data from it CSingleLock lock(g_graphicsContext); // check if control exists CGUIControl* pGUIControl = (CGUIControl*)ref(window)->GetControl(iControlId); if (!pGUIControl) { // control does not exist. throw WindowException("Non-Existent Control %d",iControlId); } // allocate a new control with a new reference CLabelInfo li; Control* pControl = NULL; // TODO: Yuck! Should probably be done with a Factory pattern switch(pGUIControl->GetControlType()) { case CGUIControl::GUICONTROL_BUTTON: pControl = new ControlButton(); li = ((CGUIButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlButton*)pControl)->disabledColor = li.disabledColor; ((ControlButton*)pControl)->focusedColor = li.focusedColor; ((ControlButton*)pControl)->textColor = li.textColor; ((ControlButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlButton*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_CHECKMARK: pControl = new ControlCheckMark(); li = ((CGUICheckMarkControl *)pGUIControl)->GetLabelInfo(); // note: conversion to plain colors from infocolors. ((ControlCheckMark*)pControl)->disabledColor = li.disabledColor; //((ControlCheckMark*)pControl)->shadowColor = li.shadowColor; ((ControlCheckMark*)pControl)->textColor = li.textColor; if (li.font) ((ControlCheckMark*)pControl)->strFont = li.font->GetFontName(); ((ControlCheckMark*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_LABEL: pControl = new ControlLabel(); break; case CGUIControl::GUICONTROL_SPIN: pControl = new ControlSpin(); break; case CGUIControl::GUICONTROL_FADELABEL: pControl = new ControlFadeLabel(); break; case CGUIControl::GUICONTROL_TEXTBOX: pControl = new ControlTextBox(); break; case CGUIControl::GUICONTROL_IMAGE: pControl = new ControlImage(); break; case CGUIControl::GUICONTROL_PROGRESS: pControl = new ControlProgress(); break; case CGUIControl::GUICONTROL_SLIDER: pControl = new ControlSlider(); break; case CGUIControl::GUICONTAINER_LIST: case CGUIControl::GUICONTAINER_WRAPLIST: case CGUIControl::GUICONTAINER_FIXEDLIST: case CGUIControl::GUICONTAINER_PANEL: pControl = new ControlList(); // create a python spin control ((ControlList*)pControl)->pControlSpin = new ControlSpin(); break; case CGUIControl::GUICONTROL_GROUP: pControl = new ControlGroup(); break; case CGUIControl::GUICONTROL_RADIO: pControl = new ControlRadioButton(); li = ((CGUIRadioButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlRadioButton*)pControl)->disabledColor = li.disabledColor; ((ControlRadioButton*)pControl)->focusedColor = li.focusedColor; ((ControlRadioButton*)pControl)->textColor = li.textColor; ((ControlRadioButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlRadioButton*)pControl)->strFont = li.font->GetFontName(); ((ControlRadioButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_EDIT: pControl = new ControlEdit(); li = ((CGUIEditControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlEdit*)pControl)->disabledColor = li.disabledColor; ((ControlEdit*)pControl)->textColor = li.textColor; if (li.font) ((ControlEdit*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; default: break; } if (!pControl) // throw an exeption throw WindowException("Unknown control type for python"); // we have a valid control here, fill in all the 'Control' data pControl->pGUIControl = pGUIControl; pControl->iControlId = pGUIControl->GetID(); pControl->iParentId = iWindowId; pControl->dwHeight = (int)pGUIControl->GetHeight(); pControl->dwWidth = (int)pGUIControl->GetWidth(); pControl->dwPosX = (int)pGUIControl->GetXPosition(); pControl->dwPosY = (int)pGUIControl->GetYPosition(); pControl->iControlUp = pGUIControl->GetControlIdUp(); pControl->iControlDown = pGUIControl->GetControlIdDown(); pControl->iControlLeft = pGUIControl->GetControlIdLeft(); pControl->iControlRight = pGUIControl->GetControlIdRight(); // It got this far so means the control isn't actually in the vector of controls // so lets add it to save doing all that next time vecControls.push_back(AddonClass::Ref<Control>(pControl)); // return the control with increased reference (+1) return pControl; }