mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 23:47:43 +00:00
Better tooltip rendering; floating-point pixel factor
This commit is contained in:
@@ -7,7 +7,6 @@ namespace Specter
|
||||
|
||||
#define TOOLTIP_MAX_WIDTH 316
|
||||
#define TOOLTIP_MAX_TEXT_WIDTH 300
|
||||
#define TOOLTIP_MARGIN 8
|
||||
|
||||
Tooltip::Tooltip(ViewResources& res, View& parentView, const std::string& title,
|
||||
const std::string& message)
|
||||
@@ -45,32 +44,30 @@ Tooltip::Tooltip(ViewResources& res, View& parentView, const std::string& title,
|
||||
resetResources(res);
|
||||
}
|
||||
|
||||
#define EDGE_EPSILON 0.25
|
||||
|
||||
void Tooltip::setVerts(int width, int height, float pf)
|
||||
{
|
||||
int margin = TOOLTIP_MARGIN * pf;
|
||||
width = std::max(width, margin*2);
|
||||
height = std::max(height, margin*2);
|
||||
std::pair<int,int> margin = m_cornersFilled[0]->queryGlyphDimensions(0);
|
||||
width = std::max(width, margin.first*2);
|
||||
height = std::max(height, margin.second*2);
|
||||
|
||||
m_ttVerts[0].m_pos.assign(0, height-margin-EDGE_EPSILON, 0);
|
||||
m_ttVerts[1].m_pos.assign(0, margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[2].m_pos.assign(width, height-margin-EDGE_EPSILON, 0);
|
||||
m_ttVerts[3].m_pos.assign(width, margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[4].m_pos.assign(width, margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[0].m_pos.assign(0, height-margin.second, 0);
|
||||
m_ttVerts[1].m_pos.assign(0, margin.second, 0);
|
||||
m_ttVerts[2].m_pos.assign(width, height-margin.second, 0);
|
||||
m_ttVerts[3].m_pos.assign(width, margin.second, 0);
|
||||
m_ttVerts[4].m_pos.assign(width, margin.second, 0);
|
||||
|
||||
m_ttVerts[5].m_pos.assign(margin+EDGE_EPSILON, height, 0);
|
||||
m_ttVerts[6].m_pos.assign(margin+EDGE_EPSILON, height, 0);
|
||||
m_ttVerts[7].m_pos.assign(margin+EDGE_EPSILON, height-margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[8].m_pos.assign(width-margin-EDGE_EPSILON, height, 0);
|
||||
m_ttVerts[9].m_pos.assign(width-margin-EDGE_EPSILON, height-margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[10].m_pos.assign(width-margin-EDGE_EPSILON, height-margin+EDGE_EPSILON, 0);
|
||||
m_ttVerts[5].m_pos.assign(margin.first, height, 0);
|
||||
m_ttVerts[6].m_pos.assign(margin.first, height, 0);
|
||||
m_ttVerts[7].m_pos.assign(margin.first, height-margin.second, 0);
|
||||
m_ttVerts[8].m_pos.assign(width-margin.first, height, 0);
|
||||
m_ttVerts[9].m_pos.assign(width-margin.first, height-margin.second, 0);
|
||||
m_ttVerts[10].m_pos.assign(width-margin.first, height-margin.second, 0);
|
||||
|
||||
m_ttVerts[11].m_pos.assign(margin+EDGE_EPSILON, margin-EDGE_EPSILON, 0);
|
||||
m_ttVerts[12].m_pos.assign(margin+EDGE_EPSILON, margin-EDGE_EPSILON, 0);
|
||||
m_ttVerts[13].m_pos.assign(margin+EDGE_EPSILON, 0, 0);
|
||||
m_ttVerts[14].m_pos.assign(width-margin-EDGE_EPSILON, margin-EDGE_EPSILON, 0);
|
||||
m_ttVerts[15].m_pos.assign(width-margin-EDGE_EPSILON, 0, 0);
|
||||
m_ttVerts[11].m_pos.assign(margin.first, margin.second, 0);
|
||||
m_ttVerts[12].m_pos.assign(margin.first, margin.second, 0);
|
||||
m_ttVerts[13].m_pos.assign(margin.first, 0, 0);
|
||||
m_ttVerts[14].m_pos.assign(width-margin.first, margin.second, 0);
|
||||
m_ttVerts[15].m_pos.assign(width-margin.first, 0, 0);
|
||||
|
||||
m_ttVertsBuf->load(m_ttVerts, sizeof(SolidShaderVert) * 16);
|
||||
}
|
||||
@@ -83,25 +80,27 @@ void Tooltip::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
||||
m_ttBlock.setViewRect(root, sub);
|
||||
m_ttBlockBuf->load(&m_ttBlock, sizeof(ViewBlock));
|
||||
|
||||
std::pair<int,int> margin = m_cornersFilled[0]->queryGlyphDimensions(0);
|
||||
|
||||
boo::SWindowRect textRect = sub;
|
||||
textRect.location[0] += TOOLTIP_MARGIN * pf;
|
||||
textRect.location[1] += TOOLTIP_MARGIN * 1.5 * pf;
|
||||
textRect.location[0] += margin.first;
|
||||
textRect.location[1] += margin.second * 1.5;
|
||||
m_message->resized(root, textRect);
|
||||
|
||||
textRect.location[1] += m_message->nominalHeight() + TOOLTIP_MARGIN * pf;
|
||||
textRect.location[1] += m_message->nominalHeight() + margin.second;
|
||||
m_title->resized(root, textRect);
|
||||
|
||||
boo::SWindowRect cornerRect = sub;
|
||||
cornerRect.location[1] += m_nomHeight - TOOLTIP_MARGIN * pf;
|
||||
cornerRect.location[1] += m_nomHeight - margin.second; // Upper left
|
||||
m_cornersOutline[0]->resized(root, cornerRect);
|
||||
m_cornersFilled[0]->resized(root, cornerRect);
|
||||
cornerRect.location[0] += m_nomWidth - TOOLTIP_MARGIN * pf;
|
||||
cornerRect.location[0] += m_nomWidth - margin.first; // Upper right
|
||||
m_cornersOutline[1]->resized(root, cornerRect);
|
||||
m_cornersFilled[1]->resized(root, cornerRect);
|
||||
cornerRect.location[1] = sub.location[1];
|
||||
cornerRect.location[1] = sub.location[1]; // Lower right
|
||||
m_cornersOutline[2]->resized(root, cornerRect);
|
||||
m_cornersFilled[2]->resized(root, cornerRect);
|
||||
cornerRect.location[0] = sub.location[0];
|
||||
cornerRect.location[0] = sub.location[0]; // Lower left
|
||||
m_cornersOutline[3]->resized(root, cornerRect);
|
||||
m_cornersFilled[3]->resized(root, cornerRect);
|
||||
}
|
||||
@@ -126,12 +125,13 @@ void Tooltip::resetResources(ViewResources& res)
|
||||
m_title->typesetGlyphs(m_titleStr);
|
||||
m_message.reset(new MultiLineTextView(res, *this, res.m_mainFont));
|
||||
m_message->typesetGlyphs(m_messageStr, Zeus::CColor::skWhite,
|
||||
int(TOOLTIP_MAX_TEXT_WIDTH * rootView().viewRes().pixelFactor()));
|
||||
int(TOOLTIP_MAX_TEXT_WIDTH * res.pixelFactor()));
|
||||
|
||||
float pf = res.pixelFactor();
|
||||
std::pair<int,int> margin = m_cornersOutline[0]->queryGlyphDimensions(0);
|
||||
m_nomWidth = std::min(int(TOOLTIP_MAX_WIDTH * pf),
|
||||
int(std::max(m_title->nominalWidth(), m_message->nominalWidth()) + TOOLTIP_MARGIN * 2 * pf));
|
||||
m_nomHeight = m_title->nominalHeight() + m_message->nominalHeight() + TOOLTIP_MARGIN * 3 * pf;
|
||||
int(std::max(m_title->nominalWidth(), m_message->nominalWidth()) + margin.first * 2));
|
||||
m_nomHeight = m_title->nominalHeight() + m_message->nominalHeight() + margin.second * 3;
|
||||
}
|
||||
|
||||
void Tooltip::draw(boo::IGraphicsCommandQueue* gfxQ)
|
||||
|
||||
Reference in New Issue
Block a user