gpick_0.2.5/SConscript 0000644 0001750 0001750 00000015632 12113713537 013431 0 ustar zbyg zbyg #!/usr/bin/env python
import os
import string
import sys
from tools.gpick import *
env = GpickEnvironment(ENV=os.environ, BUILDERS = {'WriteNsisVersion' : Builder(action = WriteNsisVersion, suffix = ".nsi")})
vars = Variables(os.path.join(env.GetLaunchDir(), 'user-config.py'))
vars.Add('DESTDIR', 'Directory to install under', '/usr/local')
vars.Add('LOCALEDIR', 'Path to locale directory', '')
vars.Add('DEBARCH', 'Debian package architecture', 'i386')
vars.Add(BoolVariable('ENABLE_NLS', 'Compile with gettext support', True))
vars.Add(BoolVariable('DEBUG', 'Compile with debug information', False))
vars.Add('BUILD_TARGET', 'Build target', '')
vars.Add('TOOLCHAIN', 'Toolchain', 'gcc')
vars.Add(BoolVariable('EXPERIMENTAL_CSS_PARSER', 'Compile with experimental CSS parser', False))
vars.Add(BoolVariable('DOWNLOAD_RESENE_COLOR_LIST', 'Download Resene color list file at program startup', False))
vars.Add('MSVS_VERSION', 'Visual Studio version', '11.0')
vars.Add(BoolVariable('PREBUILD_GRAMMAR', 'Use prebuild grammar files', False))
vars.Update(env)
if env['LOCALEDIR'] == '':
env['LOCALEDIR'] = env['DESTDIR'] + '/share/locale'
v = Variables(os.path.join(env.GetLaunchDir(), 'version.py'))
v.Add('GPICK_BUILD_VERSION', '', '0.0')
v.Update(env)
if not env['BUILD_TARGET']:
env['BUILD_TARGET'] = sys.platform
if env['BUILD_TARGET'] == 'win32':
if env['TOOLCHAIN'] == 'msvc':
env['TARGET_ARCH'] = 'x86'
env['MSVS'] = {'VERSION': env['MSVS_VERSION']}
env['MSVC_VERSION'] = env['MSVS_VERSION']
Tool('msvc')(env)
else:
if sys.platform != 'win32':
env.Tool('crossmingw', toolpath = ['tools'])
else:
env.Tool('mingw')
env.AddCustomBuilders()
env.GetVersionInfo()
try:
umask = os.umask(022)
except OSError: # ignore on systems that don't support umask
pass
if not env.GetOption('clean'):
conf = Configure(env)
programs = {}
if env['ENABLE_NLS']:
programs['GETTEXT'] = {'checks':{'msgfmt':'GETTEXT'}}
programs['XGETTEXT'] = {'checks':{'xgettext':'XGETTEXT'}, 'required':False}
programs['MSGMERGE'] = {'checks':{'msgmerge':'MSGMERGE'}, 'required':False}
programs['MSGCAT'] = {'checks':{'msgcat':'MSGCAT'}, 'required':False}
if env['EXPERIMENTAL_CSS_PARSER'] and not env['PREBUILD_GRAMMAR']:
programs['LEMON'] = {'checks':{'lemon':'LEMON'}}
programs['FLEX'] = {'checks':{'flex':'FLEX'}}
env.ConfirmPrograms(conf, programs)
libs = {}
if not env['TOOLCHAIN'] == 'msvc':
libs['GTK_PC'] = {'checks':{'gtk+-2.0':'>= 2.24.0'}}
libs['GIO_PC'] = {'checks':{'gio-unix-2.0':'>= 2.26.0', 'gio-2.0':'>= 2.26.0'}}
libs['LUA_PC'] = {'checks':{'lua':'>= 5.2', 'lua5.2':'>= 5.2'}}
if env['DOWNLOAD_RESENE_COLOR_LIST']:
libs['CURL_PC'] = {'checks':{'libcurl':'>= 7'}}
env.ConfirmLibs(conf, libs)
env = conf.Finish()
if os.environ.has_key('CC'):
env['CC'] = os.environ['CC']
if os.environ.has_key('CFLAGS'):
env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
if os.environ.has_key('CXX'):
env['CXX'] = os.environ['CXX']
if os.environ.has_key('CXXFLAGS'):
env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
if os.environ.has_key('LDFLAGS'):
env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
Decider('MD5-timestamp')
if not env['TOOLCHAIN'] == 'msvc':
if not (os.environ.has_key('CFLAGS') or os.environ.has_key('CXXFLAGS') or os.environ.has_key('LDFLAGS')):
if env['DEBUG']:
env.Append(
CPPFLAGS = ['-Wall', '-g3', '-O0'],
CFLAGS = ['-Wall', '-g3', '-O0'],
LINKFLAGS = ['-Wl,-as-needed'],
)
else:
env.Append(
CPPDEFINES = ['NDEBUG'],
CDEFINES = ['NDEBUG'],
CPPFLAGS = ['-Wall', '-O3'],
CFLAGS = ['-Wall', '-O3'],
LINKFLAGS = ['-Wl,-as-needed', '-s'],
)
if env['BUILD_TARGET'] == 'win32':
env.Append(
LINKFLAGS = ['-Wl,--enable-auto-import', '-static-libgcc', '-static-libstdc++'],
CPPDEFINES = ['_WIN32_WINNT=0x0501'],
)
else:
env['LINKCOM'] = [env['LINKCOM'], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1']
if env['DEBUG']:
env.Append(
CPPFLAGS = ['/Od', '/EHsc', '/MD', '/Gy', '/Zi', '/TP', '/wd4819'],
CPPDEFINES = ['WIN32', '_DEBUG'],
LINKFLAGS = ['/MANIFEST', '/DEBUG'],
)
else:
env.Append(
CPPFLAGS = ['/O2', '/Oi', '/GL', '/EHsc', '/MD', '/Gy', '/Zi', '/TP', '/wd4819'],
CPPDEFINES = ['WIN32', 'NDEBUG'],
LINKFLAGS = ['/MANIFEST', '/LTCG'],
)
extern_libs = SConscript(['extern/SConscript'], exports='env')
executable, parser_files = SConscript(['source/SConscript'], exports='env')
env.Alias(target="build", source=[
executable
])
if 'debian' in COMMAND_LINE_TARGETS:
SConscript("deb/SConscript", exports='env')
if env['ENABLE_NLS']:
locales = env.Gettext(env.Glob('share/locale/*/LC_MESSAGES/gpick.po'))
Depends(executable, locales)
env.Alias(target="locales", source=[
locales
])
template_c = env.Xgettext("template_c.pot", env.Glob('source/*.cpp') + env.Glob('source/tools/*.cpp') + env.Glob('source/transformation/*.cpp'), XGETTEXT_FLAGS = ['--keyword=N_', '--from-code=UTF-8', '--package-version="$GPICK_BUILD_VERSION"'])
template_lua = env.Xgettext("template_lua.pot", env.Glob('share/gpick/*.lua'), XGETTEXT_FLAGS = ['--language=C++', '--keyword=N_', '--from-code=UTF-8', '--package-version="$GPICK_BUILD_VERSION"'])
template = env.Msgcat("template.pot", [template_c, template_lua], MSGCAT_FLAGS = ['--use-first'])
env.Alias(target="template", source=[
template
])
env.Alias(target="install", source=[
env.InstallProgram(dir=env['DESTDIR'] +'/bin', source=[executable]),
env.InstallData(dir=env['DESTDIR'] +'/share/applications', source=['share/applications/gpick.desktop']),
env.InstallData(dir=env['DESTDIR'] +'/share/doc/gpick', source=['share/doc/gpick/copyright']),
env.InstallData(dir=env['DESTDIR'] +'/share/gpick', source=[env.Glob('share/gpick/*.png'), env.Glob('share/gpick/*.lua'), env.Glob('share/gpick/*.txt')]),
env.InstallData(dir=env['DESTDIR'] +'/share/man/man1', source=['share/man/man1/gpick.1']),
env.InstallData(dir=env['DESTDIR'] +'/share/icons/hicolor/48x48/apps/', source=[env.Glob('share/icons/hicolor/48x48/apps/*.png')]),
env.InstallData(dir=env['DESTDIR'] +'/share/icons/hicolor/scalable/apps/', source=[env.Glob('share/icons/hicolor/scalable/apps/*.svg')]),
env.InstallDataAutoDir(dir=env['DESTDIR'] + '/share/locale/', relative_dir='share/locale/', source=[env.Glob('share/locale/*/LC_MESSAGES/gpick.mo')]),
])
env.Alias(target="nsis", source=[
env.WriteNsisVersion("version.py")
])
tarFiles = env.GetSourceFiles( "("+RegexEscape(os.sep)+r"\.)|("+RegexEscape(os.sep)+r"\.svn$)|(^"+RegexEscape(os.sep)+r"build$)", r"(^\.)|(\.pyc$)|(\.orig$)|(~$)|(\.log$)|(\.diff)|(\.mo$)|(^gpick-.*\.tar\.gz$)|(^user-config\.py$)")
for item in parser_files:
tarFiles.append(str(item))
if 'TAR' in env:
env.Alias(target="tar", source=[
env.Append(TARFLAGS = ['-z']),
env.Prepend(TARFLAGS = ['--transform', '"s,(^(build/)?),gpick_'+str(env['GPICK_BUILD_VERSION'])+'/,x"']),
env.Tar('gpick_'+str(env['GPICK_BUILD_VERSION'])+'.tar.gz', tarFiles)
])
env.Default(executable)
gpick_0.2.5/res/gray-pattern.svg 0000644 0001750 0001750 00000007550 12070605213 015337 0 ustar zbyg zbyg
gpick_0.2.5/res/gpick.svg 0000644 0001750 0001750 00000022555 12070605213 014021 0 ustar zbyg zbyg
gpick_0.2.5/res/falloff-cubic.svg 0000644 0001750 0001750 00000007773 12070605213 015425 0 ustar zbyg zbyg
gpick_0.2.5/res/falloff-linear.svg 0000644 0001750 0001750 00000010161 12070605213 015573 0 ustar zbyg zbyg
gpick_0.2.5/res/falloff-none.svg 0000644 0001750 0001750 00000007425 12070605213 015271 0 ustar zbyg zbyg
gpick_0.2.5/res/falloff-quadratic.svg 0000644 0001750 0001750 00000007765 12070605213 016316 0 ustar zbyg zbyg
gpick_0.2.5/res/falloff-exponential.svg 0000644 0001750 0001750 00000010202 12070605213 016643 0 ustar zbyg zbyg
gpick_0.2.5/source/ColorWheelType.h 0000644 0001750 0001750 00000005403 12070605214 015762 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COLOR_WHEEL_TYPE_H_
#define COLOR_WHEEL_TYPE_H_
#include "Color.h"
#include
/** \file source/ColorWheelType.h
* \brief Color wheel type description structure and functions
*/
/** \struct ColorWheelType
* \brief ColorWheelType structure contains color wheel type name and conversion functions
*/
typedef struct ColorWheelType{
const char *name; /**< Name of a color wheel */
/**
* Callback used to convert color wheel specific hue into the color in a HSL color space
* @param[in] hue Color wheel specific hue value
* @param[out] hsl Result as a color in HSL color space
*/
void (*hue_to_hsl)(double hue, Color* hsl);
/**
* Callback used to convert HSL color space hue into color wheel specific hue
* @param[in] rgbhue HSL color space hue value
* @param[out] hue Color wheel specific hue value
*/
void (*rgbhue_to_hue)(double rgbhue, double *hue);
}ColorWheelType;
/**
* Get available color wheel types
* @return Constant array of available color wheel types
*/
const ColorWheelType* color_wheel_types_get();
/**
* Get the number of available color wheel types
* @return Number of available color wheel types
*/
const uint32_t color_wheel_types_get_n();
#endif /* COLOR_WHEEL_TYPE_H_ */
gpick_0.2.5/source/ColorRYB.cpp 0000644 0001750 0001750 00000020313 12070605214 015040 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ColorRYB.h"
#include "MathUtil.h"
#include "BezierCubicCurve.h"
#include "Vector2.h"
#include
#include
#include
#include
using namespace std;
typedef math::Vec2 point;
typedef math::BezierCubicCurve bezier;
double bezier_eval_at_x(list& channel, double x, double delta){
for (list::iterator i=channel.begin(); i!=channel.end(); ++i){
if (x>=(*i)->p0.x && x<=(*i)->p3.x){
double width = ((*i)->p3.x-(*i)->p0.x);
double t = (x-(*i)->p0.x)/width;
double d;
point v;
for (int limit=50; limit>0; --limit){
v = (**i)(t);
d = v.x - x;
if (fabs(d)1)
t=1;
else if (t<0)
t=0;
}
}
}
return 0;
}
static void color_get_ryb_curves(list &red, list &green, list &blue){
static bezier red_v[]={
bezier( point(0.0, 1.0), point(1.0, 1.0), point(13.0, 1.0), point(14.0, 1.0) ),
bezier( point(14.0, 1.0), point(16.0, 0.6405), point(16.9, 0.0), point(21.0, 0.0) ),
bezier( point(21.0, 0.0), point(28.0, 0.0), point(33.0, 1.0), point(36.0, 1.0) )
};
static bezier green_v[]={
bezier( point(0.0, 0.0), point(4.0, 0.4), point(13.0, 1.0), point(14.0, 1.0) ),
bezier( point(14.0, 1.0), point(14.85, 1.0), point(17.05, 0.9525), point(19.0, 0.7) ),
bezier( point(19.0, 0.7), point(24.0, 0.05), point(31.0, 0.0), point(36.0, 0.0) )
};
static bezier blue_v[]={
bezier( point(0.0, 0.0), point(1.0, 0.0), point(18.0, 0.0), point(19.0, 0.0) ),
bezier( point(19.0, 0.0), point(22.0, 1.0), point(33.0, 1.0), point(36.0, 0.0) )
};
for (uint32_t i=0; i red, green, blue;
color_get_ryb_curves(red, green, blue);
double hue = rgb_hue;
double d;
double delta = 1/3600.0;
Color color, color2;
for (int limit=100; limit>0; --limit){
color.rgb.red = bezier_eval_at_x(red, hue*36, 0.01),
color.rgb.green = bezier_eval_at_x(green, hue*36, 0.01),
color.rgb.blue = bezier_eval_at_x(blue, hue*36, 0.01);
color_rgb_to_hsv(&color, &color2);
d = rgb_hue - color2.hsv.hue;
if (fabs(d)1) hue=1;
else if (hue<0) hue=0;
}
*ryb_hue = hue;
return -1;
}
double color_rybhue_to_rgbhue_f(double hue){
if (hue>=4.0/6.0 && hue<=6.0/6.0){
return ((285.12*hue*hue)-(81.252*hue)+155.18)/360.0;
}else if (hue>=0.0/6.0 && hue<=1.0/6.0){
return ((-544.32*hue*hue)+(301.896*hue))/360.0;
}else if (hue>=1.0/6.0 && hue<=3.0/6.0){
return ((609.12*hue*hue)-(153.72*hue)+45.166)/360.0;
}else if (hue>=3.0/6.0 && hue<=4.0/6.0){
return ((-1088.64*hue*hue)+(1916.46*hue)-567.45)/360.0;
}
return 0;
}
int color_rgbhue_to_rybhue_f(double rgb_hue, double* ryb_hue){
double hue = rgb_hue;
double d;
double delta = 1/3600.0;
for (int limit=100; limit>0; --limit){
d = rgb_hue - color_rybhue_to_rgbhue_f(hue);
if (fabs(d)1) hue=1;
else if (hue<0) hue=0;
}
*ryb_hue = hue;
return -1;
}
void color_rybhue_to_rgb(double hue, Color* color){
list red, green, blue;
color_get_ryb_curves(red, green, blue);
color->rgb.red = bezier_eval_at_x(red, hue*36, 0.01),
color->rgb.green = bezier_eval_at_x(green, hue*36, 0.01),
color->rgb.blue = bezier_eval_at_x(blue, hue*36, 0.01);
}
double color_ryb_transform_lightness(double hue1, double hue2){
double t;
hue1 = modf(hue1, &t);
hue2 = modf(hue2, &t);
double values[]={
0.50000000, 0.50000000, 0.50000000, 0.50000000,
0.50000000, 0.50000000, 0.50000000, 0.50000000,
0.50000000, 0.50000000, 0.50000000, 0.50000000,
0.50000000, 0.46470600, 0.42745101, 0.39215699,
0.37450999, 0.35490200, 0.33725500, 0.35294101,
0.36862749, 0.38431349, 0.37254900, 0.36078450,
0.34901950, 0.34313750, 0.33529401, 0.32941201,
0.32549000, 0.31960800, 0.31568649, 0.33921549,
0.36470601, 0.38823551, 0.42548999, 0.46274501,
0.50000000,
};
int32_t samples=sizeof(values)/sizeof(double)-1;
double n;
return mix_double(values[int(floor(hue2*samples))], values[int(floor(hue2*samples))+1], modf(hue2*samples,&n))/
mix_double(values[int(floor(hue2*samples))], values[int(floor(hue1*samples))+1], modf(hue1*samples,&n));
}
double color_ryb_transform_hue(double hue, bool forward){
double values[]={
0.00000000, 0.02156867, 0.04248367, 0.06405234,
0.07385617, 0.08431367, 0.09411767, 0.10653600,
0.11830067, 0.13071899, 0.14248367, 0.15490200,
0.16666667, 0.18354435, 0.19954120, 0.21666662,
0.25130904, 0.28545108, 0.31976745, 0.38981494,
0.46010628, 0.53061217, 0.54649121, 0.56159425,
0.57771534, 0.60190469, 0.62573093, 0.64980155,
0.68875504, 0.72801632, 0.76708061, 0.80924863,
0.85215056, 0.89478123, 0.92933953, 0.96468931,
1.00000000, 1.00000000,
};
int32_t samples=sizeof(values)/sizeof(double)-2;
double new_hue;
double t;
hue = modf(hue, &t);
if (!forward){
for (int32_t i=0; i=hue){
int index1, index2;
double value1, value2, mix;
index1=i;
index2=i+1;
value1=index1 / (double)samples;
value2=index2 / (double)samples;
mix = (hue-values[index1])/(values[index2]-values[index1]);
new_hue= mix_double(value1, value2, mix);
return new_hue;
}
}
return 1;
}else{
double value1=values[int(hue*samples)];
double value2=values[int(hue*samples+1)];
double n;
double mix = modf(hue*samples, &n);
new_hue = mix_double(value1, value2, mix);
return new_hue;
}
return 0;
}
gpick_0.2.5/source/uiDialogVariations.h 0000644 0001750 0001750 00000003437 12070605214 016657 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UIDIALOGVARIATIONS_H_
#define UIDIALOGVARIATIONS_H_
#include
#include "ColorList.h"
#include "GlobalState.h"
void dialog_variations_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState *gs);
#endif /* UIDIALOGVARIATIONS_H_ */
gpick_0.2.5/source/BrightnessDarkness.h 0000644 0001750 0001750 00000003331 12070605214 016656 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BRIGHTNESS_DARKNESS_H_
#define BRIGHTNESS_DARKNESS_H_
#include "ColorSourceManager.h"
int brightness_darkness_source_register(ColorSourceManager *csm);
#endif /* BRIGHTNESS_DARKNESS_H_ */
gpick_0.2.5/source/GenerateScheme.cpp 0000644 0001750 0001750 00000103630 12070605214 016270 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "GenerateScheme.h"
#include "DragDrop.h"
#include "GlobalStateStruct.h"
#include "ToolColorNaming.h"
#include "uiUtilities.h"
#include "ColorList.h"
#include "MathUtil.h"
#include "ColorRYB.h"
#include "gtk/ColorWidget.h"
#include "gtk/ColorWheel.h"
#include "ColorWheelType.h"
#include "uiColorInput.h"
#include "CopyPaste.h"
#include "Converter.h"
#include "DynvHelpers.h"
#include "Internationalisation.h"
#include "uiApp.h"
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAX_COLOR_WIDGETS 6
typedef struct GenerateSchemeArgs{
ColorSource source;
GtkWidget* main;
GtkWidget* statusbar;
GtkWidget *gen_type;
GtkWidget *wheel_type;
GtkWidget *color_wheel;
GtkWidget *hue;
GtkWidget *saturation;
GtkWidget *lightness;
GtkWidget *color_previews;
GtkWidget *last_focused_color;
GtkWidget *colors[MAX_COLOR_WIDGETS];
double color_hue[MAX_COLOR_WIDGETS];
struct{
double orig_hue;
double orig_saturation;
double orig_value;
double hue;
double saturation;
double value;
}mod[MAX_COLOR_WIDGETS];
bool wheel_locked;
int colors_visible;
struct dynvSystem *params;
GlobalState* gs;
struct ColorList *preview_color_list;
}GenerateSchemeArgs;
const SchemeType scheme_types[]={
{N_("Complementary"), 1, 1, {180}},
{N_("Analogous"), 5, 1, {30}},
{N_("Triadic"), 2, 1, {120}},
{N_("Split-Complementary"), 2, 2, {150, 60}},
{N_("Rectangle (tetradic)"), 3, 2, {60, 120}},
{N_("Square"), 3, 1, {90}},
{N_("Neutral"), 5, 1, {15}},
{N_("Clash"), 2, 2, {90, 180}},
{N_("Five-Tone"), 4, 4, {115, 40, 50, 40}},
{N_("Six-Tone"), 5, 2, {30, 90}},
};
class GenerateSchemeColorNameAssigner: public ToolColorNameAssigner {
protected:
stringstream m_stream;
int32_t m_ident;
int32_t m_schemetype;
public:
GenerateSchemeColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){
}
void assign(struct ColorObject *color_object, Color *color, const int32_t ident, const int32_t schemetype){
m_ident = ident;
m_schemetype = schemetype;
ToolColorNameAssigner::assign(color_object, color);
}
virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){
m_stream.str("");
m_stream << _("scheme") << " " << _(generate_scheme_get_scheme_type(m_schemetype)->name) << " #" << m_ident << "[" << color_names_get(m_gs->color_names, color, false) << "]";
return m_stream.str();
}
};
static int set_rgb_color(GenerateSchemeArgs *args, struct ColorObject* color, uint32_t color_index);
static int set_rgb_color_by_widget(GenerateSchemeArgs *args, struct ColorObject* color, GtkWidget* color_widget);
// XXX needs to have name assignment in here.
static void calc(GenerateSchemeArgs *args, bool preview, bool save_settings){
int32_t type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->gen_type));
int32_t wheel_type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->wheel_type));
gtk_color_wheel_set_color_wheel_type(GTK_COLOR_WHEEL(args->color_wheel), &color_wheel_types_get()[wheel_type]);
gtk_color_wheel_set_n_colors(GTK_COLOR_WHEEL(args->color_wheel), generate_scheme_get_scheme_type(type)->colors + 1);
//gfloat chaos = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_chaos));
//gboolean correction = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_brightness_correction));
double hue = gtk_range_get_value(GTK_RANGE(args->hue));
double saturation = gtk_range_get_value(GTK_RANGE(args->saturation));
double lightness = gtk_range_get_value(GTK_RANGE(args->lightness));
if (save_settings){
dynv_set_int32(args->params, "type", type);
dynv_set_int32(args->params, "wheel_type", wheel_type);
dynv_set_float(args->params, "hue", hue);
dynv_set_float(args->params, "saturation", saturation);
dynv_set_float(args->params, "lightness", lightness);
}
hue /= 360.0;
saturation /= 100.0;
lightness /= 100.0;
Color color, hsl, r;
gint step_i;
struct ColorList *color_list;
if (preview)
color_list = args->preview_color_list;
else
color_list = args->gs->colors;
const ColorWheelType *wheel = &color_wheel_types_get()[wheel_type];
float chaos = 0;
float hue_offset = 0;
float hue_step;
Color hsv;
for (step_i = 0; step_i <= generate_scheme_get_scheme_type(type)->colors; ++step_i) {
wheel->hue_to_hsl(wrap_float(hue + args->mod[step_i].hue), &hsl);
hsl.hsl.lightness = clamp_float(hsl.hsl.lightness + lightness, 0, 1);
hsl.hsl.saturation = clamp_float(hsl.hsl.saturation * saturation, 0, 1);
color_hsl_to_hsv(&hsl, &hsv);
args->mod[step_i].orig_hue = hue;
args->mod[step_i].orig_saturation = hsv.hsv.saturation;
args->mod[step_i].orig_value = hsv.hsv.value;
hsv.hsv.saturation = clamp_float(hsv.hsv.saturation + args->mod[step_i].saturation, 0, 1);
hsv.hsv.value = clamp_float(hsv.hsv.value + args->mod[step_i].value, 0, 1);
color_hsv_to_rgb(&hsv, &r);
struct ColorObject *color_object=color_list_new_color_object(color_list, &r);
dynv_set_float(color_object->params, "hue_offset", hue_offset);
color_list_add_color_object(color_list, color_object, 1);
color_object_release(color_object);
//color_rgb_to_hsv(&r, &hsv);
gtk_color_wheel_set_hue(GTK_COLOR_WHEEL(args->color_wheel), step_i, wrap_float(hue + args->mod[step_i].hue));
gtk_color_wheel_set_saturation(GTK_COLOR_WHEEL(args->color_wheel), step_i, hsv.hsv.saturation);
gtk_color_wheel_set_value(GTK_COLOR_WHEEL(args->color_wheel), step_i, hsv.hsv.value);
hue_step = (generate_scheme_get_scheme_type(type)->turn[step_i % generate_scheme_get_scheme_type(type)->turn_types]) / (360.0)
+ chaos*(((random_get(args->gs->random)&0xFFFFFFFF)/(gdouble)0xFFFFFFFF)-0.5);
hue = wrap_float(hue + hue_step);
hue_offset = wrap_float(hue_offset + hue_step);
}
if (preview){
uint32_t total_colors = generate_scheme_get_scheme_type(type)->colors + 1;
if (total_colors > MAX_COLOR_WIDGETS) total_colors = MAX_COLOR_WIDGETS;
for (uint32_t i = args->colors_visible; i > total_colors; --i)
gtk_widget_hide(args->colors[i-1]);
for (uint32_t i = args->colors_visible; i < total_colors; ++i)
gtk_widget_show(args->colors[i]);
args->colors_visible = total_colors;
uint32_t j = 0;
char* text;
for (ColorList::iter i = color_list->colors.begin(); i!=color_list->colors.end(); ++i){
color_object_get_color(*i, &color);
text = main_get_color_text(args->gs, &color, COLOR_TEXT_TYPE_DISPLAY);
args->color_hue[j] = dynv_get_float_wd((*i)->params, "hue_offset", 0);
gtk_color_set_color(GTK_COLOR(args->colors[j]), &color, text);
if (text) g_free(text);
++j;
if (j >= total_colors) break;
}
}
}
static void update(GtkWidget *widget, GenerateSchemeArgs *args ){
color_list_remove_all(args->preview_color_list);
calc(args, true, false);
}
static void hue_changed_cb(GtkWidget *widget, gint color_id, GenerateSchemeArgs *args){
if (args->wheel_locked){
double hue = gtk_range_get_value(GTK_RANGE(args->hue)) / 360.0;
hue = wrap_float(hue - args->mod[color_id].hue + gtk_color_wheel_get_hue(GTK_COLOR_WHEEL(widget), color_id) - args->mod[color_id].orig_hue);
gtk_range_set_value(GTK_RANGE(args->hue), hue * 360.0);
}else{
args->mod[color_id].hue = gtk_color_wheel_get_hue(GTK_COLOR_WHEEL(widget), color_id) - args->mod[color_id].orig_hue;
update(widget, args);
}
}
static void saturation_value_changed_cb(GtkWidget *widget, gint color_id, GenerateSchemeArgs *args){
if (args->wheel_locked){
double saturation = gtk_range_get_value(GTK_RANGE(args->saturation)) / 100.0;
double lightness = gtk_range_get_value(GTK_RANGE(args->lightness)) / 100.0;
//lightness = gtk_color_wheel_get_value(GTK_COLOR_WHEEL(widget), color_id);
gtk_range_set_value(GTK_RANGE(args->saturation), saturation * 100.0);
gtk_range_set_value(GTK_RANGE(args->lightness), lightness * 100.0);
}else{
args->mod[color_id].saturation = gtk_color_wheel_get_saturation(GTK_COLOR_WHEEL(widget), color_id) - args->mod[color_id].orig_saturation;
args->mod[color_id].value = gtk_color_wheel_get_value(GTK_COLOR_WHEEL(widget), color_id) - args->mod[color_id].orig_value;
update(widget, args);
}
}
static void color_wheel_locked_toggled_cb(GtkWidget* widget, GenerateSchemeArgs* args){
args->wheel_locked = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
gtk_color_wheel_set_block_editable(GTK_COLOR_WHEEL(args->color_wheel), !args->wheel_locked);
}
static void color_reset_scheme_cb(GtkWidget *widget, GenerateSchemeArgs *args){
for (int i = 0; i < MAX_COLOR_WIDGETS; ++i){
args->mod[i].hue = 0;
args->mod[i].saturation = 0;
args->mod[i].value = 0;
}
update(widget, args);
}
static void color_wheel_show_menu(GtkWidget* widget, GenerateSchemeArgs* args, GdkEventButton *event ){
GtkWidget *menu;
GtkWidget* item;
menu = gtk_menu_new();
item = gtk_check_menu_item_new_with_mnemonic(_("_Locked"));
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), args->wheel_locked);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(G_OBJECT(item), "toggled", G_CALLBACK(color_wheel_locked_toggled_cb), args);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_image(_("_Reset scheme"), gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(color_reset_scheme_cb), args);
gtk_widget_show_all(GTK_WIDGET(menu));
gint32 button, event_time;
if (event){
button = event->button;
event_time = event->time;
}else{
button = 0;
event_time = gtk_get_current_event_time ();
}
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time);
g_object_ref_sink(menu);
g_object_unref(menu);
}
static gboolean color_wheel_button_press_cb(GtkWidget *widget, GdkEventButton *event, GenerateSchemeArgs* args) {
if (event->button == 3 && event->type == GDK_BUTTON_PRESS){
color_wheel_show_menu(widget, args, event);
}
return false;
}
static void color_wheel_popup_menu_cb(GtkWidget *widget, GenerateSchemeArgs* args){
color_wheel_show_menu(widget, args, 0);
}
static void on_color_paste(GtkWidget *widget, gpointer item) {
GenerateSchemeArgs* args=(GenerateSchemeArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
struct ColorObject* color_object;
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
}
static void color_reset_cb(GtkWidget *widget, GenerateSchemeArgs *args){
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
for (int i = 0; i < args->colors_visible; ++i){
if (args->colors[i] == color_widget){
args->mod[i].hue = 0;
args->mod[i].saturation = 0;
args->mod[i].value = 0;
update(widget, args);
return;
}
}
}
static void on_color_edit(GtkWidget *widget, gpointer item) {
GenerateSchemeArgs* args=(GenerateSchemeArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
Color c;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
struct ColorObject* color_object = color_list_new_color_object(args->gs->colors, &c);
struct ColorObject* new_color_object = 0;
if (dialog_color_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs, color_object, &new_color_object )==0){
set_rgb_color_by_widget(args, new_color_object, color_widget);
color_object_release(new_color_object);
}
color_object_release(color_object);
}
static string identify_color_widget(GtkWidget *widget, GenerateSchemeArgs *args)
{
for (int i = 0; i < MAX_COLOR_WIDGETS; ++i){
if (args->colors[i] == widget){
return "result " + boost::lexical_cast(i + 1);
}
}
return "unknown";
}
static void add_color_to_palette(GtkWidget *color_widget, GenerateSchemeColorNameAssigner &name_assigner, GenerateSchemeArgs *args)
{
Color c;
struct ColorObject *color_object;
string widget_ident;
int32_t type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->gen_type));
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
widget_ident = identify_color_widget(color_widget, args);
name_assigner.assign(color_object, &c, atoi(widget_ident.c_str()+7), type);
color_list_add_color_object(args->gs->colors, color_object, 1);
color_object_release(color_object);
}
static void on_color_add_to_palette(GtkWidget *widget, gpointer item) {
GenerateSchemeArgs* args = (GenerateSchemeArgs*)item;
GtkWidget *color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
GenerateSchemeColorNameAssigner name_assigner(args->gs);
add_color_to_palette(color_widget, name_assigner, args);
}
static void on_color_add_all_to_palette(GtkWidget *widget, gpointer item) {
GenerateSchemeArgs* args = (GenerateSchemeArgs*)item;
GenerateSchemeColorNameAssigner name_assigner(args->gs);
for (int i = 0; i < args->colors_visible; ++i){
add_color_to_palette(args->colors[i], name_assigner, args);
}
}
static gboolean color_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, GenerateSchemeArgs *args){
args->last_focused_color = widget;
for (int i = 0; i < MAX_COLOR_WIDGETS; ++i){
if (widget == args->colors[i]){
gtk_color_wheel_set_selected(GTK_COLOR_WHEEL(args->color_wheel), i);
return false;
}
}
return false;
}
static void on_color_activate(GtkWidget *widget, gpointer item) {
GenerateSchemeArgs* args=(GenerateSchemeArgs*)item;
GenerateSchemeColorNameAssigner name_assigner(args->gs);
add_color_to_palette(widget, name_assigner, args);
}
static void color_show_menu(GtkWidget* widget, GenerateSchemeArgs* args, GdkEventButton *event ){
GtkWidget *menu;
GtkWidget* item;
menu = gtk_menu_new ();
item = gtk_menu_item_new_with_image (_("_Add to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image (_("A_dd all to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_all_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_mnemonic (_("_Copy to clipboard"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
Color c;
gtk_color_get_color(GTK_COLOR(widget), &c);
struct ColorObject* color_object;
color_object = color_list_new_color_object(args->gs->colors, &c);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (color_object, 0, args->gs));
color_object_release(color_object);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_image (_("_Edit..."), gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_edit), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image (_("_Paste"), gtk_image_new_from_stock(GTK_STOCK_PASTE, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_paste), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
if (copypaste_is_color_object_available(args->gs)!=0){
gtk_widget_set_sensitive(item, false);
}
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_image(_("_Reset"), gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(color_reset_cb), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
gtk_widget_show_all (GTK_WIDGET(menu));
gint32 button, event_time;
if (event){
button = event->button;
event_time = event->time;
}else{
button = 0;
event_time = gtk_get_current_event_time ();
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time);
g_object_ref_sink(menu);
g_object_unref(menu);
}
static gboolean on_color_button_press (GtkWidget *widget, GdkEventButton *event, GenerateSchemeArgs* args) {
if (event->button == 3 && event->type == GDK_BUTTON_PRESS){
color_show_menu(widget, args, event);
}
return false;
}
static void on_color_popup_menu(GtkWidget *widget, GenerateSchemeArgs* args){
color_show_menu(widget, args, 0);
}
static gboolean on_color_key_press (GtkWidget *widget, GdkEventKey *event, GenerateSchemeArgs* args){
guint modifiers = gtk_accelerator_get_default_mod_mask();
Color c;
struct ColorObject* color_object;
GtkWidget* color_widget = widget;
switch(event->keyval){
case GDK_c:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
Converters *converters = (Converters*)dynv_get_pointer_wd(args->gs->params, "Converters", 0);
Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COPY);
if (converter){
converter_get_clipboard(converter->function_name, color_object, 0, args->gs->params);
}
color_object_release(color_object);
return true;
}
return false;
break;
case GDK_v:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
return true;
}
return false;
break;
default:
return false;
break;
}
return false;
}
static gchar* format_saturation_value_cb (GtkScale *scale, gdouble value){
return g_strdup_printf ("%d%%", int(value));
}
static gchar* format_lightness_value_cb (GtkScale *scale, gdouble value){
if (value>=0)
return g_strdup_printf ("+%d%%", int(value));
else
return g_strdup_printf ("-%d%%", -int(value));
}
static int source_destroy(GenerateSchemeArgs *args){
color_list_destroy(args->preview_color_list);
dynv_system_release(args->params);
gtk_widget_destroy(args->main);
delete args;
return 0;
}
static int source_get_color(GenerateSchemeArgs *args, ColorObject** color){
GenerateSchemeColorNameAssigner name_assigner(args->gs);
Color c;
string widget_ident;
int32_t type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->gen_type));
if (args->last_focused_color){
gtk_color_get_color(GTK_COLOR(args->last_focused_color), &c);
widget_ident = identify_color_widget(args->last_focused_color, args);
}else{
gtk_color_get_color(GTK_COLOR(args->colors[0]), &c);
widget_ident = identify_color_widget(args->colors[0], args);
}
*color = color_list_new_color_object(args->gs->colors, &c);
name_assigner.assign(*color, &c, atoi(widget_ident.c_str() + 7), type);
return 0;
}
static int set_rgb_color_by_widget(GenerateSchemeArgs *args, struct ColorObject* color_object, GtkWidget* color_widget){
for (int i=0; icolors_visible; ++i){
if (args->colors[i]==color_widget){
set_rgb_color(args, color_object, i);
return 0;
}
}
return -1;
}
static int set_rgb_color(GenerateSchemeArgs *args, struct ColorObject* color, uint32_t color_index){
Color c;
color_object_get_color(color, &c);
double hue;
double saturation;
double lightness;
double shifted_hue;
Color hsl, hsv, hsl_results;
color_rgb_to_hsv(&c, &hsv);
//hsv.hsv.saturation = clamp_float(hsv.hsv.saturation - args->mod[color_index].saturation, 0, 1);
//hsv.hsv.value = clamp_float(hsv.hsv.value - args->mod[color_index].value, 0, 1);
color_hsv_to_hsl(&hsv, &hsl);
int32_t wheel_type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->wheel_type));
const ColorWheelType *wheel = &color_wheel_types_get()[wheel_type];
wheel->rgbhue_to_hue(hsl.hsl.hue, &hue);
//color_rgbhue_to_rybhue(hsl.hsl.hue, &hue);
shifted_hue = wrap_float(hue - args->color_hue[color_index] - args->mod[color_index].hue);
wheel->hue_to_hsl(hue, &hsl_results);
saturation = hsl.hsl.saturation * 1/hsl_results.hsl.saturation;
lightness = hsl.hsl.lightness - hsl_results.hsl.lightness;
shifted_hue *= 360.0;
saturation *= 100.0;
lightness *= 100.0;
gtk_range_set_value(GTK_RANGE(args->hue), shifted_hue);
gtk_range_set_value(GTK_RANGE(args->saturation), saturation);
gtk_range_set_value(GTK_RANGE(args->lightness), lightness);
return 0;
}
static int source_set_nth_color(GenerateSchemeArgs *args, uint32_t color_n, ColorObject* color){
if (color_n < 0 || color_n > 6) return -1;
return set_rgb_color(args, color, color_n);
}
static int source_set_color(GenerateSchemeArgs *args, struct ColorObject* color){
if (args->last_focused_color){
return set_rgb_color_by_widget(args, color, args->last_focused_color);
}else{
return set_rgb_color(args, color, 0);
}
}
static int source_activate(GenerateSchemeArgs *args){
transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0));
for (uint32_t i = 0; i < MAX_COLOR_WIDGETS; ++i){
gtk_color_set_transformation_chain(GTK_COLOR(args->colors[i]), chain);
}
gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "empty"), "");
return 0;
}
static int source_deactivate(GenerateSchemeArgs *args){
color_list_remove_all(args->preview_color_list);
calc(args, true, true);
dynv_set_bool(args->params, "wheel_locked", args->wheel_locked);
float hsv_shift_array[MAX_COLOR_WIDGETS * 3];
for (uint32_t i = 0; i < MAX_COLOR_WIDGETS; ++i){
hsv_shift_array[i * 3 + 0] = args->mod[i].hue;
hsv_shift_array[i * 3 + 1] = args->mod[i].saturation;
hsv_shift_array[i * 3 + 2] = args->mod[i].value;
}
dynv_set_float_array(args->params, "hsv_shift", hsv_shift_array, MAX_COLOR_WIDGETS * 3);
return 0;
}
static struct ColorObject* get_color_object(struct DragDrop* dd){
GenerateSchemeArgs* args = (GenerateSchemeArgs*)dd->userdata;
struct ColorObject* colorobject;
if (source_get_color(args, &colorobject) == 0){
return colorobject;
}
return 0;
}
static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){
GenerateSchemeArgs* args = static_cast(dd->userdata);
set_rgb_color(args, colorobject, (uintptr_t)dd->userdata2);
return 0;
}
static int set_color_object_at_color_wheel(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){
int item = gtk_color_wheel_get_at(GTK_COLOR_WHEEL(dd->widget), x, y);
GenerateSchemeArgs* args = static_cast(dd->userdata);
if (item == -1){
}else if (item >= 0){
Color c, hsl;
double hue;
color_object_get_color(colorobject, &c);
color_rgb_to_hsl(&c, &hsl);
int32_t wheel_type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->wheel_type));
const ColorWheelType *wheel = &color_wheel_types_get()[wheel_type];
wheel->rgbhue_to_hue(hsl.hsl.hue, &hue);
if (args->wheel_locked){
double hue_shift = (hue - args->mod[item].orig_hue) - args->mod[item].hue;
hue = wrap_float(gtk_range_get_value(GTK_RANGE(args->hue)) / 360.0 + hue_shift);
gtk_range_set_value(GTK_RANGE(args->hue), hue * 360.0);
}else{
args->mod[item].hue = hue - args->mod[item].orig_hue;
update(dd->widget, args);
}
}
return 0;
}
static bool test_at_color_wheel(struct DragDrop* dd, int x, int y){
int item = gtk_color_wheel_get_at(GTK_COLOR_WHEEL(dd->widget), x, y);
if (item == -1){
}else if (item >= 0){
return true;
}
return false;
}
static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){
GenerateSchemeArgs* args = new GenerateSchemeArgs;
args->params = dynv_system_ref(dynv_namespace);
args->statusbar = (GtkWidget*)dynv_get_pointer_wd(gs->params, "StatusBar", 0);
color_source_init(&args->source, source->identificator, source->hr_name);
args->source.destroy = (int (*)(ColorSource *source))source_destroy;
args->source.get_color = (int (*)(ColorSource *source, ColorObject** color))source_get_color;
args->source.set_color = (int (*)(ColorSource *source, ColorObject* color))source_set_color;
args->source.set_nth_color = (int (*)(ColorSource *source, uint32_t color_n, ColorObject* color))source_set_nth_color;
args->source.deactivate = (int (*)(ColorSource *source))source_deactivate;
args->source.activate = (int (*)(ColorSource *source))source_activate;
uint32_t hsv_shift_array_size = 0;
float *hsv_shift_array = dynv_get_float_array_wd(args->params, "hsv_shift", 0, 0, &hsv_shift_array_size);
hsv_shift_array_size /= 3;
for (uint32_t i = 0; i < MAX_COLOR_WIDGETS; ++i){
if (i < hsv_shift_array_size){
args->mod[i].hue = hsv_shift_array[i * 3 + 0];
args->mod[i].saturation = hsv_shift_array[i * 3 + 1];
args->mod[i].value = hsv_shift_array[i * 3 + 2];
}else{
args->mod[i].hue = 0;
args->mod[i].saturation = 0;
args->mod[i].value = 0;
}
}
if (hsv_shift_array) delete [] hsv_shift_array;
GtkWidget *table, *vbox, *hbox, *widget, *hbox2;
hbox = gtk_hbox_new(FALSE, 5);
vbox = gtk_vbox_new(FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 5);
args->color_previews = gtk_table_new(3, 2, false);
gtk_box_pack_start(GTK_BOX(vbox), args->color_previews, true, true, 0);
struct DragDrop dd;
dragdrop_init(&dd, gs);
dd.userdata = args;
dd.get_color_object = get_color_object;
dd.set_color_object_at = set_color_object_at;
for (intptr_t i = 0; i < MAX_COLOR_WIDGETS; ++i){
widget = gtk_color_new();
gtk_color_set_rounded(GTK_COLOR(widget), true);
gtk_color_set_roundness(GTK_COLOR(widget), 5);
gtk_color_set_hcenter(GTK_COLOR(widget), true);
gtk_table_attach(GTK_TABLE(args->color_previews), widget, i % 2, (i % 2) + 1, i / 2, i / 2 + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 0, 0);
//gtk_box_pack_start(GTK_BOX(args->color_previews), widget, TRUE, TRUE, 0);
args->colors[i] = widget;
g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(on_color_button_press), args);
g_signal_connect(G_OBJECT(widget), "activated", G_CALLBACK(on_color_activate), args);
g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_color_key_press), args);
g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(on_color_popup_menu), args);
g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(color_focus_in_cb), args);
//setup drag&drop
gtk_drag_dest_set( widget, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)i;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd);
}
hbox2 = gtk_hbox_new(FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, false, false, 0);
args->color_wheel = gtk_color_wheel_new();
gtk_box_pack_start(GTK_BOX(hbox2), args->color_wheel, false, false, 0);
g_signal_connect(G_OBJECT(args->color_wheel), "hue_changed", G_CALLBACK(hue_changed_cb), args);
g_signal_connect(G_OBJECT(args->color_wheel), "saturation_value_changed", G_CALLBACK(saturation_value_changed_cb), args);
g_signal_connect(G_OBJECT(args->color_wheel), "popup-menu", G_CALLBACK(color_wheel_popup_menu_cb), args);
g_signal_connect(G_OBJECT(args->color_wheel), "button-press-event", G_CALLBACK(color_wheel_button_press_cb), args);
args->wheel_locked = dynv_get_bool_wd(args->params, "wheel_locked", true);
gtk_color_wheel_set_block_editable(GTK_COLOR_WHEEL(args->color_wheel), !args->wheel_locked);
gtk_drag_dest_set(args->color_wheel, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata = args;
dd.userdata2 = 0;
dd.set_color_object_at = set_color_object_at_color_wheel;
dd.test_at = test_at_color_wheel;
dragdrop_widget_attach(args->color_wheel, DragDropFlags(DRAGDROP_DESTINATION), &dd);
gint table_y;
table = gtk_table_new(5, 2, false);
gtk_box_pack_start(GTK_BOX(hbox2), table, true, true, 0);
table_y = 0;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Hue:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
args->hue = gtk_hscale_new_with_range(0, 360, 1);
gtk_range_set_value(GTK_RANGE(args->hue), dynv_get_float_wd(args->params, "hue", 180));
g_signal_connect (G_OBJECT (args->hue), "value-changed", G_CALLBACK (update), args);
gtk_table_attach(GTK_TABLE(table), args->hue,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Saturation:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
args->saturation = gtk_hscale_new_with_range(0, 120, 1);
gtk_range_set_value(GTK_RANGE(args->saturation), dynv_get_float_wd(args->params, "saturation", 100));
g_signal_connect (G_OBJECT (args->saturation), "value-changed", G_CALLBACK (update), args);
g_signal_connect (G_OBJECT (args->saturation), "format-value", G_CALLBACK (format_saturation_value_cb), args);
gtk_table_attach(GTK_TABLE(table), args->saturation,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Lightness:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
args->lightness = gtk_hscale_new_with_range(-50, 80, 1);
gtk_range_set_value(GTK_RANGE(args->lightness), dynv_get_float_wd(args->params, "lightness", 0));
g_signal_connect (G_OBJECT (args->lightness), "value-changed", G_CALLBACK (update), args);
g_signal_connect (G_OBJECT (args->lightness), "format-value", G_CALLBACK (format_lightness_value_cb), args);
gtk_table_attach(GTK_TABLE(table), args->lightness,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
//table_y=0;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Type:"),0,0.5,0,0),0,1,table_y,table_y+1, GTK_FILL, GTK_SHRINK, 5, 5);
args->gen_type = gtk_combo_box_new_text();
for (uint32_t i = 0; i < generate_scheme_get_n_scheme_types(); i++){
gtk_combo_box_append_text(GTK_COMBO_BOX(args->gen_type), _(generate_scheme_get_scheme_type(i)->name));
}
gtk_combo_box_set_active(GTK_COMBO_BOX(args->gen_type), dynv_get_int32_wd(args->params, "type", 0));
g_signal_connect (G_OBJECT (args->gen_type), "changed", G_CALLBACK(update), args);
gtk_table_attach(GTK_TABLE(table), args->gen_type,1,2,table_y,table_y+1, GTK_FILL, GTK_SHRINK,5,0);
table_y++;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Color wheel:"),0,0.5,0,0),0,1,table_y,table_y+1, GTK_FILL, GTK_SHRINK, 5, 5);
args->wheel_type = gtk_combo_box_new_text();
for (uint32_t i = 0; i < color_wheel_types_get_n(); i++){
gtk_combo_box_append_text(GTK_COMBO_BOX(args->wheel_type), _(color_wheel_types_get()[i].name));
}
gtk_combo_box_set_active(GTK_COMBO_BOX(args->wheel_type), dynv_get_int32_wd(args->params, "wheel_type", 0));
g_signal_connect (G_OBJECT (args->wheel_type), "changed", G_CALLBACK(update), args);
gtk_table_attach(GTK_TABLE(table), args->wheel_type,1,2,table_y,table_y+1, GTK_FILL, GTK_SHRINK,5,0);
table_y++;
struct dynvHandlerMap* handler_map=dynv_system_get_handler_map(gs->colors->params);
struct ColorList* preview_color_list = color_list_new(handler_map);
dynv_handler_map_release(handler_map);
args->preview_color_list = preview_color_list;
args->colors_visible = MAX_COLOR_WIDGETS;
args->gs = gs;
gtk_widget_show_all(hbox);
update(0, args);
args->main = hbox;
args->source.widget = hbox;
return (ColorSource*)args;
}
int generate_scheme_source_register(ColorSourceManager *csm){
ColorSource *color_source = new ColorSource;
color_source_init(color_source, "generate_scheme", _("Scheme generation"));
color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement;
color_source->default_accelerator = GDK_g;
color_source_manager_add_source(csm, color_source);
return 0;
}
const SchemeType* generate_scheme_get_scheme_type(uint32_t index)
{
if (index >= 0 && index < generate_scheme_get_n_scheme_types())
return &scheme_types[index];
else
return 0;
}
uint32_t generate_scheme_get_n_scheme_types()
{
return sizeof(scheme_types) / sizeof(SchemeType);
}
gpick_0.2.5/source/uiStatusIcon.h 0000644 0001750 0001750 00000003644 12070605214 015514 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UISTATUSICON_H_
#define UISTATUSICON_H_
#include "FloatingPicker.h"
#include "GlobalState.h"
#include
struct uiStatusIcon;
struct uiStatusIcon* status_icon_new(GtkWidget* parent, GlobalState* gs, FloatingPicker floating_picker);
void status_icon_set_visible(struct uiStatusIcon* si, bool visible);
void status_icon_destroy(struct uiStatusIcon* si);
#endif /* UISTATUSICON_H_ */
gpick_0.2.5/source/Paths.h 0000644 0001750 0001750 00000004232 12070605214 014133 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PATHS_H_
#define PATHS_H_
#include
/** \file source/Paths.h
* \brief Data and configuration filename building functions.
*/
/**
* Construct filename to a data file.
* @param[in] filename Relative data file name.
* @return Filename to the data file. This value must be released by using g_free.
*/
gchar* build_filename(const gchar* filename);
/**
* Construct filename to a configuration file.
* @param[in] filename Relative configuration file name.
* @return Filename to the configuration file. This value must be released by using g_free.
*/
gchar* build_config_path(const gchar *filename);
#endif /* PATHS_H_ */
gpick_0.2.5/source/Vector2.h 0000644 0001750 0001750 00000005020 12070605214 014374 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef VECTOR2_H_
#define VECTOR2_H_
#include
namespace math{
/** \class Vec2
* \brief Two dimensional vector
*/
template
class Vec2{
public:
Vec2(){
x = y = 0;
};
Vec2(const T &x_, const T &y_){
x = x_;
y = y_;
};
Vec2(T &x_, T &y_){
x = x_;
y = y_;
};
Vec2& operator= (const Vec2& v){
x = v.x;
y = v.y;
return *this;
};
Vec2 operator* (const Vec2& v){
Vec2 r;
r.x = x * v.x;
r.y = y * v.y;
return r;
};
Vec2 operator* (const double& v){
Vec2 r;
r.x = x * v;
r.y = y * v;
return r;
};
Vec2 operator+ (const Vec2& v){
Vec2 r;
r.x = x + v.x;
r.y = y + v.y;
return r;
};
friend bool operator!= (const Vec2& lhs, const Vec2& rhs){
if (lhs.x != rhs.x) return false;
if (lhs.y != rhs.y) return false;
return true;
};
static T distance(const Vec2&a, const Vec2& b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
};
T x;
T y;
};
}
#endif /* VECTOR2_H_ */
gpick_0.2.5/source/SConscript 0000644 0001750 0001750 00000003720 12113713537 014724 0 ustar zbyg zbyg #!/usr/bin/env python
import os
import sys
from tools.gpick import *
Import('*')
local_env = env.Clone()
if not local_env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
local_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
local_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
if env['DOWNLOAD_RESENE_COLOR_LIST']:
local_env.ParseConfig('pkg-config --libs $CURL_PC')
if local_env['ENABLE_NLS']:
local_env.Append(
CPPDEFINES = ['ENABLE_NLS'],
)
sources = local_env.Glob('*.cpp') + local_env.Glob('dynv/*.cpp') + local_env.Glob('transformation/*.cpp')
objects = []
objects.append(SConscript(['version/SConscript'], exports='env'))
objects.append(SConscript(['gtk/SConscript'], exports='env'))
objects.append(SConscript(['layout/SConscript'], exports='env'))
objects.append(SConscript(['internationalisation/SConscript'], exports='env'))
objects.append(SConscript(['dbus/SConscript'], exports='env'))
objects.append(SConscript(['tools/SConscript'], exports='env'))
if env['EXPERIMENTAL_CSS_PARSER']:
parser_objects, generated_files = SConscript(['cssparser/SConscript'], exports='env')
objects.append(parser_objects)
else:
generated_files = []
objects.append(SConscript(['color_names/SConscript'], exports='env'))
if env['TOOLCHAIN'] == 'msvc':
local_env.Append(LIBS = ['glib-2.0', 'gtk-win32-2.0', 'gobject-2.0', 'gdk-win32-2.0', 'cairo', 'gdk_pixbuf-2.0', 'lua5.2', 'expat2.1', 'pango-1.0', 'pangocairo-1.0', 'intl'])
if local_env['BUILD_TARGET'] == 'win32':
if not (env['TOOLCHAIN'] == 'msvc'):
local_env.Append(LINKFLAGS = '-mwindows')
local_env.Append(LIBS=['expat'])
else:
local_env.Append(LINKFLAGS = ['/SUBSYSTEM:WINDOWS', '/ENTRY:mainCRTStartup'], CPPDEFINES = ['XML_STATIC'])
objects.append(SConscript(['winres/SConscript'], exports='env'))
elif local_env['BUILD_TARGET'] == 'linux2':
local_env.Append(LIBS=['rt', 'expat'])
executable = local_env.Program(
'gpick',
source = [sources, objects])
Return('executable', 'generated_files')
gpick_0.2.5/source/ColorSource.cpp 0000644 0001750 0001750 00000007756 12070605214 015664 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ColorSource.h"
#include
#include
using namespace std;
int color_source_init(ColorSource* source, const char *identificator, const char *name){
source->identificator = g_strdup(identificator);
source->hr_name = g_strdup(name);
source->set_color = 0;
source->get_color = 0;
source->set_nth_color = 0;
source->get_nth_color = 0;
source->activate = 0;
source->deactivate = 0;
source->destroy = 0;
source->set_slot_color = 0;
source->query_slots = 0;
source->userdata = 0;
source->implement = 0;
source->widget = 0;
source->single_instance_only = false;
source->needs_viewport = true;
return 0;
}
int color_source_activate(ColorSource *source){
if (source->activate) return source->activate(source);
return -1;
}
int color_source_deactivate(ColorSource *source){
if (source->deactivate) return source->deactivate(source);
return -1;
}
int color_source_set_color(ColorSource *source, ColorObject *color){
if (source && source->set_color)
return source->set_color(source, color);
else if (!source)
cerr << "Color source undefined" << endl;
return -1;
}
int color_source_get_color(ColorSource *source, ColorObject **color){
if (source && source->get_color)
return source->get_color(source, color);
else if (!source)
cerr << "Color source undefined" << endl;
return -1;
}
int color_source_set_nth_color(ColorSource *source, uint32_t color_n, ColorObject *color){
if (source && source->set_nth_color)
return source->set_nth_color(source, color_n, color);
else if (!source)
cerr << "Color source undefined" << endl;
return -1;
}
int color_source_get_nth_color(ColorSource *source, uint32_t color_n, ColorObject **color){
if (source && source->get_nth_color)
return source->get_nth_color(source, color_n, color);
else if (!source)
cerr << "Color source undefined" << endl;
return -1;
}
int color_source_get_default_accelerator(ColorSource *source)
{
if (source && source->default_accelerator)
return source->default_accelerator;
else if (!source)
cerr << "Color source undefined" << endl;
return 0;
}
int color_source_destroy(ColorSource* source){
if (source->destroy) return source->destroy(source);
g_free(source->identificator);
g_free(source->hr_name);
delete source;
return 0;
}
ColorSource* color_source_implement(ColorSource* source, GlobalState *gs, struct dynvSystem *dynv_namespace){
return source->implement(source, gs, dynv_namespace);
}
GtkWidget* color_source_get_widget(ColorSource* source){
return source->widget;
}
gpick_0.2.5/source/Variations.cpp 0000644 0001750 0001750 00000064166 12113713537 015550 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Variations.h"
#include "DragDrop.h"
#include "GlobalStateStruct.h"
#include "ToolColorNaming.h"
#include "uiUtilities.h"
#include "ColorList.h"
#include "MathUtil.h"
#include "ColorRYB.h"
#include "gtk/ColorWidget.h"
#include "gtk/ColorWheel.h"
#include "ColorWheelType.h"
#include "uiColorInput.h"
#include "CopyPaste.h"
#include "Converter.h"
#include "DynvHelpers.h"
#include "Internationalisation.h"
#include "uiApp.h"
#include
#include
#include
#include
#include
#include
using namespace std;
#define VAR_COLOR_WIDGETS 8
#define MAX_COLOR_LINES 3
#define COMPONENT_ID_HSL_HUE 1
#define COMPONENT_ID_HSL_SATURATION 2
#define COMPONENT_ID_HSL_LIGHTNESS 3
#define COMPONENT_ID_LAB_LIGHTNESS 4
typedef struct VariationType{
const char *name;
const char *symbol;
const char *unique_name;
int component_id;
double strength_mult;
}VariationType;
const VariationType variation_types[] = {
{N_("Hue"), "HHSL", "hsl_hue", COMPONENT_ID_HSL_HUE, 1},
{N_("Saturation"), "SHSL", "hsl_saturation", COMPONENT_ID_HSL_SATURATION, 1},
{N_("Lightness"), "LHSL", "hsl_lightness", COMPONENT_ID_HSL_LIGHTNESS, 1},
{N_("Lightness (Lab)"), "LLab", "lab_lightness", COMPONENT_ID_LAB_LIGHTNESS, 1},
};
typedef struct VariationsArgs{
ColorSource source;
GtkWidget* main;
GtkWidget* statusbar;
GtkWidget *strength;
GtkWidget *last_focused_color;
GtkWidget *color_previews;
GtkWidget *all_colors;
struct{
GtkWidget *color;
GtkWidget *var_colors[VAR_COLOR_WIDGETS + 1];
const VariationType *type;
}color[MAX_COLOR_LINES];
struct dynvSystem *params;
struct ColorList *preview_color_list;
GlobalState* gs;
}VariationsArgs;
class VariationsColorNameAssigner: public ToolColorNameAssigner {
protected:
stringstream m_stream;
const char *m_ident;
public:
VariationsColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){
}
void assign(struct ColorObject *color_object, Color *color, const char *ident){
m_ident = ident;
ToolColorNameAssigner::assign(color_object, color);
}
virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){
m_stream.str("");
m_stream << color_names_get(m_gs->color_names, color, false) << " " << _("variations") << " " << m_ident;
return m_stream.str();
}
};
static boost::format format_ignore_arg_errors(const std::string &f_string) {
boost::format fmter(f_string);
fmter.exceptions(boost::io::all_error_bits ^ (boost::io::too_many_args_bit | boost::io::too_few_args_bit));
return fmter;
}
static int set_rgb_color(VariationsArgs *args, struct ColorObject* color, uint32_t color_index);
static int set_rgb_color_by_widget(VariationsArgs *args, struct ColorObject* color, GtkWidget* color_widget);
static void calc(VariationsArgs *args, bool preview, bool save_settings){
double strength = gtk_range_get_value(GTK_RANGE(args->strength));
if (save_settings){
dynv_set_float(args->params, "strength", strength);
}
Color color, hsl, lab, r, hsl_mod, lab_mod;
for (int i = 0; i < MAX_COLOR_LINES; ++i){
gtk_color_get_color(GTK_COLOR(args->color[i].color), &color);
switch (args->color[i].type->component_id){
case COMPONENT_ID_HSL_HUE:
case COMPONENT_ID_HSL_SATURATION:
case COMPONENT_ID_HSL_LIGHTNESS:
color_rgb_to_hsl(&color, &hsl);
break;
case COMPONENT_ID_LAB_LIGHTNESS:
{
color_rgb_to_lab_d50(&color, &lab);
}
break;
}
for (int j = 0; j < VAR_COLOR_WIDGETS + 1; ++j){
if (j == VAR_COLOR_WIDGETS / 2) continue;
switch (args->color[i].type->component_id){
case COMPONENT_ID_HSL_HUE:
color_copy(&hsl, &hsl_mod);
hsl_mod.hsl.hue = wrap_float(hsl.hsl.hue + (args->color[i].type->strength_mult * strength * (j - VAR_COLOR_WIDGETS / 2)) / 400.0);
color_hsl_to_rgb(&hsl_mod, &r);
break;
case COMPONENT_ID_HSL_SATURATION:
color_copy(&hsl, &hsl_mod);
hsl_mod.hsl.saturation = clamp_float(hsl.hsl.saturation + (args->color[i].type->strength_mult * strength * (j - VAR_COLOR_WIDGETS / 2)) / 400.0, 0, 1);
color_hsl_to_rgb(&hsl_mod, &r);
break;
case COMPONENT_ID_HSL_LIGHTNESS:
color_copy(&hsl, &hsl_mod);
hsl_mod.hsl.lightness = clamp_float(hsl.hsl.lightness + (args->color[i].type->strength_mult * strength * (j - VAR_COLOR_WIDGETS / 2)) / 400.0, 0, 1);
color_hsl_to_rgb(&hsl_mod, &r);
break;
case COMPONENT_ID_LAB_LIGHTNESS:
color_copy(&lab, &lab_mod);
lab_mod.lab.L = clamp_float(lab.lab.L + (args->color[i].type->strength_mult * strength * (j - VAR_COLOR_WIDGETS / 2)) / 4.0, 0, 100);
color_lab_to_rgb_d50(&lab_mod, &r);
color_rgb_normalize(&r);
break;
}
gtk_color_set_color(GTK_COLOR(args->color[i].var_colors[j]), &r, "");
}
}
}
static void update(GtkWidget *widget, VariationsArgs *args ){
color_list_remove_all(args->preview_color_list);
calc(args, true, false);
}
static void on_color_paste(GtkWidget *widget, gpointer item) {
VariationsArgs* args=(VariationsArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
struct ColorObject* color_object;
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
}
static void on_color_edit(GtkWidget *widget, gpointer item) {
VariationsArgs* args=(VariationsArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
Color c;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
struct ColorObject* color_object = color_list_new_color_object(args->gs->colors, &c);
struct ColorObject* new_color_object = 0;
if (dialog_color_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs, color_object, &new_color_object )==0){
set_rgb_color_by_widget(args, new_color_object, color_widget);
color_object_release(new_color_object);
}
color_object_release(color_object);
}
static string identify_color_widget(GtkWidget *widget, VariationsArgs *args)
{
if (args->all_colors == widget){
return _("all colors");
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].color == widget){
try{
return (format_ignore_arg_errors(_("primary %d")) % (i + 1)).str();
}catch(const boost::io::format_error &e){
return (format_ignore_arg_errors("primary %d") % (i + 1)).str();
}
}
for (int j = 0; j <= VAR_COLOR_WIDGETS; ++j){
if (args->color[i].var_colors[j] == widget){
if (j > VAR_COLOR_WIDGETS / 2)
j--;
try{
return (format_ignore_arg_errors(_("result %d line %d")) % (j + 1) % (i + 1)).str();
}catch(const boost::io::format_error &e){
return (format_ignore_arg_errors("result %d line %d") % (j + 1) % (i + 1)).str();
}
}
}
}
return "unknown";
}
static void add_color_to_palette(GtkWidget *color_widget, VariationsColorNameAssigner &name_assigner, VariationsArgs *args)
{
Color c;
struct ColorObject *color_object;
string widget_ident;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
widget_ident = identify_color_widget(color_widget, args);
name_assigner.assign(color_object, &c, widget_ident.c_str());
color_list_add_color_object(args->gs->colors, color_object, 1);
color_object_release(color_object);
}
static void on_color_add_to_palette(GtkWidget *widget, gpointer item) {
VariationsArgs* args = (VariationsArgs*)item;
GtkWidget *color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
VariationsColorNameAssigner name_assigner(args->gs);
add_color_to_palette(color_widget, name_assigner, args);
}
static void on_color_add_all_to_palette(GtkWidget *widget, gpointer item) {
VariationsArgs* args = (VariationsArgs*)item;
VariationsColorNameAssigner name_assigner(args->gs);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
for (int j = 0; j < VAR_COLOR_WIDGETS + 1; ++j){
add_color_to_palette(args->color[i].var_colors[j], name_assigner, args);
}
}
}
static gboolean color_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, VariationsArgs *args){
args->last_focused_color = widget;
return false;
}
static void on_color_activate(GtkWidget *widget, gpointer item) {
VariationsArgs* args=(VariationsArgs*)item;
Color c;
gtk_color_get_color(GTK_COLOR(widget), &c);
struct ColorObject *color_object=color_list_new_color_object(args->gs->colors, &c);
string name = color_names_get(args->gs->color_names, &c, dynv_get_bool_wd(args->gs->params, "gpick.color_names.imprecision_postfix", true));
dynv_set_string(color_object->params, "name", name.c_str());
color_list_add_color_object(args->gs->colors, color_object, 1);
color_object_release(color_object);
}
static void type_toggled_cb(GtkWidget *widget, VariationsArgs *args) {
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
const VariationType *var_type = static_cast(g_object_get_data(G_OBJECT(widget), "variation_type"));
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))){
int line_id = -1;
for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].color == color_widget){
line_id = i;
break;
}
}
args->color[line_id].type = var_type;
Color c;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
struct ColorObject *color_object = color_list_new_color_object(args->gs->colors, &c);
set_rgb_color(args, color_object, line_id);
color_object_release(color_object);
}
}
static void color_show_menu(GtkWidget* widget, VariationsArgs* args, GdkEventButton *event ){
GtkWidget *menu;
GtkWidget* item;
menu = gtk_menu_new ();
item = gtk_menu_item_new_with_image(_("_Add to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image(_("A_dd all to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_all_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_mnemonic(_("_Copy to clipboard"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
Color c;
gtk_color_get_color(GTK_COLOR(widget), &c);
struct ColorObject* color_object;
color_object = color_list_new_color_object(args->gs->colors, &c);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (color_object, 0, args->gs));
color_object_release(color_object);
int line_id = -1;
bool all_colors = false;
if (args->all_colors == widget){
all_colors = true;
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].color == widget){
line_id = i;
}
}
if (line_id >= 0 || all_colors){
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
if (!all_colors){
GSList *group = 0;
for (uint32_t i = 0; i < sizeof(variation_types) / sizeof(VariationType); i++){
item = gtk_radio_menu_item_new_with_label(group, _(variation_types[i].name));
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
if (args->color[line_id].type == &variation_types[i]){
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), true);
}
g_object_set_data(G_OBJECT(item), "color_widget", widget);
g_object_set_data(G_OBJECT(item), "variation_type", (void*)&variation_types[i]);
g_signal_connect(G_OBJECT(item), "toggled", G_CALLBACK(type_toggled_cb), args);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
}
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
}
item = gtk_menu_item_new_with_image (_("_Edit..."), gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_edit), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image (_("_Paste"), gtk_image_new_from_stock(GTK_STOCK_PASTE, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_paste), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
if (copypaste_is_color_object_available(args->gs)!=0){
gtk_widget_set_sensitive(item, false);
}
}
gtk_widget_show_all (GTK_WIDGET(menu));
gint32 button, event_time;
if (event){
button = event->button;
event_time = event->time;
}else{
button = 0;
event_time = gtk_get_current_event_time ();
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time);
g_object_ref_sink(menu);
g_object_unref(menu);
}
static gboolean on_color_button_press (GtkWidget *widget, GdkEventButton *event, VariationsArgs* args) {
if (event->button == 3 && event->type == GDK_BUTTON_PRESS){
color_show_menu(widget, args, event);
}
return false;
}
static void on_color_popup_menu(GtkWidget *widget, VariationsArgs* args){
color_show_menu(widget, args, 0);
}
static gboolean on_color_key_press (GtkWidget *widget, GdkEventKey *event, VariationsArgs* args){
guint modifiers = gtk_accelerator_get_default_mod_mask();
Color c;
struct ColorObject* color_object;
GtkWidget* color_widget = widget;
switch(event->keyval){
case GDK_c:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
Converters *converters = (Converters*)dynv_get_pointer_wd(args->gs->params, "Converters", 0);
Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COPY);
if (converter){
converter_get_clipboard(converter->function_name, color_object, 0, args->gs->params);
}
color_object_release(color_object);
return true;
}
return false;
break;
case GDK_v:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
return true;
}
return false;
break;
default:
return false;
break;
}
return false;
}
static int source_destroy(VariationsArgs *args){
Color c;
char tmp[32];
for (gint i = 0; i < MAX_COLOR_LINES; ++i){
sprintf(tmp, "type%d", i);
dynv_set_string(args->params, tmp, args->color[i].type->unique_name);
sprintf(tmp, "color%d", i);
gtk_color_get_color(GTK_COLOR(args->color[i].color), &c);
dynv_set_color(args->params, tmp, &c);
}
gtk_color_get_color(GTK_COLOR(args->all_colors), &c);
dynv_set_color(args->params, "all_colors", &c);
color_list_destroy(args->preview_color_list);
dynv_system_release(args->params);
gtk_widget_destroy(args->main);
delete args;
return 0;
}
static int source_get_color(VariationsArgs *args, ColorObject** color){
VariationsColorNameAssigner name_assigner(args->gs);
Color c;
string widget_ident;
if (args->last_focused_color){
gtk_color_get_color(GTK_COLOR(args->last_focused_color), &c);
widget_ident = identify_color_widget(args->last_focused_color, args);
}else{
gtk_color_get_color(GTK_COLOR(args->color[0].color), &c);
widget_ident = identify_color_widget(args->color[0].color, args);
}
*color = color_list_new_color_object(args->gs->colors, &c);
name_assigner.assign(*color, &c, widget_ident.c_str());
return 0;
}
static int set_rgb_color_by_widget(VariationsArgs *args, struct ColorObject* color_object, GtkWidget* color_widget){
if (args->all_colors){
set_rgb_color(args, color_object, -1);
return 0;
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].color == color_widget){
set_rgb_color(args, color_object, i);
return 0;
}
}
return -1;
}
static int set_rgb_color(VariationsArgs *args, struct ColorObject* color, uint32_t color_index){
Color c;
color_object_get_color(color, &c);
if (color_index == (uint32_t)-1){
gtk_color_set_color(GTK_COLOR(args->all_colors), &c, "");
for (int i = 0; i < MAX_COLOR_LINES; ++i){
gtk_color_set_color(GTK_COLOR(args->color[i].color), &c, args->color[i].type->symbol);
}
}else{
gtk_color_set_color(GTK_COLOR(args->color[color_index].color), &c, args->color[color_index].type->symbol);
}
update(0, args);
return 0;
}
static int source_set_color(VariationsArgs *args, struct ColorObject* color){
if (args->last_focused_color){
return set_rgb_color_by_widget(args, color, args->last_focused_color);
}else{
return set_rgb_color(args, color, 0);
}
}
static int source_activate(VariationsArgs *args){
transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0));
gtk_color_set_transformation_chain(GTK_COLOR(args->all_colors), chain);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
gtk_color_set_transformation_chain(GTK_COLOR(args->color[i].color), chain);
for (int j = 0; j < VAR_COLOR_WIDGETS + 1; ++j){
gtk_color_set_transformation_chain(GTK_COLOR(args->color[i].var_colors[j]), chain);
}
}
gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "empty"), "");
return 0;
}
static int source_deactivate(VariationsArgs *args){
color_list_remove_all(args->preview_color_list);
calc(args, true, true);
return 0;
}
static struct ColorObject* get_color_object(struct DragDrop* dd){
VariationsArgs* args = (VariationsArgs*)dd->userdata;
struct ColorObject* colorobject;
if (source_get_color(args, &colorobject) == 0){
return colorobject;
}
return 0;
}
static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){
VariationsArgs* args = static_cast(dd->userdata);
set_rgb_color(args, colorobject, (uintptr_t)dd->userdata2);
return 0;
}
static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){
VariationsArgs* args = new VariationsArgs;
args->params = dynv_system_ref(dynv_namespace);
args->statusbar = (GtkWidget*)dynv_get_pointer_wd(gs->params, "StatusBar", 0);
color_source_init(&args->source, source->identificator, source->hr_name);
args->source.destroy = (int (*)(ColorSource *source))source_destroy;
args->source.get_color = (int (*)(ColorSource *source, ColorObject** color))source_get_color;
args->source.set_color = (int (*)(ColorSource *source, ColorObject* color))source_set_color;
args->source.deactivate = (int (*)(ColorSource *source))source_deactivate;
args->source.activate = (int (*)(ColorSource *source))source_activate;
GtkWidget *table, *vbox, *hbox, *widget, *hbox2;
hbox = gtk_hbox_new(FALSE, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 5);
args->color_previews = gtk_table_new(MAX_COLOR_LINES, VAR_COLOR_WIDGETS + 1, false);
gtk_box_pack_start(GTK_BOX(vbox), args->color_previews, true, true, 0);
struct DragDrop dd;
dragdrop_init(&dd, gs);
dd.userdata = args;
dd.get_color_object = get_color_object;
dd.set_color_object_at = set_color_object_at;
widget = gtk_color_new();
gtk_color_set_rounded(GTK_COLOR(widget), true);
gtk_color_set_hcenter(GTK_COLOR(widget), true);
gtk_color_set_roundness(GTK_COLOR(widget), 5);
gtk_table_attach(GTK_TABLE(args->color_previews), widget, VAR_COLOR_WIDGETS / 2, VAR_COLOR_WIDGETS / 2 + 1, 0, 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(0), 0, 0);
args->all_colors = widget;
g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(on_color_button_press), args);
g_signal_connect(G_OBJECT(widget), "activated", G_CALLBACK(on_color_activate), args);
g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_color_key_press), args);
g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(on_color_popup_menu), args);
g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(color_focus_in_cb), args);
//setup drag&drop
gtk_widget_set_size_request(widget, 50, 20);
gtk_drag_dest_set( widget, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)-1;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd);
for (intptr_t i = 0; i < MAX_COLOR_LINES; ++i){
for (intptr_t j = 0; j < VAR_COLOR_WIDGETS + 1; ++j){
widget = gtk_color_new();
gtk_color_set_rounded(GTK_COLOR(widget), true);
gtk_color_set_hcenter(GTK_COLOR(widget), true);
gtk_color_set_roundness(GTK_COLOR(widget), 5);
gtk_table_attach(GTK_TABLE(args->color_previews), widget, j, j + 1, i + 1, i + 2, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(0), 0, 0);
args->color[i].var_colors[j] = widget;
args->color[i].type = &variation_types[i];
g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(on_color_button_press), args);
g_signal_connect(G_OBJECT(widget), "activated", G_CALLBACK(on_color_activate), args);
g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_color_key_press), args);
g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(on_color_popup_menu), args);
g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(color_focus_in_cb), args);
//setup drag&drop
if (j == VAR_COLOR_WIDGETS / 2){
gtk_widget_set_size_request(widget, 50, 30);
gtk_drag_dest_set( widget, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)i;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd);
args->color[i].color = args->color[i].var_colors[j];
}else{
gtk_widget_set_size_request(widget, 30, 25);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)i;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE), &dd);
}
}
}
Color c;
color_set(&c, 0.5);
char tmp[32];
for (gint i = 0; i < MAX_COLOR_LINES; ++i){
sprintf(tmp, "type%d", i);
const char *type_name = dynv_get_string_wd(args->params, tmp, "lab_lightness");
for (uint32_t j = 0; j < sizeof(variation_types) / sizeof(VariationType); j++){
if (g_strcmp0(variation_types[j].unique_name, type_name)==0){
args->color[i].type = &variation_types[j];
break;
}
}
sprintf(tmp, "color%d", i);
gtk_color_set_color(GTK_COLOR(args->color[i].color), dynv_get_color_wdc(args->params, tmp, &c), args->color[i].type->symbol);
}
gtk_color_set_color(GTK_COLOR(args->all_colors), dynv_get_color_wdc(args->params, "all_colors", &c), "");
hbox2 = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, false, false, 0);
gint table_y;
table = gtk_table_new(5, 2, false);
gtk_box_pack_start(GTK_BOX(hbox2), table, true, true, 0);
table_y = 0;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Strength:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,0,0);
args->strength = gtk_hscale_new_with_range(1, 100, 1);
gtk_range_set_value(GTK_RANGE(args->strength), dynv_get_float_wd(args->params, "strength", 30));
g_signal_connect(G_OBJECT(args->strength), "value-changed", G_CALLBACK (update), args);
gtk_table_attach(GTK_TABLE(table), args->strength,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,0,0);
table_y++;
struct dynvHandlerMap* handler_map=dynv_system_get_handler_map(gs->colors->params);
struct ColorList* preview_color_list = color_list_new(handler_map);
dynv_handler_map_release(handler_map);
args->preview_color_list = preview_color_list;
//args->colors_visible = MAX_COLOR_WIDGETS;
args->gs = gs;
gtk_widget_show_all(hbox);
update(0, args);
args->main = hbox;
args->source.widget = hbox;
return (ColorSource*)args;
}
int variations_source_register(ColorSourceManager *csm){
ColorSource *color_source = new ColorSource;
color_source_init(color_source, "variations", _("Variations"));
color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement;
color_source->default_accelerator = GDK_v;
color_source_manager_add_source(csm, color_source);
return 0;
}
gpick_0.2.5/source/main.cpp 0000644 0001750 0001750 00000007645 12072045012 014342 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "main.h"
#include "Paths.h"
#include "uiAbout.h"
#include "uiApp.h"
#include "Internationalisation.h"
#include "version/Version.h"
#include "DynvHelpers.h"
#include
#include
using namespace std;
static gchar **commandline_filename = NULL;
static gchar *commandline_geometry = NULL;
static gboolean pick_color = FALSE;
static gboolean version_information = FALSE;
static GOptionEntry commandline_entries[] =
{
{ "geometry", 'g', 0, G_OPTION_ARG_STRING, &commandline_geometry, "Window geometry", "GEOMETRY" },
{ "pick", 'p', 0, G_OPTION_ARG_NONE, &pick_color, "Pick a color", NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version_information, "Print version information", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &commandline_filename, NULL, "[FILE...]" },
{ NULL }
};
int main(int argc, char **argv){
gtk_set_locale();
gtk_init(&argc, &argv);
initialize_internationalisation();
g_set_application_name(program_name);
gchar* tmp;
GtkIconTheme *icon_theme;
icon_theme = gtk_icon_theme_get_default ();
gtk_icon_theme_append_search_path(icon_theme, tmp=build_filename(0));
g_free(tmp);
GError *error = NULL;
GOptionContext *context;
context = g_option_context_new ("- advanced color picker");
g_option_context_add_main_entries (context, commandline_entries, 0);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
if (!g_option_context_parse (context, &argc, &argv, &error)){
g_print ("option parsing failed: %s\n", error->message);
return -1;
}
if (version_information){
string version = string(program_name) + " version " + string(gpick_build_version);
string revision = "Revision " + string(gpick_build_revision);
string build_date = "Built at " + string(gpick_build_date);
g_print ("%s\n%s\n%s\n", version.c_str(), revision.c_str(), build_date.c_str());
return 0;
}
AppOptions options;
options.floating_picker_mode = pick_color;
AppArgs *args = app_create_main(&options);
if (args){
if (commandline_filename){
app_load_file(args, commandline_filename[0]);
}else{
if (app_is_autoload_enabled(args)){
gchar* autosave_file = build_config_path("autosave.gpa");
app_load_file(args, autosave_file, true);
g_free(autosave_file);
}
}
if (commandline_geometry) app_parse_geometry(args, commandline_geometry);
int r = app_run(args);
if (r){
}
}
g_option_context_free(context);
return 0;
}
gpick_0.2.5/source/ColorMixer.cpp 0000644 0001750 0001750 00000062446 12113713537 015513 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ColorMixer.h"
#include "DragDrop.h"
#include "GlobalStateStruct.h"
#include "ToolColorNaming.h"
#include "uiUtilities.h"
#include "ColorList.h"
#include "MathUtil.h"
#include "ColorRYB.h"
#include "gtk/ColorWidget.h"
#include "gtk/ColorWheel.h"
#include "ColorWheelType.h"
#include "uiColorInput.h"
#include "CopyPaste.h"
#include "Converter.h"
#include "DynvHelpers.h"
#include "Internationalisation.h"
#include "uiApp.h"
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAX_COLOR_LINES 3
#define MODE_ID_NORMAL 1
#define MODE_ID_MULTIPLY 2
#define MODE_ID_DIFFERENCE 3
#define MODE_ID_ADD 4
#define MODE_ID_HUE 5
#define MODE_ID_SATURATION 6
#define MODE_ID_LIGHTNESS 7
typedef struct ColorMixerType{
const char *name;
const char *unique_name;
int mode_id;
}ColorMixerType;
const ColorMixerType color_mixer_types[] = {
{N_("Normal"), "normal", MODE_ID_NORMAL},
{N_("Multiply"), "multiply", MODE_ID_MULTIPLY},
{N_("Add"), "add", MODE_ID_ADD},
{N_("Difference"), "difference", MODE_ID_DIFFERENCE},
{N_("Hue"), "hue", MODE_ID_HUE},
{N_("Saturation"), "saturation", MODE_ID_SATURATION},
{N_("Lightness"), "lightness", MODE_ID_LIGHTNESS},
};
typedef struct ColorMixerArgs{
ColorSource source;
GtkWidget* main;
GtkWidget* statusbar;
GtkWidget *secondary_color;
GtkWidget *opacity;
GtkWidget *last_focused_color;
GtkWidget *color_previews;
const ColorMixerType *mixer_type;
struct{
GtkWidget *input;
GtkWidget *output;
}color[MAX_COLOR_LINES];
struct dynvSystem *params;
struct ColorList *preview_color_list;
GlobalState* gs;
}ColorMixerArgs;
class ColorMixerColorNameAssigner: public ToolColorNameAssigner {
protected:
stringstream m_stream;
const char *m_ident;
public:
ColorMixerColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){
}
void assign(struct ColorObject *color_object, Color *color, const char *ident){
m_ident = ident;
ToolColorNameAssigner::assign(color_object, color);
}
virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){
m_stream.str("");
m_stream << color_names_get(m_gs->color_names, color, false) << " " << _("color mixer") << " " << m_ident;
return m_stream.str();
}
};
static int set_rgb_color(ColorMixerArgs *args, struct ColorObject* color, uint32_t color_index);
static int set_rgb_color_by_widget(ColorMixerArgs *args, struct ColorObject* color, GtkWidget* color_widget);
static void calc(ColorMixerArgs *args, bool preview, bool save_settings){
double opacity = gtk_range_get_value(GTK_RANGE(args->opacity));
if (save_settings){
dynv_set_float(args->params, "opacity", opacity);
}
Color color, color2, r, hsv1, hsv2;
gtk_color_get_color(GTK_COLOR(args->secondary_color), &color2);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
gtk_color_get_color(GTK_COLOR(args->color[i].input), &color);
switch (args->mixer_type->mode_id){
case MODE_ID_NORMAL:
r.rgb.red = color2.rgb.red;
r.rgb.green = color2.rgb.green;
r.rgb.blue = color2.rgb.blue;
break;
case MODE_ID_MULTIPLY:
r.rgb.red = color.rgb.red * color2.rgb.red;
r.rgb.green = color.rgb.green * color2.rgb.green;
r.rgb.blue = color.rgb.blue * color2.rgb.blue;
break;
case MODE_ID_ADD:
r.rgb.red = clamp_float(color.rgb.red + color2.rgb.red, 0, 1);
r.rgb.green = clamp_float(color.rgb.green + color2.rgb.green, 0, 1);
r.rgb.blue = clamp_float(color.rgb.blue + color2.rgb.blue, 0, 1);
break;
case MODE_ID_DIFFERENCE:
r.rgb.red = fabs(color.rgb.red - color2.rgb.red);
r.rgb.green = fabs(color.rgb.green - color2.rgb.green);
r.rgb.blue = fabs(color.rgb.blue - color2.rgb.blue);
break;
case MODE_ID_HUE:
color_rgb_to_hsv(&color, &hsv1);
color_rgb_to_hsv(&color2, &hsv2);
hsv1.hsv.hue = hsv2.hsv.hue;
color_hsv_to_rgb(&hsv1, &r);
break;
case MODE_ID_SATURATION:
color_rgb_to_hsv(&color, &hsv1);
color_rgb_to_hsv(&color2, &hsv2);
hsv1.hsv.saturation = hsv2.hsv.saturation;
color_hsv_to_rgb(&hsv1, &r);
break;
case MODE_ID_LIGHTNESS:
color_rgb_to_hsl(&color, &hsv1);
color_rgb_to_hsl(&color2, &hsv2);
hsv1.hsl.lightness = hsv2.hsl.lightness;
color_hsl_to_rgb(&hsv1, &r);
break;
}
r.rgb.red = (color.rgb.red * (100 - opacity) + r.rgb.red * opacity) / 100;
r.rgb.green = (color.rgb.green * (100 - opacity) + r.rgb.green * opacity) / 100;
r.rgb.blue = (color.rgb.blue * (100 - opacity) + r.rgb.blue * opacity) / 100;
gtk_color_set_color(GTK_COLOR(args->color[i].output), &r, "");
}
}
static void update(GtkWidget *widget, ColorMixerArgs *args ){
color_list_remove_all(args->preview_color_list);
calc(args, true, false);
}
static void on_color_paste(GtkWidget *widget, gpointer item) {
ColorMixerArgs* args=(ColorMixerArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
struct ColorObject* color_object;
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
}
static void on_color_edit(GtkWidget *widget, gpointer item) {
ColorMixerArgs* args=(ColorMixerArgs*)item;
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
Color c;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
struct ColorObject* color_object = color_list_new_color_object(args->gs->colors, &c);
struct ColorObject* new_color_object = 0;
if (dialog_color_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs, color_object, &new_color_object )==0){
set_rgb_color_by_widget(args, new_color_object, color_widget);
color_object_release(new_color_object);
}
color_object_release(color_object);
}
static boost::format format_ignore_arg_errors(const std::string &f_string) {
boost::format fmter(f_string);
fmter.exceptions(boost::io::all_error_bits ^ (boost::io::too_many_args_bit | boost::io::too_few_args_bit));
return fmter;
}
static string identify_color_widget(GtkWidget *widget, ColorMixerArgs *args)
{
if (args->secondary_color == widget){
return _("secondary");
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].input == widget){
try{
return (format_ignore_arg_errors(_("primary %d")) % (i + 1)).str();
}catch(const boost::io::format_error &e){
return (format_ignore_arg_errors("primary %d") % (i + 1)).str();
}
}else if (args->color[i].output == widget){
try{
return (format_ignore_arg_errors(_("result %d")) % (i + 1)).str();
}catch(const boost::io::format_error &e){
return (format_ignore_arg_errors("result %d") % (i + 1)).str();
}
}
}
return "unknown";
}
static void add_color_to_palette(GtkWidget *color_widget, ColorMixerColorNameAssigner &name_assigner, ColorMixerArgs *args)
{
Color c;
struct ColorObject *color_object;
string widget_ident;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
widget_ident = identify_color_widget(color_widget, args);
name_assigner.assign(color_object, &c, widget_ident.c_str());
color_list_add_color_object(args->gs->colors, color_object, 1);
color_object_release(color_object);
}
static void on_color_add_to_palette(GtkWidget *widget, gpointer item) {
ColorMixerArgs* args = (ColorMixerArgs*)item;
GtkWidget *color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
ColorMixerColorNameAssigner name_assigner(args->gs);
add_color_to_palette(color_widget, name_assigner, args);
}
static void on_color_add_all_to_palette(GtkWidget *widget, gpointer item) {
ColorMixerArgs* args = (ColorMixerArgs*)item;
ColorMixerColorNameAssigner name_assigner(args->gs);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
add_color_to_palette(args->color[i].input, name_assigner, args);
}
add_color_to_palette(args->secondary_color, name_assigner, args);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
add_color_to_palette(args->color[i].output, name_assigner, args);
}
}
static gboolean color_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, ColorMixerArgs *args){
args->last_focused_color = widget;
return false;
}
static void on_color_activate(GtkWidget *widget, gpointer item) {
ColorMixerArgs* args=(ColorMixerArgs*)item;
ColorMixerColorNameAssigner name_assigner(args->gs);
add_color_to_palette(widget, name_assigner, args);
}
static void type_toggled_cb(GtkWidget *widget, ColorMixerArgs *args) {
GtkWidget* color_widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "color_widget"));
const ColorMixerType *mixer_type = static_cast(g_object_get_data(G_OBJECT(widget), "color_mixer_type"));
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))){
args->mixer_type = mixer_type;
Color c;
gtk_color_get_color(GTK_COLOR(color_widget), &c);
gtk_color_set_color(GTK_COLOR(args->secondary_color), &c, _(args->mixer_type->name));
update(0, args);
}
}
static void color_show_menu(GtkWidget* widget, ColorMixerArgs* args, GdkEventButton *event ){
GtkWidget *menu;
GtkWidget* item;
menu = gtk_menu_new ();
item = gtk_menu_item_new_with_image (_("_Add to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image (_("A_dd all to palette"), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_add_all_to_palette), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
item = gtk_menu_item_new_with_mnemonic (_("_Copy to clipboard"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
Color c;
gtk_color_get_color(GTK_COLOR(widget), &c);
struct ColorObject* color_object;
color_object = color_list_new_color_object(args->gs->colors, &c);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (color_object, 0, args->gs));
color_object_release(color_object);
int line_id = -1;
bool secondary_color = false;
if (args->secondary_color == widget){
secondary_color = true;
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].input == widget){
line_id = i;
}
}
if (line_id >= 0 || secondary_color){
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
if (secondary_color){
GSList *group = 0;
for (uint32_t i = 0; i < sizeof(color_mixer_types) / sizeof(ColorMixerType); i++){
item = gtk_radio_menu_item_new_with_label(group, _(color_mixer_types[i].name));
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
if (args->mixer_type == &color_mixer_types[i]){
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), true);
}
g_object_set_data(G_OBJECT(item), "color_widget", widget);
g_object_set_data(G_OBJECT(item), "color_mixer_type", (void*)&color_mixer_types[i]);
g_signal_connect(G_OBJECT(item), "toggled", G_CALLBACK(type_toggled_cb), args);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
}
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
}
item = gtk_menu_item_new_with_image (_("_Edit..."), gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_edit), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
item = gtk_menu_item_new_with_image (_("_Paste"), gtk_image_new_from_stock(GTK_STOCK_PASTE, GTK_ICON_SIZE_MENU));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (on_color_paste), args);
g_object_set_data(G_OBJECT(item), "color_widget", widget);
if (copypaste_is_color_object_available(args->gs)!=0){
gtk_widget_set_sensitive(item, false);
}
}
gtk_widget_show_all (GTK_WIDGET(menu));
gint32 button, event_time;
if (event){
button = event->button;
event_time = event->time;
}else{
button = 0;
event_time = gtk_get_current_event_time ();
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time);
g_object_ref_sink(menu);
g_object_unref(menu);
}
static gboolean on_color_button_press (GtkWidget *widget, GdkEventButton *event, ColorMixerArgs* args) {
if (event->button == 3 && event->type == GDK_BUTTON_PRESS){
color_show_menu(widget, args, event);
}
return false;
}
static void on_color_popup_menu(GtkWidget *widget, ColorMixerArgs* args){
color_show_menu(widget, args, 0);
}
static gboolean on_color_key_press (GtkWidget *widget, GdkEventKey *event, ColorMixerArgs* args){
guint modifiers = gtk_accelerator_get_default_mod_mask();
Color c;
struct ColorObject* color_object;
GtkWidget* color_widget = widget;
switch(event->keyval){
case GDK_c:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
gtk_color_get_color(GTK_COLOR(color_widget), &c);
color_object = color_list_new_color_object(args->gs->colors, &c);
Converters *converters = (Converters*)dynv_get_pointer_wd(args->gs->params, "Converters", 0);
Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COPY);
if (converter){
converter_get_clipboard(converter->function_name, color_object, 0, args->gs->params);
}
color_object_release(color_object);
return true;
}
return false;
break;
case GDK_v:
if ((event->state&modifiers)==GDK_CONTROL_MASK){
if (copypaste_get_color_object(&color_object, args->gs)==0){
set_rgb_color_by_widget(args, color_object, color_widget);
color_object_release(color_object);
}
return true;
}
return false;
break;
default:
return false;
break;
}
return false;
}
static int source_destroy(ColorMixerArgs *args){
Color c;
char tmp[32];
dynv_set_string(args->params, "mixer_type", args->mixer_type->unique_name);
for (gint i = 0; i < MAX_COLOR_LINES; ++i){
sprintf(tmp, "color%d", i);
gtk_color_get_color(GTK_COLOR(args->color[i].input), &c);
dynv_set_color(args->params, tmp, &c);
}
gtk_color_get_color(GTK_COLOR(args->secondary_color), &c);
dynv_set_color(args->params, "secondary_color", &c);
color_list_destroy(args->preview_color_list);
dynv_system_release(args->params);
gtk_widget_destroy(args->main);
delete args;
return 0;
}
static int source_get_color(ColorMixerArgs *args, ColorObject** color){
ColorMixerColorNameAssigner name_assigner(args->gs);
Color c;
string widget_ident;
if (args->last_focused_color){
gtk_color_get_color(GTK_COLOR(args->last_focused_color), &c);
widget_ident = identify_color_widget(args->last_focused_color, args);
}else{
gtk_color_get_color(GTK_COLOR(args->color[0].input), &c);
widget_ident = identify_color_widget(args->color[0].input, args);
}
*color = color_list_new_color_object(args->gs->colors, &c);
name_assigner.assign(*color, &c, widget_ident.c_str());
return 0;
}
static int set_rgb_color_by_widget(ColorMixerArgs *args, struct ColorObject* color_object, GtkWidget* color_widget){
if (args->secondary_color == color_widget){
set_rgb_color(args, color_object, -1);
return 0;
}else for (int i = 0; i < MAX_COLOR_LINES; ++i){
if (args->color[i].input == color_widget){
set_rgb_color(args, color_object, i);
return 0;
}else if (args->color[i].output == color_widget){
set_rgb_color(args, color_object, i);
return 0;
}
}
return -1;
}
static int set_rgb_color(ColorMixerArgs *args, struct ColorObject* color, uint32_t color_index){
Color c;
color_object_get_color(color, &c);
if (color_index == (uint32_t)-1){
gtk_color_set_color(GTK_COLOR(args->secondary_color), &c, _(args->mixer_type->name));
}else{
gtk_color_set_color(GTK_COLOR(args->color[color_index].input), &c, "");
}
update(0, args);
return 0;
}
static int source_set_color(ColorMixerArgs *args, struct ColorObject* color){
if (args->last_focused_color){
return set_rgb_color_by_widget(args, color, args->last_focused_color);
}else{
return set_rgb_color(args, color, 0);
}
}
static int source_activate(ColorMixerArgs *args){
transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0));
gtk_color_set_transformation_chain(GTK_COLOR(args->secondary_color), chain);
for (int i = 0; i < MAX_COLOR_LINES; ++i){
gtk_color_set_transformation_chain(GTK_COLOR(args->color[i].input), chain);
gtk_color_set_transformation_chain(GTK_COLOR(args->color[i].output), chain);
}
gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "empty"), "");
return 0;
}
static int source_deactivate(ColorMixerArgs *args){
color_list_remove_all(args->preview_color_list);
calc(args, true, true);
return 0;
}
static struct ColorObject* get_color_object(struct DragDrop* dd){
ColorMixerArgs* args = (ColorMixerArgs*)dd->userdata;
struct ColorObject* colorobject;
if (source_get_color(args, &colorobject) == 0){
return colorobject;
}
return 0;
}
static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){
ColorMixerArgs* args = static_cast(dd->userdata);
set_rgb_color(args, colorobject, (uintptr_t)dd->userdata2);
return 0;
}
static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){
ColorMixerArgs* args = new ColorMixerArgs;
args->params = dynv_system_ref(dynv_namespace);
args->statusbar = (GtkWidget*)dynv_get_pointer_wd(gs->params, "StatusBar", 0);
color_source_init(&args->source, source->identificator, source->hr_name);
args->source.destroy = (int (*)(ColorSource *source))source_destroy;
args->source.get_color = (int (*)(ColorSource *source, ColorObject** color))source_get_color;
args->source.set_color = (int (*)(ColorSource *source, ColorObject* color))source_set_color;
args->source.deactivate = (int (*)(ColorSource *source))source_deactivate;
args->source.activate = (int (*)(ColorSource *source))source_activate;
GtkWidget *table, *vbox, *hbox, *widget, *hbox2;
hbox = gtk_hbox_new(FALSE, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 5);
args->color_previews = gtk_table_new(MAX_COLOR_LINES, 3, false);
gtk_box_pack_start(GTK_BOX(vbox), args->color_previews, true, true, 0);
struct DragDrop dd;
dragdrop_init(&dd, gs);
dd.userdata = args;
dd.get_color_object = get_color_object;
dd.set_color_object_at = set_color_object_at;
widget = gtk_color_new();
gtk_color_set_rounded(GTK_COLOR(widget), true);
gtk_color_set_hcenter(GTK_COLOR(widget), true);
gtk_color_set_roundness(GTK_COLOR(widget), 5);
gtk_table_attach(GTK_TABLE(args->color_previews), widget, 1, 2, 0, 3, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 0, 0);
args->secondary_color = widget;
g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(on_color_button_press), args);
g_signal_connect(G_OBJECT(widget), "activated", G_CALLBACK(on_color_activate), args);
g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_color_key_press), args);
g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(on_color_popup_menu), args);
g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(color_focus_in_cb), args);
gtk_widget_set_size_request(widget, 50, 50);
//setup drag&drop
gtk_drag_dest_set( widget, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)-1;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd);
for (intptr_t i = 0; i < MAX_COLOR_LINES; ++i){
for (intptr_t j = 0; j < 2; ++j){
widget = gtk_color_new();
gtk_color_set_rounded(GTK_COLOR(widget), true);
gtk_color_set_hcenter(GTK_COLOR(widget), true);
gtk_color_set_roundness(GTK_COLOR(widget), 5);
gtk_table_attach(GTK_TABLE(args->color_previews), widget, j * 2, j * 2 + 1, i, i + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(0), 0, 0);
if (j){
args->color[i].output = widget;
}else{
args->color[i].input = widget;
}
g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(on_color_button_press), args);
g_signal_connect(G_OBJECT(widget), "activated", G_CALLBACK(on_color_activate), args);
g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_color_key_press), args);
g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(on_color_popup_menu), args);
g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(color_focus_in_cb), args);
if (j == 0){
//setup drag&drop
gtk_widget_set_size_request(widget, 30, 30);
gtk_drag_dest_set( widget, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)i;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd);
}else{
gtk_widget_set_size_request(widget, 30, 30);
gtk_drag_source_set( widget, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY);
dd.handler_map = dynv_system_get_handler_map(gs->colors->params);
dd.userdata2 = (void*)i;
dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE), &dd);
}
}
}
Color c;
color_set(&c, 0.5);
char tmp[32];
const char *type_name = dynv_get_string_wd(args->params, "mixer_type", "normal");
for (uint32_t j = 0; j < sizeof(color_mixer_types) / sizeof(ColorMixerType); j++){
if (g_strcmp0(color_mixer_types[j].unique_name, type_name)==0){
args->mixer_type = &color_mixer_types[j];
break;
}
}
for (gint i = 0; i < MAX_COLOR_LINES; ++i){
sprintf(tmp, "color%d", i);
gtk_color_set_color(GTK_COLOR(args->color[i].input), dynv_get_color_wdc(args->params, tmp, &c), "");
}
gtk_color_set_color(GTK_COLOR(args->secondary_color), dynv_get_color_wdc(args->params, "secondary_color", &c), _(args->mixer_type->name));
hbox2 = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, false, false, 0);
gint table_y;
table = gtk_table_new(5, 2, false);
gtk_box_pack_start(GTK_BOX(hbox2), table, true, true, 0);
table_y = 0;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Opacity:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,0,0);
args->opacity = gtk_hscale_new_with_range(1, 100, 1);
gtk_range_set_value(GTK_RANGE(args->opacity), dynv_get_float_wd(args->params, "opacity", 50));
g_signal_connect(G_OBJECT(args->opacity), "value-changed", G_CALLBACK (update), args);
gtk_table_attach(GTK_TABLE(table), args->opacity, 1, 2, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL,0,0);
table_y++;
struct dynvHandlerMap* handler_map=dynv_system_get_handler_map(gs->colors->params);
struct ColorList* preview_color_list = color_list_new(handler_map);
dynv_handler_map_release(handler_map);
args->preview_color_list = preview_color_list;
//args->colors_visible = MAX_COLOR_WIDGETS;
args->gs = gs;
gtk_widget_show_all(hbox);
update(0, args);
args->main = hbox;
args->source.widget = hbox;
return (ColorSource*)args;
}
int color_mixer_source_register(ColorSourceManager *csm){
ColorSource *color_source = new ColorSource;
color_source_init(color_source, "color_mixer", _("Color mixer"));
color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement;
color_source->default_accelerator = GDK_m;
color_source_manager_add_source(csm, color_source);
return 0;
}
gpick_0.2.5/source/uiExport.h 0000644 0001750 0001750 00000004334 12070605214 014676 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UIEXPORT_H_
#define UIEXPORT_H_
#include
#include
#include "GlobalState.h"
int32_t palette_export_gpl(struct ColorList *color_list, const gchar* filename, gboolean selected);
int32_t palette_import_gpl(struct ColorList *color_list, const gchar* filename);
int32_t palette_export_ase(struct ColorList *color_list, const gchar* filename, gboolean selected);
int32_t palette_import_ase(struct ColorList *color_list, const gchar* filename);
int dialog_export_show(GtkWindow* parent, struct ColorList *selected_color_list, gboolean selected, GlobalState *gs);
int dialog_import_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState *gs);
#endif /* UIEXPORT_H_ */
gpick_0.2.5/source/Random.cpp 0000644 0001750 0001750 00000006671 12070605214 014640 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Random.h"
#include
static unsigned long random_function_znew(struct Random* r, unsigned long seed_offset) {
return (r->seed[seed_offset] = 36969 * (r->seed[seed_offset] & 65535) + (r->seed[seed_offset] >> 16));
}
static unsigned long random_function_wnew(struct Random* r, unsigned long seed_offset) {
return (r->seed[seed_offset] = 18000 * (r->seed[seed_offset] & 65535) + (r->seed[seed_offset] >> 16));
}
static unsigned long random_function_MWC(struct Random* r, unsigned long seed_offset) {
return (random_function_znew(r, 0)<<16) + random_function_wnew(r, 1);
}
static unsigned long random_function_SHR3(struct Random* r, unsigned long seed_offset) {
r->seed[seed_offset] ^= r->seed[seed_offset] << 17;
r->seed[seed_offset] ^= (r->seed[seed_offset]&0xFFFFFFFF) >> 13;
return (r->seed[seed_offset] ^= r->seed[seed_offset] << 5);
}
struct Random* random_new(const char* random_function){
struct Random* r=new struct Random;
struct RandomFunction{
const char* name;
unsigned long (*function)(struct Random* r, unsigned long seed_offset);
unsigned long seed_size;
};
struct RandomFunction functions[]={
{"znew", random_function_znew, 1},
{"wnew", random_function_wnew, 1},
{"MWC", random_function_MWC, 2},
{"SHR3", random_function_SHR3, 1},
};
int found=0;
for (unsigned long i=0; ifunction= functions[i].function;
r->seed_size=functions[i].seed_size;
r->seed=new unsigned long [r->seed_size];
found=1;
break;
}
}
if (found) return r;
delete r;
return 0;
}
unsigned long random_get(struct Random* r){
if (!r) return 0;
return r->function(r, 0);
}
void random_seed(struct Random* r, void* seed){
if (!r) return;
memcpy(r->seed, seed, r->seed_size*sizeof(unsigned long));
}
void random_destroy(struct Random* r){
if (r){
delete [] r->seed;
delete r;
}
}
gpick_0.2.5/source/LuaExt.cpp 0000644 0001750 0001750 00000025543 12113713537 014627 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "LuaExt.h"
#include
#include "Internationalisation.h"
#include
using namespace std;
static int lua_newcolor (lua_State *L) {
Color *c = (Color*)lua_newuserdata(L, sizeof(Color));
luaL_getmetatable(L, "color");
lua_setmetatable(L, -2);
if (lua_type(L, 2)==LUA_TNUMBER && lua_type(L, 3)==LUA_TNUMBER && lua_type(L, 4)==LUA_TNUMBER ){
c->rgb.red = luaL_checknumber(L, 2);
c->rgb.green = luaL_checknumber(L, 3);
c->rgb.blue = luaL_checknumber(L, 4);
}else{
color_zero(c);
}
return 1;
}
Color *lua_checkcolor (lua_State *L, int index) {
void *ud = luaL_checkudata(L, index, "color");
luaL_argcheck(L, ud != NULL, index, "`color' expected");
return (Color *)ud;
}
int lua_pushcolor (lua_State *L, const Color* color) {
Color *c = (Color*)lua_newuserdata(L, sizeof(Color));
luaL_getmetatable(L, "color");
lua_setmetatable(L, -2);
color_copy(color, c);
return 1;
}
static int lua_color2string (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
lua_pushfstring(L, "color(%f, %f, %f)", c->rgb.red, c->rgb.green, c->rgb.blue);
return 1;
}
static int lua_color_rgb (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER && lua_type(L, 3)==LUA_TNUMBER && lua_type(L, 4)==LUA_TNUMBER ){
c->rgb.red = luaL_checknumber(L, 2);
c->rgb.green = luaL_checknumber(L, 3);
c->rgb.blue = luaL_checknumber(L, 4);
}
lua_pushnumber(L, c->rgb.red);
lua_pushnumber(L, c->rgb.green);
lua_pushnumber(L, c->rgb.blue);
return 3;
}
static int lua_color_red (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->rgb.red=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->rgb.red);
return 1;
}
static int lua_color_green (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->rgb.green=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->rgb.green);
return 1;
}
static int lua_color_blue (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->rgb.blue=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->rgb.blue);
return 1;
}
static int lua_color_hsl (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER && lua_type(L, 3)==LUA_TNUMBER && lua_type(L, 4)==LUA_TNUMBER ){
c->hsl.hue = luaL_checknumber(L, 2);
c->hsl.saturation = luaL_checknumber(L, 3);
c->hsl.lightness = luaL_checknumber(L, 4);
}
lua_pushnumber(L, c->hsl.hue);
lua_pushnumber(L, c->hsl.saturation);
lua_pushnumber(L, c->hsl.lightness);
return 3;
}
static int lua_color_hue (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->hsl.hue=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->hsl.hue);
return 1;
}
static int lua_color_saturation (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->hsl.saturation=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->hsl.saturation);
return 1;
}
static int lua_color_lightness (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->hsl.lightness=luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->hsl.lightness);
return 1;
}
static int lua_color_cmyk (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER && lua_type(L, 3)==LUA_TNUMBER && lua_type(L, 4)==LUA_TNUMBER && lua_type(L, 5)==LUA_TNUMBER ){
c->cmyk.c = luaL_checknumber(L, 2);
c->cmyk.m = luaL_checknumber(L, 3);
c->cmyk.y = luaL_checknumber(L, 4);
c->cmyk.k = luaL_checknumber(L, 5);
}
lua_pushnumber(L, c->cmyk.c);
lua_pushnumber(L, c->cmyk.m);
lua_pushnumber(L, c->cmyk.y);
lua_pushnumber(L, c->cmyk.k);
return 4;
}
static int lua_color_cyan (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->cmyk.c = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->cmyk.c);
return 1;
}
static int lua_color_magenta (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->cmyk.m = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->cmyk.m);
return 1;
}
static int lua_color_yellow (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->cmyk.y = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->cmyk.y);
return 1;
}
static int lua_color_key_black (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->cmyk.k = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->cmyk.k);
return 1;
}
static int lua_color_lab_lightness (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lab.L = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lab.L);
return 1;
}
static int lua_color_lab_a (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lab.a = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lab.a);
return 1;
}
static int lua_color_lab_b (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lab.b = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lab.b);
return 1;
}
static int lua_color_rgb_to_hsl (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
Color c2;
color_rgb_to_hsl(c, &c2);
lua_pushcolor(L, &c2);
return 1;
}
static int lua_color_hsl_to_rgb (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
Color c2;
color_hsl_to_rgb(c, &c2);
lua_pushcolor(L, &c2);
return 1;
}
static int lua_color_rgb_to_cmyk (lua_State *L) {
Color *c = lua_checkcolor(L, 1);
Color c2, c3;
color_rgb_to_cmy(c, &c3);
color_cmy_to_cmyk(&c3, &c2);
lua_pushcolor(L, &c2);
return 1;
}
static int lua_color_lch_lightness(lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lch.L = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lch.L);
return 1;
}
static int lua_color_lch_chroma(lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lch.C = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lch.C);
return 1;
}
static int lua_color_lch_hue(lua_State *L) {
Color *c = lua_checkcolor(L, 1);
if (lua_type(L, 2)==LUA_TNUMBER){
c->lch.h = luaL_checknumber(L, 2);
}
lua_pushnumber(L, c->lch.h);
return 1;
}
static const struct luaL_Reg lua_colorlib_f [] = {
{"new", lua_newcolor},
{NULL, NULL}
};
static const struct luaL_Reg lua_colorlib_m [] = {
{"__tostring", lua_color2string},
{"red", lua_color_red},
{"green", lua_color_green},
{"blue", lua_color_blue},
{"rgb", lua_color_rgb},
{"hue", lua_color_hue},
{"saturation", lua_color_saturation},
{"lightness", lua_color_lightness},
{"value", lua_color_lightness},
{"hsl", lua_color_hsl},
{"cyan", lua_color_cyan},
{"magenta", lua_color_magenta},
{"yellow", lua_color_yellow},
{"key_black", lua_color_key_black},
{"cmyk", lua_color_cmyk},
{"lab_lightness", lua_color_lab_lightness},
{"lab_a", lua_color_lab_a},
{"lab_b", lua_color_lab_b},
{"lch_lightness", lua_color_lch_lightness},
{"lch_chroma", lua_color_lch_chroma},
{"lch_hue", lua_color_lch_hue},
{"rgb_to_hsl", lua_color_rgb_to_hsl},
{"hsl_to_rgb", lua_color_hsl_to_rgb},
{"rgb_to_cmyk", lua_color_rgb_to_cmyk},
{NULL, NULL}
};
static int luaopen_color(lua_State *L) {
luaL_newmetatable(L, "color");
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaL_setfuncs(L, lua_colorlib_m, 0);
lua_pop(L, 1);
luaL_newlibtable(L, lua_colorlib_f);
luaL_setfuncs(L, lua_colorlib_f, 0);
lua_setglobal(L, "color");
return 1;
}
static int lua_newcolorobject (lua_State *L) {
struct ColorObject** c = (struct ColorObject**)lua_newuserdata(L, sizeof(struct ColorObject*));
luaL_getmetatable(L, "colorobject");
lua_setmetatable(L, -2);
*c=NULL;
return 1;
}
struct ColorObject** lua_checkcolorobject (lua_State *L, int index) {
void *ud = luaL_checkudata(L, index, "colorobject");
luaL_argcheck(L, ud != NULL, index, "`colorobject' expected");
return (struct ColorObject **)ud;
}
int lua_pushcolorobject (lua_State *L, struct ColorObject* color_object) {
struct ColorObject** c = (struct ColorObject**)lua_newuserdata(L, sizeof(struct ColorObject*));
luaL_getmetatable(L, "colorobject");
lua_setmetatable(L, -2);
*c=color_object;
return 1;
}
int lua_colorobject_get_color(lua_State *L) {
struct ColorObject** color_object=lua_checkcolorobject(L, 1);
Color tmp;
color_object_get_color(*color_object, &tmp);
lua_pushcolor(L, &tmp);
return 1;
}
int lua_colorobject_set_color(lua_State *L) {
struct ColorObject** color_object=lua_checkcolorobject(L, 1);
Color *c = lua_checkcolor(L, 2);
color_object_set_color(*color_object, c);
return 0;
}
static const struct luaL_Reg lua_colorobjectlib_f [] = {
{"new", lua_newcolorobject},
{NULL, NULL}
};
static const struct luaL_Reg lua_colorobjectlib_m [] = {
{"get_color", lua_colorobject_get_color},
{"set_color", lua_colorobject_set_color},
{NULL, NULL}
};
int luaopen_colorobject (lua_State *L) {
luaL_newmetatable(L, "colorobject");
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaL_setfuncs(L, lua_colorobjectlib_m, 0);
lua_pop(L, 1);
luaL_newlibtable(L, lua_colorobjectlib_f);
luaL_setfuncs(L, lua_colorobjectlib_f, 0);
lua_setglobal(L, "colorobject");
return 1;
}
int lua_i18n_gettext(lua_State *L)
{
const char *text = luaL_checkstring(L, 1);
lua_pushstring(L, _(text));
return 1;
}
int luaopen_i18n(lua_State *L)
{
lua_pushcclosure(L, lua_i18n_gettext, 0);
lua_setglobal(L, "_");
return 1;
}
int lua_ext_colors_openlib(lua_State *L){
luaopen_color(L);
luaopen_colorobject(L);
luaopen_i18n(L);
return 0;
}
gpick_0.2.5/source/LayoutPreview.h 0000644 0001750 0001750 00000003300 12070605214 015666 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LAYOUTPREVIEW_H_
#define LAYOUTPREVIEW_H_
#include "ColorSourceManager.h"
int layout_preview_source_register(ColorSourceManager *csm);
#endif /* LAYOUTPREVIEW_H_ */
gpick_0.2.5/source/uiDialogVariations.cpp 0000644 0001750 0001750 00000025060 12070605214 017206 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "uiDialogVariations.h"
#include "uiListPalette.h"
#include "uiUtilities.h"
#include "MathUtil.h"
#include "DynvHelpers.h"
#include "GlobalStateStruct.h"
#include "ToolColorNaming.h"
#include "Internationalisation.h"
#include
using namespace std;
typedef struct DialogVariationsArgs{
GtkWidget *toggle_multiplication;
GtkWidget *range_lightness_from, *range_lightness_to, *range_steps;
GtkWidget *range_saturation_from, *range_saturation_to;
struct ColorList *selected_color_list;
struct ColorList *preview_color_list;
struct dynvSystem *params;
GlobalState* gs;
}DialogVariationsArgs;
class VariationsColorNameAssigner: public ToolColorNameAssigner {
protected:
stringstream m_stream;
const char *m_name;
uint32_t m_step_i;
public:
VariationsColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){}
void assign(struct ColorObject *color_object, Color *color, const char *name, uint32_t step_i){
m_name = name;
m_step_i = step_i;
ToolColorNameAssigner::assign(color_object, color);
}
virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){
m_stream.str("");
m_stream << m_name << " " << _("variation") << " " << m_step_i;
return m_stream.str();
}
};
static void calc( DialogVariationsArgs *args, bool preview, int limit){
gint steps = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->range_steps));
gfloat lightness_from = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_lightness_from));
gfloat lightness_to = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_lightness_to));
gfloat saturation_from = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_saturation_from));
gfloat saturation_to = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_saturation_to));
gboolean multiplication = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_multiplication));
if (!preview){
dynv_set_int32(args->params, "steps", steps);
dynv_set_float(args->params, "lightness_from", lightness_from);
dynv_set_float(args->params, "lightness_to", lightness_to);
dynv_set_float(args->params, "saturation_from", saturation_from);
dynv_set_float(args->params, "saturation_to", saturation_to);
dynv_set_bool(args->params, "multiplication", multiplication);
}
Color r, hsl;
gint step_i;
struct ColorList *color_list;
if (preview)
color_list = args->preview_color_list;
else
color_list = args->gs->colors;
VariationsColorNameAssigner name_assigner(args->gs);
for (ColorList::iter i=args->selected_color_list->colors.begin(); i!=args->selected_color_list->colors.end(); ++i){
Color in;
color_object_get_color(*i, &in);
const char* name = dynv_get_string_wd((*i)->params, "name", 0);
for (step_i = 0; step_i < steps; ++step_i) {
if (preview){
if (limit <= 0) return;
limit--;
}
color_rgb_to_hsl(&in, &hsl);
if (multiplication){
hsl.hsl.saturation *= mix_float(saturation_from, saturation_to, (step_i / (float) (steps - 1)));
hsl.hsl.lightness *= mix_float(lightness_from, lightness_to, (step_i / (float) (steps - 1)));
}else{
hsl.hsl.saturation += mix_float(saturation_from, saturation_to, (step_i / (float) (steps - 1)));
hsl.hsl.lightness += mix_float(lightness_from, lightness_to, (step_i / (float) (steps - 1)));
}
hsl.hsl.saturation = clamp_float(hsl.hsl.saturation, 0, 1);
hsl.hsl.lightness = clamp_float(hsl.hsl.lightness, 0, 1);
color_hsl_to_rgb(&hsl, &r);
struct ColorObject *color_object = color_list_new_color_object(color_list, &r);
name_assigner.assign(color_object, &r, name, step_i);
color_list_add_color_object(color_list, color_object, 1);
color_object_release(color_object);
}
}
}
static void update(GtkWidget *widget, DialogVariationsArgs *args ){
color_list_remove_all(args->preview_color_list);
calc(args, true, 100);
}
void dialog_variations_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState* gs) {
DialogVariationsArgs *args = new DialogVariationsArgs;
args->gs = gs;
args->params = dynv_get_dynv(args->gs->params, "gpick.variations");
GtkWidget *table, *toggle_multiplication;
GtkWidget *range_lightness_from, *range_lightness_to, *range_steps;
GtkWidget *range_saturation_from, *range_saturation_to;
GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Variations"), parent, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
gtk_window_set_default_size(GTK_WINDOW(dialog), dynv_get_int32_wd(args->params, "window.width", -1),
dynv_get_int32_wd(args->params, "window.height", -1));
gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1);
gint table_y;
table = gtk_table_new(5, 3, FALSE);
table_y=0;
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Lightness:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
range_lightness_from = gtk_spin_button_new_with_range (-100,100,0.001);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(range_lightness_from), dynv_get_float_wd(args->params, "lightness_from", 1));
gtk_table_attach(GTK_TABLE(table), range_lightness_from,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
args->range_lightness_from = range_lightness_from;
g_signal_connect (G_OBJECT (range_lightness_from), "value-changed", G_CALLBACK (update), args);
range_lightness_to = gtk_spin_button_new_with_range (-100,100,0.001);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(range_lightness_to), dynv_get_float_wd(args->params, "lightness_to", 1));
gtk_table_attach(GTK_TABLE(table), range_lightness_to,2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
args->range_lightness_to = range_lightness_to;
g_signal_connect (G_OBJECT (range_lightness_to), "value-changed", G_CALLBACK (update), args);
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Saturation:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
range_saturation_from = gtk_spin_button_new_with_range (-100,100,0.001);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(range_saturation_from), dynv_get_float_wd(args->params, "saturation_from", 0));
gtk_table_attach(GTK_TABLE(table), range_saturation_from,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
args->range_saturation_from = range_saturation_from;
g_signal_connect (G_OBJECT (range_saturation_from), "value-changed", G_CALLBACK (update), args);
range_saturation_to = gtk_spin_button_new_with_range (-100,100,0.001);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(range_saturation_to), dynv_get_float_wd(args->params, "saturation_to", 1));
gtk_table_attach(GTK_TABLE(table), range_saturation_to,2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
args->range_saturation_to = range_saturation_to;
g_signal_connect (G_OBJECT (range_saturation_to), "value-changed", G_CALLBACK (update), args);
gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Steps:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5);
range_steps = gtk_spin_button_new_with_range (3,255,1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(range_steps), dynv_get_int32_wd(args->params, "steps", 3));
gtk_table_attach(GTK_TABLE(table), range_steps,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
args->range_steps = range_steps;
g_signal_connect (G_OBJECT (range_steps), "value-changed", G_CALLBACK (update), args);
toggle_multiplication = gtk_check_button_new_with_mnemonic (_("_Use multiplication"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_multiplication), dynv_get_bool_wd(args->params, "multiplication", true));
gtk_table_attach(GTK_TABLE(table), toggle_multiplication,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0);
table_y++;
args->toggle_multiplication = toggle_multiplication;
g_signal_connect (G_OBJECT (toggle_multiplication), "toggled", G_CALLBACK (update), args);
GtkWidget* preview_expander;
struct ColorList* preview_color_list=NULL;
gtk_table_attach(GTK_TABLE(table), preview_expander=palette_list_preview_new(gs, true, dynv_get_bool_wd(args->params, "show_preview", true), gs->colors, &preview_color_list), 0, 3, table_y, table_y+1 , GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 5, 5);
table_y++;
args->selected_color_list = selected_color_list;
args->preview_color_list = preview_color_list;
update(0, args);
gtk_widget_show_all(table);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) calc(args, false, 0);
gint width, height;
gtk_window_get_size(GTK_WINDOW(dialog), &width, &height);
dynv_set_int32(args->params, "window.width", width);
dynv_set_int32(args->params, "window.height", height);
dynv_set_bool(args->params, "show_preview", gtk_expander_get_expanded(GTK_EXPANDER(preview_expander)));
gtk_widget_destroy(dialog);
color_list_destroy(args->preview_color_list);
dynv_system_release(args->params);
delete args;
}
gpick_0.2.5/source/Variations.h 0000644 0001750 0001750 00000003264 12070605214 015177 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef VARIATIONS_H_
#define VARIATIONS_H_
#include "ColorSourceManager.h"
int variations_source_register(ColorSourceManager *csm);
#endif /* VARIATIONS_H_ */
gpick_0.2.5/source/BezierCubicCurve.h 0000644 0001750 0001750 00000004150 12070605214 016246 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BEZIERCUBICCURVE_H_
#define BEZIERCUBICCURVE_H_
namespace math{
template
class BezierCubicCurve{
public:
BezierCubicCurve(const PT &p0_, const PT &p1_, const PT &p2_, const PT &p3_):p0(p0_),p1(p1_),p2(p2_),p3(p3_){
};
PT operator() (const T &t){
T t2 = 1-t;
return p0*(t2*t2*t2) + p1*(3*(t2*t2)*t) + p2*(3*t2*t*t) + p3*(t*t*t);
};
BezierCubicCurve& operator= (const BezierCubicCurve& curve){
p0 = curve.p0;
p1 = curve.p1;
p2 = curve.p2;
p3 = curve.p3;
return *this;
};
PT p0;
PT p1;
PT p2;
PT p3;
};
}
#endif /* BEZIERCUBICCURVE_H_ */
gpick_0.2.5/source/ColorSourceManager.cpp 0000644 0001750 0001750 00000005401 12070605214 017140 0 ustar zbyg zbyg /*
* Copyright (c) 2009-2012, Albertas Vyšniauskas
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ColorSourceManager.h"
#include
#include
using namespace std;
ColorSourceManager* color_source_manager_create(){
ColorSourceManager *csm = new ColorSourceManager;
return csm;
}
int color_source_manager_add_source(ColorSourceManager *csm, ColorSource *source){
pair