// ---------------------------------------------------------------------------- void CViewBitmap::draw () { CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); CRGBA col; if(getModulateGlobalColor()) { col.modulateFromColor (_Color, pIM->getGlobalColorForContent()); } else { col= _Color; col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8); } if (_InheritGCAlpha) { // search a parent container CInterfaceGroup *gr = getParent(); while (gr) { if (gr->isGroupContainer()) { CGroupContainer *gc = static_cast<CGroupContainer *>(gr); col.A = (uint8)(((sint32)col.A*((sint32)gc->getCurrentContainerAlpha()+1))>>8); break; } gr = gr->getParent(); } }
void CIconWnd::modulateIcon(NLMISC::CBitmap &dst, const NLMISC::CRGBA &col) { // modulate an icon by a color CObjectVector<uint8> &data = dst.getPixels(); for (uint y=0 ; y<dst.getHeight() ; y++) { for (uint x=0 ; x<dst.getWidth() ; x++) { CRGBA c; c.modulateFromColor(col, dst.getPixelColor(x, y)); data[(x+y*dst.getWidth())*4] = c.R; data[(x+y*dst.getWidth())*4+1] = c.G; data[(x+y*dst.getWidth())*4+2] = c.B; data[(x+y*dst.getWidth())*4+3] = dst.getPixelColor(x, y).A; } } }
// ---------------------------------------------------------------------------- void CViewRadar::draw () { CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); CEntityCL *user = EntitiesMngr.entity(0); if (user == NULL) return; CVectorD xyzRef = user->pos(); const CVector dir = user->front(); float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0)); CMatrix mat; mat.identity(); // Scale to transform from world to interface screen mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) ); // local to user mat.rotateZ(-angle); xyzRef.z = 0; mat.translate(-xyzRef); float maxSqrRadius= (float)sqr(_WorldSize/2); for (sint32 i = 1; i < 256; ++i) { CEntityCL *entity = EntitiesMngr.entity(i); if (entity == NULL) continue; // if the entity must not be shown in radar if(!entity->getDisplayInRadar()) continue; // get entity pos CVectorD xyz = entity->pos(); xyz.z = 0; // if the distance is too big so do not display the entity if ((sqr(xyz.x - xyzRef.x)+sqr(xyz.y - xyzRef.y)) > maxSqrRadius) continue; // Transform the dot xyz = mat * xyz; // Convert to screen sint32 x = OptFastFloor((float)xyz.x); sint32 y = OptFastFloor((float)xyz.y); CRGBA col = entity->getColor(); if(getModulateGlobalColor()) col.modulateFromColor (col, pIM->getGlobalColorForContent()); else col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8); // Select the icon to display and draw it uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId(); CRadarSpotDesc spotDesc = _SpotDescriptions[spotId]; if (!_MissionIconsObs._displayMissionSpots) spotDesc = _SpotDescriptions[0]; if (spotDesc.isMissionSpot) col = CRGBA(255, 255, 255, 255); if (entity->isTarget()) spotId = 4; // to make it over other spots // Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range) if (spotDesc.isMissionSpot && _MiniMissionSpotsObs._displayMiniMissionSpots) rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2), spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col ); else rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.TxW/2)+(_WReal/2), _YReal+y-(spotDesc.TxH/2)+(_HReal/2), spotDesc.TxW, spotDesc.TxH, 0, false, spotDesc.TextureId, col ); } }
// ---------------------------------------------------------------------------- void CGroupList::draw () { // TEMP TEMP //CViewRenderer &rVR = *CViewRenderer::getInstance(); //rVR.drawRotFlipBitmap _RenderLayer, (_XReal, _YReal, _WReal, _HReal, 0, false, rVR.getBlankTextureId(), CRGBA(0, 255, 0, 255) ); if (_Over) { CViewRenderer &rVR = *CViewRenderer::getInstance(); if (CWidgetManager::getInstance()->getModalWindow() == NULL) { sint32 x = CWidgetManager::getInstance()->getPointer()->getX(); sint32 y = CWidgetManager::getInstance()->getPointer()->getY(); CInterfaceGroup *pIG = CWidgetManager::getInstance()->getWindowUnder(x, y); CInterfaceGroup *pParent = this; bool bFound = false; while (pParent != NULL) { if (pParent == pIG) { bFound = true; break; } pParent = pParent->getParent(); } sint32 clipx, clipy, clipw, cliph; getClip(clipx, clipy, clipw, cliph); if ((x < clipx) || (x > (clipx + clipw)) || (y < clipy) || (y > (clipy + cliph)) || !bFound) { _OverElt = -1; } else { for (uint32 i = 0; i < _Elements.size(); ++i) if (_Elements[i].Element->getActive()) { CViewBase *pVB = _Elements[i].Element; if ((x >= pVB->getXReal()) && (x < (pVB->getXReal() + pVB->getWReal()))&& (y >= pVB->getYReal()) && (y < (pVB->getYReal() + pVB->getHReal()))) { _OverElt = i; } } } } if (_OverElt != -1) { // Find the first container CInterfaceGroup *pIG = _Parent; CGroupContainerBase *pGC = dynamic_cast<CGroupContainerBase*>(pIG); while (pIG != NULL) { pIG = pIG->_Parent; if (pIG == NULL) break; if (dynamic_cast<CGroupContainerBase*>(pIG) != NULL) pGC = dynamic_cast<CGroupContainerBase*>(pIG); } bool bDisplayOverSelection = true; if (pGC != NULL) { if (pGC->isGrayed()) bDisplayOverSelection = false; } if (bDisplayOverSelection) { CViewBase *pVB = _Elements[_OverElt].Element; CRGBA col = _OverColor; if(getModulateGlobalColor()) { col.modulateFromColor (_OverColor, CWidgetManager::getInstance()->getGlobalColorForContent()); } else { col= _OverColor; col.A = (uint8)(((sint32)col.A*((sint32)CWidgetManager::getInstance()->getGlobalColorForContent().A+1))>>8); } rVR.drawRotFlipBitmap (_RenderLayer, pVB->getXReal(), pVB->getYReal(), pVB->getWReal(), pVB->getHReal(), 0, false, rVR.getBlankTextureId(), col ); } } }
// *************************************************************************** void CGroupFrame::draw () { if (_DisplayFrame) { CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = pIM->getViewRenderer(); // get global color CRGBA col; if(getModulateGlobalColor()) col.modulateFromColor (_Color, pIM->getGlobalColor()); else col= _Color; // draw the background sint xId = 0, yId = 0; for (yId = 0; yId < 3; yId++) { for (xId = 0; xId < 3; xId++) { sint32 x = _XReal; sint32 y = _YReal; sint32 w, h; // top if (yId == 0) { y += _HReal-_DispTypes[_DispType].TopBorder; h = _DispTypes[_DispType].TopBorder; } // Middle else if (yId == 1) { y += _DispTypes[_DispType].BottomBorder; h = _HReal-_DispTypes[_DispType].TopBorder-_DispTypes[_DispType].BottomBorder; } // Bottom else { h = _DispTypes[_DispType].BottomBorder; } // Left if (xId == 0) { w = _DispTypes[_DispType].LeftBorder; } else if (xId == 1) { x += _DispTypes[_DispType].LeftBorder; w = _WReal-_DispTypes[_DispType].LeftBorder-_DispTypes[_DispType].RightBorder; } else { x += _WReal-_DispTypes[_DispType].RightBorder; w = _DispTypes[_DispType].RightBorder; } // render uint8 tile = _DispTypes[_DispType].TileBorder[yId*3+xId]; if (tile == 0) rVR.drawRotFlipBitmap (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], col); else rVR.drawRotFlipBitmapTiled (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], tile-1, col); } } } // draw the components CInterfaceGroup::draw(); }
// -------------------------------------------------------------------------------------------------------------------- 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); } }
//********************************************************************************* void CViewPolygon::draw() { if (_Tris.empty()) return; if (!_Parent) return; CInterfaceManager *im = CInterfaceManager::getInstance(); CViewRenderer &vr = im->getViewRenderer(); if (_Touched) { _RealTris.clear(); uint numTris = (uint)_Tris.size(); sint32 cornerX, cornerY; static std::vector<NLMISC::CTriangle> winTris; winTris.resize(numTris); _Parent->getCorner(cornerX, cornerY, _ParentPosRef); for(uint k = 0; k < numTris; ++k) { winTris[k].V0.set((float) (_Tris[k].V0.x + cornerX), (float) (_Tris[k].V0.y + cornerY), 0.f); winTris[k].V1.set((float) (_Tris[k].V1.x + cornerX), (float) (_Tris[k].V1.y + cornerY), 0.f); winTris[k].V2.set((float) (_Tris[k].V2.x + cornerX), (float) (_Tris[k].V2.y + cornerY), 0.f); } // recompute & reclip poly _RealTris.clear(); sint32 cx, cy, cw, ch; vr.getClipWindow(cx, cy, cw, ch); // per tri clip NLMISC::CVector minCorner; NLMISC::CVector maxCorner; for(uint k = 0; k < numTris; ++k) { winTris[k].getMinCorner(minCorner); winTris[k].getMaxCorner(minCorner); if (totallyOutside(minCorner, maxCorner, cx, cy, cw, ch)) continue; if (totallyInside(minCorner, maxCorner, cx, cy, cw, ch)) { _RealTris.push_back(winTris[k]); } else { const uint maxNumCorners = 8; static CVector outPos0[maxNumCorners]; static CVector outPos1[maxNumCorners]; // outPos0[0] = winTris[k].V0; outPos0[1] = winTris[k].V1; outPos0[2] = winTris[k].V2; // CVector *pPos0 = outPos0; CVector *pPos1 = outPos1; // sint count = 3; // if ((sint32) minCorner.x < cx) { // clip left CPlane clipper(-1.f, 0.f, 0.f, (float) cx); count = clipper.clipPolygonBack(pPos0, pPos1, count); std::swap(pPos0, pPos1); } if ((sint32) maxCorner.x > cx + cw) { // clip right CPlane clipper(1.f, 0.f, 0.f, - (float) (cx + cw)); count = clipper.clipPolygonBack(pPos0, pPos1, count); std::swap(pPos0, pPos1); } // if ((sint32) minCorner.y < cy) { // clip bottom CPlane clipper(0.f, -1.f, 0.f, (float) cy); count = clipper.clipPolygonBack(pPos0, pPos1, count); std::swap(pPos0, pPos1); } if ((sint32) maxCorner.y > cy + ch) { // clip top CPlane clipper(0.f, 1.f, 0.f, - (float) (cy + ch)); count = clipper.clipPolygonBack(pPos0, pPos1, count); std::swap(pPos0, pPos1); } nlassert(count <= 8); if (count >= 3) { for(uint k = 0; k < (uint) (count - 2); ++k) { _RealTris.push_back(NLMISC::CTriangle(pPos0[0], pPos0[k + 1], pPos0[k + 2])); } } } } _Touched = false; } if (_RealTris.empty()) return; CRGBA col; if(getModulateGlobalColor()) { col.modulateFromColor (_Color, im->getGlobalColorForContent()); } else { col= _Color; col.A = (uint8)(((sint32)col.A*((sint32)im->getGlobalColorForContent().A+1))>>8); } vr.drawUnclippedTriangles(_RenderLayer, _RealTris, col); }