Skip to content

Commit

Permalink
Support Picture affected_by_tint flags
Browse files Browse the repository at this point in the history
* Adds blend(Tone, Tone)
* Also fixes operator== for Tone to be non-member inline
  • Loading branch information
fmatthew5876 committed Dec 8, 2018
1 parent 9f42c3e commit 6dcc947
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
13 changes: 9 additions & 4 deletions src/game_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ void Game_Picture::UpdateSprite() {
(int)(255 * (100 - data.current_bot_trans) / 100));
if (data.current_bot_trans != data.current_top_trans)
sprite->SetBushDepth(sprite->GetHeight() / 2);
sprite->SetTone(Tone((int) (data.current_red * 128 / 100),
(int) (data.current_green * 128 / 100),
(int) (data.current_blue * 128 / 100),
(int) (data.current_sat * 128 / 100)));
auto tone = Tone((int) (data.current_red * 128 / 100),
(int) (data.current_green * 128 / 100),
(int) (data.current_blue * 128 / 100),
(int) (data.current_sat * 128 / 100));
if (data.flags.affected_by_tint) {
auto screen_tone = Main_Data::game_screen->GetTone();
tone = blend(tone, screen_tone);
}
sprite->SetTone(tone);
}

void Game_Picture::Show(const ShowParams& params) {
Expand Down
8 changes: 0 additions & 8 deletions src/tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ Tone::Tone(int red, int green, int blue, int gray) :
gray(min(255, max(0, gray))) {
}

bool Tone::operator==(const Tone &other) const {
return red == other.red && green == other.green && blue == other.blue && gray == other.gray;
}

bool Tone::operator!=(const Tone &other) const {
return red != other.red || green != other.green || blue != other.blue || gray != other.gray;
}

void Tone::Set(int nred, int ngreen, int nblue, int ngray) {
red = min(255, max(0, nred));
green = min(255, max(0, ngreen));
Expand Down
29 changes: 19 additions & 10 deletions src/tone.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ class Tone {
*/
Tone(int red, int green, int blue, int gray);

/**
* Equality operator.
*/
bool operator==(const Tone &other) const;

/**
* Inequality operator.
*/
bool operator!=(const Tone &other) const;

/**
* Set all color properties.
*
Expand All @@ -71,4 +61,23 @@ class Tone {
int gray;
};

inline Tone blend(const Tone& l, const Tone& r) {
return Tone((l.red + r.red) / 2,
(l.green + r.green) / 2,
(l.blue + r.blue) / 2,
(l.gray * r.gray) / 128);
}

inline bool operator==(const Tone &l, const Tone& r) {
return l.red == r.red
&& l.green == r.green
&& l.blue == r.blue
&& l.gray == r.gray;
}

inline bool operator!=(const Tone &l, const Tone& r) {
return !(l == r);
}


#endif

0 comments on commit 6dcc947

Please sign in to comment.