int CUIHelper::CalcItemEntryHeight (CSpaceObject *pSource, const CItem &Item, const RECT &rcRect, DWORD dwOptions) const // CalcItemEntryHeight // // Computes the height necessary to paint the item entry. { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &LargeBold = VI.GetFont(fontLargeBold); const CG16bitFont &Medium = VI.GetFont(fontMedium); bool bNoIcon = ((dwOptions & OPTION_NO_ICON) == OPTION_NO_ICON); bool bTitle = ((dwOptions & OPTION_TITLE) == OPTION_TITLE); // Get the item CItemCtx Ctx(&Item, pSource); CItemType *pType = Item.GetType(); if (pType == NULL) return ITEM_DEFAULT_HEIGHT; // Compute the rect where the reference text will paint RECT rcDrawRect = rcRect; rcDrawRect.left += ITEM_TEXT_MARGIN_X; rcDrawRect.right -= ITEM_TEXT_MARGIN_X; if (!bNoIcon) rcDrawRect.left += ICON_WIDTH; int iLevel = pType->GetApparentLevel(); // Compute the height of the row int cyHeight = 0; // Account for margin cyHeight += ITEM_TEXT_MARGIN_Y; // Item title cyHeight += LargeBold.GetHeight(); if (bTitle) cyHeight += ITEM_TITLE_EXTRA_MARGIN; // Attributes TArray<SDisplayAttribute> Attribs; if (Item.GetDisplayAttributes(Ctx, &Attribs)) { int cyAttribs; FormatDisplayAttributes(Attribs, rcDrawRect, &cyAttribs); cyHeight += cyAttribs + ATTRIB_SPACING_Y; } // Reference CString sReference = pType->GetReference(Ctx); // If this is a weapon, then add room for the weapon damage if (Item.GetReferenceDamageType(pSource, -1, 0, NULL, NULL)) cyHeight += Medium.GetHeight(); // If this is armor or a shield, then add room for damage resistance else if (Item.GetReferenceDamageAdj(pSource, 0, NULL, NULL)) cyHeight += Medium.GetHeight(); // Measure the reference text int iLines; if (!sReference.IsBlank()) { iLines = Medium.BreakText(sReference, RectWidth(rcDrawRect), NULL, 0); cyHeight += iLines * Medium.GetHeight(); } // Measure the description CString sDesc = Item.GetDesc(); iLines = Medium.BreakText(sDesc, RectWidth(rcDrawRect), NULL, 0); cyHeight += iLines * Medium.GetHeight(); // Margin cyHeight += ITEM_TEXT_MARGIN_BOTTOM; // Done cyHeight = Max(ITEM_DEFAULT_HEIGHT, cyHeight); return cyHeight; }
int CGItemListArea::CalcRowHeight (int iRow) // CalcRowHeight // // Returns the height of the given row { // Set the position int iOldPos = m_pListData->GetCursor(); m_pListData->SetCursor(iRow); // Compute the rect where we're painting (we only care about width) RECT rcRect = GetRect(); // Compute row height based on type of list int cyHeight; switch (m_iType) { case listItem: { // Get the item if (!m_pListData->IsCursorValid()) { cyHeight = DEFAULT_ROW_HEIGHT; break; } const CItem &Item = m_pListData->GetItemAtCursor(); CItemCtx Ctx(&Item, m_pListData->GetSource()); CItemType *pType = Item.GetType(); if (pType == NULL) { cyHeight = DEFAULT_ROW_HEIGHT; break; } int iLevel = pType->GetApparentLevel(); // Compute the height of the row cyHeight = 0; // Account for margin cyHeight += ITEM_TEXT_MARGIN_Y; // Item title cyHeight += m_pFonts->LargeBold.GetHeight(); // Reference CString sReference = pType->GetReference(Ctx); // If this is a weapon, then add room for the weapon damage if (Item.GetReferenceDamageType(m_pListData->GetSource(), -1, 0, NULL, NULL)) cyHeight += m_pFonts->Medium.GetHeight(); // If this is armor or a shield, then add room for damage resistance else if (Item.GetReferenceDamageAdj(m_pListData->GetSource(), 0, NULL, NULL)) cyHeight += m_pFonts->Medium.GetHeight(); // Otherwise, we add the level to the reference else { if (sReference.IsBlank()) sReference = strPatternSubst("Level %s", strLevel(iLevel)); else sReference = strPatternSubst("Level %s — %s", strLevel(iLevel), sReference); } // Compute the rect where the reference text will paint RECT rcDrawRect = rcRect; rcDrawRect.left += ICON_WIDTH + ITEM_TEXT_MARGIN_X; rcDrawRect.right -= ITEM_TEXT_MARGIN_X; // Measure the reference text int iLines = m_pFonts->Medium.BreakText(sReference, RectWidth(rcDrawRect), NULL, 0); cyHeight += iLines * m_pFonts->Medium.GetHeight(); // Measure the description CString sDesc = Item.GetDesc(); iLines = m_pFonts->Medium.BreakText(sDesc, RectWidth(rcDrawRect), NULL, 0); cyHeight += iLines * m_pFonts->Medium.GetHeight(); // Margin cyHeight += ITEM_TEXT_MARGIN_BOTTOM; // Done cyHeight = Max(DEFAULT_ROW_HEIGHT, cyHeight); break; } case listCustom: cyHeight = m_cyRow; break; default: cyHeight = DEFAULT_ROW_HEIGHT; break; } // Done m_pListData->SetCursor(iOldPos); return cyHeight; }
void CUIHelper::PaintItemEntry (CG16bitImage &Dest, CSpaceObject *pSource, const CItem &Item, const RECT &rcRect, DWORD dwOptions) const // PaintItemEntry // // Paints an item entry suitable for an item list. { const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &LargeBold = VI.GetFont(fontLargeBold); const CG16bitFont &Medium = VI.GetFont(fontMedium); WORD wColorTitle = VI.GetColor(colorTextHighlight); WORD wColorRef = VI.GetColor(colorTextHighlight); WORD wColorDescSel = CG16bitImage::RGBValue(200,200,200); WORD wColorDesc = CG16bitImage::RGBValue(128,128,128); bool bSelected = ((dwOptions & OPTION_SELECTED) == OPTION_SELECTED); bool bNoIcon = ((dwOptions & OPTION_NO_ICON) == OPTION_NO_ICON); bool bTitle = ((dwOptions & OPTION_TITLE) == OPTION_TITLE); // Item context CItemCtx Ctx(&Item, pSource); CItemType *pItemType = Item.GetType(); // Calc the rect where we will draw RECT rcDrawRect = rcRect; rcDrawRect.left += ITEM_TEXT_MARGIN_X; rcDrawRect.right -= ITEM_TEXT_MARGIN_X; rcDrawRect.top += ITEM_TEXT_MARGIN_Y; // Paint the image if (!bNoIcon) { DrawItemTypeIcon(Dest, rcRect.left, rcRect.top, pItemType); rcDrawRect.left += ICON_WIDTH; } // Paint the item name DWORD dwNounPhraseFlags = nounNoModifiers; if (bTitle) dwNounPhraseFlags |= nounTitleCapitalize | nounShort; else dwNounPhraseFlags |= nounCount; int cyHeight; RECT rcTitle = rcDrawRect; LargeBold.DrawText(Dest, rcTitle, wColorTitle, Item.GetNounPhrase(dwNounPhraseFlags), 0, CG16bitFont::SmartQuotes | CG16bitFont::TruncateLine, &cyHeight); rcDrawRect.top += cyHeight; if (bTitle) rcDrawRect.top += ITEM_TITLE_EXTRA_MARGIN; // Paint the display attributes TArray<SDisplayAttribute> Attribs; if (Item.GetDisplayAttributes(Ctx, &Attribs)) { FormatDisplayAttributes(Attribs, rcDrawRect, &cyHeight); PaintDisplayAttributes(Dest, Attribs); rcDrawRect.top += cyHeight + ATTRIB_SPACING_Y; } // Stats CString sStat; int iLevel = pItemType->GetApparentLevel(); CString sReference = pItemType->GetReference(Ctx); DamageTypes iDamageType; CString sDamageRef; int iDamageAdj[damageCount]; int iHP; if (Item.GetReferenceDamageType(pSource, -1, 0, &iDamageType, &sDamageRef)) { // Paint the damage type reference PaintReferenceDamageType(Dest, rcDrawRect.left + DAMAGE_ADJ_SPACING_X, rcDrawRect.top, iDamageType, sDamageRef); rcDrawRect.top += Medium.GetHeight(); // Paint additional reference in the line below if (!sReference.IsBlank()) { Medium.DrawText(Dest, rcDrawRect, wColorRef, sReference, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } } else if (Item.GetReferenceDamageAdj(pSource, 0, &iHP, iDamageAdj)) { // Paint the initial text sStat = strPatternSubst("hp: %d ", iHP); int cxWidth = Medium.MeasureText(sStat, &cyHeight); Medium.DrawText(Dest, rcDrawRect, wColorRef, sStat, 0, 0, &cyHeight); // Paint the damage type array PaintReferenceDamageAdj(Dest, rcDrawRect.left + cxWidth + DAMAGE_ADJ_SPACING_X, rcDrawRect.top, iLevel, iHP, iDamageAdj); rcDrawRect.top += cyHeight; // Paint additional reference in the line below if (!sReference.IsBlank()) { Medium.DrawText(Dest, rcDrawRect, wColorRef, sReference, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } } else { Medium.DrawText(Dest, rcDrawRect, wColorRef, sReference, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } // Description CString sDesc = Item.GetDesc(); Medium.DrawText(Dest, rcDrawRect, (bSelected ? wColorDescSel : wColorDesc), sDesc, 0, CG16bitFont::SmartQuotes, &cyHeight); rcDrawRect.top += cyHeight; }
void CGItemListArea::PaintItem (CG16bitImage &Dest, const CItem &Item, const RECT &rcRect, bool bSelected) // PaintItem // // Paints the item { // Item context CItemCtx Ctx(&Item, m_pListData->GetSource()); CItemType *pItemType = Item.GetType(); // Paint the image DrawItemTypeIcon(Dest, rcRect.left, rcRect.top, pItemType); RECT rcDrawRect = rcRect; rcDrawRect.left += ICON_WIDTH + ITEM_TEXT_MARGIN_X; rcDrawRect.right -= ITEM_TEXT_MARGIN_X; rcDrawRect.top += ITEM_TEXT_MARGIN_Y; // Paint the attribute blocks RECT rcAttrib; rcAttrib = rcDrawRect; rcAttrib.bottom = rcAttrib.top + m_pFonts->MediumHeavyBold.GetHeight(); if (Item.IsDamaged()) PaintItemModifier(Dest, CONSTLIT("Damaged"), RGB_ILLEGAL_BACKGROUND, &rcAttrib); else if (Item.IsDisrupted()) PaintItemModifier(Dest, CONSTLIT("Ionized"), RGB_ILLEGAL_BACKGROUND, &rcAttrib); if (pItemType->IsKnown() && pItemType->HasAttribute(CONSTLIT("Military"))) PaintItemModifier(Dest, CONSTLIT("Military"), RGB_MILITARY_BACKGROUND, &rcAttrib); if (pItemType->IsKnown() && pItemType->HasAttribute(CONSTLIT("Illegal"))) PaintItemModifier(Dest, CONSTLIT("Illegal"), RGB_ILLEGAL_BACKGROUND, &rcAttrib); CString sEnhanced = Item.GetEnhancedDesc(m_pListData->GetSource()); if (!sEnhanced.IsBlank()) { bool bDisadvantage = (*(sEnhanced.GetASCIIZPointer()) == '-'); PaintItemModifier(Dest, sEnhanced, (bDisadvantage ? RGB_ILLEGAL_BACKGROUND : RGB_MILITARY_BACKGROUND), &rcAttrib); } // Paint the item name int cyHeight; RECT rcTitle = rcDrawRect; rcTitle.right = rcAttrib.right; m_pFonts->LargeBold.DrawText(Dest, rcTitle, m_pFonts->wItemTitle, Item.GetNounPhrase(nounCount | nounNoModifiers), 0, CG16bitFont::SmartQuotes | CG16bitFont::TruncateLine, &cyHeight); rcDrawRect.top += cyHeight; // Stats CString sStat; int iLevel = pItemType->GetApparentLevel(); CString sReference = pItemType->GetReference(Ctx); DamageTypes iDamageType; CString sDamageRef; int iDamageAdj[damageCount]; int iHP; if (Item.GetReferenceDamageType(m_pListData->GetSource(), -1, 0, &iDamageType, &sDamageRef)) { // Paint the initial text sStat = strPatternSubst("Level %s —", strLevel(iLevel)); int cxWidth = m_pFonts->Medium.MeasureText(sStat, &cyHeight); m_pFonts->Medium.DrawText(Dest, rcDrawRect, m_pFonts->wItemRef, sStat, 0, 0, &cyHeight); // Paint the damage type reference m_pUIRes->DrawReferenceDamageType(Dest, rcDrawRect.left + cxWidth + DAMAGE_ADJ_SPACING_X, rcDrawRect.top, iDamageType, sDamageRef); rcDrawRect.top += cyHeight; // Paint additional reference in the line below if (!sReference.IsBlank()) { m_pFonts->Medium.DrawText(Dest, rcDrawRect, m_pFonts->wItemRef, sReference, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } } else if (Item.GetReferenceDamageAdj(m_pListData->GetSource(), 0, &iHP, iDamageAdj)) { // Paint the initial text sStat = strPatternSubst("Level %s — hp: %d ", strLevel(iLevel), iHP); int cxWidth = m_pFonts->Medium.MeasureText(sStat, &cyHeight); m_pFonts->Medium.DrawText(Dest, rcDrawRect, m_pFonts->wItemRef, sStat, 0, 0, &cyHeight); // Paint the damage type array m_pUIRes->DrawReferenceDamageAdj(Dest, rcDrawRect.left + cxWidth + DAMAGE_ADJ_SPACING_X, rcDrawRect.top, iLevel, iHP, iDamageAdj); rcDrawRect.top += cyHeight; // Paint additional reference in the line below if (!sReference.IsBlank()) { m_pFonts->Medium.DrawText(Dest, rcDrawRect, m_pFonts->wItemRef, sReference, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } } else { if (sReference.IsBlank()) sStat = strPatternSubst("Level %s", strLevel(iLevel)); else sStat = strPatternSubst("Level %s — %s", strLevel(iLevel), sReference); m_pFonts->Medium.DrawText(Dest, rcDrawRect, m_pFonts->wItemRef, sStat, 0, 0, &cyHeight); rcDrawRect.top += cyHeight; } // Description CString sDesc = Item.GetDesc(); m_pFonts->Medium.DrawText(Dest, rcDrawRect, (bSelected ? m_pFonts->wItemDescSelected : m_pFonts->wItemDesc), sDesc, 0, CG16bitFont::SmartQuotes, &cyHeight); rcDrawRect.top += cyHeight; }