void GfxBase::saveState(SaveGame *state) { state->beginSection('DRVR'); byte r, g, b; getShadowColor(&r, &g, &b); state->writeByte(r), state->writeByte(g), state->writeByte(b), state->writeLEBool(_renderBitmaps); state->writeLEBool(_renderZBitmaps); state->endSection(); }
/*! Draw the statistics lines. */ void SimpleStatisticsForeground::draw(DrawEnv *pEnv, Viewport *pPort) { if(getActive() == false) return; if(_face == 0) initText(getFamily(), getSize()); if ((getCollector() == NULL) || (!getCollector()->getNumOfElems() && !getMFElementIDs()->size())) return; // nothing to do Real32 pw = Real32(pPort->getPixelWidth ()); Real32 ph = Real32(pPort->getPixelHeight()); if(pw < 1 || ph < 1) return; glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_DEPTH_TEST); glDisable(GL_COLOR_MATERIAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // Set viewport. We want to map one unit to one pixel on the // screen. Some sources in the internet say that we should // add an offset of -0.375 to prevent rounding errors. Don't // know if that is true, but it seems to work. glOrtho(0 - 0.375, pw - 0.375, 0 - 0.375, ph - 0.375, 0, 1); // retrieve text std::vector < std::string > stat; StatCollector *col = this->getCollector(); StatElem *el; if(getMFElementIDs()->size() != 0) { for(UInt32 i = 0; i < getMFElementIDs()->size(); ++i) { Int32 id(getElementIDs(i)); el = ((id >= 0) ? col->getElem(id) : 0); stat.resize(stat.size() + 1); std::vector < std::string >::iterator str = stat.end() - 1; const char *format = NULL; if(i < getMFFormats()->size() && getFormats(i).length()) { format = getFormats(i).c_str(); } if (el) el->putToString(*str, format); else *str = format; } } else // fallback, show all elements { for(UInt32 i = 0; i < col->getNumOfElems(); ++i) { el = col->getElem(i, false); if(el) { std::string desc(el->getDesc()->getName()), eltext; el->putToString(eltext); desc = desc + " : " + eltext; stat.resize(stat.size() + 1); std::vector < std::string >::iterator str = stat.end() - 1; *str = desc; } } } TextLayoutParam layoutParam; layoutParam.spacing = 1.1f; layoutParam.majorAlignment = TextLayoutParam::ALIGN_BEGIN; layoutParam.minorAlignment = TextLayoutParam::ALIGN_BEGIN; TextLayoutResult layoutResult; _face->layout(stat, layoutParam, layoutResult); Real32 scale = 1 / _face->getScale(); Real32 size = _face->getParam().size; Real32 textWidth = layoutResult.textBounds.x() * scale + size + getTextMargin().x() * 2.0f; Real32 textHeight = layoutResult.textBounds.y() * scale + size + getTextMargin().y() * 2.0f; // Let's do some simple form of layout management Real32 orthoX = 0, orthoY = ph; switch ( getHorizontalAlign() ) { case Right: orthoX = pw - textWidth; break; case Middle: orthoX = (pw - textWidth) * 0.5; break; case Left: default: break; } switch ( getVerticalAlign() ) { case Bottom: orthoY = textHeight; break; case Center: orthoY = (ph - textHeight) * 0.5 + textHeight; break; case Top: default: break; } glTranslatef(orthoX, orthoY, 0.0); // draw background glColor4fv(static_cast<const GLfloat *>(getBgColor().getValuesRGBA())); glBegin(GL_QUADS); glVertex2f(0, -textHeight); glVertex2f(textWidth, -textHeight); glVertex2f(textWidth, 0); glVertex2f(0, 0); glEnd(); // draw border if(getBorderColor().alpha() >= 0.0f) { glColor4fv( static_cast<const GLfloat *>(getBorderColor().getValuesRGBA())); glBegin(GL_LINE_LOOP); glVertex2f(getBorderOffset().x(), -textHeight + 1 + getBorderOffset().y()); glVertex2f(textWidth - 1 - getBorderOffset().x(), -textHeight + 1 + getBorderOffset().y()); glVertex2f(textWidth - 1 - getBorderOffset().x(), -1 - getBorderOffset().y()); glVertex2f(getBorderOffset().x(), -1 - getBorderOffset().y()); glEnd(); } glTranslatef( 0.5 * size + getTextMargin().x(), -0.5 * size - getTextMargin().y(), 0.0); _texchunk ->activate(pEnv); _texenvchunk->activate(pEnv); // draw text shadow glColor4fv(static_cast<const GLfloat *>(getShadowColor().getValuesRGBA())); glPushMatrix(); glTranslatef(getShadowOffset().x(), getShadowOffset().y(), 0); glScalef(scale, scale, 1); _face->drawCharacters(layoutResult); // draw text glColor4fv(static_cast<const GLfloat *>(getColor().getValuesRGBA())); glPopMatrix(); glScalef(scale, scale, 1); _face->drawCharacters(layoutResult); _texchunk ->deactivate(pEnv); _texenvchunk->deactivate(pEnv); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); }
bool MMSLabelWidget::draw(bool *backgroundFilled) { int width, height, x, y; bool myBackgroundFilled = false; if(!surface) return false; if (backgroundFilled) { if (this->has_own_surface) *backgroundFilled = false; } else backgroundFilled = &myBackgroundFilled; // lock this->surface->lock(); // draw widget basics if (MMSWidget::draw(backgroundFilled)) { // draw my things if (prepareText(&width, &height)) { // text is translated and font is set MMSFBRectangle surfaceGeom = getSurfaceGeometry(); // save the width of the text this->slide_width = width; switch ((!this->swap_left_right) ? getAlignment() : swapAlignmentHorizontal(getAlignment())) { case MMSALIGNMENT_LEFT: x = surfaceGeom.x; y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y; break; case MMSALIGNMENT_RIGHT: x = surfaceGeom.x + surfaceGeom.w - width; y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y; break; case MMSALIGNMENT_CENTER: x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x; y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y; break; case MMSALIGNMENT_TOP_CENTER: x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x; y = surfaceGeom.y; break; case MMSALIGNMENT_TOP_LEFT: x = surfaceGeom.x; y = surfaceGeom.y; break; case MMSALIGNMENT_TOP_RIGHT: x = surfaceGeom.x + surfaceGeom.w - width; y = surfaceGeom.y; break; case MMSALIGNMENT_BOTTOM_CENTER: x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x; y = surfaceGeom.y + surfaceGeom.h - height; break; case MMSALIGNMENT_BOTTOM_LEFT: x = surfaceGeom.x; y = surfaceGeom.y + surfaceGeom.h - height; break; case MMSALIGNMENT_BOTTOM_RIGHT: x = surfaceGeom.x + surfaceGeom.w - width; y = surfaceGeom.y + surfaceGeom.h - height; break; default: x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x; y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y; break; } // get color MMSFBColor color; getForeground(&color); this->current_fgcolor = color; this->current_fgset = true; if (color.a) { // prepare for drawing this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity( color, (isSelected())?getSelShadowColor(MMSPOSITION_TOP):getShadowColor(MMSPOSITION_TOP), (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM):getShadowColor(MMSPOSITION_BOTTOM), (isSelected())?getSelShadowColor(MMSPOSITION_LEFT):getShadowColor(MMSPOSITION_LEFT), (isSelected())?getSelShadowColor(MMSPOSITION_RIGHT):getShadowColor(MMSPOSITION_RIGHT), (isSelected())?getSelShadowColor(MMSPOSITION_TOP_LEFT):getShadowColor(MMSPOSITION_TOP_LEFT), (isSelected())?getSelShadowColor(MMSPOSITION_TOP_RIGHT):getShadowColor(MMSPOSITION_TOP_RIGHT), (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM_LEFT):getShadowColor(MMSPOSITION_BOTTOM_LEFT), (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM_RIGHT):getShadowColor(MMSPOSITION_BOTTOM_RIGHT), getBrightness(), getOpacity()); // draw the text this->surface->drawString(this->translated_text, -1, x - this->slide_offset, y); } } // update window surface with an area of surface updateWindowSurfaceWithSurface(!*backgroundFilled); } // unlock this->surface->unlock(); // draw widgets debug frame return MMSWidget::drawDebug(); }