bool GeometryAdapter::ConvertTextVAlign(const MdfModel::MdfString& valign, RS_VAlignment& rsvalign) { // first check if the expression is a constant - in that case it can be cached if (valign == L"'Bottom'") { rsvalign = RS_VAlignment_Descent; return true; } else if (valign == L"'Baseline'") { rsvalign = RS_VAlignment_Base; return true; } else if (valign == L"'Halfline'") { rsvalign = RS_VAlignment_Half; return true; } else if (valign == L"'Capline'") { rsvalign = RS_VAlignment_Cap; return true; } else if (valign == L"'Top'") { rsvalign = RS_VAlignment_Ascent; return true; } // Otherwise we need to evaluate as expression. If it is an expression, // the value will come back without quotes. RS_String str; /*bool dummy =*/ EvalString(valign, str); if (str == L"Bottom") { rsvalign = RS_VAlignment_Descent; } else if (str == L"Baseline") { rsvalign = RS_VAlignment_Base; } else if (str == L"Halfline") { rsvalign = RS_VAlignment_Half; } else if (str == L"Capline") { rsvalign = RS_VAlignment_Cap; } else if (str == L"Top") { rsvalign = RS_VAlignment_Ascent; } // not cacheable return false; }
bool GeometryAdapter::ConvertTextHAlign(const MdfModel::MdfString& halign, RS_HAlignment& rshalign) { // first check if the expression is a constant - in that case it can be cached if (halign == L"'Center'") { rshalign = RS_HAlignment_Center; return true; } else if (halign == L"'Left'") { rshalign = RS_HAlignment_Left; return true; } else if (halign == L"'Right'") { rshalign = RS_HAlignment_Right; return true; } else if (halign == L"'Path'") { rshalign = RS_HAlignment_Path; return true; } // Otherwise we need to evaluate as expression. If it is an expression, // the value will come back without quotes. RS_String str; /*bool dummy =*/ EvalString(halign, str); if (str == L"Center") { rshalign = RS_HAlignment_Center; } else if (str == L"Left") { rshalign = RS_HAlignment_Left; } else if (str == L"Right") { rshalign = RS_HAlignment_Right; } else if (halign == L"Path") { rshalign = RS_HAlignment_Path; } // not cacheable return false; }
void GeometryAdapter::AddLabel(double x, double y, double slope_rad, bool useSlope, MdfModel::Label* label, RS_OverpostType type, bool exclude, Renderer* renderer, LineBuffer* lb) { MdfModel::TextSymbol* text = label->GetSymbol(); RS_String txt; EvalString(text->GetText(), txt); if (!txt.empty()) { RS_TextDef def; ConvertTextDef(text, def); if (useSlope) def.rotation() = slope_rad * M_180PI; RS_LabelInfo info(x, y, 0.0, 0.0, RS_Units_Model, def); renderer->ProcessLabelGroup(&info, 1, txt, type, exclude, lb, text->GetScaleLimit()); } }
/** ** Draw text with variable. ** ** @param unit unit with variable to show. ** @param defaultfont default font if no specific font in extra data. */ /* virtual */ void CContentTypeText::Draw(const CUnit &unit, CFont *defaultfont) const { std::string text; // Optional text to display. int x = this->Pos.x; int y = this->Pos.y; CFont &font = this->Font ? *this->Font : *defaultfont; Assert(&font); Assert(this->Index == -1 || ((unsigned int) this->Index < UnitTypeVar.GetNumberVariable())); //Wyrmgus start // CLabel label(font); CLabel label(font, this->TextColor, this->HighlightColor); //Wyrmgus end if (this->Text) { text = EvalString(this->Text); std::string::size_type pos; if ((pos = text.find("~|")) != std::string::npos) { x += (label.Draw(x - font.getWidth(text.substr(0, pos)), y, text) - font.getWidth(text.substr(0, pos))); } else if (this->Centered) { x += (label.DrawCentered(x, y, text) * 2); } else { x += label.Draw(x, y, text); } } if (this->ShowName) { //Wyrmgus start // label.DrawCentered(x, y, unit.Type->Name); label.DrawCentered(x, y, unit.GetTypeName()); //Wyrmgus end return; } if (this->Index != -1) { if (!this->Stat) { EnumVariable component = this->Component; switch (component) { case VariableValue: case VariableMax: case VariableIncrease: case VariableDiff: case VariablePercent: label.Draw(x, y, GetComponent(unit, this->Index, component, 0).i); break; case VariableName: label.Draw(x, y, GetComponent(unit, this->Index, component, 0).s); break; default: Assert(0); } } else { int value = unit.Type->MapDefaultStat.Variables[this->Index].Value; int diff = unit.Stats->Variables[this->Index].Value - value; if (!diff) { label.Draw(x, y, value); } else { char buf[64]; snprintf(buf, sizeof(buf), diff > 0 ? "%d~<+%d~>" : "%d~<-%d~>", value, diff); label.Draw(x, y, buf); } } } }
/** ** Draw text with variable. ** ** @param unit unit with variable to show. ** @param defaultfont default font if no specific font in extra data. */ void CContentTypeText::Draw(const CUnit *unit, CFont *defaultfont) const { char *text; // Optional text to display. CFont *font; // Font to use. int x; // X coordinate to display. int y; // Y coordinate to display. x = this->PosX; y = this->PosY; font = this->Font ? this->Font : defaultfont; Assert(font); Assert(unit || this->Index == -1); Assert(this->Index == -1 || (0 <= this->Index && this->Index < UnitTypeVar.NumberVariable)); if (this->Text) { text = EvalString(this->Text); if (this->Centered) { VideoDrawTextCentered(x, y, font, text); } else { VideoDrawText(x, y, font, text); } x += font->Width(text); delete[] text; } if (this->ShowName) { VideoDrawTextCentered(x, y, font, unit->Type->Name); return; } if (this->Index != -1) { if (!this->Stat) { EnumVariable component = this->Component; switch (component) { case VariableValue: case VariableMax: case VariableIncrease: case VariableDiff: case VariablePercent: VideoDrawNumber(x, y, font, GetComponent(unit, this->Index, component, 0).i); break; case VariableName: VideoDrawText(x, y, font, GetComponent(unit, this->Index, component, 0).s); break; default: Assert(0); } } else { int value = unit->Type->Variable[this->Index].Value; int diff = unit->Stats->Variables[this->Index].Value - value; if (!diff) { VideoDrawNumber(x, y, font, value); } else { char buf[64]; sprintf(buf, diff > 0 ? "%d~<+%d~>" : "%d~<-%d~>", value, diff); VideoDrawText(x, y, font, buf); } } } }
ALERROR CDockScreenItemList::OnInitList (SInitCtx &Ctx, const SDisplayOptions &Options, CString *retsError) // OnInitList // // Initialize list { DEBUG_TRY // Figure out where to get the data from: either the station // or the player's ship. CSpaceObject *pListSource = EvalListSource(Options.sDataFrom, retsError); if (pListSource == NULL) return ERR_FAIL; // Set the list control m_pItemListControl->SetList(pListSource); // Initialize flags that control what items we will show CString sCriteria; if (!EvalString(Options.sItemCriteria, false, eventNone, &sCriteria)) { *retsError = sCriteria; return ERR_FAIL; } CItem::ParseCriteria(sCriteria, &m_ItemCriteria); m_pItemListControl->SetFilter(m_ItemCriteria); // If we have content, then eval the function (note that this might // re-enter and set the filter) if (!Options.sCode.IsBlank()) { if (!EvalString(Options.sCode, true, eventInitDockScreenList, retsError)) return ERR_FAIL; } // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) if (!Options.sInitialItemCode.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(Options.sInitialItemCode, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } // Done return NOERROR; DEBUG_CATCH }
void PolygonAdapter::Stylize(Renderer* renderer, RS_FeatureReader* features, bool initialPass, SE_Evaluator* eval, LineBuffer* geometry, MdfModel::FeatureTypeStyle* style, const MdfModel::MdfString* tooltip, const MdfModel::MdfString* url, RS_ElevationSettings* elevSettings, CSysTransformer* /*layer2mapxformer*/) { m_eval = eval; // no need to do anything if the style is not an area style, so quit if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(style) != FeatureTypeStyleVisitor::ftsArea) return; //------------------------------------------------------- // determine the rule for the feature //------------------------------------------------------- MdfModel::RuleCollection* arc = style->GetRules(); MdfModel::AreaRule* rule = NULL; for (int i=0; i<arc->GetCount(); ++i) { rule = static_cast<MdfModel::AreaRule*>(arc->GetAt(i)); // apply any filter on the rule - if it fails move to the next rule if (!ExecFilter(&rule->GetFilter())) { // don't stylize with failed rule rule = NULL; continue; } break; } if (!rule) return; MdfModel::AreaSymbolization2D* asym = rule->GetSymbolization(); if (asym == NULL) return; //------------------------------------------------------- // evaluate the style to use //------------------------------------------------------- // quick check if style is already cached RS_FillStyle* fillStyle = m_hAreaSymCache[asym]; if (!fillStyle) { // if not, then we need to either cache or evaluate it fillStyle = &m_fillStyle; ObtainStyle(asym, *fillStyle); } //------------------------------------------------------- // compute the clip offset from the styles //------------------------------------------------------- double clipOffsetWU = 0.0; // in mapping units bool bClip = renderer->RequiresClipping(); bool bLabelClip = renderer->RequiresLabelClipping(); if (bClip || bLabelClip) { double mapScale = renderer->GetMapScale(); // in meters in device units double clipOffsetMeters = GetClipOffset(fillStyle->outline(), mapScale); // add one pixel's worth to handle any roundoff clipOffsetMeters += METERS_PER_INCH / renderer->GetDpi(); // limit the offset to something reasonable if (clipOffsetMeters > MAX_CLIPOFFSET_IN_METERS) clipOffsetMeters = MAX_CLIPOFFSET_IN_METERS; // convert to mapping units clipOffsetWU = clipOffsetMeters * mapScale / renderer->GetMetersPerUnit(); } //------------------------------------------------------- // prepare the geometry on which to apply the style //------------------------------------------------------- LineBuffer* lb = geometry; std::auto_ptr<LineBuffer> spClipLB; if (bClip) { // the clip region is the map request extents expanded by the offset RS_Bounds clip = renderer->GetBounds(); clip.minx -= clipOffsetWU; clip.miny -= clipOffsetWU; clip.maxx += clipOffsetWU; clip.maxy += clipOffsetWU; // clip geometry to given extents LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool); if (lbc != lb) { // if the clipped buffer is NULL (completely clipped) just move on to // the next feature if (!lbc) return; // otherwise continue processing with the clipped buffer lb = lbc; if (lb != geometry) spClipLB.reset(lb); } } //------------------------------------------------------- // do the StartFeature notification //------------------------------------------------------- RS_String tip; //TODO: this should be quick since we are not assigning RS_String eurl; const RS_String &theme = rule->GetLegendLabel(); if (tooltip && !tooltip->empty()) EvalString(*tooltip, tip); if (url && !url->empty()) EvalString(*url, eurl); // elevation settings RS_ElevationType elevType = RS_ElevationType_RelativeToGround; double zOffset = 0.0; double zExtrusion = 0.0; GetElevationParams(elevSettings, zOffset, zExtrusion, elevType); renderer->StartFeature(features, initialPass, tip.empty()? NULL : &tip, eurl.empty()? NULL : &eurl, theme.empty()? NULL : &theme, zOffset, zExtrusion, elevType); //------------------------------------------------------- // apply the style to the geometry using the renderer //------------------------------------------------------- renderer->ProcessPolygon(lb, *fillStyle); //------------------------------------------------------- // do labeling if needed //------------------------------------------------------- MdfModel::Label* label = rule->GetLabel(); if (label && label->GetSymbol()) { // Make sure the geometry is clipped if label clipping is specified. // If bClip is true then the geometry is already clipped. if (!bClip && bLabelClip) { // the clip region is the map request extents expanded by the offset RS_Bounds clip = renderer->GetBounds(); clip.minx -= clipOffsetWU; clip.miny -= clipOffsetWU; clip.maxx += clipOffsetWU; clip.maxy += clipOffsetWU; LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool); if (lbc != lb) { // if the clipped buffer is NULL (completely clipped) just move on to // the next feature if (!lbc) return; // otherwise continue processing with the clipped buffer lb = lbc; if (lb != geometry) spClipLB.reset(lb); } } double cx = std::numeric_limits<double>::quiet_NaN(); double cy = std::numeric_limits<double>::quiet_NaN(); double dummy; // multi should work for simple polygons too lb->Centroid(LineBuffer::ctArea, &cx, &cy, &dummy); if (!_isnan(cx) && !_isnan(cy)) AddLabel(cx, cy, 0.0, false, label, RS_OverpostType_AllFit, true, renderer, lb); } // free clipped line buffer if the geometry was clipped if (spClipLB.get()) LineBufferPool::FreeLineBuffer(m_lbPool, spClipLB.release()); }
ALERROR CDockScreenCustomList::OnInitList (SInitCtx &Ctx, CString *retsError) // OnInitList // // Initialize list { // Get the list element CXMLElement *pListData = Ctx.pDesc->GetContentElementByTag(LIST_TAG); if (pListData == NULL) return ERR_FAIL; // See if we define a custom row height CString sRowHeight; if (pListData->FindAttribute(ROW_HEIGHT_ATTRIB, &sRowHeight)) { CString sResult; if (!EvalString(sRowHeight, false, eventNone, &sResult)) { *retsError = sResult; return ERR_FAIL; } int cyRow = strToInt(sResult, -1); if (cyRow > 0) m_pItemListControl->SetRowHeight(cyRow); } // Get the list to show CCodeChain &CC = g_pUniverse->GetCC(); ICCItem *pExp = CC.Link(pListData->GetContentText(0), 0, NULL); // Evaluate the function CCodeChainCtx CCCtx; CCCtx.SetScreen(m_pDockScreen); CCCtx.SaveAndDefineSourceVar(m_pLocation); CCCtx.SaveAndDefineDataVar(m_pData); ICCItem *pResult = CCCtx.Run(pExp); // LATER:Event CCCtx.Discard(pExp); if (pResult->IsError()) { *retsError = pResult->GetStringValue(); return ERR_FAIL; } // Set this expression as the list m_pItemListControl->SetList(CC, pResult); CCCtx.Discard(pResult); // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) CString sInitialItemFunc = pListData->GetAttribute(INITIAL_ITEM_ATTRIB); if (!sInitialItemFunc.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(sInitialItemFunc, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } return NOERROR; }
void PolylineAdapter::Stylize(Renderer* renderer, RS_FeatureReader* features, bool initialPass, FdoExpressionEngine* exec, LineBuffer* geometry, MdfModel::FeatureTypeStyle* style, const MdfModel::MdfString* tooltip, const MdfModel::MdfString* url, RS_ElevationSettings* elevSettings, CSysTransformer* /*layer2mapxformer*/) { m_exec = exec; // no need to do anything if the style is not a line style, so quit if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(style) != FeatureTypeStyleVisitor::ftsLine) return; //------------------------------------------------------- // determine the rule for the feature //------------------------------------------------------- MdfModel::RuleCollection* lrc = style->GetRules(); MdfModel::LineRule* rule = NULL; for (int i=0; i<lrc->GetCount(); ++i) { rule = static_cast<MdfModel::LineRule*>(lrc->GetAt(i)); // apply any filter on the rule - if it fails move to the next rule if (!ExecFdoFilter(&rule->GetFilter())) { // don't stylize with failed rule rule = NULL; continue; } break; } if (!rule) return; MdfModel::LineSymbolizationCollection* lsymc = rule->GetSymbolizations(); if (lsymc == NULL) return; int nSyms = lsymc->GetCount(); //------------------------------------------------------- // evaluate all the styles once //------------------------------------------------------- // temporary array used to store pointers to each evaluated style RS_LineStroke** ppStrokes = (RS_LineStroke**)alloca(nSyms * sizeof(RS_LineStroke*)); if (!ppStrokes) return; size_t tempIndex = 0; for (int i=0; i<nSyms; ++i) { MdfModel::LineSymbolization2D* lsym = lsymc->GetAt(i); // don't render if there's no symbolization if (lsym == NULL) { ppStrokes[i] = NULL; continue; } // quick check if style is already cached RS_LineStroke* cachedStyle = m_hLineSymCache[lsym]; if (cachedStyle) { ppStrokes[i] = cachedStyle; } else { // if not, then we need to either cache or evaluate it // make sure the vector has a style in the slot we need if (tempIndex >= m_lineSyms.size()) { _ASSERT(tempIndex == m_lineSyms.size()); // allocate a new style and add it to the vector m_lineSyms.push_back(new RS_LineStroke()); } // use the existing style in the vector ppStrokes[i] = m_lineSyms[tempIndex]; ObtainStyle(lsym, *ppStrokes[i]); ++tempIndex; } } //------------------------------------------------------- // compute the clip offset from the styles //------------------------------------------------------- double clipOffsetWU = 0.0; // in mapping units bool bClip = renderer->RequiresClipping(); bool bLabelClip = renderer->RequiresLabelClipping(); if (bClip || bLabelClip) { double mapScale = renderer->GetMapScale(); double clipOffsetMeters = 0.0; // in device units for (int i=0; i<nSyms; ++i) { if (ppStrokes[i]) { double styleClipOffset = GetClipOffset(*ppStrokes[i], mapScale); clipOffsetMeters = rs_max(styleClipOffset, clipOffsetMeters); } } // add one pixel's worth to handle any roundoff clipOffsetMeters += METERS_PER_INCH / renderer->GetDpi(); // limit the offset to something reasonable if (clipOffsetMeters > MAX_CLIPOFFSET_IN_METERS) clipOffsetMeters = MAX_CLIPOFFSET_IN_METERS; // convert to mapping units clipOffsetWU = clipOffsetMeters * mapScale / renderer->GetMetersPerUnit(); } //------------------------------------------------------- // prepare the geometry on which to apply the style //------------------------------------------------------- LineBuffer* lb = geometry; std::auto_ptr<LineBuffer> spClipLB; if (bClip) { // the clip region is the map request extents expanded by the offset RS_Bounds clip = renderer->GetBounds(); clip.minx -= clipOffsetWU; clip.miny -= clipOffsetWU; clip.maxx += clipOffsetWU; clip.maxy += clipOffsetWU; // clip geometry to given extents LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool); if (lbc != lb) { // if the clipped buffer is NULL (completely clipped) just move on to // the next feature if (!lbc) return; // otherwise continue processing with the clipped buffer lb = lbc; if (lb != geometry) spClipLB.reset(lb); } } //------------------------------------------------------- // do the StartFeature notification //------------------------------------------------------- RS_String tip; //TODO: this should be quick since we are not assigning RS_String eurl; const RS_String &theme = rule->GetLegendLabel(); if (tooltip && !tooltip->empty()) EvalString(*tooltip, tip); if (url && !url->empty()) EvalString(*url, eurl); // elevation settings RS_ElevationType elevType = RS_ElevationType_RelativeToGround; double zOffset = 0.0; double zExtrusion = 0.0; GetElevationParams(elevSettings, zOffset, zExtrusion, elevType); renderer->StartFeature(features, initialPass, tip.empty()? NULL : &tip, eurl.empty()? NULL : &eurl, theme.empty()? NULL : &theme, zOffset, zExtrusion, elevType); //------------------------------------------------------- // apply the style to the geometry using the renderer //------------------------------------------------------- for (int i=0; i<nSyms; ++i) { if (ppStrokes[i]) renderer->ProcessPolyline(lb, *ppStrokes[i]); } //------------------------------------------------------- // do labeling if needed //------------------------------------------------------- MdfModel::Label* label = rule->GetLabel(); if (label && label->GetSymbol()) { // Make sure the geometry is clipped if label clipping is specified. // If bClip is true then the geometry is already clipped. if (!bClip && bLabelClip) { // the clip region is the map request extents expanded by the offset RS_Bounds clip = renderer->GetBounds(); clip.minx -= clipOffsetWU; clip.miny -= clipOffsetWU; clip.maxx += clipOffsetWU; clip.maxy += clipOffsetWU; LineBuffer* lbc = lb->Clip(clip, LineBuffer::ctAGF, m_lbPool); if (lbc != lb) { // if the clipped buffer is NULL (completely clipped) just move on to // the next feature if (!lbc) return; // otherwise continue processing with the clipped buffer lb = lbc; if (lb != geometry) spClipLB.reset(lb); } } double cx = std::numeric_limits<double>::quiet_NaN(); double cy = std::numeric_limits<double>::quiet_NaN(); double slope_rad = 0.0; // multi should work for simple polylines too lb->Centroid(LineBuffer::ctLine, &cx, &cy, &slope_rad); if (!_isnan(cx) && !_isnan(cy)) AddLabel(cx, cy, slope_rad, true, label, RS_OverpostType_AllFit, true, renderer, label->GetSymbol()->IsAdvancedPlacement()? lb : NULL); } // free clipped line buffer if the geometry was clipped if (spClipLB.get()) LineBufferPool::FreeLineBuffer(m_lbPool, spClipLB.release()); }
void PointAdapter::Stylize(Renderer* renderer, RS_FeatureReader* features, bool initialPass, SE_Evaluator* eval, LineBuffer* geometry, MdfModel::FeatureTypeStyle* style, const MdfModel::MdfString* tooltip, const MdfModel::MdfString* url, RS_ElevationSettings* elevSettings, CSysTransformer* /*layer2mapxformer*/) { m_eval = eval; // no need to do anything if the style is not a point style, so quit if (FeatureTypeStyleVisitor::DetermineFeatureTypeStyle(style) != FeatureTypeStyleVisitor::ftsPoint) return; //------------------------------------------------------- // determine the rule for the feature //------------------------------------------------------- MdfModel::RuleCollection* prc = style->GetRules(); MdfModel::PointRule* rule = NULL; for (int i=0; i<prc->GetCount(); ++i) { rule = static_cast<MdfModel::PointRule*>(prc->GetAt(i)); // apply any filter on the rule - if it fails move to the next rule if (!ExecFilter(&rule->GetFilter())) { // don't stylize with failed rule rule = NULL; continue; } break; } if (!rule) return; MdfModel::PointSymbolization2D* psym = rule->GetSymbolization(); MdfModel::PointTypeStyle* pfs = (MdfModel::PointTypeStyle*)style; //------------------------------------------------------- // prepare the geometry on which to apply the style //------------------------------------------------------- // NOTE: clipping of geometry for rendering (the RequiresClipping // option) does not need to be done for points. Points // outside the map extents already get clipped away as part // of the FDO query. LineBuffer* lb = geometry; std::auto_ptr<LineBuffer> spClipLB; if (renderer->RequiresClipping()) { // clip geometry to given extents // NOTE: point styles do not require a clip offset LineBuffer* lbc = lb->Clip(renderer->GetBounds(), LineBuffer::ctAGF, m_lbPool); if (lbc != lb) { // if the clipped buffer is NULL (completely clipped) just move on to // the next feature if (!lbc) return; // otherwise continue processing with the clipped buffer lb = lbc; if (lb != geometry) spClipLB.reset(lb); } } //------------------------------------------------------- // do the StartFeature notification //------------------------------------------------------- RS_String tip; //TODO: this should be quick since we are not assigning RS_String eurl; const RS_String &theme = rule->GetLegendLabel(); if (tooltip && !tooltip->empty()) EvalString(*tooltip, tip); if (url && !url->empty()) EvalString(*url, eurl); // elevation settings RS_ElevationType elevType = RS_ElevationType_RelativeToGround; double zOffset = 0.0; double zExtrusion = 0.0; GetElevationParams(elevSettings, zOffset, zExtrusion, elevType); renderer->StartFeature(features, initialPass, tip.empty()? NULL : &tip, eurl.empty()? NULL : &eurl, theme.empty()? NULL : &theme, zOffset, zExtrusion, elevType); //------------------------------------------------------- // apply the style to the geometry using the renderer //------------------------------------------------------- // Process point symbol, if any. If there is no point symbol, there may // be a label which we will use as a symbol instead. This one does not // obey overposting, it is always there. The marker specified in the rule // is the one that does overposting. double mdefW = 0.01; double mdefH = 0.01; RS_Units mdefU = RS_Units_Device; double mdefRot = 0.0; // the actual position used for the marker by the renderer // may be returned in this structure to help place labels better RS_Bounds bounds = RS_Bounds(1.0, 1.0, 0.0, 0.0); // init invalid if (psym && psym->GetSymbol()) { // quick check if style is already cached RS_MarkerDef* cachedStyle = m_hPointSymCache[psym]; if (cachedStyle) { mdefW = cachedStyle->width(); mdefH = cachedStyle->height(); mdefU = cachedStyle->units(); mdefRot = cachedStyle->rotation(); renderer->ProcessMarker(lb, *cachedStyle, pfs->IsAllowOverpost(), &bounds); } else { RS_MarkerDef mdef; ObtainStyle(psym, mdef); mdefW = mdef.width(); mdefH = mdef.height(); mdefU = mdef.units(); mdefRot = mdef.rotation(); renderer->ProcessMarker(lb, mdef, pfs->IsAllowOverpost(), &bounds); } } //------------------------------------------------------- // do labeling if needed //------------------------------------------------------- MdfModel::Label* label = rule->GetLabel(); if (label && label->GetSymbol()) { // NOTE: clipping of geometry for labeling (the RequiresLabelClipping // option) does not need to be done for points. // TODO: compute label position double cx = std::numeric_limits<double>::quiet_NaN(); double cy = std::numeric_limits<double>::quiet_NaN(); double dummy; // multi should work for simple polygons also lb->Centroid(LineBuffer::ctPoint, &cx, &cy, &dummy); if (!_isnan(cx) && !_isnan(cy)) { // if there was no point symbol, the label is the symbol, // so we send without overposting and at the center point if (!psym || !psym->GetSymbol() || pfs->IsDisplayAsText()) { AddLabel(cx, cy, 0.0, false, label, RS_OverpostType_All, !pfs->IsAllowOverpost(), renderer, lb); } else { MdfModel::TextSymbol* text = label->GetSymbol(); RS_String txt; EvalString(text->GetText(), txt); if (!txt.empty()) { RS_TextDef def; ConvertTextDef(text, def); // if there's a symbol there are 8 possible positions to place the label // around the symbol // NOTE: at this point we know that mdef has been initialized with // whatever was in psym->GetSymbol() and that expressions have // been evaluated double op_pts[16]; // offset the label from the symbol's edge double offset = 0.001 * POINT_LABEL_OFFSET_MM; // in meters if (def.rotation() != 0.0) { // if the text label has rotation put the text at least half the font height // away, so that it doesn't intersect with the marker at the worst-case (45 // degree) rotation. offset += 0.5*def.font().height(); } // in case of mapping space we need to scale by map scale if (mdefU != RS_Units_Device) offset *= renderer->GetMapScale(); // compute how far label needs to be offset from center point of symbol double w = 0.5 * mdefW; double h = 0.5 * mdefH; double ch = 0; // vertical center point double cw = 0; // horizontal center point w += offset; h += offset; bool useBounds = bounds.IsValid(); if (useBounds) { bounds.maxx += offset; bounds.maxy += offset; bounds.minx -= offset; bounds.miny -= offset; ch = 0.5*(bounds.maxy + bounds.miny); cw = 0.5*(bounds.maxx + bounds.minx); } // take into account rotation of the symbol // find increased extents of the symbol bounds due to the rotation if (mdefRot != 0.0) { double rotRad = mdefRot * M_PI180; double cs = cos(rotRad); double sn = sin(rotRad); double wcs, nwcs, wsn, nwsn, hsn, nhsn, hcs, nhcs, cwsn, cwcs, chsn, chcs; // check to see if the bounds have been set if (useBounds) { wcs = bounds.maxx * cs; nwcs = bounds.minx * cs; wsn = bounds.maxx * sn; nwsn = bounds.minx * sn; hsn = bounds.maxy * sn; nhsn = bounds.miny * sn; hcs = bounds.maxy * cs; nhcs = bounds.miny * cs; } else { wcs = w * cs; nwcs = -wcs; wsn = w * sn; nwsn = -wsn; hsn = h * sn; nhsn = -hsn; hcs = h * cs; nhcs = -hcs; } cwsn = cw * sn; chsn = ch * sn; cwcs = cw * cs; chcs = ch * cs; // find the octant that the marker is rotated into, and shift the points accordingly. // this way, the overpost points are still within 22.5 degrees of an axis-aligned box. // (position 0 will always be the closest to Center-Right) double nangle = fmod(mdefRot, 360.0); if (nangle < 0.0) nangle += 360.0; int i = (((int)((nangle/45.0) + 0.5)) << 1) & 0x0000000f; // i is 2 * the octant op_pts[i++] = wcs - chsn; op_pts[i++] = wsn + chcs; i &= 0x0000000f; // & 15 does (mod 16) op_pts[i++] = wcs - hsn; op_pts[i++] = wsn + hcs; i &= 0x0000000f; op_pts[i++] = cwcs - hsn; op_pts[i++] = cwsn + hcs; i &= 0x0000000f; op_pts[i++] = nwcs - hsn; op_pts[i++] = nwsn + hcs; i &= 0x0000000f; op_pts[i++] = nwcs - chsn; op_pts[i++] = nwsn + chcs; i &= 0x0000000f; op_pts[i++] = nwcs - nhsn; op_pts[i++] = nwsn + nhcs; i &= 0x0000000f; op_pts[i++] = cwcs - nhsn; op_pts[i++] = cwsn + nhcs; i &= 0x0000000f; op_pts[i++] = wcs - nhsn; op_pts[i] = wsn + nhcs; } else { if (!useBounds) { bounds.maxx = w; bounds.minx = -w; bounds.maxy = h; bounds.miny = -h; } op_pts[ 0] = bounds.maxx; op_pts[ 1] = ch; op_pts[ 2] = bounds.maxx; op_pts[ 3] = bounds.maxy; op_pts[ 4] = cw; op_pts[ 5] = bounds.maxy; op_pts[ 6] = bounds.minx; op_pts[ 7] = bounds.maxy; op_pts[ 8] = bounds.minx; op_pts[ 9] = ch; op_pts[10] = bounds.minx; op_pts[11] = bounds.miny; op_pts[12] = cw; op_pts[13] = bounds.miny; op_pts[14] = bounds.maxx; op_pts[15] = bounds.miny; } RS_LabelInfo candidates[8]; def.halign() = RS_HAlignment_Left; def.valign() = RS_VAlignment_Half; candidates[0] = RS_LabelInfo(cx, cy, op_pts[0], op_pts[1], mdefU, def); def.valign() = RS_VAlignment_Descent; candidates[1] = RS_LabelInfo(cx, cy, op_pts[2], op_pts[3], mdefU, def); def.halign() = RS_HAlignment_Center; candidates[2] = RS_LabelInfo(cx, cy, op_pts[4], op_pts[5], mdefU, def); def.halign() = RS_HAlignment_Right; candidates[3] = RS_LabelInfo(cx, cy, op_pts[6], op_pts[7], mdefU, def); def.valign() = RS_VAlignment_Half; candidates[4] = RS_LabelInfo(cx, cy, op_pts[8], op_pts[9], mdefU, def); def.valign() = RS_VAlignment_Ascent; candidates[5] = RS_LabelInfo(cx, cy, op_pts[10], op_pts[11], mdefU, def); def.halign() = RS_HAlignment_Center; candidates[6] = RS_LabelInfo(cx, cy, op_pts[12], op_pts[13], mdefU, def); def.halign() = RS_HAlignment_Left; candidates[7] = RS_LabelInfo(cx, cy, op_pts[14], op_pts[15], mdefU, def); renderer->ProcessLabelGroup(candidates, 8, txt, RS_OverpostType_FirstFit, true, lb, text->GetScaleLimit()); } } } } // free clipped line buffer if the geometry was clipped if (spClipLB.get()) LineBufferPool::FreeLineBuffer(m_lbPool, spClipLB.release()); }
ALERROR CDockScreenItemList::OnInitList (SInitCtx &Ctx, CString *retsError) // OnInitList // // Initialize list { CSpaceObject *pListSource; // Get the list options element CXMLElement *pOptions = Ctx.pDesc->GetContentElementByTag(LIST_OPTIONS_TAG); if (pOptions == NULL) { *retsError = CONSTLIT("<ListOptions> expected."); return ERR_FAIL; } // Figure out where to get the data from: either the station // or the player's ship. pListSource = EvalListSource(pOptions->GetAttribute(DATA_FROM_ATTRIB), retsError); if (pListSource == NULL) return ERR_FAIL; // Set the list control m_pItemListControl->SetList(pListSource); // Initialize flags that control what items we will show CString sCriteria; if (!EvalString(pOptions->GetAttribute(LIST_ATTRIB), false, eventNone, &sCriteria)) { *retsError = sCriteria; return ERR_FAIL; } CItem::ParseCriteria(sCriteria, &m_ItemCriteria); m_pItemListControl->SetFilter(m_ItemCriteria); // If we have content, then eval the function (note that this might // re-enter and set the filter) CString sCode = pOptions->GetContentText(0); if (!sCode.IsBlank()) { if (!EvalString(sCode, true, eventInitDockScreenList, retsError)) return ERR_FAIL; } // Position the cursor on the next relevant item SelectNextItem(); // Give the screen a chance to start at a different item (other // than the first) CString sInitialItemFunc = pOptions->GetAttribute(INITIAL_ITEM_ATTRIB); if (!sInitialItemFunc.IsBlank()) { bool bMore = IsCurrentItemValid(); while (bMore) { bool bResult; if (!EvalBool(sInitialItemFunc, &bResult, retsError)) return ERR_FAIL; if (bResult) break; bMore = SelectNextItem(); } } // Done return NOERROR; }