// -------------------------------------------------------------------------------------------------------------------- bool CViewPointer::drawCustom(CCtrlBase* pCB) { string texName; uint8 rot; NLMISC::CRGBA col; if (pCB->getMouseOverShape(texName, rot, col)) { if (texName[0] == '@') { const string &tooltipInfos = texName.substr(1); string tooltip; vector<string> tooltipInfosList; splitString(tooltipInfos, "@", tooltipInfosList); texName = tooltipInfosList[0]; tooltip = tooltipInfosList[1]; nlinfo(tooltip.c_str()); setString(ucstring(tooltip)); CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); sint32 texId = rVR.getTextureIdFromName (texName); CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor; if (stringCursor) { stringCursor->setX(_PointerX); stringCursor->setY(_PointerY); stringCursor->updateCoords(); stringCursor->draw(); // if in hardware mode, force to draw the default cursor no matter what.. if (IsMouseCursorHardware()) drawCursor(texId, col, 0); } else { drawCursor(texId, col, 0); } return true; } else { CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); sint32 texId = rVR.getTextureIdFromName (texName); drawCursor(texId, col, 0); return true; } } return false; }
//***************************************************************************************************************** void CGroupHeader::enlargeColumns(sint32 margin) { std::vector<CGroupHeaderEntry *> entries; getEntries(entries); sint32 totalWidth = 0; for (uint k = 0; k < entries.size(); ++k) { CInterfaceGroup *colEnclosing = entries[k]->getTargetColumn(); if (colEnclosing && !colEnclosing->getGroups().empty()) { CInterfaceGroup *col = colEnclosing->getGroups()[0]; if (col) { // enlarge to the max to be able to measure the sub text (they may clamp themselves based // on their first non-"child resizing" parent (see CViewText::updateCoords) colEnclosing->setW(16384); colEnclosing->invalidateCoords(); colEnclosing->updateCoords(); // assume that first child is resizing from its children width (either 'child_resize_w=true' or a CGroupList) entries[k]->setW(std::max(entries[k]->getMinSize(), col->getW() + margin)); entries[k]->invalidateCoords(); totalWidth += entries[k]->getW(); } } } // if total width bigger than allowed, reduce proportionnally if (totalWidth > _HeaderMaxSize) { while (totalWidth > _HeaderMaxSize) { bool adjusted = false; // stupid algo here, but ponctual ... for (uint k = 0; k < entries.size() && totalWidth > _HeaderMaxSize; ++k) { if (entries[k]->getW() > entries[k]->getMinSize()) { entries[k]->setW(entries[k]->getW() - 1); entries[k]->invalidateCoords(); --totalWidth; adjusted = true; } } // if all at min size, just exit ... if (!adjusted) break; } } else { // search first parent that limit size, if it is larger then enlarge to fit size CInterfaceGroup *limitingParent = getParent(); while (limitingParent && (limitingParent->getResizeFromChildW() || dynamic_cast<CGroupList *>(limitingParent))) { // NB nico : the dynamic_cast for CGroupList is bad!! // can't avoid it for now, because, CGroupList implicitly does a "resize from child" in its update coords // ... limitingParent = limitingParent->getParent(); } if (limitingParent && limitingParent->getWReal() > totalWidth) { while (limitingParent->getWReal() > totalWidth && totalWidth < _HeaderMaxSize) { // enlarge to matche parent size // stupid algo here, but ponctual ... for (uint k = 0; k < entries.size(); ++k) { entries[k]->setW(entries[k]->getW() + 1); entries[k]->invalidateCoords(); ++totalWidth; if (limitingParent->getWReal() <= totalWidth || totalWidth >= _HeaderMaxSize) break; } } } } invalidateCoords(); }
//***************************************************************************************************************** void CGroupHeader::resizeColumnsAndContainer(sint32 margin) { std::vector<CGroupHeaderEntry *> entries; getEntries(entries); sint32 totalWidth = 0; for (uint k = 0; k < entries.size(); ++k) { CInterfaceGroup *colEnclosing = entries[k]->getTargetColumn(); if (colEnclosing && !colEnclosing->getGroups().empty()) { CInterfaceGroup *col = colEnclosing->getGroups()[0]; if (col) { // enlarge to the max to be able to measure the sub text (they may clamp themselves based // on their first non-"child resizing" parent (see CViewText::updateCoords) colEnclosing->setW(16384); colEnclosing->invalidateCoords(); colEnclosing->updateCoords(); // assume that first child is resizing from its children width (either 'child_resize_w=true' or a CGroupList) entries[k]->setW(std::max(entries[k]->getMinSize(), col->getW() + margin)); entries[k]->invalidateCoords(); totalWidth += entries[k]->getW(); } } } // resize W if (totalWidth <= _HeaderMaxSize) { // search first parent that limit size, if it is larger then enlarge to fit size CInterfaceGroup *limitingParent = getParent(); while (limitingParent && (limitingParent->getResizeFromChildW() || dynamic_cast<CGroupList *>(limitingParent))) { // NB nico : the dynamic_cast for CGroupList is bad!! // can't avoid it for now, because, CGroupList implicitly does a "resize from child" in its update coords // ... limitingParent = limitingParent->getParent(); } getParentContainer()->setW(totalWidth + getParentContainer()->getWReal() - limitingParent->getWReal()); } // resize H if(entries.size()>0) { CInterfaceGroup *colEnclosing = entries[0]->getTargetColumn(); if (colEnclosing && !colEnclosing->getGroups().empty()) { CInterfaceGroup *col = colEnclosing->getGroups()[0]; if (col) { // search first parent that limit size, if it is larger then enlarge to fit size CInterfaceGroup *limitingParent = colEnclosing->getParent(); while (limitingParent && (limitingParent->getResizeFromChildH() || dynamic_cast<CGroupList *>(limitingParent))) limitingParent = limitingParent->getParent(); getParentContainer()->setH(col->getH() + getParentContainer()->getHReal() - limitingParent->getHReal()); } } } invalidateCoords(); }
// -------------------------------------------------------------------------------------------------------------------- void CViewPointer::draw () { // Do not display the pointer if not visible. if(!_PointerVisible) return; CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); if (pIM->isInGame()) if (!_StringCursor) { // Create the string cursor instance std::vector<std::pair<std::string,std::string> > templateParams; templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor")); _StringCursor = pIM->createGroupInstance("string_cursor", "", templateParams); if (_StringCursor) _StringCursor->setParentPos(pIM->getElementFromId("ui:interface")); templateParams.clear(); templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor_hardware")); _StringCursorHardware = pIM->createGroupInstance("string_cursor_hardware", "", templateParams); if (_StringCursorHardware) _StringCursorHardware->setParentPos(pIM->getElementFromId("ui:interface")); } CRGBA col; if(getModulateGlobalColor()) col.modulateFromColor (_Color, pIM->getGlobalColor()); else col= _Color; //col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColor().A+1))>>8); col.A = _Color.A; if (_LastHightLight != NULL) { _LastHightLight->setHighLighted(false,0); _LastHightLight = NULL; } if (pIM->getCapturePointerLeft() != NULL && pIM->isMouseHandlingEnabled()) { CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pIM->getCapturePointerLeft()); if ((pCM != NULL) && (pCM->canMove() == true)) { CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent()); if (pGC != NULL && !pGC->isLocked()) { pGC->setHighLighted(true, 255); _LastHightLight = pGC; } } } if (_TxIdDefault == -2) { _TxIdDefault = rVR.getTextureIdFromName (_TxDefault); _TxIdMoveWindow = rVR.getTextureIdFromName (_TxMoveWindow); _TxIdResizeBRTL = rVR.getTextureIdFromName (_TxResizeBRTL); _TxIdResizeBLTR = rVR.getTextureIdFromName (_TxResizeBLTR); _TxIdResizeTB = rVR.getTextureIdFromName (_TxResizeTB); _TxIdResizeLR = rVR.getTextureIdFromName (_TxResizeLR); _TxIdRotate = rVR.getTextureIdFromName (_TxRotate); _TxIdScale = rVR.getTextureIdFromName (_TxScale); _TxIdColPick = rVR.getTextureIdFromName (_TxColPick); _TxIdPan = rVR.getTextureIdFromName (_TxPan); _TxIdCanPan = rVR.getTextureIdFromName (_TxCanPan); if (ClientCfg.R2EDEnabled) { _TxIdPanR2 = rVR.getTextureIdFromName (_TxPanR2); _TxIdCanPanR2 = rVR.getTextureIdFromName (_TxCanPanR2); } } const vector<CCtrlBase *> &rICL = pIM->getCtrlsUnderPointer (); // Draw the captured cursor CCtrlBase *pCB = pIM->getCapturePointerLeft(); if (pCB != NULL) { if (drawResizer(pCB,col)) return; //if (drawMover(pCB,col)) return; if (drawColorPicker(pCB,col)) return; if (drawRotate(pCB,col)) return; if (drawPan(pCB,col)) return; if (drawCustom(pCB)) return; drawCursor(_TxIdDefault, col, 0); return; } const vector<CViewBase *> &vUP = pIM->getViewsUnderPointer (); for(uint i=0;i<vUP.size();i++) { CViewLink *vLink = dynamic_cast<CViewLink*>(vUP[i]); if (vLink != NULL) { string tooltip; uint8 rot; if (vLink->getMouseOverShape(tooltip, rot, col)) { setString(ucstring(tooltip)); sint32 texId = rVR.getTextureIdFromName ("curs_pick.tga"); CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor; if (stringCursor) { stringCursor->setX(_PointerX); stringCursor->setY(_PointerY); stringCursor->updateCoords(); stringCursor->draw(); // if in hardware mode, force to draw the default cursor no matter what.. if (IsMouseCursorHardware()) drawCursor(texId, col, 0); } else { drawCursor(texId, col, 0); } return; } } } // Draw if capture right pCB = pIM->getCapturePointerRight(); if (pCB != NULL) { // Is it a 3d scene ? if (drawScale(pCB,col)) return; drawCursor(_TxIdDefault, col, 0); return; } bool overModalWindow = false; // is the cursor currently over a modal window ? CInterfaceGroup *currModal = pIM->getModalWindow(); if (currModal) { sint32 xPos = _XReal + _OffsetX; sint32 yPos = _YReal + _OffsetY; overModalWindow = currModal->isIn(xPos, yPos, _WReal, _HReal); } // Draw the cursor type that are under the pointer if (pIM->isMouseHandlingEnabled()) { // Sorts the controls according to their depth, to approximate as best the CapturePointerLeft algo. // Especially important so that Resizers controls get the precedence over the move control (else could randomly bug like in chat group) static vector<CCtrlDepthEntry> sortedControls; sortedControls.clear(); for(uint i=0;i<rICL.size();i++) { CCtrlDepthEntry cde; cde.Ctrl= rICL[i]; // NB: not the exact CInterfaceManager getDepth test here, but should work fine cde.Depth= cde.Ctrl->getParentDepth() + cde.Ctrl->getDeltaDepth(); sortedControls.push_back(cde); } std::sort(sortedControls.begin(), sortedControls.end()); // Then draw the correct cursor for (uint32 i = 0; i < sortedControls.size(); ++i) { CCtrlBase *pCB = sortedControls[i].Ctrl; if (overModalWindow) { if (!pCB->isSonOf(currModal)) continue; } if (drawBrowse(pCB, col)) return; if (drawResizer(pCB,col)) return; if (drawColorPicker(pCB,col)) return; if (drawLink (pCB, col)) return; if (drawCustom(pCB)) return; // test for move highlight if (_LastHightLight == NULL) { CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pCB); if ( (pCM != NULL) && (pCM->canMove() == true) ) { CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent()); if (pGC != NULL && !pGC->isLocked()) { if (pIM->getCapturePointerLeft() != pCM) pGC->setHighLighted(true, 128); else pGC->setHighLighted(true, 255); _LastHightLight = pGC; break; } } } //if (drawMover(pCB,col)) return; } } if (pIM->isMouseHandlingEnabled()) { if (rICL.empty()) { const vector<CInterfaceGroup *> &rIGL = pIM->getGroupsUnderPointer (); for (uint32 i = 0; i < rIGL.size(); ++i) { CInterfaceGroup *pG = rIGL[i]; if (overModalWindow) { if (!pG->isSonOf(currModal)) continue; } if (drawPan (pG, col)) return; if (drawBrowse(pG, col)) return; } } } if (_StringMode && pIM->isMouseHandlingEnabled()) { CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor; if (stringCursor) { stringCursor->setX(_PointerX); stringCursor->setY(_PointerY); stringCursor->updateCoords(); stringCursor->draw(); // if in hardware mode, force to draw the default cursor no matter what.. if (IsMouseCursorHardware()) { drawCursor(_TxIdDefault, col, 0); } } } else { // Draw the default cursor drawCursor(_TxIdDefault, col, 0); } }