// ---------------------------------------------------------------------------- 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 CVegetableApperancePage::OnDblclkListVegetableColor() { CRGBA color; // get the current color of the value. int id= ColorList.GetCurSel(); if(id!=LB_ERR) { color= ColorList.getValue(id); // Open a colorDialog. CColorDialog colorDialog(RGB(color.R, color.G, color.B), CC_FULLOPEN); if( colorDialog.DoModal()==IDOK ) { // update view COLORREF cref = colorDialog.GetColor(); color.set(GetRValue(cref), GetGValue(cref), GetBValue(cref)); ColorList.changeCurSelValue(color); // update vegetable writeToVegetableColor(_Vegetable); // update 3D view _VegetableDlg->refreshVegetableDisplay(); } } }
bool ReadColor (CRGBA &color, xmlNodePtr node) { // Read the color float r = DEFAULT_PRIMITIVE_COLOR.R; float g = DEFAULT_PRIMITIVE_COLOR.G; float b = DEFAULT_PRIMITIVE_COLOR.B; float a = DEFAULT_PRIMITIVE_COLOR.A; // Read the value if (!ReadFloat ("R", r, node)) return false; if (!ReadFloat ("G", g, node)) return false; if (!ReadFloat ("B", b, node)) return false; if (!ReadFloat ("A", a, node)) a = 255; // Clamp clamp (r, 0.f, 255.f); clamp (g, 0.f, 255.f); clamp (b, 0.f, 255.f); clamp (a, 0.f, 255.f); // Set color.set((uint8)r, (uint8)g, (uint8)b, (uint8)a); return true; }
void CQImageViewRenderer:: drawPoint(int x, int y, const CRGBA &rgba) { if (x >= 0 && x < width_ && y >= 0 && y < height_) //image_->setPixel(x, y, CQUtil::rgbaToColor(rgba).rgba()); image_->setPixel(x, y, rgba.encodeARGB()); }
CRGBA CSVGStroke:: getAlphaColor() const { CRGBA rgba; if (color_.getValid()) { rgba = color_.getValue(); if (getOpacityValid()) rgba.setAlpha(getOpacity()); } else rgba = CRGBA(0,0,0,0); return rgba; }
void CGnuPlotStyleRadar:: getPointsColor(CGnuPlotRadarStyleValue *value, int pi, CRGBA &lc, CRGBA &fc) { lc = CGnuPlotStyleInst->indexColor(value->palette(), pi); fc = lc; fc.setAlpha(0.5); }
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 cbUpdateCompass (CConfigFile::CVar &var) { if (var.Name == "CompassPosX") CompassPosX = var.asFloat (); else if (var.Name == "CompassPosY") CompassPosY = var.asFloat (); else if (var.Name == "CompassRadius") CompassRadius = var.asFloat (); else if (var.Name == "CompassColor") { CompassColor.set(var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); CompassMaterial.setColor(CompassColor); } else nlwarning ("Unknown variable update %s", var.Name.c_str()); }
void cbUpdateRadar (CConfigFile::CVar &var) { if (var.Name == "RadarPosX") RadarPosX = var.asFloat (); else if (var.Name == "RadarPosY") RadarPosY = var.asFloat (); else if (var.Name == "RadarWidth") RadarWidth = var.asFloat (); else if (var.Name == "RadarHeight") RadarHeight = var.asFloat (); else if (var.Name == "RadarBackColor") RadarBackColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarFrontColor") RadarFrontColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarSelfColor") RadarSelfColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarOtherColor") RadarOtherColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarDynamicColor") RadarDynamicColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarPlaceColor") RadarPlaceColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); else if (var.Name == "RadarEntitySize") RadarEntitySize = var.asFloat (); else if (var.Name == "RadarState") RadarState = var.asInt (); else if (var.Name == "RadarDistance") RadarDistance = var.asInt (); else if (var.Name == "RadarMinDistance") RadarMinDistance = var.asInt (); else if (var.Name == "RadarMaxDistance") RadarMaxDistance = var.asInt (); else if (var.Name == "URLSelectionTimeout") SelectionTimeOut = var.asInt (); else if (var.Name == "RadarParticularPlaces") { RadarParticularPlaces.clear (); for (sint i = 0; i < var.size(); i += 4) { RadarParticularPlaces.push_back (RadarParticularPlace(var.asFloat(i), var.asFloat(i+1), var.asString(i+2), var.asString(i+3))); } } else if (var.Name == "RadarFontSize") RadarFontSize = var.asInt (); else if (var.Name == "RadarLittlePosX") RadarLittlePosX = var.asFloat (); else if (var.Name == "RadarLittlePosY") RadarLittlePosY = var.asFloat (); else if (var.Name == "RadarLittleRadius") RadarLittleRadius = var.asFloat (); else nlwarning ("Unknown variable update %s", var.Name.c_str()); }
// *************************************************************************** void drawDisc(CBitmap &dest, float x, float y, float radius, const CRGBA &color, bool additif /*= false*/, uint numSegs /*= 127*/) { CPolygon2D poly; poly.Vertices.resize(numSegs); for(uint k = 0; k < numSegs; ++k) { poly.Vertices[k].set(x + radius * (float) cos(k / (float) numSegs * 2 * Pi), y + radius * (float) sin(k / (float) numSegs * 2 * Pi)); } CPolygon2D::TRasterVect rasters; sint minY; poly.computeOuterBorders(rasters, minY); sint maxY = std::min((sint) dest.getHeight(), (sint) rasters.size() + minY); for (sint y = std::max((sint) 0, minY); y < maxY; ++y) { nlassert(y >= 0 && y < (sint) dest.getHeight()); sint minX = std::max((sint) 0, rasters[y - minY].first); sint maxX = std::min((sint) dest.getWidth(), rasters[y - minY].second); if (maxX > minX) { CRGBA *pt = (CRGBA *) &dest.getPixels(0)[0]; pt += y * dest.getWidth() + minX; const CRGBA *endPt = pt + (maxX - minX); while (pt != endPt) { if (additif) { pt->add(*pt, color); } else { *pt = color; } ++ pt; } } } }
void CIconWnd::blendIcons(NLMISC::CBitmap &dst, const NLMISC::CBitmap &src) { // blend between two icons nlassert(dst.getWidth() == src.getWidth()); nlassert(dst.getHeight() == src.getHeight()); CObjectVector<uint8> &data = dst.getPixels(); for (uint y=0 ; y<dst.getHeight() ; y++) { for (uint x=0 ; x<dst.getWidth() ; x++) { CRGBA c; c.blendFromui(dst.getPixelColor(x, y), src.getPixelColor(x, y), src.getPixelColor(x, y).A); 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] = c.A; } } }
void CImageView:: getRGBAPixel(int x, int y, CRGBA &rgba) { image_->getRGBAPixel(x, y, rgba); if (mode_ == Mode::GRAY) rgba = rgba.getGrayRGBA(); else if (mode_ == Mode::SEPIA) rgba = rgba.sepia(); else if (mode_ == Mode::RED) { rgba.setGreen(0); rgba.setBlue (0); } else if (mode_ == Mode::GREEN) { rgba.setRed (0); rgba.setBlue(0); } else if (mode_ == Mode::BLUE) { rgba.setRed (0); rgba.setGreen(0); } }
void CXCursor:: recolor(const CRGBA &bg, const CRGBA &fg) { Display *display = screen_.getDisplay(); XColor fg_xcolor; XColor bg_xcolor; fg_xcolor.red = (int) (fg.getRed ()*65535); fg_xcolor.green = (int) (fg.getGreen()*65535); fg_xcolor.blue = (int) (fg.getBlue ()*65535); bg_xcolor.red = (int) (bg.getRed ()*65535); bg_xcolor.green = (int) (bg.getGreen()*65535); bg_xcolor.blue = (int) (bg.getBlue ()*65535); XRecolorCursor(display, xcursor_, &fg_xcolor, &bg_xcolor); }
// ---------------------------------------------------------------------------- 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 CGIFImage:: readAnimData(CFile *file, CGenImage *proto, CGIFAnim *image_anim, CGIFImageData *gif_data) { int inum = 0; int delay = 0; bool transparent = false; uint transparent_color = 0; int dispose = 0; int user_input = 0; uint file_size = file->getSize(); while (true) { uchar id; try { if (! file->read(&id, 1)) break; } catch (...) { break; } if (id == IMAGE_ID) { ++inum; if (CGIFImage::getDebug()) std::cerr << "Image Id" << std::endl; CGIFImageImageHeader *image_header = new CGIFImageImageHeader; try { uchar byte1; uchar byte2; file->read(&byte1, 1); file->read(&byte2, 1); image_header->left = (byte2 << 8) | byte1; file->read(&byte1, 1); file->read(&byte2, 1); image_header->top = (byte2 << 8) | byte1; file->read(&byte1, 1); file->read(&byte2, 1); image_header->width = (byte2 << 8) | byte1; file->read(&byte1, 1); file->read(&byte2, 1); image_header->height = (byte2 << 8) | byte1; file->read(&image_header->flags, 1); image_header->local_color_table = (image_header->flags >> 7) & 0x01; image_header->interlaced = (image_header->flags >> 6) & 0x01; image_header->colors_sorted = (image_header->flags >> 5) & 0x01; image_header->color_bits = (image_header->flags ) & 0x07; if (CGIFImage::getDebug()) { std::cerr << "Left " << image_header->left << std::endl; std::cerr << "Top " << image_header->top << std::endl; std::cerr << "Width " << image_header->width << std::endl; std::cerr << "Height " << image_header->height << std::endl; std::cerr << "Local Colors " << image_header->local_color_table << std::endl; std::cerr << "Interlaced " << image_header->interlaced << std::endl; std::cerr << "Colors Sorted " << image_header->colors_sorted << std::endl; std::cerr << "Num Colors " << (1 << (image_header->color_bits + 1)) << std::endl; } if (image_header->local_color_table && image_header->color_bits > 0) { gif_data->num_local_colors = 1 << (image_header->color_bits + 1); gif_data->local_colors = new CGIFImageColorTable [gif_data->num_local_colors]; for (int i = 0; i < gif_data->num_local_colors; ++i) file->read((uchar *) &gif_data->local_colors[i], 3); if (CGIFImage::getDebug()) { for (int i = 0; i < gif_data->num_local_colors; ++i) std::cerr << gif_data->local_colors[i].r << " " << gif_data->local_colors[i].g << " " << gif_data->local_colors[i].b << std::endl; } } file->read(&compress_data.code_size, 1); compress_data.clear_code = 1 << compress_data.code_size; compress_data.eof_code = compress_data.clear_code + 1; compress_data.free_code = compress_data.clear_code + 2; ++compress_data.code_size; compress_data.init_code_size = compress_data.code_size; compress_data.max_code = 1 << compress_data.code_size; compress_data.code_mask = compress_data.max_code - 1; uint num_image_bytes = image_header->width*image_header->height; uchar *data = new uchar [file_size]; uchar size; file->read(&size, 1); uint num_bytes_read = 0; while (size > 0) { while (size--) { file->read(&data[num_bytes_read], 1); ++num_bytes_read; } file->read(&size, 1); } if (num_bytes_read < file_size) memset(&data[num_bytes_read], 0, file_size - num_bytes_read); //------ uchar *raw_data = new uchar [num_image_bytes]; decompressData(data, num_bytes_read, raw_data, num_image_bytes); delete [] data; if (image_header->interlaced) deInterlace(raw_data, image_header); //------ CGenImage *image = proto->dup(); image->setType(CFILE_TYPE_IMAGE_GIF); image->setColormap(true); image->setDataSize(image_header->width, image_header->height); int bottom = gif_data->header->height - image_header->height - image_header->top; int right = gif_data->header->width - image_header->width - image_header->left; //image->setBorder(image_header->left, bottom, right, image_header->top); if (bottom != 0 || right != 0) std::cerr << "Unhandled border" << std::endl; if (gif_data->num_local_colors > 0) { for (int i = 0; i < gif_data->num_local_colors; ++i) { CRGBA rgba; rgba.setRGBAI(gif_data->local_colors[i].r, gif_data->local_colors[i].g, gif_data->local_colors[i].b); image->addColor(rgba); } } else { for (int i = 0; i < gif_data->num_global_colors; ++i) { CRGBA rgba; rgba.setRGBAI(gif_data->global_colors[i].r, gif_data->global_colors[i].g, gif_data->global_colors[i].b); image->addColor(rgba); } //image->setBackground(image->getColor(gif_data->header->background)); } //------ if (transparent) image->setTransparentColor(transparent_color); //------ for (int y = 0, k = 0; y < image_header->height; ++y) for (int x = 0; x < image_header->width; ++x, ++k) image->setColorIndex(x, y, raw_data[k]); delete [] raw_data; //------ CGIFFrame *frame = new CGIFFrame(image); frame->setDelay(delay); frame->setDispose(dispose); frame->setUserInput(user_input); image_anim->add(frame); //------ delay = 0; transparent = false; transparent_color = 0; dispose = 0; user_input = 0; //------ delete image_header; image_header = NULL; } catch (...) { delete image_header; CTHROW("Failed to read GIF file"); } } else if (id == CONTROL_ID) {
namespace SBCLIENT { // // Variables // static NL3D::UMaterial CompassMaterial = NULL; // These variables are automatically set with the config file static float CompassPosX, CompassPosY, CompassRadius; static CRGBA CompassColor; // // Functions // void cbUpdateCompass (CConfigFile::CVar &var) { if (var.Name == "CompassPosX") CompassPosX = var.asFloat (); else if (var.Name == "CompassPosY") CompassPosY = var.asFloat (); else if (var.Name == "CompassRadius") CompassRadius = var.asFloat (); else if (var.Name == "CompassColor") { CompassColor.set(var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3)); CompassMaterial.setColor(CompassColor); } else nlwarning ("Unknown variable update %s", var.Name.c_str()); } void initCompass () { CompassMaterial = Driver->createMaterial (); CompassMaterial.initUnlit (); CompassMaterial.setBlendFunc (UMaterial::srcalpha, UMaterial::invsrcalpha); CompassMaterial.setBlend(true); ConfigFile->setCallback ("CompassPosX", cbUpdateCompass); ConfigFile->setCallback ("CompassPosY", cbUpdateCompass); ConfigFile->setCallback ("CompassRadius", cbUpdateCompass); ConfigFile->setCallback ("CompassColor", cbUpdateCompass); cbUpdateCompass (ConfigFile->getVar ("CompassPosX")); cbUpdateCompass (ConfigFile->getVar ("CompassPosY")); cbUpdateCompass (ConfigFile->getVar ("CompassRadius")); cbUpdateCompass (ConfigFile->getVar ("CompassColor")); } void updateCompass () { float x = CompassPosX; float y = CompassPosY; float radius = CompassRadius; // tri CTriangle tri; tri.V0.set (-radius, 0, 0); tri.V1.set (radius, 0, 0); tri.V2.set (0, 3*radius, 0); CQuad quad; // quad quad.V0.set (-radius, -radius, 0); quad.V1.set ( radius, -radius, 0); quad.V2.set ( radius, radius, 0); quad.V3.set (-radius, radius, 0); Driver->setMatrixMode2D43 (); CMatrix mtx; // up mtx.identity(); mtx.translate(CVector(x,y,0)); mtx.rotateZ(MouseListener->getOrientation() - (float)Pi/2); mtx.translate(CVector(0,radius,0)); Driver->setModelMatrix (mtx); Driver->drawTriangle (tri, CompassMaterial); // down mtx.identity(); mtx.translate(CVector(x,y,0)); mtx.rotateZ(MouseListener->getOrientation() + (float)Pi/2); mtx.translate(CVector(0,radius,0)); Driver->setModelMatrix (mtx); Driver->drawTriangle (tri, CompassMaterial); // left mtx.identity(); mtx.translate(CVector(x,y,0)); mtx.rotateZ(MouseListener->getOrientation()); mtx.translate(CVector(0,radius,0)); Driver->setModelMatrix (mtx); Driver->drawTriangle (tri, CompassMaterial); // right mtx.identity(); mtx.translate(CVector(x,y,0)); mtx.rotateZ(MouseListener->getOrientation() - (float)Pi); mtx.translate(CVector(0,radius,0)); Driver->setModelMatrix (mtx); Driver->drawTriangle (tri, CompassMaterial); // center mtx.identity(); mtx.translate(CVector(x,y,0)); mtx.rotateZ(MouseListener->getOrientation()); Driver->setModelMatrix (mtx); Driver->drawQuad (quad, CompassMaterial); x *= 3.0/4.0f; // Print position TextContext->setHotSpot(UTextContext::MiddleTop); TextContext->setColor(CompassColor); TextContext->setFontSize(14); if (Self != NULL) TextContext->printfAt(x, y-4.0f*radius, "%.2f %.2f %.2f", Self->Position.x, Self->Position.y, Self->Position.z); else TextContext->printfAt(x, y-4.0f*radius, "%.2f %.2f %.2f", MouseListener->getPosition().x, MouseListener->getPosition().y, MouseListener->getPosition().z); } void releaseCompass () { ConfigFile->setCallback("CompassPosX", NULL); ConfigFile->setCallback("CompassPosY", NULL); ConfigFile->setCallback("CompassRadius", NULL); ConfigFile->setCallback("CompassColor", NULL); Driver->deleteMaterial (CompassMaterial); CompassMaterial = NULL; } } /* namespace SBCLIENT */
// *************************************************************************** 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 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 CGraph::renderGraph () { // Display the background uint32 w, h; CNELU::Driver->getWindowSize (w, h); float ScreenWidth = (float) w; float ScreenHeight = (float) h; if (w == 0 || h == 0) return; float iw = 1.f / w; float ih = 1.f / h; NL3D::CViewport vp; CDRU::drawQuad(X * iw, Y * ih, (X+Width) * iw, (Y+Height) * ih, *CNELU::Driver, BackColor, vp); Peak = 0.0f; float sum = 0.0f; CRGBA lineCol; if ( LineMode ) { lineCol.set (BackColor.R, BackColor.G, BackColor.B, 255); } else { lineCol.set (255,255,255,BackColor.A); } float pos = X+Width-1; uint i = 0; for (deque<float>::reverse_iterator it = Values.rbegin(); it != Values.rend(); it++) { float value = (*it) * Height / MaxValue; if (value > Height) value = Height; CVector vect1; if ( LineMode ) { vect1.x = pos-1; vect1.y = PrevY; } else { vect1.x = pos; vect1.y = Y; } PrevY = Y + value; CDRU::drawLine(vect1.x * iw, vect1.y * ih, pos * iw, PrevY * ih, *CNELU::Driver, lineCol); pos--; if ((*it) > Peak) Peak = *it; sum += *it; i++; } // Display max float value = Peak * Height / MaxValue; if (value > Height) value = Height; float peakval = Y+value; CRGBA frontCol (min(BackColor.R*2,255),min(BackColor.G*2,255),min(BackColor.B*2,255),min(BackColor.A*2,255)); CDRU::drawLine(X * iw, peakval * ih, (X+Width) * iw, peakval * ih, *CNELU::Driver, frontCol); // Display average float average = sum / (float)Values.size(); value = average * Height / MaxValue; if (value > Height) value = Height; float avrval = Y+value; CDRU::drawLine(X * iw, avrval * ih, (X+Width) * iw, avrval * ih, *CNELU::Driver, frontCol); }
void FontRendererImpl::DrawText(fwWString text, const CRect& rect, const CRGBA& color, float fontSize, float fontScale, fwString fontRef) { // wait for a swap to complete FrpSeqAllocatorWaitForSwap(); m_mutex.lock(); // create or find a text format ComPtr<IDWriteTextFormat> textFormat; auto formatKey = std::make_pair(fontRef, fontSize); auto formatIter = m_textFormatCache.find(formatKey); if (formatIter != m_textFormatCache.end()) { textFormat = formatIter->second; } else { wchar_t fontRefWide[128]; mbstowcs(fontRefWide, fontRef.c_str(), _countof(fontRefWide)); m_dwFactory->CreateTextFormat(fontRefWide, nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf()); m_textFormatCache[formatKey] = textFormat; } // create or find a cached text layout ComPtr<IDWriteTextLayout> textLayout; auto layoutKey = std::make_pair(textFormat.Get(), std::make_pair(color.AsARGB(), text)); auto layoutIter = m_textLayoutCache.find(layoutKey); if (layoutIter != m_textLayoutCache.end()) { textLayout = layoutIter->second; } else { m_dwFactory->CreateTextLayout(text.c_str(), text.length(), textFormat.Get(), rect.Width(), rect.Height(), textLayout.GetAddressOf()); m_textLayoutCache[layoutKey] = textLayout; // set effect DWRITE_TEXT_RANGE effectRange = { 0, UINT32_MAX }; ComPtr<CitizenDrawingEffect> effect = Make<CitizenDrawingEffect>(); effect->SetColor(color); textLayout->SetDrawingEffect((IUnknown*)effect.Get(), effectRange); } // draw auto drawingContext = new CitizenDrawingContext(); textLayout->Draw(drawingContext, m_textRenderer.Get(), rect.Left(), rect.Top()); auto numRuns = drawingContext->glyphRuns.size(); if (numRuns) { for (auto& run : drawingContext->glyphRuns) { m_queuedGlyphRuns.push_back(run); } } delete drawingContext; m_mutex.unlock(); }
//********************************************************************************* 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); }
void CGnuPlotStyleRadar:: draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotRadarStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotRadarStyleValue>(plot); if (! value) { value = plot->app()->device()->createRadarStyleValue(plot); CGnuPlotStyleValueMgrInst->setValue<CGnuPlotRadarStyleValue>(plot, value); } //--- const CBBox2D &bbox = plot->bbox2D(); CPoint2D pc = bbox.getCenter(); double r = bbox.getWidth()/2; int np = -1; for (const auto &point : plot->getPoints2D()) { np = std::min(np < 0 ? INT_MAX : np, point.getNumValues()); } if (np < 3) return; //double pw = renderer->pixelWidthToWindowWidth (1); //double ph = renderer->pixelHeightToWindowHeight(1); CGnuPlotGroup *group = plot->group(); const CGnuPlotKeyData &keyData = plot->keyData(); const CGnuPlotAxisData &xaxis = group->xaxis(1); const CGnuPlotKey::Columns &columns = keyData.columns(); double da = 360/np; std::vector<CPoint2D> points = radarPoints(value->angleStart(), pc, r, np); double v = getRange(plot); //--- // draw border renderer->drawPolygon(points, value->borderColor(), value->borderWidth(), value->borderDash()); //--- // draw column labels (how determine indices) { double a = value->angleStart(); for (int i = 1; i <= np && i < int(columns.size()); ++i) { CPoint2D p = radarPoint(pc, r, a); CHAlignType halign = CHALIGN_TYPE_CENTER; CVAlignType valign = CVALIGN_TYPE_CENTER; double dx = 0; double dy = 0; if (p.x < pc.x - v/2) { halign = CHALIGN_TYPE_RIGHT; dx = -8; } else if (p.x > pc.x + v/2) { halign = CHALIGN_TYPE_LEFT; dx = 8; } if (p.y < pc.y - v/2) { valign = CVALIGN_TYPE_TOP; dy = 8; } else if (p.y > pc.y + v/2) { valign = CVALIGN_TYPE_BOTTOM; dy = -8; } CRGBA tc = CRGBA(0,0,0); renderer->drawHAlignedText(p, HAlignPos(halign, dx), VAlignPos(valign, dy), columns[i], tc), a -= da; } } //--- // draw axis if needed if (xaxis.isDisplayed()) { CRGBA ac = value->axisColor(); ac.setAlpha(value->axisAlpha()); double dr = 0.1; double ra = 0.1; while (ra < v) { std::vector<CPoint2D> points1 = radarPoints(value->angleStart(), pc, ra, np); renderer->drawPolygon(points1, ac, value->axisWidth(), value->axisDash()); ra += dr; } for (const auto &p : points) renderer->drawLine(p, pc, ac, value->axisWidth(), value->axisDash()); } //--- bool cache = false; if (! renderer->isPseudo() && plot->isCacheActive()) { plot->updatePolygonCacheSize(plot->numPoints2D()); cache = true; } int pi = 0; for (const auto &point : plot->getPoints2D()) { std::vector<CPoint2D> points1; double a = value->angleStart(); for (int i = 0; i < np; ++i) { double v1; if (! point.getValue(i + 1, v1)) continue; CPoint2D p = radarPoint(pc, v1, a); points1.push_back(p); a -= da; } CRGBA lc, fc; getPointsColor(value, pi + 1, lc, fc); if (cache) { //std::string label = (pi < int(columns.size()) ? columns[pi] : ""); std::string label = xaxis.iticLabel(pi); auto polygon = plot->polygonObjects()[pi]; polygon->setPoints(points1); polygon->setTipText(label); if (! polygon->testAndSetUsed()) { CGnuPlotFillP fill (polygon->fill ()->dup()); CGnuPlotStrokeP stroke(polygon->stroke()->dup()); fill->setColor(fc); fill->setType (CGnuPlotTypes::FillType::SOLID); stroke->setColor (lc); stroke->setWidth (value->strokeWidth()); stroke->setLineDash(value->strokeDash()); polygon->setFill (fill ); polygon->setStroke(stroke); } } else { renderer->fillPolygon(points1, fc); renderer->drawPolygon(points1, lc, value->strokeWidth(), value->strokeDash()); } ++pi; } if (cache) { for (const auto &polygon : plot->polygonObjects()) polygon->draw(renderer); } }
// -------------------------------------------------------------------------------------------------------------------- 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); } }