/** \param other Color to add to this color \return Addition of the two colors, clamped to 0..255 values */ NColor operator+(const NColor& other) const { return NColor( (std::min)( getAlpha() + other.getAlpha(), 255 ), (std::min)(getRed() + other.getRed(), 255), (std::min)(getGreen() + other.getGreen(), 255), (std::min)(getBlue() + other.getBlue(), 255)); }
void Font::setColor( const NColor& color ) { _d->color.b = color.getBlue(); _d->color.g = color.getGreen(); _d->color.r = color.getRed(); _d->color.unused = color.getAlpha(); }
/** \param other: Other color \param d: value between 0.0f and 1.0f \return Interpolated color. */ NColor getInterpolated(const NColor &other, float d) const { d = math::clamp(d, 0.f, 1.f); const float inv = 1.0f - d; return NColor((unsigned int)floor(other.getAlpha()*inv + getAlpha()*d), (unsigned int)floor(other.getRed()*inv + getRed()*d), (unsigned int)floor(other.getGreen()*inv + getGreen()*d), (unsigned int)floor(other.getBlue()*inv + getBlue()*d)); }
void NColorProp::Init() { udword dwVal; m_pvarBloc->GetValue(m_dwvarIdx, 0.0f, dwVal); NColor col; col.SetFromRGBA(dwVal); m_button.Create(col, NRect(0,0,0,0), m_pParent, 0); m_button.OnChanged = FDelegate(this, (TDelegate)&NColorProp::OnValueChanged); }
void Decorator::drawLines(Picture& dstpic, NColor color, const Lines& lines) { for( const auto& line : lines ) lineColor( dstpic.surface(), line.begin.x(), line.begin.y(), line.end.x(), line.end.y(), color.rgba() ); }
void FontCollection::addFont(const int key, const std::string& name, vfs::Path pathFont, const int size, const NColor& color ) { TTF_Font* ttf = TTF_OpenFont(pathFont.toCString(), size); if( ttf == NULL ) { std::string errorStr( TTF_GetError() ); #ifdef CAESARIA_PLATFORM_WIN errorStr += "\n Is it only latin symbols in path to game?"; #endif OSystem::error( "CRITICAL!!! ", errorStr ); THROW( errorStr ); } Font font0; font0._d->ttfFont = ttf; SDL_Color c = { color.red(), color.green(), color.blue(), color.alpha() }; font0._d->color = c; setFont( key, name, font0); }
//============================================================================ // NCGShading::EvaluateCallback : Evaluate callback. //---------------------------------------------------------------------------- void NCGShading::EvaluateCallback(void *info, const CGFloat *in, CGFloat *out) { float32_t colRed, colGreen, colBlue, colAlpha; NCGShading *thisPtr = (NCGShading *) info; NColor theColor; // Validate our parameters NN_ASSERT(in[0] >= 0.0f && in[0] <= 1.0f); // Evaluate the shading theColor = thisPtr->Evaluate(in[0]); theColor.GetColor(colRed, colGreen, colBlue, colAlpha); out[0] = (CGFloat) colRed; out[1] = (CGFloat) colGreen; out[2] = (CGFloat) colBlue; out[3] = (CGFloat) colAlpha; }
void Font::setColor( NColor color ) { #ifdef CAESARIA_PLATFORM_ANDROID color = color.abgr(); #endif _d->color.b = color.blue(); _d->color.g = color.green(); _d->color.r = color.red(); #if SDL_MAJOR_VERSION>1 _d->color.a = color.alpha(); #else _d->color.unused = color.alpha(); #endif }
void HelpClass::Deserialize(const Serializator &s) { Text *oldtext = atext; DateTime *olddatetime = adatetime; NObjectCollection *oldnobjectcollection = nobjectcollection; NObjectDictionary *oldnobjectdictionary = nobjectdictionary; Buffer *oldbuffer = abuffer; TextBuffer *oldtextbuffer = atextbuffer; NBool *oldnnbool = nnbool; NChar *oldnnchar = nnchar; NWChar *oldnnwchar = nnwchar; NShort *oldnnshort = nnshort; NInt *oldnnint = nnint; NLong *oldnnlong = nnlong; NLongLong *oldnnlonglong = nnlonglong; NUChar *oldnnuchar = nnuchar; NUShort *oldnnushort = nnushort; NUInt *oldnnuint = nnuint; NULong *oldnnulong = nnulong; NULongLong *oldnnulonglong = nnulonglong; NFloat *oldnnfloat = nnfloat; NDouble *oldnndouble = nndouble; NLongDouble *oldnnlongdouble = nnlongdouble; NSize *oldnnsize = nnsize; NPoint *oldnnpoint = nnpoint; NRectangle *oldnnrectangle = nnrectangle; NColor *oldnncolor = nncolor; nbool = ((Serializator *)&s)->GetBool(); nchar = ((Serializator *)&s)->GetChar(); nshort = ((Serializator *)&s)->GetShort(); nint = ((Serializator *)&s)->GetInt(); nlong = ((Serializator *)&s)->GetLong(); nlonglong = ((Serializator *)&s)->GetLongLong(); nuchar = ((Serializator *)&s)->GetUChar(); nushort = ((Serializator *)&s)->GetUShort(); nuint = ((Serializator *)&s)->GetUInt(); nulong = ((Serializator *)&s)->GetULong(); nulonglong = ((Serializator *)&s)->GetULongLong(); nfloat = ((Serializator *)&s)->GetFloat(); ndouble = ((Serializator *)&s)->GetDouble(); nlongdouble = ((Serializator *)&s)->GetLongDouble(); nnbool = (NBool *)((Serializator *)&s)->GetNObject(); nnchar = (NChar *)((Serializator *)&s)->GetNObject(); nnwchar = (NWChar *)((Serializator *)&s)->GetNObject(); nnshort = (NShort *)((Serializator *)&s)->GetNObject(); nnint = (NInt *)((Serializator *)&s)->GetNObject(); nnlong = (NLong *)((Serializator *)&s)->GetNObject(); nnlonglong = (NLongLong *)((Serializator *)&s)->GetNObject(); nnuchar = (NUChar *)((Serializator *)&s)->GetNObject(); nnushort = (NUShort *)((Serializator *)&s)->GetNObject(); nnuint = (NUInt *)((Serializator *)&s)->GetNObject(); nnulong = (NULong *)((Serializator *)&s)->GetNObject(); nnulonglong = (NULongLong *)((Serializator *)&s)->GetNObject(); nnfloat = (NFloat *)((Serializator *)&s)->GetNObject(); nndouble = (NDouble *)((Serializator *)&s)->GetNObject(); nnlongdouble = (NLongDouble *)((Serializator *)&s)->GetNObject(); nnsize = (NSize *)((Serializator *)&s)->GetNObject(); nnpoint = (NPoint *)((Serializator *)&s)->GetNObject(); nnrectangle = (NRectangle *)((Serializator *)&s)->GetNObject(); nncolor = (NColor *)((Serializator *)&s)->GetNObject(); atext = (Text *)((Serializator *)&s)->GetNObject(); adatetime = (DateTime *)((Serializator *)&s)->GetNObject(); nobjectcollection = (NObjectCollection *)((Serializator *)&s)->GetNObject(); nobjectdictionary = (NObjectDictionary *)((Serializator *)&s)->GetNObject(); abuffer = (Buffer *)((Serializator *)&s)->GetNObject(); atextbuffer = (TextBuffer *)((Serializator *)&s)->GetNObject(); if (nbool != true || nchar != 1 || nshort != 2 || nint != 3 || nlong != 4 || nlonglong != 5 || nuchar != 6 || nushort != 7 || nuint != 8 || nulong != 9 || nulonglong != 10 || nfloat != 11 || ndouble != 12 || nlongdouble != 13) { throw new Exception("Numbers not propertly deserializated", __FILE__, __LINE__, __func__); } if (nnbool->Value() != true) throw new Exception("NBool::Deserialize error", __FILE__, __LINE__, __func__); if (nnchar->Value() != 'c') throw new Exception("NChar::Deserialize error", __FILE__, __LINE__, __func__); if (nnwchar->Value() != L'd') throw new Exception("NWChar::Deserialize error", __FILE__, __LINE__, __func__); if (nnshort->Value() != -22000) throw new Exception("NShort::Deserialize error", __FILE__, __LINE__, __func__); if (nnint->Value() != -34000) throw new Exception("NInt::Deserialize error", __FILE__, __LINE__, __func__); if (nnlong->Value() != -22000000000) throw new Exception("NLong::Deserialize error", __FILE__, __LINE__, __func__); if (nnlonglong->Value() != -44000000000000) throw new Exception("NLongLong::Deserialize error", __FILE__, __LINE__, __func__); if (nnuchar->Value() != 'c') throw new Exception("NUChar::Deserialize error", __FILE__, __LINE__, __func__); if (nnushort->Value() != 44000) throw new Exception("NUShort::Deserialize error", __FILE__, __LINE__, __func__); if (nnuint->Value() != 88000) throw new Exception("NUInt::Deserialize error", __FILE__, __LINE__, __func__); if (nnulong->Value() != 44000000000) throw new Exception("NULong::Deserialize error", __FILE__, __LINE__, __func__); if (nnulonglong->Value() != 88000000000000L) throw new Exception("NULongLong::Deserialize error", __FILE__, __LINE__, __func__); if (nnfloat->Value() != -1e15f) throw new Exception("NFloat::Deserialize error", __FILE__, __LINE__, __func__); if (nndouble->Value() != -1e40) throw new Exception("NDouble::Deserialize error", __FILE__, __LINE__, __func__); if (nnlongdouble->Value() != -1e400L) throw new Exception("NLongDouble::Deserialize error", __FILE__, __LINE__, __func__); if (nnsize->GetWidth() != 400) throw new Exception("NNSize::Deserialize error", __FILE__, __LINE__, __func__); if (nnsize->GetHeight() != 300) throw new Exception("NNSize::Deserialize error", __FILE__, __LINE__, __func__); if (nnpoint->GetX() != 3) throw new Exception("NPoint::Deserialize error", __FILE__, __LINE__, __func__); if (nnpoint->GetY() != 4) throw new Exception("NPoint::Deserialize error", __FILE__, __LINE__, __func__); if (nnrectangle->GetX() != 4) throw new Exception("NRectangle::Deserialize error", __FILE__, __LINE__, __func__); if (nnrectangle->GetY() != 5) throw new Exception("NRectangle::Deserialize error", __FILE__, __LINE__, __func__); if (nnrectangle->GetWidth() != 6) throw new Exception("NRectangle::Deserialize error", __FILE__, __LINE__, __func__); if (nnrectangle->GetHeight() != 7) throw new Exception("NRectangle::Deserialize error", __FILE__, __LINE__, __func__); if (nncolor->R() != 1 || nncolor->G() != 0 || nncolor->B() != 0 || nncolor->A() != 0.5) throw new Exception("NColor::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnbool->Value() != nnbool->Value()) throw new Exception("NBool::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnchar->Value() != nnchar->Value()) throw new Exception("NChar::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnwchar->Value() != nnwchar->Value()) throw new Exception("NWChar::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnshort->Value() != nnshort->Value()) throw new Exception("NShort::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnint->Value() != nnint->Value()) throw new Exception("NInt::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnlong->Value() != nnlong->Value()) throw new Exception("NLong::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnlonglong->Value() != nnlonglong->Value()) throw new Exception("NLongLong::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnuchar->Value() != nnuchar->Value()) throw new Exception("NUChar::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnushort->Value() != nnushort->Value()) throw new Exception("NUShort::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnuint->Value() != nnuint->Value()) throw new Exception("NUInt::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnulong->Value() != nnulong->Value()) throw new Exception("NULong::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnulonglong->Value() != nnulonglong->Value()) throw new Exception("NULongLong::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnfloat->Value() != nnfloat->Value()) throw new Exception("NFloat::Deserialize error", __FILE__, __LINE__, __func__); if (oldnndouble->Value() != nndouble->Value()) throw new Exception("NDouble::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnlongdouble->Value() != nnlongdouble->Value()) throw new Exception("NLongDouble::Deserialize error", __FILE__, __LINE__, __func__); if (oldnnsize->GetWidth() != nnsize->GetWidth()) throw new Exception("NSize::Deserialize error", __FILE__, __LINE__, __func__); if (!oldnnpoint->Equals(*nnpoint)) throw new Exception("NPoint::Deserialize error", __FILE__, __LINE__, __func__); if (!oldnnrectangle->Equals(*nnrectangle)) throw new Exception("NRectangle::Deserialize error", __FILE__, __LINE__, __func__); if (!oldnncolor->Equals(*nncolor)) throw new Exception("NColor::Deserilize error", __FILE__, __LINE__, __func__); if (*oldtext != *atext) throw new Exception("Text not propertly deserializated", __FILE__, __LINE__, __func__); if (*olddatetime != *adatetime) throw new Exception("DateTime not propertly deserializated", __FILE__, __LINE__, __func__); if (oldnobjectcollection->ToText() != nobjectcollection->ToText()) throw new Exception("NObjectCollection not propertly deserializated", __FILE__, __LINE__, __func__); if (oldnobjectdictionary->ToText() != nobjectdictionary->ToText()) throw new Exception("NObjectDictionary not propertly deserializated", __FILE__, __LINE__, __func__); if (*oldbuffer != *abuffer) throw new Exception("Buffer not propertly deserializated", __FILE__, __LINE__, __func__); if (oldtextbuffer->ToText() != atextbuffer->ToText()) throw new Exception("TextBuffer not propertly deserializated", __FILE__, __LINE__, __func__); oldnobjectcollection->DeleteAndClear(); oldnobjectdictionary->DeleteAndClear(); delete oldtext; delete olddatetime; delete oldnobjectcollection; delete oldnobjectdictionary; delete oldbuffer; delete oldtextbuffer; delete oldnnbool; delete oldnnchar; delete oldnnwchar; delete oldnnshort; delete oldnnint; delete oldnnlong; delete oldnnlonglong; delete oldnnuchar; delete oldnnushort; delete oldnnuint; delete oldnnulong; delete oldnnulonglong; delete oldnnfloat; delete oldnndouble; delete oldnnlongdouble; delete oldnnsize; delete oldnnpoint; delete oldnnrectangle; delete oldnncolor; }
void Picture::fill( const NColor& color, const Rect& rect ) { SDL_Surface* source = _d->surface; SDL_LockSurface( source ); SDL_Rect sdlRect = { (short)rect.getLeft(), (short)rect.getTop(), (Uint16)rect.getWidth(), (Uint16)rect.getHeight() }; SDL_FillRect(source, rect.getWidth() > 0 ? &sdlRect : NULL, SDL_MapRGBA( source->format, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() )); SDL_UnlockSurface(source); }
void Decorator::drawLine( Picture& dstpic, const Point& p1, const Point& p2, NColor color) { if( dstpic.isValid() ) lineColor( dstpic.surface(), p1.x(), p1.y(), p2.x(), p2.y(), color.rgba() ); }
void GraphicsPatternRadial::AddColorAtDistance(const NColor &c, double distance) { NColor *cc = (NColor *)&c; cairo_pattern_add_color_stop_rgba(pattern, distance, cc->R(), cc->G(), cc->B(), cc->A()); }
void Console::draw( gfx::Engine& painter ) { if( !font().isValid() ) { Widget::draw( painter ); return; } if( visible() ) // render only if the console is visible { if( toggle_visible_ != NONE ) { if( toggle_visible_ == DOWNLIGTH ) { if (_opacity > 5) _opacity -= 9; else setVisible(false); _d->dirty = true; } else { if (_opacity < 0xff) _opacity += 3; else toggle_visible_ = NONE; _d->dirty = true; } } Rect textRect, shellRect; //we calculate where the message log shall be printed and where the prompt shall be printed calculatePrintRects(textRect,shellRect); if(_d->dirty) { Decorator::drawLines(_d->bg, ColorList::red, relativeRect().lines()); _d->bg.fill(ColorList::blue); unsigned int maxLines, lineHeight; //now, render the messages int fontHeight=0; if (!calculateLimits(maxLines,lineHeight,fontHeight)) { return; } Rect lineRect( textRect.left(), //calculate the line rectangle textRect.top(), textRect.right(), textRect.bottom() + lineHeight); for (unsigned int index = 0; index < console_messages_.size(); index++) { unsigned int rindex = (_d->curIndex + index) % console_messages_.size(); const std::string& line = console_messages_[rindex]; font().draw(_d->bg, line, lineRect.lefttop(), false, false); lineRect += Point(0, lineHeight); //update line rectangle } std::string shellText = "$>" + currentCommand_; font().draw( _d->bg, shellText, shellRect.lefttop(), false, false); //draw the prompt string _d->dirty = false; _d->bg.update(); _d->bg.setAlpha(_opacity/3*2); } painter.draw( _d->bg, absoluteRect().lefttop() ); if( DateTime::elapsedTime() % 700 < 350 ) { NColor color = ColorList::white; color.setAlpha(_opacity/2); painter.fillRect( color, Rect(0, 0, _d->commandCursorWidth,shellRect.height()*0.8) +absoluteRect().leftbottom() + Point(_d->commandTextSize.width(), -shellRect.height()) ); } } Widget::draw( painter ); }