38 changes: 19 additions & 19 deletions src/ColorScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class ColorScheme

/**
* Returns true if this color scheme has a dark background.
* The background color is said to be dark if it has a value of less than 127
* in the HSV color space.
* The background color is said to be dark if it has a lightness
* of less than 50% in the HSLuv color space.
*/
bool hasDarkBackground() const;

Expand Down Expand Up @@ -169,15 +169,15 @@ class ColorScheme
ColorSchemeWallpaper::Ptr wallpaper() const;

/**
* Enables randomization of the background color. This will cause
* the palette returned by getColorTable() and colorEntry() to
* be adjusted depending on the value of the random seed argument
* to them.
* Enables colors randomization. This will cause the palette
* returned by getColorTable() and colorEntry() to be adjusted
* depending on the parameters of color randomization and the
* random seed parameter passed to them.
*/
void setRandomizedBackgroundColor(bool randomize);
void setColorRandomization(bool randomize);

/** Returns true if the background color is randomized. */
bool randomizedBackgroundColor() const;
/** Returns true if color randomization is enabled. */
bool isColorRandomizationEnabled() const;

static const ColorEntry defaultTable[]; // table of default color entries

Expand All @@ -189,20 +189,20 @@ class ColorScheme
class RandomizationRange
{
public:
RandomizationRange() : hue(0),
saturation(0),
value(0)
RandomizationRange() : hue(0.0),
saturation(0.0),
lightness(0.0)
{
}

bool isNull() const
{
return hue == 0 && saturation == 0 && value == 0;
return qFuzzyIsNull(hue) && qFuzzyIsNull(saturation) && qFuzzyIsNull(lightness);
}

quint16 hue;
quint8 saturation;
quint8 value;
double hue;
double saturation;
double lightness;
};

// returns the active color table. if none has been set specifically,
Expand All @@ -218,7 +218,7 @@ class ColorScheme
// sets the amount of randomization allowed for a particular color
// in the palette. creates the randomization table if
// it does not already exist
void setRandomizationRange(int index, quint16 hue, quint8 saturation, quint8 value);
void setRandomizationRange(int index, double hue, double saturation, double lightness);

QString _description;
QString _name;
Expand All @@ -236,9 +236,9 @@ class ColorScheme
// enables blur behind the terminal window
bool _blur;

ColorSchemeWallpaper::Ptr _wallpaper;
bool _colorRandomization;

static const quint16 MAX_HUE = 340;
ColorSchemeWallpaper::Ptr _wallpaper;

static const char * const colorNames[TABLE_COLORS];
static const char * const translatedColorNames[TABLE_COLORS];
Expand Down
4 changes: 2 additions & 2 deletions src/ColorSchemeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void ColorSchemeEditor::setBlur(bool blur)

void ColorSchemeEditor::setRandomizedBackgroundColor(bool randomized)
{
_colors->setRandomizedBackgroundColor(randomized);
_colors->setColorRandomization(randomized);
}

void ColorSchemeEditor::setup(const ColorScheme *scheme, bool isNewScheme)
Expand Down Expand Up @@ -291,7 +291,7 @@ void ColorSchemeEditor::setup(const ColorScheme *scheme, bool isNewScheme)
_ui->blurCheckBox->setChecked(scheme->blur());

// randomized background color checkbox
_ui->randomizedBackgroundCheck->setChecked(scheme->randomizedBackgroundColor());
_ui->randomizedBackgroundCheck->setChecked(scheme->isColorRandomizationEnabled());

// wallpaper stuff
_ui->wallpaperPath->setText(scheme->wallpaper()->path());
Expand Down
6 changes: 5 additions & 1 deletion src/ColorSchemeEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
</item>
<item>
<widget class="QCheckBox" name="randomizedBackgroundCheck">
<property name="toolTip">
<string>Hue and saturation values of default foreground and background colors are randomized by default. Some color schemes might use different randomization settings.
To see any effect, set colors with saturation value greater than 0.</string>
</property>
<property name="text">
<string>Vary the background color for each tab</string>
<string>Randomly adjust colors for each session</string>
</property>
</widget>
</item>
Expand Down
3 changes: 2 additions & 1 deletion src/ViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,10 @@ void ViewManager::viewDestroyed(QWidget *view)
TerminalDisplay *ViewManager::createTerminalDisplay(Session *session)
{
auto display = new TerminalDisplay(nullptr);
display->setRandomSeed(session->sessionId() * 31);
display->setRandomSeed(session->sessionId() | (qApp->applicationPid() << 10));
connect(display, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal);

return display;
}

Expand Down
453 changes: 453 additions & 0 deletions src/hsluv.c

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions src/hsluv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* HSLuv-C: Human-friendly HSL
* <http://github.com/hsluv/hsluv-c>
* <http://www.hsluv.org/>
*
* Copyright (c) 2015 Alexei Boronine (original idea, JavaScript implementation)
* Copyright (c) 2015 Roger Tallada (Obj-C implementation)
* Copyright (c) 2017 Martin Mitas (C implementation, based on Obj-C implementation)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#ifndef HSLUV_H
#define HSLUV_H

#ifdef __cplusplus
extern "C" {
#endif


/**
* Convert HSLuv to RGB.
*
* @param h Hue. Between 0.0 and 360.0.
* @param s Saturation. Between 0.0 and 100.0.
* @param l Lightness. Between 0.0 and 100.0.
* @param[out] pr Red component. Between 0.0 and 1.0.
* @param[out] pr Green component. Between 0.0 and 1.0.
* @param[out] pr Blue component. Between 0.0 and 1.0.
*/
void hsluv2rgb(double h, double s, double l, double* pr, double* pg, double* pb);

/**
* Convert RGB to HSLuv.
*
* @param r Red component. Between 0.0 and 1.0.
* @param g Green component. Between 0.0 and 1.0.
* @param b Blue component. Between 0.0 and 1.0.
* @param[out] ph Hue. Between 0.0 and 360.0.
* @param[out] ps Saturation. Between 0.0 and 100.0.
* @param[out] pl Lightness. Between 0.0 and 100.0.
*/
void rgb2hsluv(double r, double g, double b, double* ph, double* ps, double* pl);

/**
* Convert HPLuv to RGB.
*
* @param h Hue. Between 0.0 and 360.0.
* @param s Saturation. Between 0.0 and 100.0.
* @param l Lightness. Between 0.0 and 100.0.
* @param[out] pr Red component. Between 0.0 and 1.0.
* @param[out] pg Green component. Between 0.0 and 1.0.
* @param[out] pb Blue component. Between 0.0 and 1.0.
*/
void hpluv2rgb(double h, double s, double l, double* pr, double* pg, double* pb);

/**
* Convert RGB to HPLuv.
*
* @param r Red component. Between 0.0 and 1.0.
* @param g Green component. Between 0.0 and 1.0.
* @param b Blue component. Between 0.0 and 1.0.
* @param[out] ph Hue. Between 0.0 and 360.0.
* @param[out] ps Saturation. Between 0.0 and 100.0.
* @param[out] pl Lightness. Between 0.0 and 100.0.
*/
void rgb2hpluv(double r, double g, double b, double* ph, double* ps, double* pl);


#ifdef __cplusplus
}
#endif

#endif /* HSLUV_H */