void DrawPointTint(GraphicsDevice *device, Vec2i pos, HSV tint) { Uint32 *screen = device->buf; int idx = PixelIndex( pos.x, pos.y, device->cachedConfig.Res.x, device->cachedConfig.Res.y); color_t c; if (pos.x < device->clipping.left || pos.x > device->clipping.right || pos.y < device->clipping.top || pos.y > device->clipping.bottom) { return; } c = PIXEL2COLOR(screen[idx]); c = ColorTint(c, tint); screen[idx] = COLOR2PIXEL(c); }
static void DrawBackground( GraphicsDevice *g, SDL_Texture *tTgt, SDL_Texture *t, DrawBuffer *buffer, Map *map, const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra) { BlitClearBuf(g); DrawBufferSetFromMap(buffer, map, pos, X_TILES); DrawBufferDraw(buffer, svec2i_zero(), extra); BlitUpdateFromBuf(g, t); BlitClearBuf(g); const color_t mask = ColorTint(colorWhite, tint); if (SDL_SetTextureColorMod(t, mask.r, mask.g, mask.b) != 0) { LOG(LM_GFX, LL_ERROR, "cannot set background tint: %s", SDL_GetError()); } if (SDL_SetTextureColorMod(tTgt, mask.r, mask.g, mask.b) != 0) { LOG(LM_GFX, LL_ERROR, "cannot set background tint: %s", SDL_GetError()); } }
static void DrawHealth( GraphicsDevice *device, const TActor *actor, const Vec2i pos, const FontAlign hAlign, const FontAlign vAlign) { char s[50]; Vec2i gaugePos = Vec2iAdd(pos, Vec2iNew(-1, -1)); Vec2i size = Vec2iNew(GAUGE_WIDTH, FontH() + 2); HSV hsv = { 0.0, 1.0, 1.0 }; color_t barColor; int health = actor->health; const int maxHealth = ActorGetCharacter(actor)->maxHealth; int innerWidth; color_t backColor = { 50, 0, 0, 255 }; innerWidth = MAX(1, size.x * health / maxHealth); if (actor->poisoned) { hsv.h = 120.0; hsv.v = 0.5; } else { double maxHealthHue = 50.0; double minHealthHue = 0.0; hsv.h = ((maxHealthHue - minHealthHue) * health / maxHealth + minHealthHue); } barColor = ColorTint(colorWhite, hsv); DrawGauge( device, gaugePos, size, innerWidth, barColor, backColor, hAlign, vAlign); sprintf(s, "%d", health); FontOpts opts = FontOptsNew(); opts.HAlign = hAlign; opts.VAlign = vAlign; opts.Area = gGraphicsDevice.cachedConfig.Res; opts.Pad = pos; FontStrOpt(s, Vec2iZero(), opts); }
FEATURE_END FEATURE(ColorTint, "Tint") SCENARIO("Tint to gray (0 saturation)") GIVEN("a color") color_t c; c.r = 123; c.g = 234; c.b = 45; WHEN("I tint it with 0 saturation") HSV hsv; hsv.h = 0.0; hsv.s = 0.0; hsv.v = 1.0; c = ColorTint(c, hsv); THEN("the result should have equal RGB components") SHOULD_INT_EQUAL(c.r, c.g); SHOULD_INT_EQUAL(c.g, c.b); SCENARIO_END SCENARIO("Tint to white (max value)") GIVEN("a color") color_t c; c.r = 123; c.g = 234; c.b = 45; WHEN("I tint it with max value and no hue") HSV hsv;