void WallScreen::drawArrow () { cairo_t *cr; float outline = 2.0f; float r, g, b, a; destroyCairoContext (arrowContext); setupCairoContext (arrowContext); cr = arrowContext.cr; clearCairoLayer (cr); cairo_translate (cr, outline / 2.0f, outline / 2.0f); /* apply the pattern for thumb background */ cairo_set_line_width (cr, outline); /* draw top part of the arrow */ getColorRGBA (ArrowBaseColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_move_to (cr, 15, 0); cairo_line_to (cr, 30, 30); cairo_line_to (cr, 15, 24.5); cairo_line_to (cr, 15, 0); cairo_fill (cr); /* draw bottom part of the arrow */ getColorRGBA (ArrowShadowColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_move_to (cr, 15, 0); cairo_line_to (cr, 0, 30); cairo_line_to (cr, 15, 24.5); cairo_line_to (cr, 15, 0); cairo_fill (cr); /* draw the arrow outline */ getColorRGBA (OutlineColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_move_to (cr, 15, 0); cairo_line_to (cr, 30, 30); cairo_line_to (cr, 15, 24.5); cairo_line_to (cr, 0, 30); cairo_line_to (cr, 15, 0); cairo_stroke (cr); cairo_restore (cr); }
void WallScreen::drawHighlight () { cairo_t *cr; cairo_pattern_t *pattern; int width, height; float r, g, b, a; float outline = 2.0f; destroyCairoContext (highlightContext); setupCairoContext (highlightContext); cr = highlightContext.cr; clearCairoLayer (cr); width = highlightContext.width - outline; height = highlightContext.height - outline; cairo_translate (cr, outline / 2.0f, outline / 2.0f); pattern = cairo_pattern_create_linear (0, 0, width, height); getColorRGBA (ThumbHighlightGradientBaseColor); cairo_pattern_add_color_stop_rgba (pattern, 0.0f, r, g, b, a); getColorRGBA (ThumbHighlightGradientShadowColor); cairo_pattern_add_color_stop_rgba (pattern, 1.0f, r, g, b, a); /* apply the pattern for thumb background */ cairo_set_source (cr, pattern); cairo_rectangle (cr, 0, 0, width, height); cairo_fill_preserve (cr); cairo_set_line_width (cr, outline); getColorRGBA (OutlineColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_stroke (cr); cairo_pattern_destroy (pattern); cairo_restore (cr); }
// ------------------------------------------------------------------- // Loads the material description void ObjFileMtlImporter::load() { if ( m_DataIt == m_DataItEnd ) return; while ( m_DataIt != m_DataItEnd ) { switch (*m_DataIt) { case 'K': { ++m_DataIt; if (*m_DataIt == 'a') // Ambient color { ++m_DataIt; getColorRGBA( &m_pModel->m_pCurrentMaterial->ambient ); } else if (*m_DataIt == 'd') // Diffuse color { ++m_DataIt; getColorRGBA( &m_pModel->m_pCurrentMaterial->diffuse ); } else if (*m_DataIt == 's') { ++m_DataIt; getColorRGBA( &m_pModel->m_pCurrentMaterial->specular ); } m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; case 'd': // Alpha value { ++m_DataIt; getFloatValue( m_pModel->m_pCurrentMaterial->alpha ); m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; case 'N': // Shineness { ++m_DataIt; switch(*m_DataIt) { case 's': ++m_DataIt; getFloatValue(m_pModel->m_pCurrentMaterial->shineness); break; case 'i': //Index Of refraction ++m_DataIt; getFloatValue(m_pModel->m_pCurrentMaterial->ior); break; } m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); break; } break; case 'm': // Texture case 'b': // quick'n'dirty - for 'bump' sections { getTexture(); m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; case 'n': // New material name { createMaterial(); m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; case 'i': // Illumination model { m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); getIlluminationModel( m_pModel->m_pCurrentMaterial->illumination_model ); m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; default: { m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine ); } break; } } }
void WallScreen::drawSwitcherBackground () { cairo_t *cr; cairo_pattern_t *pattern; float outline = 2.0f; int width, height, radius; float r, g, b, a; destroyCairoContext (switcherContext); setupCairoContext (switcherContext); cr = switcherContext.cr; clearCairoLayer (cr); width = switcherContext.width - outline; height = switcherContext.height - outline; cairo_save (cr); cairo_translate (cr, outline / 2.0f, outline / 2.0f); /* set the pattern for the switcher's background */ pattern = cairo_pattern_create_linear (0, 0, width, height); getColorRGBA (BackgroundGradientBaseColor); cairo_pattern_add_color_stop_rgba (pattern, 0.00f, r, g, b, a); getColorRGBA (BackgroundGradientHighlightColor); cairo_pattern_add_color_stop_rgba (pattern, 0.65f, r, g, b, a); getColorRGBA (BackgroundGradientShadowColor); cairo_pattern_add_color_stop_rgba (pattern, 0.85f, r, g, b, a); cairo_set_source (cr, pattern); /* draw the border's shape */ radius = optionGetEdgeRadius (); if (radius) { cairo_arc (cr, radius, radius, radius, PI, 1.5f * PI); cairo_arc (cr, radius + width - 2 * radius, radius, radius, 1.5f * PI, 2.0 * PI); cairo_arc (cr, width - radius, height - radius, radius, 0, PI / 2.0f); cairo_arc (cr, radius, height - radius, radius, PI / 2.0f, PI); } else { cairo_rectangle (cr, 0, 0, width, height); } cairo_close_path (cr); /* apply pattern to background... */ cairo_fill_preserve (cr); /* ... and draw an outline */ cairo_set_line_width (cr, outline); getColorRGBA (OutlineColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_stroke (cr); cairo_pattern_destroy (pattern); cairo_restore (cr); cairo_save (cr); for (unsigned int i = 0; i < (unsigned int) screen->vpSize ().height (); i++) { cairo_translate (cr, 0.0, viewportBorder); cairo_save (cr); for (unsigned int j = 0; j < (unsigned int) screen->vpSize ().width (); j++) { cairo_translate (cr, viewportBorder, 0.0); /* this cuts a hole into our background */ cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); cairo_rectangle (cr, 0, 0, viewportWidth, viewportHeight); cairo_fill_preserve (cr); cairo_set_operator (cr, CAIRO_OPERATOR_XOR); cairo_fill (cr); cairo_translate (cr, viewportWidth, 0.0); } cairo_restore(cr); cairo_translate (cr, 0.0, viewportHeight); } cairo_restore (cr); }
void BandwidthMeter::renderBox(int x, int y, int w, int h, unsigned c) { DependencyManager::get<GeometryCache>()->renderQuad(x, y, w, h, getColorRGBA(c)); }
void BandwidthMeter::render(int screenWidth, int screenHeight) { int x = BORDER_DISTANCE_HORIZ + (AREA_WIDTH >= 0 ? 0 : screenWidth + AREA_WIDTH); int y = BORDER_DISTANCE_VERT + (AREA_HEIGHT >= 0 ? 0 : screenHeight + AREA_HEIGHT); int w = glm::abs(AREA_WIDTH), h = glm::abs(AREA_HEIGHT); // Determine total float totalIn = 0.0f, totalOut = 0.0f; for (size_t i = 0; i < N_CHANNELS; ++i) { totalIn += inputStream(ChannelIndex(i)).getValue(); totalOut += outputStream(ChannelIndex(i)).getValue(); } totalIn *= UNIT_SCALE; totalOut *= UNIT_SCALE; float totalMax = glm::max(totalIn, totalOut); // Get font / caption metrics QFontMetrics const& fontMetrics = _textRenderer->metrics(); int fontDescent = fontMetrics.descent(); int labelWidthIn = fontMetrics.width(CAPTION_IN); int labelWidthOut = fontMetrics.width(CAPTION_OUT); int labelWidthInOut = glm::max(labelWidthIn, labelWidthOut); int labelHeight = fontMetrics.ascent() + fontDescent; int labelWidthUnit = fontMetrics.width(CAPTION_UNIT); int labelsWidth = labelWidthInOut + SPACING_RIGHT_CAPTION_IN_OUT + SPACING_LEFT_CAPTION_UNIT + labelWidthUnit; // Calculate coordinates and dimensions int barX = x + labelWidthInOut + SPACING_RIGHT_CAPTION_IN_OUT; int barWidth = w - labelsWidth; int barHeight = (h - SPACING_VERT_BARS) / 2; int textYcenteredLine = h - centered(labelHeight, h) - fontDescent; int textYupperLine = barHeight - centered(labelHeight, barHeight) - fontDescent; int textYlowerLine = h - centered(labelHeight, barHeight) - fontDescent; // Center of coordinate system -> upper left of bar glPushMatrix(); glTranslatef((float)barX, (float)y, 0.0f); // Render captions glm::vec4 textColor = getColorRGBA(COLOR_TEXT); _textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT, textColor); _textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN, textColor); _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT, textColor); // Render vertical lines for the frame // TODO: I think there may be a bug in this newest code and/or the GeometryCache code, because it seems like // sometimes the bandwidth meter doesn't render the vertical lines renderVerticalLine(0, 0, h, COLOR_FRAME); renderVerticalLine(barWidth, 0, h, COLOR_FRAME); // Adjust scale int steps; double step, scaleMax; bool commit = false; do { steps = (_scaleMaxIndex % 9) + 2; step = pow(10.0, (_scaleMaxIndex / 9) - 10); scaleMax = step * steps; if (commit) { // printLog("Bandwidth meter scale: %d\n", _scaleMaxIndex); break; } if (totalMax < scaleMax * 0.5) { _scaleMaxIndex = glm::max(0, _scaleMaxIndex - 1); commit = true; } else if (totalMax > scaleMax) { _scaleMaxIndex += 1; commit = true; } } while (commit); step = scaleMax / NUMBER_OF_MARKERS; if (scaleMax < MIN_METER_SCALE) { scaleMax = MIN_METER_SCALE; } // Render scale indicators for (int j = NUMBER_OF_MARKERS; --j > 0;) { renderVerticalLine((barWidth * j) / NUMBER_OF_MARKERS, 0, h, COLOR_INDICATOR); } // Render bars int xIn = 0, xOut = 0; for (size_t i = 0; i < N_CHANNELS; ++i) { ChannelIndex chIdx = ChannelIndex(i); int wIn = (int)(barWidth * inputStream(chIdx).getValue() * UNIT_SCALE / scaleMax); int wOut = (int)(barWidth * outputStream(chIdx).getValue() * UNIT_SCALE / scaleMax); if (wIn > 0) { renderBox(xIn, 0, wIn, barHeight, channelInfo(chIdx).colorRGBA); } xIn += wIn; if (wOut > 0) { renderBox(xOut, h - barHeight, wOut, barHeight, channelInfo(chIdx).colorRGBA); } xOut += wOut; } // Render numbers char fmtBuf[8]; sprintf(fmtBuf, "%0.1f", totalIn); _textRenderer->draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, PADDING_HORIZ_VALUE), textYupperLine, fmtBuf, textColor); sprintf(fmtBuf, "%0.1f", totalOut); _textRenderer->draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, PADDING_HORIZ_VALUE), textYlowerLine, fmtBuf, textColor); glPopMatrix(); // After rendering, indicate that no data has been sent/received since the last feed. // This way, the meters fall when not continuously fed. for (size_t i = 0; i < N_CHANNELS; ++i) { inputStream(ChannelIndex(i)).updateValue(0); outputStream(ChannelIndex(i)).updateValue(0); } }
void BandwidthMeter::renderVerticalLine(int x, int y, int h, unsigned c) { DependencyManager::get<GeometryCache>()->renderLine(glm::vec2(x, y), glm::vec2(x, y + h), getColorRGBA(c)); }