colordialog/wheel/gradient: implemented basic UI components for color picking

This commit is contained in:
itsmattkc
2020-04-02 13:02:30 +11:00
parent 3bec108fee
commit f3290003be
27 changed files with 792 additions and 27 deletions
+1 -1
View File
@@ -205,7 +205,7 @@ void OpenGLProxy::RunNodeAccelerated(const Node *node, const TimeRange &range, c
vert_code = OpenGLShader::CodeDefaultVertex();
}
shader = std::make_shared<OpenGLShader>();
shader = OpenGLShader::Create();
shader->create();
shader->addShaderFromSourceCode(QOpenGLShader::Fragment, frag_code);
shader->addShaderFromSourceCode(QOpenGLShader::Vertex, vert_code);
@@ -132,7 +132,13 @@ GLenum OpenGLRenderFunctions::GetPixelType(const PixelFormat::Format &format)
return GL_INVALID_VALUE;
}
void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix4x4 matrix) {
void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix4x4 matrix)
{
Blit(pipeline.get(), flipped, matrix);
}
void OpenGLRenderFunctions::Blit(OpenGLShader *pipeline, bool flipped, QMatrix4x4 matrix)
{
// FIXME: is currentContext() reliable here?
QOpenGLFunctions* func = QOpenGLContext::currentContext()->functions();
@@ -181,7 +187,12 @@ void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix
m_vao.destroy();
}
void OpenGLRenderFunctions::OCIOBlit(OpenGLShaderPtr pipeline,
void OpenGLRenderFunctions::OCIOBlit(OpenGLShaderPtr pipeline, GLuint lut, bool flipped, QMatrix4x4 matrix)
{
OCIOBlit(pipeline.get(), lut, flipped, matrix);
}
void OpenGLRenderFunctions::OCIOBlit(OpenGLShader *pipeline,
GLuint lut,
bool flipped,
QMatrix4x4 matrix)
@@ -46,8 +46,10 @@ public:
* Transformation matrix to use when drawing (defaults to no transform)
*/
static void Blit(OpenGLShaderPtr pipeline, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
static void Blit(OpenGLShader* pipeline, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
static void OCIOBlit(OpenGLShaderPtr pipeline, GLuint lut, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
static void OCIOBlit(OpenGLShader* pipeline, GLuint lut, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
static void PrepareToDraw(QOpenGLFunctions* f);
+6 -1
View File
@@ -7,9 +7,14 @@ OpenGLShader::OpenGLShader()
}
OpenGLShaderPtr OpenGLShader::Create()
{
return std::make_shared<OpenGLShader>();
}
OpenGLShaderPtr OpenGLShader::CreateDefault(const QString &function_name, const QString &shader_code)
{
OpenGLShaderPtr program = std::make_shared<OpenGLShader>();
OpenGLShaderPtr program = Create();
// Add shaders to program
program->addShaderFromSourceCode(QOpenGLShader::Vertex, CodeDefaultVertex());
+2
View File
@@ -17,6 +17,8 @@ class OpenGLShader : public QOpenGLShaderProgram {
public:
OpenGLShader();
static OpenGLShaderPtr Create();
static OpenGLShaderPtr CreateDefault(const QString &function_name = QString(),
const QString &shader_code = QString());
+95
View File
@@ -1,5 +1,46 @@
#include "color.h"
Color Color::fromHsv(const float &h, const float &s, const float &v)
{
float C = s * v;
float X = C * (1.0f - abs(fmod(h / 60.0f, 2.0f) - 1.0f));
float m = v - C;
float Rs, Gs, Bs;
if(h >= 0.0f && h < 60.0f) {
Rs = C;
Gs = X;
Bs = 0.0f;
}
else if(h >= 60.0f && h < 120.0f) {
Rs = X;
Gs = C;
Bs = 0.0f;
}
else if(h >= 120.0f && h < 180.0f) {
Rs = 0.0f;
Gs = C;
Bs = X;
}
else if(h >= 180.0f && h < 240.0f) {
Rs = 0.0f;
Gs = X;
Bs = C;
}
else if(h >= 240.0f && h < 300.0f) {
Rs = X;
Gs = 0.0f;
Bs = C;
}
else {
Rs = C;
Gs = 0.0f;
Bs = X;
}
return Color(Rs + m, Gs + m, Bs + m);
}
Color::Color(const char *data, const PixelFormat::Format &format)
{
OIIO::convert_type(PixelFormat::GetOIIOTypeDesc(format),
@@ -12,3 +53,57 @@ Color::Color(const char *data, const PixelFormat::Format &format)
set_alpha(1.0f);
}
}
void Color::toHsv(float *hue, float *sat, float *val) const
{
float fCMax = qMax(qMax(red(), green()), blue());
float fCMin = qMin(qMin(red(), green()), blue());
float fDelta = fCMax - fCMin;
if(fDelta > 0) {
if(fCMax == red()) {
*hue = 60 * (fmod(((green() - blue()) / fDelta), 6));
} else if(fCMax == green()) {
*hue = 60 * (((blue() - red()) / fDelta) + 2);
} else if(fCMax == blue()) {
*hue = 60 * (((red() - green()) / fDelta) + 4);
}
if(fCMax > 0) {
*sat = fDelta / fCMax;
} else {
*sat = 0;
}
*val = fCMax;
} else {
*hue = 0;
*sat = 0;
*val = fCMax;
}
if(*hue < 0) {
*hue = 360 + *hue;
}
}
float Color::hue() const
{
float h, s, v;
toHsv(&h, &s, &v);
return h;
}
float Color::saturation() const
{
float h, s, v;
toHsv(&h, &s, &v);
return s;
}
float Color::value() const
{
float h, s, v;
toHsv(&h, &s, &v);
return v;
}
+12
View File
@@ -25,6 +25,13 @@ public:
data_[3] = a;
}
/**
* @brief Creates a Color struct from hue/saturation/value
*
* Hue expects a value between 0.0 and 360.0. Saturation and Value expect a value between 0.0 and 1.0.
*/
static Color fromHsv(const float& h, const float& s, const float &v);
Color(const char *data, const PixelFormat::Format &format);
const float& red() const {return data_[0];}
@@ -32,6 +39,11 @@ public:
const float& blue() const {return data_[2];}
const float& alpha() const {return data_[3];}
void toHsv(float* hue, float* sat, float* val) const;
float hue() const;
float saturation() const;
float value() const;
void set_red(const float& red) {data_[0] = red;}
void set_green(const float& green) {data_[1] = green;}
void set_blue(const float& blue) {data_[2] = blue;}