gpick_0.2.5/SConscript0000644000175000017500000001563212113713537013431 0ustar zbygzbyg#!/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.svg0000644000175000017500000000755012070605213015337 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/gpick.svg0000644000175000017500000002255512070605213014021 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/falloff-cubic.svg0000644000175000017500000000777312070605213015425 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/falloff-linear.svg0000644000175000017500000001016112070605213015573 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/falloff-none.svg0000644000175000017500000000742512070605213015271 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/falloff-quadratic.svg0000644000175000017500000000776512070605213016316 0ustar zbygzbyg image/svg+xml gpick_0.2.5/res/falloff-exponential.svg0000644000175000017500000001020212070605213016643 0ustar zbygzbyg image/svg+xml gpick_0.2.5/source/ColorWheelType.h0000644000175000017500000000540312070605214015762 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000002031312070605214015040 0ustar zbygzbyg/* * 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.h0000644000175000017500000000343712070605214016657 0ustar zbygzbyg/* * 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.h0000644000175000017500000000333112070605214016656 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000010363012070605214016270 0ustar zbygzbyg/* * 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.h0000644000175000017500000000364412070605214015514 0ustar zbygzbyg/* * 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.h0000644000175000017500000000423212070605214014133 0ustar zbygzbyg/* * 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.h0000644000175000017500000000502012070605214014374 0ustar zbygzbyg/* * 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/SConscript0000644000175000017500000000372012113713537014724 0ustar zbygzbyg#!/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.cpp0000644000175000017500000000775612070605214015664 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000006416612113713537015550 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000000764512072045012014342 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000006244612113713537015513 0ustar zbygzbyg/* * 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.h0000644000175000017500000000433412070605214014676 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000000667112070605214014640 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000002554312113713537014627 0ustar zbygzbyg/* * 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.h0000644000175000017500000000330012070605214015666 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000002506012070605214017206 0ustar zbygzbyg/* * 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.h0000644000175000017500000000326412070605214015177 0ustar zbygzbyg/* * 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.h0000644000175000017500000000415012070605214016246 0ustar zbygzbyg/* * 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.cpp0000644000175000017500000000540112070605214017140 0ustar zbygzbyg/* * 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::iterator, bool> r; r = csm->colorsource.insert(pair(source->identificator, source)); return r.second; } ColorSource* color_source_manager_get(ColorSourceManager *csm, const char *name){ map::iterator i = csm->colorsource.find(name); if (i != csm->colorsource.end()){ return (*i).second; } return 0; } vector color_source_manager_get_all(ColorSourceManager *csm){ vector ret; ret.resize(csm->colorsource.size()); uint32_t j = 0; for (map::iterator i = csm->colorsource.begin(); i != csm->colorsource.end(); ++i){ ret[j] = (*i).second; j++; } return ret; } int color_source_manager_destroy(ColorSourceManager *csm){ for (map::iterator i = csm->colorsource.begin(); i != csm->colorsource.end(); ++i){ color_source_destroy((*i).second); } csm->colorsource.clear(); delete csm; return 0; } gpick_0.2.5/source/FileFormat.cpp0000644000175000017500000001777012070605214015452 0ustar zbygzbyg/* * 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 "FileFormat.h" #include "Endian.h" #include "dynv/DynvSystem.h" #include "dynv/DynvMemoryIO.h" #include #include #include #include #include using namespace std; struct ChunkHeader{ char type[16]; uint64_t size; }; #define CHUNK_TYPE_VERSION "GPA version" #define CHUNK_TYPE_HANDLER_MAP "handler_map" #define CHUNK_TYPE_COLOR_LIST "color_list" #define CHUNK_TYPE_COLOR_POSITIONS "color_positions" #define CHUNK_TYPE_COLOR_ACTIONS "color_actions" static int prepare_chunk_header(struct ChunkHeader* header, const char* type, uint64_t size){ size_t len=strlen(type); if (len>=sizeof(header->type)) len=sizeof(header->type)-1; memcpy(header->type, type, len); memset(header->type+len, 0, sizeof(header->type)-len); //strncpy(header->type, type, 16); header->size=UINT64_TO_LE(size); return 0; } static int check_chunk_header(struct ChunkHeader* header){ if (header->type[sizeof(header->type)-1]!=0) return -1; return 0; } static bool color_object_position_sort(struct ColorObject* x, struct ColorObject* y){ return x->position < y->position; } int palette_file_load(const char* filename, struct ColorList* color_list) { ifstream file(filename, ios::binary); if (file.is_open()){ struct dynvIO* mem_io = dynv_io_memory_new(); struct ChunkHeader header; file.read((char*) &header, sizeof(header)); if (file.fail()){ file.close(); dynv_io_free(mem_io); return -1; } struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(color_list->params); dynvHandlerMap::HandlerVec handler_vec; list color_objects; while (check_chunk_header(&header) == 0){ //cout<params, handler_vec, mem_io)==0){ //color_list_add_color_object(color_list, color, 0); //color_object_release(color); color_objects.push_back(color); }else{ break; } } }else if (strncmp(CHUNK_TYPE_COLOR_POSITIONS, header.type, sizeof(header.type)) == 0){ dynv_io_memory_prepare_size(mem_io, header.size); file.read((char*) dynv_io_memory_get_buffer(mem_io), header.size); uint32_t index, read; for (list::iterator i=color_objects.begin(); i!=color_objects.end(); ++i){ if (dynv_io_read(mem_io, &index, sizeof(uint32_t), &read)==0){ if (read!=sizeof(uint32_t)) break; (*i)->position=index; } } color_objects.sort(color_object_position_sort); for (list::iterator i=color_objects.begin(); i!=color_objects.end(); ++i){ color_list_add_color_object(color_list, *i, ((*i)->position!=~(uint32_t)0)); color_object_release(*i); } }else if (strncmp(CHUNK_TYPE_VERSION, header.type, sizeof(header.type)) == 0){ dynv_io_memory_prepare_size(mem_io, header.size); file.read((char*) dynv_io_memory_get_buffer(mem_io), header.size); uint32_t read; uint32_t version; if (dynv_io_read(mem_io, &version, sizeof(uint32_t), &read)==0){ version=UINT32_FROM_LE(version); } }else{ file.seekg(header.size, ios_base::cur); if (file.fail() || file.eof()) break; } file.read((char*) &header, sizeof(header)); if (file.fail()) break; } dynv_handler_map_release(handler_map); dynv_io_free(mem_io); file.close(); return 0; } return -1; } int palette_file_save(const char* filename, struct ColorList* color_list){ if (!filename || !color_list) return -1; ofstream file(filename, ios::binary); if (file.is_open()){ struct dynvIO* mem_io=dynv_io_memory_new(); char* data; uint32_t size; ofstream::pos_type end_pos; struct ChunkHeader header; prepare_chunk_header(&header, CHUNK_TYPE_VERSION, 4); file.write((char*)&header, sizeof(header)); uint32_t version=1*0x10000+0; version=UINT32_TO_LE(version); file.write((char*)&version, sizeof(uint32_t)); ofstream::pos_type handler_map_pos = file.tellp(); file.write((char*)&header, sizeof(header)); struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(color_list->params); dynv_handler_map_serialize(handler_map, mem_io); dynv_io_memory_get_data(mem_io, &data, &size); file.write(data, size); dynv_io_reset(mem_io); dynv_handler_map_release(handler_map); end_pos = file.tellp(); file.seekp(handler_map_pos); prepare_chunk_header(&header, CHUNK_TYPE_HANDLER_MAP, end_pos-handler_map_pos-sizeof(struct ChunkHeader)); file.write((char*)&header, sizeof(header)); file.seekp(end_pos); ofstream::pos_type colorlist_pos = file.tellp(); file.write((char*)&header, sizeof(header)); /*struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(color_list->params); dynv_handler_map_serialize(handler_map, mem_io); dynv_io_memory_get_data(mem_io, &data, &size); file.write(data, size); dynv_io_reset(mem_io); dynv_handler_map_release(handler_map);*/ for (ColorList::iter i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ dynv_system_serialize((*i)->params, mem_io); dynv_io_memory_get_data(mem_io, &data, &size); file.write(data, size); dynv_io_reset(mem_io); } dynv_io_free(mem_io); end_pos = file.tellp(); file.seekp(colorlist_pos); prepare_chunk_header(&header, CHUNK_TYPE_COLOR_LIST, end_pos-colorlist_pos-sizeof(struct ChunkHeader)); file.write((char*)&header, sizeof(header)); file.seekp(end_pos); color_list_get_positions(color_list); uint32_t *positions=new uint32_t [color_list->colors.size()]; uint32_t *position=positions; for (ColorList::iter i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ *position=UINT32_TO_LE((*i)->position); ++position; } prepare_chunk_header(&header, CHUNK_TYPE_COLOR_POSITIONS, color_list->colors.size()*sizeof(uint32_t)); file.write((char*)&header, sizeof(header)); file.write((char*)positions, color_list->colors.size()*sizeof(uint32_t)); delete [] positions; file.close(); return 0; } return -1; } gpick_0.2.5/source/Noise.h0000644000175000017500000000355612070605214014141 0ustar zbygzbyg/* * 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 NOISE_H_ #define NOISE_H_ /** \file source/Noise.h * \brief Improved Perlin noise implementation. */ /** * Returns noise value for specified position. * @param[in] x X coordinate. * @param[in] y y coordinate. * @param[in] z Z coordinate. * @return Noise value. */ double noise(double x, double y, double z); #endif /* NOISE_H_ */ gpick_0.2.5/source/uiDialogSort.cpp0000644000175000017500000004767312070605214016034 0ustar zbygzbyg/* * 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 "uiDialogSort.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "MathUtil.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "ColorRYB.h" #include "Noise.h" #include "GenerateScheme.h" #include "Internationalisation.h" #include #include #include #include #include using namespace std; typedef struct DialogSortArgs{ GtkWidget *group_type; GtkWidget *group_sensitivity; GtkWidget *max_groups; GtkWidget *sort_type; GtkWidget *toggle_reverse; GtkWidget *toggle_reverse_groups; struct ColorList *sorted_color_list; struct ColorList *selected_color_list; struct ColorList *preview_color_list; struct dynvSystem *params; GlobalState* gs; }DialogSortArgs; typedef struct SortType{ const char *name; double (*get_value)(Color *color); }SortType; typedef struct GroupType{ const char *name; double (*get_group)(Color *color); }GroupType; static double sort_rgb_red(Color *color) { return color->rgb.red; } static double sort_rgb_green(Color *color) { return color->rgb.green; } static double sort_rgb_blue(Color *color) { return color->rgb.blue; } static double sort_rgb_grayscale(Color *color) { return (color->rgb.red + color->rgb.green + color->rgb.blue) / 3.0; } static double sort_hsl_hue(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.hue; } static double sort_hsl_saturation(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.saturation; } static double sort_hsl_lightness(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.lightness; } static double sort_lab_lightness(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return lab.lab.L; } static double sort_lab_a(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return lab.lab.a; } static double sort_lab_b(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return lab.lab.b; } static double sort_lch_lightness(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.L; } static double sort_lch_chroma(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.C; } static double sort_lch_hue(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.h; } const SortType sort_types[] = { {N_("RGB Red"), sort_rgb_red}, {N_("RGB Green"), sort_rgb_green}, {N_("RGB Blue"), sort_rgb_blue}, {N_("RGB Grayscale"), sort_rgb_grayscale}, {N_("HSL Hue"), sort_hsl_hue}, {N_("HSL Saturation"), sort_hsl_saturation}, {N_("HSL Lightness"), sort_hsl_lightness}, {N_("Lab Lightness"), sort_lab_lightness}, {N_("Lab A"), sort_lab_a}, {N_("Lab B"), sort_lab_b}, {N_("LCh Lightness"), sort_lch_lightness}, {N_("LCh Chroma"), sort_lch_chroma}, {N_("LCh Hue"), sort_lch_hue}, }; static double group_rgb_red(Color *color) { return color->rgb.red; } static double group_rgb_green(Color *color) { return color->rgb.green; } static double group_rgb_blue(Color *color) { return color->rgb.blue; } static double group_rgb_grayscale(Color *color) { return (color->rgb.red + color->rgb.green + color->rgb.blue) / 3.0; } static double group_hsl_hue(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.hue; } static double group_hsl_saturation(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.saturation; } static double group_hsl_lightness(Color *color) { Color hsl; color_rgb_to_hsl(color, &hsl); return hsl.hsl.lightness; } static double group_lab_lightness(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return lab.lab.L / 100.0; } static double group_lab_a(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return (lab.lab.a + 145) / 290.0; } static double group_lab_b(Color *color) { Color lab; color_rgb_to_lab_d50(color, &lab); return (lab.lab.b + 145) / 290.0; } static double group_lch_lightness(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.L / 100.0; } static double group_lch_chroma(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.C / 136.0; } static double group_lch_hue(Color *color) { Color lch; color_rgb_to_lch_d50(color, &lch); return lch.lch.h / 360.0; } const GroupType group_types[] = { {N_("None"), NULL}, {N_("RGB Red"), group_rgb_red}, {N_("RGB Green"), group_rgb_green}, {N_("RGB Blue"), group_rgb_blue}, {N_("RGB Grayscale"), group_rgb_grayscale}, {N_("HSL Hue"), group_hsl_hue}, {N_("HSL Saturation"), group_hsl_saturation}, {N_("HSL Lightness"), group_hsl_lightness}, {N_("Lab Lightness"), group_lab_lightness}, {N_("Lab A"), group_lab_a}, {N_("Lab B"), group_lab_b}, {N_("LCh Lightness"), group_lch_lightness}, {N_("LCh Chroma"), group_lch_chroma}, {N_("LCh Hue"), group_lch_hue}, }; typedef struct Node{ uint32_t n_values; uint32_t n_values_in; double value_sum; double distance; Node *child[2]; Node *parent; }Node; typedef struct Range{ double x; double w; }Range; static Node* node_new(Node *parent){ Node *n = new Node; n->value_sum = 0; n->distance = 0; n->n_values = 0; n->n_values_in = 0; n->parent = parent; for (int i = 0; i < 2; i++){ n->child[i] = 0; } return n; } static void node_delete(Node *node){ for (int i = 0; i < 2; i++){ if (node->child[i]){ node_delete(node->child[i]); } } delete node; } static Node* node_copy(Node *node, Node *parent){ Node *n = node_new(0); memcpy(n, node, sizeof(Node)); n->parent = parent; for (int i = 0; i < 2; i++){ if (node->child[i]){ n->child[i] = node_copy(node->child[i], n); }else{ n->child[i] = 0; } } return n; } static uint32_t node_count_leafs(Node *node){ uint32_t r = 0; if (node->n_values_in) r++; for (int i = 0; i < 2; i++){ if (node->child[i]) r += node_count_leafs(node->child[i]); } return r; } static void node_leaf_callback(Node *node, void (*leaf_cb)(Node* node, void* userdata), void* userdata){ if (node->n_values_in > 0) leaf_cb(node, userdata); for (int i = 0; i < 2; i++){ if (node->child[i]) node_leaf_callback(node->child[i], leaf_cb, userdata); } } static void node_prune(Node *node){ for (int i = 0; i < 2; i++){ if (node->child[i]){ node_prune(node->child[i]); node->child[i] = 0; } } if (node->parent){ node->parent->n_values_in += node->n_values_in; node->parent->value_sum += node->value_sum; } node_delete(node); } typedef struct PruneData{ double threshold; double min_distance; uint32_t n_values; uint32_t n_values_target; Node *prune_node; uint32_t distant_nodes; }PruneData; static bool node_prune_threshold(Node *node, PruneData *prune_data, bool leave_node){ if (node->distance <= prune_data->threshold){ uint32_t values_removed; if (leave_node){ values_removed = 0; for (int i = 0; i < 2; i++){ if (node->child[i]){ values_removed += node_count_leafs(node->child[i]); node_prune(node->child[i]); node->child[i] = 0; } } }else{ values_removed = node_count_leafs(node); node_prune(node); } prune_data->n_values -= values_removed; return true; } if (node->distance < prune_data->min_distance){ prune_data->min_distance = node->distance; } uint32_t n = node->n_values_in; for (int i = 0; i < 2; i++){ if (node->child[i]){ if (node_prune_threshold(node->child[i], prune_data, false)){ node->child[i] = 0; } } } if (node->n_values_in > 0 && n == 0) prune_data->n_values++; return false; } static void node_reduce(Node *node, double threshold, uintptr_t max_values){ PruneData prune_data; prune_data.n_values = node_count_leafs(node); prune_data.n_values_target = max_values; prune_data.threshold = threshold; prune_data.min_distance = node->distance; node_prune_threshold(node, &prune_data, true); prune_data.threshold = prune_data.min_distance; while (prune_data.n_values > max_values){ prune_data.min_distance = node->distance; if (node_prune_threshold(node, &prune_data, true)) break; prune_data.threshold = prune_data.min_distance; } } static Node* node_find(Node *node, Range *range, double value) { Range new_range; new_range.w = range->w / 2; int x; if (value - range->x < new_range.w) x = 0; else x = 1; new_range.x = range->x + new_range.w * x; if (node->child[x]){ return node_find(node->child[x], &new_range, value); }else return node; } static void node_update(Node *node, Range *range, double value, uint32_t max_depth){ Range new_range; new_range.w = range->w / 2; node->n_values++; node->distance += (value - (range->x + new_range.w)) * (value - (range->x + new_range.w)); if (!max_depth){ node->n_values_in++; node->value_sum += value; }else{ int x; if (value - range->x < new_range.w) x = 0; else x = 1; new_range.x = range->x + new_range.w * x; if (!node->child[x]) node->child[x] = node_new(node); node->n_values++; node_update(node->child[x], &new_range, value, max_depth - 1); } } static void calc(DialogSortArgs *args, bool preview, int limit){ int32_t group_type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->group_type)); double group_sensitivity = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->group_sensitivity)); int max_groups = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->max_groups)); int32_t sort_type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->sort_type)); bool reverse = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_reverse)); bool reverse_groups = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_reverse_groups)); if (!preview){ dynv_set_int32(args->params, "group_type", group_type); dynv_set_float(args->params, "group_sensitivity", group_sensitivity); dynv_set_int32(args->params, "max_groups", max_groups); dynv_set_int32(args->params, "sort_type", sort_type); dynv_set_bool(args->params, "reverse", reverse); dynv_set_bool(args->params, "reverse_groups", reverse_groups); } struct ColorList *color_list; if (preview) color_list = args->preview_color_list; else color_list = args->sorted_color_list; typedef std::multimap SortedColors; typedef std::map GroupedSortedColors; GroupedSortedColors grouped_sorted_colors; typedef std::multimap SortedGroups; SortedGroups sorted_groups; const GroupType *group = &group_types[group_type]; const SortType *sort = &sort_types[sort_type]; Color in; Node *group_nodes = node_new(0); Range range; range.x = 0; range.w = 1; int tmp_limit = limit; if (group->get_group){ for (ColorList::iter i = args->selected_color_list->colors.begin(); i != args->selected_color_list->colors.end(); ++i){ color_object_get_color(*i, &in); node_update(group_nodes, &range, group->get_group(&in), 8); if (preview){ if (tmp_limit <= 0) break; tmp_limit--; } } } node_reduce(group_nodes, group_sensitivity / 100.0, max_groups); tmp_limit = limit; for (ColorList::iter i = args->selected_color_list->colors.begin(); i != args->selected_color_list->colors.end(); ++i){ color_object_get_color(*i, &in); uintptr_t node_ptr = 0; if (group->get_group){ node_ptr = reinterpret_cast(node_find(group_nodes, &range, group->get_group(&in))); } grouped_sorted_colors[node_ptr].insert(std::pair(sort->get_value(&in), *i)); if (preview){ if (tmp_limit <= 0) break; tmp_limit--; } } node_delete(group_nodes); for (GroupedSortedColors::iterator i = grouped_sorted_colors.begin(); i != grouped_sorted_colors.end(); ++i){ color_object_get_color((*(*i).second.begin()).second, &in); sorted_groups.insert(std::pair(sort->get_value(&in), (*i).first)); } if (reverse_groups){ for (SortedGroups::reverse_iterator i = sorted_groups.rbegin(); i != sorted_groups.rend(); ++i){ GroupedSortedColors::iterator a, b; a = grouped_sorted_colors.lower_bound((*i).second); b = grouped_sorted_colors.upper_bound((*i).second); for (GroupedSortedColors::iterator j = a; j != b; ++j){ if (reverse){ for (SortedColors::reverse_iterator k = (*j).second.rbegin(); k != (*j).second.rend(); ++k){ color_list_add_color_object(color_list, (*k).second, true); } }else{ for (SortedColors::iterator k = (*j).second.begin(); k != (*j).second.end(); ++k){ color_list_add_color_object(color_list, (*k).second, true); } } } } }else{ for (SortedGroups::iterator i = sorted_groups.begin(); i != sorted_groups.end(); ++i){ GroupedSortedColors::iterator a, b; a = grouped_sorted_colors.lower_bound((*i).second); b = grouped_sorted_colors.upper_bound((*i).second); for (GroupedSortedColors::iterator j = a; j != b; ++j){ if (reverse){ for (SortedColors::reverse_iterator k = (*j).second.rbegin(); k != (*j).second.rend(); ++k){ color_list_add_color_object(color_list, (*k).second, true); } }else{ for (SortedColors::iterator k = (*j).second.begin(); k != (*j).second.end(); ++k){ color_list_add_color_object(color_list, (*k).second, true); } } } } } } static void update(GtkWidget *widget, DialogSortArgs *args ){ color_list_remove_all(args->preview_color_list); calc(args, true, 100); } bool dialog_sort_show(GtkWindow* parent, struct ColorList *selected_color_list, struct ColorList *sorted_color_list, GlobalState* gs) { DialogSortArgs *args = new DialogSortArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick.group_and_sort"); args->sorted_color_list = sorted_color_list; GtkWidget *table; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Group and sort"), 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(4, 4, FALSE); table_y = 0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Group type:"),0,0.5,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->group_type = gtk_combo_box_new_text(); for (uint32_t i = 0; i < sizeof(group_types) / sizeof(GroupType); i++){ gtk_combo_box_append_text(GTK_COMBO_BOX(args->group_type), _(group_types[i].name)); } gtk_combo_box_set_active(GTK_COMBO_BOX(args->group_type), dynv_get_int32_wd(args->params, "group_type", 0)); g_signal_connect(G_OBJECT(args->group_type), "changed", G_CALLBACK(update), args); gtk_table_attach(GTK_TABLE(table), args->group_type,3,4,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(_("Grouping sensitivity:"),0,0,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->group_sensitivity = gtk_spin_button_new_with_range(0, 100, 0.01); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->group_sensitivity), dynv_get_float_wd(args->params, "group_sensitivity", 50)); gtk_table_attach(GTK_TABLE(table), args->group_sensitivity,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect(G_OBJECT(args->group_sensitivity), "value-changed", G_CALLBACK(update), args); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Maximum number of groups:"),0,0,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->max_groups = gtk_spin_button_new_with_range(1, 255, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->max_groups), dynv_get_int32_wd(args->params, "max_groups", 10)); gtk_table_attach(GTK_TABLE(table), args->max_groups,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect(G_OBJECT(args->max_groups), "value-changed", G_CALLBACK(update), args); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Sort type:"),0,0.5,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->sort_type = gtk_combo_box_new_text(); for (uint32_t i = 0; i < sizeof(sort_types) / sizeof(SortType); i++){ gtk_combo_box_append_text(GTK_COMBO_BOX(args->sort_type), _(sort_types[i].name)); } gtk_combo_box_set_active(GTK_COMBO_BOX(args->sort_type), dynv_get_int32_wd(args->params, "sort_type", 0)); g_signal_connect (G_OBJECT (args->sort_type), "changed", G_CALLBACK(update), args); gtk_table_attach(GTK_TABLE(table), args->sort_type,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; args->toggle_reverse_groups = gtk_check_button_new_with_mnemonic(_("_Reverse group order")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_reverse_groups), dynv_get_bool_wd(args->params, "reverse_groups", false)); gtk_table_attach(GTK_TABLE(table), args->toggle_reverse_groups,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_reverse_groups), "toggled", G_CALLBACK(update), args); table_y++; args->toggle_reverse = gtk_check_button_new_with_mnemonic(_("_Reverse order inside groups")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_reverse), dynv_get_bool_wd(args->params, "reverse", false)); gtk_table_attach(GTK_TABLE(table), args->toggle_reverse,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_reverse), "toggled", G_CALLBACK(update), args); table_y++; 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, 4, 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); bool retval = false; if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK){ calc(args, false, 0); retval = true; } 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; return retval; } gpick_0.2.5/source/uiDialogSort.h0000644000175000017500000000345612070605214015470 0ustar zbygzbyg/* * 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 UIDIALOGSORT_H_ #define UIDIALOGSORT_H_ #include #include "ColorList.h" #include "GlobalState.h" bool dialog_sort_show(GtkWindow* parent, struct ColorList *selected_color_list, struct ColorList *sorted_color_list, GlobalState* gs); #endif /* UIDIALOGSORT_H_ */ gpick_0.2.5/source/RegisterSources.h0000644000175000017500000000327112070605214016206 0ustar zbygzbyg/* * 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 REGISTERSOURCES_H_ #define REGISTERSOURCES_H_ #include "ColorSourceManager.h" int register_sources(ColorSourceManager *csm); #endif /* REGISTERSOURCES_H_ */ gpick_0.2.5/source/Rect2.h0000644000175000017500000000733212070605214014037 0ustar zbygzbyg/* * 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 RECT2_H_ #define RECT2_H_ namespace math{ template class Rect2{ public: Rect2(){ empty=true; }; Rect2(const T &x1_, const T &y1_, const T &x2_, const T &y2_):x1(x1_),y1(y1_),x2(x2_),y2(y2_){ empty=false; }; const Rect2 operator=(const Rect2 &rect){ x1 = rect.x1; y1 = rect.y1; x2 = rect.x2; y2 = rect.y2; empty = rect.empty; return *this; }; const Rect2 operator+(const Rect2 &rect) const{ if (rect.empty) return *this; if (empty) return rect; Rect2 r; if (x1 < rect.x1) r.x1 = x1; else r.x1 = rect.x1; if (y1 < rect.y1) r.y1 = y1; else r.y1 = rect.y1; if (x2 > rect.x2) r.x2 = x2; else r.x2 = rect.x2; if (y2 > rect.y2) r.y2 = y2; else r.y2 = rect.y2; return r; }; const Rect2 operator+=(const Rect2 &rect){ *this=*this+rect; return *this; }; Rect2 impose(const Rect2 &rect) const{ Rect2 r; r.x1 = rect.x1 + x1 * rect.getWidth(); r.y1 = rect.y1 + y1 * rect.getHeight(); r.x2 = rect.x1 + x2 * rect.getWidth(); r.y2 = rect.y1 + y2 * rect.getHeight(); r.empty = false; return r; } bool isInside(const T &x, const T &y) const{ if (xx2 || yy2) return false; else return true; } bool isInside(const Rect2 &r) const{ if (empty || r.empty) return false; if (x1 < r.x1 || x2 > r.x2) return false; if (y1 < r.y1 || y2 > r.y2) return false; return true; } Rect2 positionInside(const Rect2& rect) const{ Rect2 r; r.empty = false; if (rect.x1 < x1){ r.x1 = x1; r.x2 = x1 + rect.getWidth(); }else if (rect.x2 > x2){ r.x1 = x2 - rect.getWidth(); r.x2 = x2; }else{ r.x1 = rect.x1; r.x2 = rect.x2; } if (rect.y1 < y1){ r.y1 = y1; r.y2 = y1 + rect.getHeight(); }else if (rect.y2 > y2){ r.y1 = y2 - rect.getHeight(); r.y2 = y2; }else{ r.y1 = rect.y1; r.y2 = rect.y2; } return r; } bool isEmpty() const{ return empty; }; const T& getX() const{ return x1; }; const T& getY() const{ return y1; }; T getWidth() const{ return x2-x1; }; T getHeight() const{ return y2-y1; }; T getCenterX() const{ return (x1 + x2) / 2; }; T getCenterY() const{ return (y1 + y2) / 2; }; private: bool empty; T x1, y1, x2, y2; }; } #endif /* RECT2_H_ */ gpick_0.2.5/source/winres/SConscript0000644000175000017500000000147512113713537016240 0ustar zbygzbyg#!/usr/bin/env python import os import sys import re Import('*') local_env = env.Clone() local_env.Append(RESOURCE_TEMPLATE_VARS = { 'VERSION': env['GPICK_BUILD_VERSION'], 'VERSION_COMMA': env['GPICK_BUILD_VERSION'].replace('.', ','), 'REVISION': env['GPICK_BUILD_REVISION'], 'BUILD_DATE': env['GPICK_BUILD_DATE'], }) sources = local_env.Glob('*.rct') resources = local_env.AlwaysBuild(local_env.ResourceTemplate(sources)) objects = local_env.RES(resources) Command("gpick-icon.ico", File("gpick-icon.ico").srcnode(), Copy("$TARGET", "${SOURCE}")) if not (env['TOOLCHAIN'] == 'msvc'): Command("gpick.exe.manifest", File("gpick.exe.manifest").srcnode(), Copy("$TARGET", "${SOURCE}")) Depends(resources, 'gpick-icon.ico') if not (env['TOOLCHAIN'] == 'msvc'): Depends(resources, 'gpick.exe.manifest') Return('objects') gpick_0.2.5/source/winres/gpick.exe.manifest0000644000175000017500000000115012070605214017613 0ustar zbygzbyg gpick_0.2.5/source/winres/resources.rct0000644000175000017500000000125712113713537016750 0ustar zbygzbyg1 ICON "gpick-icon.ico" 1 VERSIONINFO FILEVERSION %VERSION_COMMA% PRODUCTVERSION %VERSION_COMMA% BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904E4" BEGIN VALUE "CompanyName", "Gpick developers" VALUE "FileDescription", "Gpick - Advanced color picker" VALUE "FileVersion", "%VERSION%" VALUE "InternalName", "gpick" VALUE "LegalCopyright", "New BSD License" VALUE "OriginalFilename", "gpick.exe" VALUE "ProductName", "Gpick" VALUE "ProductVersion", "%VERSION%" VALUE "Comments", "Revision %REVISION%, built at %BUILD_DATE%" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1252 END END gpick_0.2.5/source/winres/gpick-icon.ico0000644000175000017500000033305612070605214016742 0ustar zbygzbyg (f@@ (B00 %J  ^p h 0n( 6[wL!o :" 2 tXڗeJ5fڮ{r{4:]}um.Qwop- 60u9yqEKBc{sQ{!n}u?U.wd,0ٿy/zx>lQ)%4is87Ѷ wrd:Qv % |k8Dl/} nJ,n6܊S hB r^4ieܲlJQBmFÚoQ2(q+/$ va CxC<2i7 OF{ni^~=67 t';zm{n{nzmrf]SCŁ>7p609ggg4 #4DTdu{{{{: #4DTdutŏB #4DTdumxxx|ʟJ #4DTdug(slllvήS #4DTdu`&]]]pѼ^ #4DTduZ$ ~QQQli #4DTduT" jBBBiu #4DTduN  lZ444gق #4DTdvHRK(((e۾ #4DTdvC =fָ... #4DTdvR 1gѲJJJ #4DTdw!!!###""" C' jˬddd$ #4DTr###&&&%%%###"""  oĤ* #4S&&&***(((&&&%%%###""" v񼓓0 3(((---+++***(((&&&%%%###"""4}§9 +++000///---+++***((('''%%%### ~ ...333222000///---+++***((('''$$$רa"///777555333222000///---+++***(((%|NNNH,.222:::888777555333222000///---+++***tttnA@...999;;;:::888777555333222000///---,,,4rS+++666888999;;;:::888777555444222000///...$$$` a(((333444666777999;;;:::888777555444222111...,,,***""" $$$///111333444666777999;;;:::888777555444222000...,,,***(((&&&$$$""",,,...///111333444666777999::::::999888666444222000...,,,***(((&&&$$$"""M )))+++,,,...///111222444666777999:::::::::888666444222000...,,,***(((&&&$$$""" &&&((()))+++,,,...///111222444555777666888::::::888666444222000...,,,***(((%%%###"""###$$$&&&''')))+++,,,...///111222444333444666888::::::888666444222000...+++***(((%%%###!!! !!!###$$$&&&''')))+++,,,...///111222000222444666888::::::888666444222000...+++)))'''%%%###!!!%!!!###$$$&&&''')))***,,,......---...000222444666888::::::888666444222///...+++)))'''%%%###!!!!!!"""$$$&&&''')))***,,,+++***,,,...000222444666888::::::888666444222///---+++)))'''%%%###!!!!!!"""$$$&&&&&&&&&(((EEE,,,...000222444666888::::::888555333111///---+++)))'''%%%###!!!p   &&&444,,,...000222444666888;;;999888555333111///---+++)))'''%%%###!!!Fr  ]G***,,,...000222555666888;;;999777555333111///---+++)))'''%%%###!!!  u o*mmm***,,,///111222555777999;;;999777555333111///---+++)))'''%%%###!!!w<IgggEEE+++---///111333555777999;;;999777555333111///---+++)))'''%%%###!!!$ ###...+++---///111333555777999;;;999777555333111///---+++)))'''%%%###!!!)))+++---///111333555777999;;;999777555333111///---+++)))'''%%%"""  /UUUvvv)))+++---///111333555777999;;;999777555333111///---+++((('''%%%"""cqqq)))+++---///111333555777999;;;999777555333111///---+++(((&&&$$$""" &222lll)))+++---///111333555777999;;;999777555333111///,,,***(((&&&$$$iii)))+++---///111333555777999;;;999777555222111///,,,***(((&&&eee)))+++---///111333555777999;;;999777555222000...,,,***((("7$$$ddd)))+++---///111333555777999;;;888666555222000...,,,***y...444+++---///111333555888999;;;888666444222000...,,,888[[[+++---///222444555888::::::888666444222000...@@@555...///222444666888::::::888666444222---m###[[[...000222444666888::::::888666444 rrrbbb222222444666888::::::888&&&TBBBBTTT666666888:::)))SSS888s777yyy~~~FFFW& gewW ???????C!?p A ???(@ !E0 3&hF^|DI#" zrX$ )$t:1.4;xD($ f|2aj"4.;X-%!ʫ$OC7AN J$ ׯ:&B7f `'  b z% Z2e1,QIK$ (F-zm{nrfPGe0,2 "bWzm{nrfbXRJq60 Er81pdzm{nrfbXRJr71 3f[pdzm{nrfbXRJt82 "ؾ\Rvlpdzm{nrfbXRJv:4  F?ڀwpdzm{nrfbXRJx;4 !׷܇~pdzm{nrfbXRJz;5 *մލpdzm{nrfbXRJ|<6 $ (Үᖎpdzm{nrfbXRJ~=7 ( 'Χ㞗pdzm{nrfbXRJ>7 - %ʟ槠pdzm{nrfbXRJ>8 (!%ŗ诪qezm{nrfbXRJ>7 #! ٭ɾe^jwlZznXcYdE?zi2-? ǏJJJ4T ǁfff#4TW sss|||)4TS aaa04TM .QQQĤ84TT  DDDʷ@4T $$$"""666Kh ***(((%%%"""1+++Ѣ7= 000///+++(((%%%ZZZ>M666555222///+++j 666;;;888555222///$$$i ///444777;;;888555333...((( u2 )))...111444777:::999666222...***&&&!!!. """'''+++...111444555888:::666222...***%%%!!!3+!!!$$$'''***...///000444888:::666222...)))%%%!!! B(!!!$$$'''%%%)))111000444888:::555222---)))%%%!!! uuu,,,000555888999555111---)))%%%!!!L Ɋkkk,,,111555999999555111---)))%%%!!!yE\\\EEE---111555999999555111---)))%%%!!!<<<---111555999999555111---((($$$ ybbb:::---111555999999555111,,,((({ ͘888---111555999888555000,,,!!! 䤤]]]---222555:::888444000P"888222666:::888444 "dddbbb999:::mooovvv' ????~A?(0` &=:'O0D$,$ Gi f>=6Bz}q-95Qj-'$\ǮF[P*a!M5/ QJ+o]4ɇ'i1*ޮV< C5* r*% w:4JBM%"1"y"N&"zm{ng\G@G!#_/h\zm{ng\RJO&"!e 9C=mazm{ng\RJP'"! lP'#אpdzm{ng\RJR'# s.ŝ辺sgzm{ng\RJT(% z1̪vkzm{ng\RJU)% 1Ȣzozm{ng\RJW*% 1Ú~tzm{ng\RJX*&"1yzm{ng\RJW*&'άJ)TjѹT)Tci%uuu_)T] o %fffk)TW i^|WWWx)T""" lGGG@@@y***&&&!!! \<<<Ɉ:\333///***IM---|;;;777333/// |222666;;;777444...### qO***...222666999999333...(((### M!!!%%%)))...111333888888333...(((### ( !!!!!!111222333888888333---((("""  D珏...333888888222---((("""c0 www...333999888222---'''""" ]]]]]]...444999888222---''' III///444999777222,,,"""{ѯ]]]///444:::777222 J!!!ᓓAAA444:::777 DDD```I^&&&... !??|??????( @  j|_a'.+Me?/,FL<@|[S){C;_-g laB3'i%ZA:F?e0,A!p60zmrfNG@M$!j_zmrfNGB .7{zmrfNGD!E##`⚓zmrfNGH#N$$\壜zmrfNGK$ V(%Y㵰zmnbB;)6ڗ[C0zzzߠ [*lll[  %^^^殿 %%%((( !PPP///555///}###444:::666... Fp'''...333888666...%%%x===000888555---%%% A\ {LLL{{{111999555---%%%ibbb111999555---)(((ż```111999444'''?777ǡZZZ;;; FMMMQQQ+++"????q!?(  ++pt?a;;'.jǩeyjR^7 AWN܍D=a,(:TNxKCb/+<R)|JAb/+Ah..pI#* ._ zzz"""---,,,:::+++NNN888---___nnn:::'''WWWzzz,,,PNG  IHDR\rf IDATxwx?N[mL1TSM6 @^ސ1Pބ6 1%`cܛdY]wҝn?vt|E>3fwF~wΈ1EQWo@Qġ(I$1jĨ(J(I$1jĨ(J(I$1jĨ(J(I$1ENH ``  uRscLMn5*.$;"2 8މ#ƘbHp6p=0)9\.18:iG/K?Oc{DZA @I*D0 v \.D$1x^^/:|>_7⒱.$ "r)p7PGVVyyydff!CaРAihhSVVw}ڵk2*++[>.1ƬsV;=?ӝ8ENNyyy{sGp!KU֭[x뭷(--eΝرF [(q7v呗nj38c)** ]ڌ |駼k^uQYYzݭo@ @镈 `'.==" 1cz*YYY-.q@ 6rJV\ɚ5kGD(--eLc7Jm^6X| 9s&gq~ס׳b VZիz: CC}}=˖->8^ҫ[dffRXXȸq1bD%K[om۶oQ˗ƘbN D$ pG>} 9sfpH/o#mܸ7x? Y|9 %.15E) L?STTĸqOʐ!C"@ '|oի;%pwB]]˗/w ˁ1;bW2hDd$0 %%>}0m4nF233C f-[ƣ>کj~G[uVr0ƜjJEDbFqq1\p{n3q'q.]j_o!rJ@qƘ7cXLmHDX`tML:~@}}=?/83fОP[[˷~ʓƘscUN+=^zz:Çg- {>c{1ʂ"'~7-"~c ddd8Hfd/ȑ#뮻5jTs#<;Vy )tFNw 8 x6"cT93ᄏ߾};rKw,iD8]1[KXG}`=9DҥKi==S6N1 SPz"r 0Ç`?pB^|N;d @B! da5cRxmt{DdO>z 6y~[SS XjU4Ù#bh2Ά[-@ @Q#".q@nn.^{-'Ony^ߖsmy.3g<vM)jJwf(&s9r)N'~_QRR5vAZ@h| (9>Caܹ-i͛7smQ^^;t9AD2E|ĿvZ~_SSSS>AG bbRtWFdee1g2WXw[FZ@^s?9SCokrw㊗#5:B^$hP tGn^믿٘|Ko&4~ZǼD#t+ZG`M934h]+++۩NÙA{̀?(Jc͌̚5 /~c6Й?@TP "2 wawͺu뺅 tCCMMpSZ`Y6jJwvarg?C=_mV-04b\PP"R ֌ӧڴ>_|%Kt;3,=ӂm5ptNN~xD5kְhѢn)4|>_hcxn$YAqq1p@hllgq1-EDƋHZ8=NnyٱcGUz[ 466R[[di=R<ʷ-VrY,"7~Gn9 HCmy?[|GABVMCk1gѩJ3Dd.{cpvX\e˞e_~5{_Dشi>("WJM w cmcp "2&񓚚:\8*l334kv}`ʔ)꿈=\߉ v }l)lY5!\ӃO/GCCCuqvR,Cxts999;ֹ}ш+83h-P[[:}@D!G?XBhhh`vP-"a4Ƭ s41dggo)X/߽ ' &*h*pKMMv磾>Bo?" `(X[y'ر?OC9ݻ***BMrA8#L$jIk} õdddx^< f.{گ墨!;;F/廻^/uuuNGs\dee Xxtcx18,ĊƓsRSSc.ṕhEc̿cg j Ƙzw٬&ѧzXFmT`Z1fo{h' ǚwXs?%W,k`Uc%p5iԄVTuARPZ!"X&?X&0`Vmuܨ#xw2te_1,&(a"`@zz:aWk@: U =n+Nc#V(kw}z_РAaWm;m5)3Lgp1)b&"x 33A9cΊ?& w9x]ap1 b."k8L`С^s{wG@>M7{+0.ƘQ͛[=k#4_3wzzl߾=T07t  C ;DPAB ]e/zM*jJX&0u ֪c>ˆ:U^?7kTB @4"2ܰe\sB;U͝h *jkkiƘQ@ @"r""yyy1";Iggu%QYYi];1ձ,Dt9xgȑ1hU&ty຅>eVcMޒ(BDN5 `PPPPȑ##6Z~ŅOx|->&t9x{AO ܉m5**OBu۷o& gz7Ǣtx#/aZO>LN'* 8q۶m<[1fkǢx(k.aX&P\\ѣc&Uu9WeNcbU6= &a๙3g?&e@%Ν;lKs15ۨ(a<dGz_={v߇z6mZ&7@@II ֭kSшkOY2VivTXro~3/###[D̹;&;K,lرcG& c  0+ӫPP!"vT-p;٭:g?Uiii"bDL4i>N[vmLo!%%%10~oAi5%4-vU X`nA㏀۷~Nۋs>9YqĴz j "2k~;_~E)))P㧵}>֒`6nt\=';;;pnJ "#6cc=vYf\.i)~eRSS3,X0oMd%ضm6mm "ܙ_DqxeG~xgr)z[_DLuuҧ~z#`yx2-[^Vk9k:l PxLrTKᇊ)Sܵa/m߾V xH8p  Z` `Æ cƢz ZHRD`ܙR{hO%%%/5N?cp}>۶mcQBcD䠨\/C X:JY.++=a„m͋~i1El۶NBoAmd%?bB|p{YOcǎ}v‰?Ě'k,(--J_@FFFpBl>0$"c/4M}۠Aȑ#$~W_ݳ~=9/ n;Cj#T5$AD?ocǎMyw/#ӧϠHoll|g~2cƌ;;߭~yiÕ{N\H- kJ5^df덾OO:餼 /$~_?ٳg ."^=Rh р0BD$xk XOYf<7'' 6u]?'.ZR k;RǠv/$\zbpU+{WeffDn;BşxP;1Ƙ{y5JJJM:pnmD"Dd& ~7gH⯭]vb^9Xi'-0=$kcKfffj@;w:Im9f7סKqXbGjΙ3ԔH⯬\zꫯj}a:cu\""p6 C1:_½mDd2>M_u=;wmΝN<8? kG‰nlSZZ԰`zz 8sۻ@GDcїkG} =ÓO?½֭/?뉏ۂU_ہ|&HOO3kp}AF #"?Ětk+k… p '#u=9~b-;ہ%՝ρ_nM5Ic6vmPD|4mM9L$~[p'D2ഹ+?B9{!??T'&@BDnI#yyy9mS /2?&'DCƘCee3ԧZ!ﰦȂC_aÆ}WDL |1o޼UOaI ,TDkx&7`9;\Җ~}8(N1bތ1Z'Hm%QB ֛r`>`پ~....:Ϳ/n#~LkN3Ƽݒi<˗ĩ;@7EDRXgFX}g,Z¾x;w/y2'À|Ƙע\40F{)*}IǚsU =csyKrss #>%KT?V9Ƙg\4m""jy>ɨt3i!J:6vi<%ٹ_^^[rZ'zc̢( Ѝ\vaѷ墋.ww^I%%%N2/d2*@7AD ׀R,o꫇z}_D̦M^0a O)%1z(1C  "$;jV[nyG|_D̚5k4i"Ew,Ŀ_g:1GdX`Dd Mn;se]vVJJ+K=_~#v؋WhGr1薌 ޡiquXC}>YfE|_D|W{a.t1(=H"2iyۇ+\99C' b 5ϕ/5FwZntsr@kn)s{꽕*wCCeզ|unn{~56֧5ݵ5[>Ę#ۍ1?c)QF ~ ⽘xuٜt8N8n4 HȿzâgKٴ5&%% ˍ+Mo0i:硱ъ,˟$s1'q*2%Fh Έ;ۏ ^۝3a#.Oc*BwGD@ ;  ~伳'0_Qߟ*r?Icc1ũȔ'D0p0x L f?& (2?:W\_S:IS@c4OMzz&_|{+(-xxR+ͬZ4U9xkk*{InN_ (=5!"`SF9{JaA̙€95\S[ªeOkv\ eǧԔxD e\c:cNoq̙BqhioSW޺2V-[HC}[LcLC)5(#"?Z <AS'Z"r3Wk _<԰} Ƙ8 n""7}&]AAġ>")a__oxl֓_şd"r-?r >Cyg +ں=Rw{vƘ8ҍP""2kD\=R‘pƌHXWTyK= /*F ]= ʉǍ/㱧SS+ N'IYDPl =1GE<x]/k&ϱ_bJR DBXfܾ1d:s"2,_as%) Bâgv}C_e Ԗ8I~%.(!:±l1 y??Jůt5p<((lW4ؓ[(H?D' s*@zz>j)>p U$D Ap\/mu1E@ I? <+-(~]QcPS' _W+B 5?p>].7xyR\}%-  'I)J;fsof"wܼ~EDnw\W+7 ZZ^3񧤤%V˚%Wvf,@N#~o/4hu1Ej!H> 'wHg/ ɯWv5qr&\v][ۿ 4gs?<6\]חXx$%j4gsPP8:aⷶ~"tOuO%ڨ4@4 JkjB| 5N'v]J,Pk}Ƒ%{˜AxTmdղE}uNoa[b(?1⯪XϷw~8SP5&t3%|)Ze'JAAMe%߰vA?64'J2ālxMK?\i -JRH0+|]/v|L90F JQ8 H4e$.2<*YΈkken$ 8Y|(Iz'?c,~-Tmv+u5۩DU)_`s3(HzN2ufQQҒ(+YFyJ*IvwcjE jpÊdlۿ`gWڹ6X |<{BR0t eÿY|Tmj/;`eЗxJRo."fzbRR3X#[2 ~/BNHzbPP4N݀=ƘmqME)=oLcKxeMQB2Cc>IM)JIg7c̮ݕğ4B p1vW^I5D$ ?؎1ޒ$dFp읨QDT5qIc̹3EI V5 ܻ`N"gnJQEL10s\3kܙ$1w8R`)0z"2&ҏ7 "'G00>^O`- ߄ܠ$^ ("XS{!8Xg`2=1xˊ7p0g^ZO' 0+X HnI=*JB5zO j(p>y%c1aE%w|R pY:q%I5) /}y9}੭5} ;No܅?~Yy'vƃ5?*J " >ӯ \=VTӼ3G;\fOV^K4~k= ZZqgE;DX`*SO M]L]Hσ:) E'Dd p,OC _ tnf}?7 *JWmk~L[k04d9N} $(o"28 ?hwi!'X0? '+c#E=GWxʇzC ?{^vsCQz=-.àp3s hzX]t / ű̓ēmHN> RAў+]jӡ`ssD$3R i_L;38I)(J`?`h4lf. T6Tzl=fb=͙jM yaQNrG+)J'@SF JI-t¾ٰ_Ob+E#=Ddpc"=1'`0.1TϋU%^HkU?9fUj;!%p+"Cb9E=&L=*(i0y緅 D`G&;=Rxӳ F-βM%DO hgLQI3&0@@<`w B~x3(q0gqL&dh($=RDzb* 3 OPܐtǪNn_t('@E}oXmL:XzEjߊV D2m4 yS < 27.Q˙ęhkGhu?#N^4S Q5ƒCL &jޏcq`)*M0_(k.٘$L\6`gL3(1"6LW9*Z?]70} lz5Ƙpg)J@z_ X_juA01(Y|Ccȱul[cqȲĄY0Ƭ֋5Ut ߑ7_Hp\h|Y%8>7eIQJl8A;@6Gww6|o\e˝cމC%ht"{MѶ l/~{.%P1,O%x~/kpFO!%PU %V(_a?6lu~%^ pqmN5{+^e" v~@:au*n oi*J{\B,ї%Ƙޞ$1EQZӓ((J(I$1jĨ(J(I$1jĨ(J(I$1jĨ(J(I$1jĨ(J(I$1j?<>DNIENDB`gpick_0.2.5/source/Internationalisation.h0000644000175000017500000000350412070605214017253 0ustar zbygzbyg/* * 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 INTERNATIONALISATIOM_H_ #define INTERNATIONALISATIOM_H_ #ifdef ENABLE_NLS #include #define _(STRING) gettext(STRING) #define N_(STRING) STRING #else #define _(STRING) STRING #define N_(STRING) STRING #endif void initialize_internationalisation(); #endif /* INTERNATIONALISATIOM_H_ */ gpick_0.2.5/source/GlobalState.cpp0000644000175000017500000002744512113713537015631 0ustar zbygzbyg/* * 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 "GlobalState.h" #include "GlobalStateStruct.h" #include "Paths.h" #include "ScreenReader.h" #include "Converter.h" #include "color_names/DownloadNameFile.h" #include "layout/LuaBindings.h" #include "layout/Layout.h" #include "transformation/Chain.h" #include "transformation/Factory.h" #include "dynv/DynvMemoryIO.h" #include "dynv/DynvVarString.h" #include "dynv/DynvVarInt32.h" #include "dynv/DynvVarColor.h" #include "dynv/DynvVarPtr.h" #include "dynv/DynvVarFloat.h" #include "dynv/DynvVarDynv.h" #include "dynv/DynvVarBool.h" #include "dynv/DynvXml.h" #include "DynvHelpers.h" #include #include #include #include using namespace std; GlobalState* global_state_create(){ GlobalState *gs = new GlobalState; gs->params = 0; gs->lua = 0; gs->loaded_levels = GlobalStateLevel(0); gs->random = 0; return gs; } int global_state_destroy(GlobalState* gs){ delete gs; return 0; } int global_state_term(GlobalState *gs){ //write settings to file gchar* config_file = build_config_path("settings.xml"); ofstream params_file(config_file); if (params_file.is_open()){ params_file << "" << endl; dynv_xml_serialize(gs->params, params_file); params_file << "" << endl; params_file.close(); } g_free(config_file); //destroy converter system converters_term((Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0)); //destroy layout system layout::layouts_term((layout::Layouts*)dynv_get_pointer_wd(gs->params, "Layouts", 0)); //destroy transformation chain transformation::Chain *chain = reinterpret_cast(dynv_get_pointer_wdc(gs->params, "TransformationChain", 0)); delete chain; //destroy color list, random generator and other systems color_list_destroy(gs->colors); random_destroy(gs->random); color_names_destroy(gs->color_names); sampler_destroy(gs->sampler); screen_reader_destroy(gs->screen_reader); dynv_system_release(gs->params); lua_close(gs->lua); return 0; } int global_state_init(GlobalState *gs, GlobalStateLevel level){ //Create configuration directory if it doesn't exit GStatBuf st; gchar* config_dir = build_config_path(NULL); if (g_stat(config_dir, &st)!=0){ #ifndef _MSC_VER g_mkdir(config_dir, S_IRWXU); #else g_mkdir(config_dir, NULL); #endif } g_free(config_dir); if ((level & GLOBALSTATE_SCRIPTING) && !(gs->loaded_levels & GLOBALSTATE_SCRIPTING)){ //check if user has user_init.lua file, if not, then create empty file gchar *user_init_file = build_config_path("user_init.lua"); FILE *user_init = fopen(user_init_file, "r"); if (user_init){ fclose(user_init); }else{ user_init = fopen(user_init_file, "w"); if (user_init){ fclose(user_init); } } g_free(user_init_file); } if ((level & GLOBALSTATE_OTHER) && !(gs->loaded_levels & GLOBALSTATE_OTHER)){ gs->screen_reader = screen_reader_new(); gs->sampler = sampler_new(gs->screen_reader); //create and seed random generator gs->random = random_new("SHR3"); gulong seed_value=time(0)|1; random_seed(gs->random, &seed_value); } if ((level & GLOBALSTATE_COLOR_NAMES) && !(gs->loaded_levels & GLOBALSTATE_COLOR_NAMES)){ //create and load color names gs->color_names = color_names_new(); gchar* tmp; if (color_names_load_from_file(gs->color_names, tmp=build_filename("colors.txt")) != 0){ g_free(tmp); if (color_names_load_from_file(gs->color_names, tmp=build_config_path("colors.txt")) != 0){ download_name_file(tmp); color_names_load_from_file(gs->color_names, tmp); } } g_free(tmp); color_names_load_from_file(gs->color_names, tmp=build_filename("colors0.txt")); g_free(tmp); gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_COLOR_NAMES); } if ((level & GLOBALSTATE_CONFIGURATION) && !(gs->loaded_levels & GLOBALSTATE_CONFIGURATION)){ //create dynamic parameter system struct dynvHandlerMap* handler_map = dynv_handler_map_create(); dynv_handler_map_add_handler(handler_map, dynv_var_string_new()); dynv_handler_map_add_handler(handler_map, dynv_var_int32_new()); dynv_handler_map_add_handler(handler_map, dynv_var_color_new()); dynv_handler_map_add_handler(handler_map, dynv_var_ptr_new()); dynv_handler_map_add_handler(handler_map, dynv_var_float_new()); dynv_handler_map_add_handler(handler_map, dynv_var_dynv_new()); dynv_handler_map_add_handler(handler_map, dynv_var_bool_new()); gs->params = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); gchar* config_file = build_config_path("settings.xml"); ifstream params_file(config_file); if (params_file.is_open()){ dynv_xml_deserialize(gs->params, params_file); params_file.close(); } g_free(config_file); gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_CONFIGURATION); } if ((level & GLOBALSTATE_COLOR_LIST) && !(gs->loaded_levels & GLOBALSTATE_COLOR_LIST)){ //create color list / callbacks must be defined elsewhere struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(gs->params); gs->colors = color_list_new(handler_map); dynv_handler_map_release(handler_map); gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_COLOR_LIST); } if ((level & GLOBALSTATE_SCRIPTING) && !(gs->loaded_levels & GLOBALSTATE_SCRIPTING)){ //create and load lua state lua_State *L= luaL_newstate(); luaL_openlibs(L); int status; char *tmp; lua_ext_colors_openlib(L); layout::lua_ext_layout_openlib(L); gchar* lua_root_path = build_filename("?.lua"); gchar* lua_user_path = build_config_path("?.lua"); gchar* lua_path = g_strjoin(";", lua_root_path, lua_user_path, (void*)0); lua_getglobal(L, "package"); lua_pushstring(L, "path"); lua_pushstring(L, lua_path); lua_settable(L, -3); lua_pop(L, 1); g_free(lua_path); g_free(lua_root_path); g_free(lua_user_path); tmp = build_filename("init.lua"); status = luaL_loadfile(L, tmp) || lua_pcall(L, 0, 0, 0); if (status) { cerr<<"init script load failed: "<lua = L; dynv_set_pointer(gs->params, "lua_State", L); gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_SCRIPTING); } if ((level & GLOBALSTATE_CONVERTERS) && !(gs->loaded_levels & GLOBALSTATE_CONVERTERS)){ //create converter system Converters* converters = converters_init(gs->params); char** source_array; uint32_t source_array_size; if ((source_array = (char**)dynv_get_string_array_wd(gs->params, "gpick.converters.names", 0, 0, &source_array_size))){ bool* copy_array; uint32_t copy_array_size=0; bool* paste_array; uint32_t paste_array_size=0; copy_array = dynv_get_bool_array_wd(gs->params, "gpick.converters.copy", 0, 0, ©_array_size); paste_array = dynv_get_bool_array_wd(gs->params, "gpick.converters.paste", 0, 0, &paste_array_size); gsize source_array_i = 0; Converter* converter; if (copy_array_size>0 || paste_array_size>0){ while (source_array_icopy = converter->serialize_available & copy_array[source_array_i]; if (source_array_ipaste = converter->deserialize_available & paste_array[source_array_i]; } ++source_array_i; } }else{ while (source_array_icopy = converter->serialize_available; converter->paste = converter->deserialize_available; } ++source_array_i; } } if (copy_array) delete [] copy_array; if (paste_array) delete [] paste_array; converters_reorder(converters, (const char**)source_array, source_array_size); if (source_array) delete [] source_array; }else{ //Initialize default values const char* name_array[]={ "color_web_hex", "color_css_rgb", "color_css_hsl", }; source_array_size = sizeof(name_array)/sizeof(name_array[0]); gsize source_array_i = 0; Converter* converter; while (source_array_icopy = converter->serialize_available; converter->paste = converter->deserialize_available; } ++source_array_i; } converters_reorder(converters, name_array, source_array_size); } converters_rebuild_arrays(converters, CONVERTERS_ARRAY_TYPE_COPY); converters_rebuild_arrays(converters, CONVERTERS_ARRAY_TYPE_PASTE); converters_set(converters, converters_get(converters, dynv_get_string_wd(gs->params, "gpick.converters.display", "color_web_hex")), CONVERTERS_ARRAY_TYPE_DISPLAY); converters_set(converters, converters_get(converters, dynv_get_string_wd(gs->params, "gpick.converters.color_list", "color_web_hex")), CONVERTERS_ARRAY_TYPE_COLOR_LIST); gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_CONVERTERS); } if ((level & GLOBALSTATE_TRANSFORMATIONS) && !(gs->loaded_levels & GLOBALSTATE_TRANSFORMATIONS)){ transformation::Chain *chain = new transformation::Chain(); dynv_set_pointer(gs->params, "TransformationChain", chain); chain->setEnabled(dynv_get_bool_wd(gs->params, "gpick.transformations.enabled", false)); struct dynvSystem** config_array; uint32_t config_size; if ((config_array = (struct dynvSystem**)dynv_get_dynv_array_wd(gs->params, "gpick.transformations.items", 0, 0, &config_size))){ for (uint32_t i = 0; i != config_size; i++){ const char *name = dynv_get_string_wd(config_array[i], "name", 0); if (name){ boost::shared_ptr tran = transformation::Factory::create(name); if (tran){ tran->deserialize(config_array[i]); chain->add(tran); } } dynv_system_release(config_array[i]); } delete [] config_array; } gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_TRANSFORMATIONS); } if ((level & GLOBALSTATE_OTHER) && !(gs->loaded_levels & GLOBALSTATE_OTHER)){ //create layout system layout::Layouts* layout = layout::layouts_init(gs->params); layout = 0; } if (level & GLOBALSTATE_OTHER){ gs->loaded_levels = GlobalStateLevel(gs->loaded_levels | GLOBALSTATE_OTHER); } return 0; } gpick_0.2.5/source/ColorPicker.cpp0000644000175000017500000014546612071374751015654 0ustar zbygzbyg/* * 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 "GlobalStateStruct.h" #include "ColorPicker.h" #include "DragDrop.h" #include "Converter.h" #include "DynvHelpers.h" #include "CopyPaste.h" #include "FloatingPicker.h" #include "ColorRYB.h" #include "ColorWheelType.h" #include "ColorSpaceType.h" #include "gtk/Swatch.h" #include "gtk/Zoomed.h" #include "gtk/ColorComponent.h" #include "gtk/ColorWidget.h" #include "uiApp.h" #include "uiUtilities.h" #include "uiColorInput.h" #include "uiConverter.h" #include "Internationalisation.h" #include #include #ifdef _MSC_VER #define M_PI 3.14159265359 #endif #include #include #include #include #include using namespace std; using namespace math; typedef struct ColorPickerArgs{ ColorSource source; GtkWidget* main; GtkWidget* expanderRGB; GtkWidget* expanderHSV; GtkWidget* expanderHSL; GtkWidget* expanderCMYK; GtkWidget* expanderXYZ; GtkWidget* expanderLAB; GtkWidget* expanderLCH; GtkWidget* expanderInfo; GtkWidget* expanderMain; GtkWidget* expanderSettings; GtkWidget *swatch_display; GtkWidget *zoomed_display; GtkWidget *color_code; GtkWidget* hsl_control; GtkWidget* hsv_control; GtkWidget* rgb_control; GtkWidget* cmyk_control; GtkWidget* lab_control; GtkWidget* lch_control; GtkWidget* color_name; GtkWidget* statusbar; GtkWidget* contrastCheck; GtkWidget* contrastCheckMsg; guint timeout_source_id; FloatingPicker floating_picker; struct dynvSystem *params; struct dynvSystem *global_params; GlobalState* gs; }ColorPickerArgs; struct ColorCompItem{ GtkWidget *widget; GtkColorComponentComp component; int component_id; }; static int source_set_color(ColorPickerArgs *args, ColorObject* color); static int source_set_nth_color(ColorPickerArgs *args, uint32_t color_n, ColorObject* color); static int source_get_nth_color(ColorPickerArgs *args, uint32_t color_n, ColorObject** color); static void updateMainColorNow(ColorPickerArgs* args){ if (!dynv_get_bool_wd(args->params, "zoomed_enabled", true)){ Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &c); gchar* text = main_get_color_text(args->gs, &c, COLOR_TEXT_TYPE_DISPLAY); gtk_color_set_color(GTK_COLOR(args->color_code), &c, text); if (text) g_free(text); gtk_swatch_set_main_color(GTK_SWATCH(args->swatch_display), &c); } } static gboolean updateMainColor( gpointer data ){ ColorPickerArgs* args=(ColorPickerArgs*)data; GdkScreen *screen; GdkModifierType state; int x, y; int width, height; gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, &state); width = gdk_screen_get_width(screen); height = gdk_screen_get_height(screen); Vec2 pointer(x,y); Vec2 window_size(width, height); screen_reader_reset_rect(args->gs->screen_reader); Rect2 sampler_rect, zoomed_rect, final_rect; sampler_get_screen_rect(args->gs->sampler, pointer, window_size, &sampler_rect); screen_reader_add_rect(args->gs->screen_reader, screen, sampler_rect); bool zoomed_enabled = dynv_get_bool_wd(args->params, "zoomed_enabled", true); if (zoomed_enabled){ gtk_zoomed_get_screen_rect(GTK_ZOOMED(args->zoomed_display), pointer, window_size, &zoomed_rect); screen_reader_add_rect(args->gs->screen_reader, screen, zoomed_rect); } screen_reader_update_pixbuf(args->gs->screen_reader, &final_rect); Vec2 offset; offset = Vec2(sampler_rect.getX()-final_rect.getX(), sampler_rect.getY()-final_rect.getY()); Color c; sampler_get_color_sample(args->gs->sampler, pointer, window_size, offset, &c); gchar* text = main_get_color_text(args->gs, &c, COLOR_TEXT_TYPE_DISPLAY); gtk_color_set_color(GTK_COLOR(args->color_code), &c, text); if (text) g_free(text); gtk_swatch_set_main_color(GTK_SWATCH(args->swatch_display), &c); if (zoomed_enabled){ offset = Vec2(zoomed_rect.getX()-final_rect.getX(), zoomed_rect.getY()-final_rect.getY()); gtk_zoomed_update(GTK_ZOOMED(args->zoomed_display), pointer, window_size, offset, screen_reader_get_pixbuf(args->gs->screen_reader)); } return TRUE; } static gboolean updateMainColorTimer(ColorPickerArgs* args){ updateMainColor(args); return true; } static void updateComponentText(ColorPickerArgs *args, GtkColorComponent *component, const char *type){ Color transformed_color; gtk_color_component_get_transformed_color(component, &transformed_color); lua_State* L = static_cast(dynv_get_pointer_wdc(args->gs->params, "lua_State", 0)); list str = color_space_color_to_text(type, &transformed_color, L); int j = 0; const char *text[4]; memset(text, 0, sizeof(text)); for (list::iterator i = str.begin(); i != str.end(); i++){ text[j] = (*i).c_str(); j++; if (j > 3) break; } gtk_color_component_set_text(component, text); } static void updateDisplays(ColorPickerArgs *args, GtkWidget *except_widget){ updateMainColorNow(args); Color c, c2; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display),&c); if (except_widget != args->hsl_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->hsl_control), &c); if (except_widget != args->hsv_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->hsv_control), &c); if (except_widget != args->rgb_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->rgb_control), &c); if (except_widget != args->cmyk_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->cmyk_control), &c); if (except_widget != args->lab_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->lab_control), &c); if (except_widget != args->lch_control) gtk_color_component_set_color(GTK_COLOR_COMPONENT(args->lch_control), &c); updateComponentText(args, GTK_COLOR_COMPONENT(args->hsl_control), "hsl"); updateComponentText(args, GTK_COLOR_COMPONENT(args->hsv_control), "hsv"); updateComponentText(args, GTK_COLOR_COMPONENT(args->rgb_control), "rgb"); updateComponentText(args, GTK_COLOR_COMPONENT(args->cmyk_control), "cmyk"); updateComponentText(args, GTK_COLOR_COMPONENT(args->lab_control), "lab"); updateComponentText(args, GTK_COLOR_COMPONENT(args->lch_control), "lch"); string color_name = color_names_get(args->gs->color_names, &c, true); gtk_entry_set_text(GTK_ENTRY(args->color_name), color_name.c_str()); gtk_color_get_color(GTK_COLOR(args->contrastCheck), &c2); gtk_color_set_text_color(GTK_COLOR(args->contrastCheck), &c); stringstream ss; ss.setf(ios::fixed, ios::floatfield); Color c_lab, c2_lab; color_rgb_to_lab_d50(&c, &c_lab); color_rgb_to_lab_d50(&c2, &c2_lab); const ColorWheelType *wheel = &color_wheel_types_get()[0]; Color hsl1, hsl2; double hue1, hue2; color_rgb_to_hsl(&c, &hsl1); color_rgb_to_hsl(&c2, &hsl2); wheel->rgbhue_to_hue(hsl1.hsl.hue, &hue1); wheel->rgbhue_to_hue(hsl2.hsl.hue, &hue2); double complementary = std::abs(hue1 - hue2); complementary -= std::floor(complementary); complementary *= std::sin(hsl1.hsl.lightness * M_PI) * std::sin(hsl2.hsl.lightness * M_PI); complementary *= std::sin(hsl1.hsl.saturation * M_PI / 2) * std::sin(hsl2.hsl.saturation * M_PI / 2); ss << std::setprecision(1) << std::abs(c_lab.lab.L - c2_lab.lab.L) + complementary * 50 << "%"; gtk_label_set_text(GTK_LABEL(args->contrastCheckMsg), ss.str().c_str()); } static void on_swatch_active_color_changed( GtkWidget *widget, gint32 new_active_color, gpointer data ){ ColorPickerArgs* args = (ColorPickerArgs*)data; updateDisplays(args, widget); } static void on_swatch_color_changed( GtkWidget *widget, gpointer data ){ ColorPickerArgs* args=(ColorPickerArgs*)data; updateDisplays(args, widget); } static void on_swatch_menu_add_to_palette(GtkWidget *widget, gpointer item) { ColorPickerArgs* args=(ColorPickerArgs*)item; Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &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 on_swatch_menu_add_all_to_palette(GtkWidget *widget, gpointer item) { ColorPickerArgs* args=(ColorPickerArgs*)item; Color c; for (int i = 1; i < 7; ++i) { gtk_swatch_get_color(GTK_SWATCH(args->swatch_display), i, &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 on_swatch_color_activated(GtkWidget *widget, gpointer item) { ColorPickerArgs* args=(ColorPickerArgs*)item; Color c; gtk_swatch_get_active_color(GTK_SWATCH(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 on_swatch_center_activated(GtkWidget *widget, gpointer item) { ColorPickerArgs* args=(ColorPickerArgs*)item; floating_picker_activate(args->floating_picker, true); } static void on_swatch_color_edit(GtkWidget *widget, gpointer item) { ColorPickerArgs* args=(ColorPickerArgs*)item; Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &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->swatch_display)), args->gs, color_object, &new_color_object )==0){ source_set_color(args, new_color_object); color_object_release(new_color_object); } color_object_release(color_object); } static void paste_cb(GtkWidget *widget, ColorPickerArgs* args) { struct ColorObject* color_object; if (copypaste_get_color_object(&color_object, args->gs)==0){ source_set_color(args, color_object); color_object_release(color_object); } } static void swatch_popup_menu_cb(GtkWidget *widget, ColorPickerArgs* args){ GtkWidget *menu; gint32 button, event_time; Color c; updateMainColor(args); gtk_swatch_get_main_color(GTK_SWATCH(args->swatch_display), &c); struct ColorObject* color_object; color_object = color_list_new_color_object(args->gs->colors, &c); menu = converter_create_copy_menu(color_object, 0, args->gs); color_object_release(color_object); gtk_widget_show_all(GTK_WIDGET(menu)); 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 swatch_button_press_cb(GtkWidget *widget, GdkEventButton *event, ColorPickerArgs* args){ GtkWidget *menu; int color_index = gtk_swatch_get_color_at(GTK_SWATCH(widget), event->x, event->y); if (event->button == 3 && event->type == GDK_BUTTON_PRESS && color_index>0){ GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &c); 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_swatch_menu_add_to_palette), args); 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_swatch_menu_add_all_to_palette), args); 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); 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_swatch_color_edit), args); 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 (paste_cb), args); if (copypaste_is_color_object_available(args->gs)!=0){ gtk_widget_set_sensitive(item, false); } gtk_widget_show_all (GTK_WIDGET(menu)); 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); } return false; } static gboolean on_swatch_focus_change(GtkWidget *widget, GdkEventFocus *event, gpointer data) { ColorPickerArgs* args=(ColorPickerArgs*)data; if (event->in){ gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "swatch_focused"), _("Press Spacebar to sample color under mouse pointer")); }else{ gtk_statusbar_pop(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "swatch_focused")); } return FALSE; } static gboolean on_key_up (GtkWidget *widget, GdkEventKey *event, gpointer data) { ColorPickerArgs* args=(ColorPickerArgs*)data; guint modifiers = gtk_accelerator_get_default_mod_mask(); switch(event->keyval) { case GDK_m: { int x, y; gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); math::Vec2 position(x, y); if ((event->state&modifiers)==GDK_CONTROL_MASK){ gtk_zoomed_set_mark(GTK_ZOOMED(args->zoomed_display), 1, position); }else{ gtk_zoomed_set_mark(GTK_ZOOMED(args->zoomed_display), 0, position); } } break; case GDK_c: if ((event->state&modifiers)==GDK_CONTROL_MASK){ Color c; updateMainColor(args); gtk_swatch_get_main_color(GTK_SWATCH(args->swatch_display), &c); struct ColorObject* color_object; 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_1: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 1); updateDisplays(args, widget); return TRUE; break; case GDK_2: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 2); updateDisplays(args, widget); return TRUE; break; case GDK_3: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 3); updateDisplays(args, widget); return TRUE; break; case GDK_4: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 4); updateDisplays(args, widget); return TRUE; break; case GDK_5: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 5); updateDisplays(args, widget); return TRUE; break; case GDK_6: gtk_swatch_set_active_index(GTK_SWATCH(args->swatch_display), 6); updateDisplays(args, widget); return TRUE; break; case GDK_Right: gtk_swatch_move_active(GTK_SWATCH(args->swatch_display),1); updateDisplays(args, widget); return TRUE; break; case GDK_Left: gtk_swatch_move_active(GTK_SWATCH(args->swatch_display),-1); updateDisplays(args, widget); return TRUE; break; case GDK_space: updateMainColor(args); gtk_swatch_set_color_to_main(GTK_SWATCH(args->swatch_display)); if (dynv_get_bool_wd(args->params, "sampler.add_to_palette", true)){ Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &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); } if (dynv_get_bool_wd(args->params, "sampler.copy_to_clipboard", true)){ Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &c); struct ColorObject* color_object; 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); } if (dynv_get_bool_wd(args->params, "sampler.rotate_swatch_after_sample", true)){ gtk_swatch_move_active(GTK_SWATCH(args->swatch_display),1); } updateDisplays(args, widget); return TRUE; break; case GDK_a: on_swatch_menu_add_all_to_palette(NULL, args); return TRUE; break; case GDK_e: on_swatch_color_edit(NULL, args); return TRUE; break; default: return FALSE; break; } return FALSE; } int color_picker_key_up(ColorSource* color_source, GdkEventKey *event){ return on_key_up(0, event, color_source); } static void on_oversample_value_changed(GtkRange *slider, gpointer data){ ColorPickerArgs* args=(ColorPickerArgs*)data; sampler_set_oversample(args->gs->sampler, (int)gtk_range_get_value(GTK_RANGE(slider))); } static void on_zoom_value_changed(GtkRange *slider, gpointer data){ ColorPickerArgs* args=(ColorPickerArgs*)data; gtk_zoomed_set_zoom(GTK_ZOOMED(args->zoomed_display), gtk_range_get_value(GTK_RANGE(slider))); } static void color_component_change_value(GtkWidget *widget, Color* c, ColorPickerArgs* args){ gtk_swatch_set_active_color(GTK_SWATCH(args->swatch_display), c); updateDisplays(args, widget); } static void color_component_input_clicked(GtkWidget *widget, int component_id, ColorPickerArgs* args){ dialog_color_component_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), GTK_COLOR_COMPONENT(widget), component_id, dynv_get_dynv(args->params, "component_edit")); } static void ser_decimal_get(GtkColorComponentComp component, int component_id, Color* color, const char *text){ double v; stringstream ss(text); ss >> v; switch (component){ case hsv: case hsl: if (component_id == 0){ color->ma[component_id] = v / 360; }else{ color->ma[component_id] = v / 100; } break; default: color->ma[component_id] = v / 100; } } static string ser_decimal_set(GtkColorComponentComp component, int component_id, Color* color){ stringstream ss; switch (component){ case hsv: case hsl: if (component_id == 0){ ss << setprecision(0) << fixed << color->ma[component_id] * 360; }else{ ss << setprecision(0) << fixed << color->ma[component_id] * 100; } break; default: ss << setprecision(0) << fixed << color->ma[component_id] * 100; } return ss.str(); } static struct{ const char *name; const char *human_name; void (*get)(GtkColorComponentComp component, int component_id, Color* color, const char *text); string (*set)(GtkColorComponentComp component, int component_id, Color* color); }serial[] = { {"decimal", "Decimal", ser_decimal_get, ser_decimal_set}, }; static void color_component_copy(GtkWidget *widget, ColorPickerArgs* args){ struct ColorCompItem *comp_item = (struct ColorCompItem*)g_object_get_data(G_OBJECT(gtk_widget_get_parent(widget)), "comp_item"); const char *text = gtk_color_component_get_text(GTK_COLOR_COMPONENT(comp_item->widget), comp_item->component_id); if (text){ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), text, strlen(text)); gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); } } static void color_component_paste(GtkWidget *widget, ColorPickerArgs* args){ Color color; struct ColorCompItem *comp_item = (struct ColorCompItem*)g_object_get_data(G_OBJECT(gtk_widget_get_parent(widget)), "comp_item"); gtk_color_component_get_transformed_color(GTK_COLOR_COMPONENT(comp_item->widget), &color); gchar *text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); if (text){ serial[0].get(comp_item->component, comp_item->component_id, &color, text); gtk_color_component_set_transformed_color(GTK_COLOR_COMPONENT(comp_item->widget), &color); g_free(text); gtk_color_component_get_color(GTK_COLOR_COMPONENT(comp_item->widget), &color); gtk_swatch_set_active_color(GTK_SWATCH(args->swatch_display), &color); updateDisplays(args, comp_item->widget); } } static void color_component_edit(GtkWidget *widget, ColorPickerArgs* args){ struct ColorCompItem *comp_item = (struct ColorCompItem*)g_object_get_data(G_OBJECT(gtk_widget_get_parent(widget)), "comp_item"); dialog_color_component_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), GTK_COLOR_COMPONENT(comp_item->widget), comp_item->component_id, dynv_get_dynv(args->params, "component_edit")); } static void destroy_comp_item(struct ColorCompItem *comp_item){ delete comp_item; } static gboolean color_component_key_up_cb(GtkWidget *widget, GdkEventButton *event, ColorPickerArgs* args){ if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)){ GtkWidget *menu; GtkWidget* item; gint32 button, event_time; menu = gtk_menu_new (); struct ColorCompItem *comp_item = new struct ColorCompItem; comp_item->widget = widget; comp_item->component_id = gtk_color_component_get_component_id_at(GTK_COLOR_COMPONENT(widget), event->x, event->y); comp_item->component = gtk_color_component_get_component(GTK_COLOR_COMPONENT(widget)); g_object_set_data_full(G_OBJECT(menu), "comp_item", comp_item, (GDestroyNotify)destroy_comp_item); item = gtk_menu_item_new_with_image(_("Copy"), gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(color_component_copy), args); 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(color_component_paste), args); 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(color_component_edit), args); gtk_widget_show_all(GTK_WIDGET(menu)); 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); return true; } return false; } static void on_oversample_falloff_changed(GtkWidget *widget, gpointer data) { GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) { GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget)); gint32 falloff_id; gtk_tree_model_get(model, &iter, 2, &falloff_id, -1); ColorPickerArgs* args = (ColorPickerArgs*)data; sampler_set_falloff(args->gs->sampler, (enum SamplerFalloff) falloff_id); } } static GtkWidget* create_falloff_type_list (void){ GtkListStore *store; GtkCellRenderer *renderer; GtkWidget *widget; store = gtk_list_store_new (3, GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_INT); widget = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store)); gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (widget), 0); renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget),renderer,0); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer,"pixbuf",0,NULL); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget),renderer,0); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer,"text",1,NULL); g_object_unref (GTK_TREE_MODEL(store)); GtkTreeIter iter1; const char* falloff_types[][2] = { { "gpick-falloff-none", _("None")}, { "gpick-falloff-linear", _("Linear")}, { "gpick-falloff-quadratic", _("Quadratic")}, { "gpick-falloff-cubic", _("Cubic")}, { "gpick-falloff-exponential", _("Exponential")}, }; gint32 falloff_type_ids[]={ NONE, LINEAR, QUADRATIC, CUBIC, EXPONENTIAL, }; GtkIconTheme *icon_theme; icon_theme = gtk_icon_theme_get_default (); gint icon_size; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, 0, &icon_size); for (guint32 i=0;iparams, "swatch.active_color", gtk_swatch_get_active_index(GTK_SWATCH(args->swatch_display))); Color c; char tmp[32]; for (gint i=1; i<7; ++i){ sprintf(tmp, "swatch.color%d", i); gtk_swatch_get_color(GTK_SWATCH(args->swatch_display), i, &c); dynv_set_color(args->params, tmp, &c); } dynv_set_int32(args->params, "sampler.oversample", sampler_get_oversample(args->gs->sampler)); dynv_set_int32(args->params, "sampler.falloff", sampler_get_falloff(args->gs->sampler)); dynv_set_float(args->params, "zoom", gtk_zoomed_get_zoom(GTK_ZOOMED(args->zoomed_display))); dynv_set_int32(args->params, "zoom_size", gtk_zoomed_get_size(GTK_ZOOMED(args->zoomed_display))); dynv_set_bool(args->params, "expander.settings", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderSettings))); dynv_set_bool(args->params, "expander.rgb", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderRGB))); dynv_set_bool(args->params, "expander.hsv", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderHSV))); dynv_set_bool(args->params, "expander.hsl", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderHSL))); dynv_set_bool(args->params, "expander.lab", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderLAB))); dynv_set_bool(args->params, "expander.lch", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderLCH))); dynv_set_bool(args->params, "expander.cmyk", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderCMYK))); dynv_set_bool(args->params, "expander.info", gtk_expander_get_expanded(GTK_EXPANDER(args->expanderInfo))); gtk_color_get_color(GTK_COLOR(args->contrastCheck), &c); dynv_set_color(args->params, "contrast.color", &c); gtk_widget_destroy(args->main); dynv_system_release(args->params); dynv_system_release(args->global_params); delete args; return 0; } static int source_get_color(ColorPickerArgs *args, ColorObject** color){ Color c; gtk_swatch_get_active_color(GTK_SWATCH(args->swatch_display), &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 = color_object; return 0; } static int source_set_nth_color(ColorPickerArgs *args, uint32_t color_n, ColorObject* color){ if (color_n < 0 || color_n > 6) return -1; Color c; color_object_get_color(color, &c); gtk_swatch_set_color(GTK_SWATCH(args->swatch_display), color_n + 1, &c); updateDisplays(args, 0); return 0; } static int source_get_nth_color(ColorPickerArgs *args, uint32_t color_n, ColorObject** color){ if (color_n < 0 || color_n > 6) return -1; Color c; gtk_swatch_get_color(GTK_SWATCH(args->swatch_display), color_n + 1, &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 = color_object; return 0; } static int source_set_color(ColorPickerArgs *args, ColorObject* color){ Color c; color_object_get_color(color, &c); gtk_swatch_set_active_color(GTK_SWATCH(args->swatch_display), &c); updateDisplays(args, 0); return 0; } static int source_activate(ColorPickerArgs *args){ if (args->timeout_source_id > 0) { g_source_remove(args->timeout_source_id); args->timeout_source_id = 0; } struct{ GtkWidget *widget; const char *setting; }color_spaces[] = { {args->expanderCMYK, "color_space.cmyk"}, {args->expanderHSL, "color_space.hsl"}, {args->expanderHSV, "color_space.hsv"}, {args->expanderLAB, "color_space.lab"}, {args->expanderLCH, "color_space.lch"}, {args->expanderRGB, "color_space.rgb"}, {0, 0}, }; for (int i = 0; color_spaces[i].setting; i++){ if (dynv_get_bool_wd(args->params, color_spaces[i].setting, true)) gtk_widget_show(color_spaces[i].widget); else gtk_widget_hide(color_spaces[i].widget); } bool out_of_gamut_mask = dynv_get_bool_wd(args->params, "out_of_gamut_mask", true); gtk_color_component_set_out_of_gamut_mask(GTK_COLOR_COMPONENT(args->lab_control), out_of_gamut_mask); gtk_color_component_set_lab_illuminant(GTK_COLOR_COMPONENT(args->lab_control), color_get_illuminant(dynv_get_string_wd(args->params, "lab.illuminant", "D50"))); gtk_color_component_set_lab_observer(GTK_COLOR_COMPONENT(args->lab_control), color_get_observer(dynv_get_string_wd(args->params, "lab.observer", "2"))); updateComponentText(args, GTK_COLOR_COMPONENT(args->lab_control), "lab"); gtk_color_component_set_out_of_gamut_mask(GTK_COLOR_COMPONENT(args->lch_control), out_of_gamut_mask); gtk_color_component_set_lab_illuminant(GTK_COLOR_COMPONENT(args->lch_control), color_get_illuminant(dynv_get_string_wd(args->params, "lab.illuminant", "D50"))); gtk_color_component_set_lab_observer(GTK_COLOR_COMPONENT(args->lch_control), color_get_observer(dynv_get_string_wd(args->params, "lab.observer", "2"))); updateComponentText(args, GTK_COLOR_COMPONENT(args->lch_control), "lch"); transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); gtk_swatch_set_transformation_chain(GTK_SWATCH(args->swatch_display), chain); gtk_color_set_transformation_chain(GTK_COLOR(args->color_code), chain); gtk_color_set_transformation_chain(GTK_COLOR(args->contrastCheck), chain); if (dynv_get_bool_wd(args->params, "zoomed_enabled", true)){ float refresh_rate = dynv_get_float_wd(args->global_params, "refresh_rate", 30); args->timeout_source_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 1000/refresh_rate, (GSourceFunc)updateMainColorTimer, args, (GDestroyNotify)NULL); } gtk_zoomed_set_size(GTK_ZOOMED(args->zoomed_display), dynv_get_int32_wd(args->params, "zoom_size", 150)); gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "focus_swatch"), _("Click on swatch area to begin adding colors to palette")); return 0; } static int source_deactivate(ColorPickerArgs *args){ gtk_statusbar_pop(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "focus_swatch")); if (args->timeout_source_id > 0){ g_source_remove(args->timeout_source_id); args->timeout_source_id = 0; } return 0; } static struct ColorObject* get_color_object(struct DragDrop* dd){ ColorPickerArgs* args=(ColorPickerArgs*)dd->userdata; ColorObject *colorobject; source_get_color(args, &colorobject); return colorobject; } static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){ gint color_index = gtk_swatch_get_color_at(GTK_SWATCH(dd->widget), x, y); Color c; color_object_get_color(colorobject, &c); gtk_swatch_set_color(GTK_SWATCH(dd->widget), color_index, &c); updateDisplays((ColorPickerArgs*)dd->userdata, 0); return 0; } static bool test_at(struct DragDrop* dd, int x, int y){ gint color_index = gtk_swatch_get_color_at(GTK_SWATCH(dd->widget), x, y); if (color_index>0) return true; return false; } void color_picker_set_floating_picker(ColorSource *color_source, FloatingPicker floating_picker){ ColorPickerArgs* args = (ColorPickerArgs*)color_source; args->floating_picker = floating_picker; } static struct ColorObject* get_color_object_contrast(struct DragDrop* dd){ ColorPickerArgs* args = static_cast(dd->userdata); Color c; gtk_color_get_color(GTK_COLOR(dd->widget), &c); struct ColorObject* colorobject = color_object_new(dd->handler_map); color_object_set_color(colorobject, &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(colorobject->params, "name", name.c_str()); return colorobject; } static int set_color_object_at_contrast(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){ ColorPickerArgs* args = static_cast(dd->userdata); Color c; color_object_get_color(colorobject, &c); gtk_color_set_color(GTK_COLOR(args->contrastCheck), &c, "Sample"); updateDisplays((ColorPickerArgs*)dd->userdata, 0); return 0; } static void show_dialog_converter(GtkWidget *widget, ColorPickerArgs *args){ dialog_converter_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs); return; } static void on_zoomed_activate(GtkWidget *widget, ColorPickerArgs *args){ if (dynv_get_bool_wd(args->params, "zoomed_enabled", true)){ gtk_zoomed_set_fade(GTK_ZOOMED(args->zoomed_display), true); dynv_set_bool(args->params, "zoomed_enabled", false); if (args->timeout_source_id > 0){ g_source_remove(args->timeout_source_id); args->timeout_source_id = 0; } }else{ gtk_zoomed_set_fade(GTK_ZOOMED(args->zoomed_display), false); dynv_set_bool(args->params, "zoomed_enabled", true); if (args->timeout_source_id > 0){ g_source_remove(args->timeout_source_id); args->timeout_source_id = 0; } float refresh_rate = dynv_get_float_wd(args->global_params, "refresh_rate", 30); args->timeout_source_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 1000/refresh_rate, (GSourceFunc)updateMainColorTimer, args, (GDestroyNotify)NULL); } return; } static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){ ColorPickerArgs* args = new ColorPickerArgs; args->params = dynv_system_ref(dynv_namespace); args->global_params = dynv_get_dynv(gs->params, "gpick.picker"); args->statusbar = (GtkWidget*)dynv_get_pointer_wd(gs->params, "StatusBar", 0); args->floating_picker = 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.get_nth_color = (int (*)(ColorSource *source, uint32_t color_n, ColorObject** color))source_get_nth_color; args->source.set_nth_color = (int (*)(ColorSource *source, uint32_t color_n, ColorObject* color))source_set_nth_color; args->source.activate = (int (*)(ColorSource *source))source_activate; args->source.deactivate = (int (*)(ColorSource *source))source_deactivate; args->gs = gs; args->timeout_source_id = 0; GtkWidget *vbox, *widget, *expander, *table, *main_hbox, *scrolled; int table_y; main_hbox = gtk_hbox_new(false, 5); vbox = gtk_vbox_new(false, 5); gtk_box_pack_start(GTK_BOX(main_hbox), vbox, false, false, 0); widget = gtk_swatch_new(); gtk_box_pack_start(GTK_BOX(vbox), widget, false, false, 0); g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(on_swatch_focus_change), args); g_signal_connect(G_OBJECT(widget), "focus-out-event", G_CALLBACK(on_swatch_focus_change), args); g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK(on_key_up), args); g_signal_connect(G_OBJECT(widget), "active_color_changed", G_CALLBACK(on_swatch_active_color_changed), args); g_signal_connect(G_OBJECT(widget), "color_changed", G_CALLBACK(on_swatch_color_changed), args); g_signal_connect(G_OBJECT(widget), "color_activated", G_CALLBACK(on_swatch_color_activated), args); g_signal_connect(G_OBJECT(widget), "center_activated", G_CALLBACK(on_swatch_center_activated), args); g_signal_connect_after(G_OBJECT(widget), "button-press-event",G_CALLBACK(swatch_button_press_cb), args); g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(swatch_popup_menu_cb), args); gtk_swatch_set_active_index(GTK_SWATCH(widget), dynv_get_int32_wd(args->params, "swatch.active_color", 1)); args->swatch_display = widget; 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); 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; dd.test_at = test_at; dd.handler_map = dynv_system_get_handler_map(gs->colors->params); dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); { char tmp[32]; const Color *c; for (gint i=1; i<7; ++i){ sprintf(tmp, "swatch.color%d", i); c = dynv_get_color_wd(args->params, tmp, 0); if (c){ gtk_swatch_set_color(GTK_SWATCH(args->swatch_display), i, (Color*)c); } } } args->color_code = gtk_color_new(); gtk_box_pack_start (GTK_BOX(vbox), args->color_code, false, true, 0); g_signal_connect(G_OBJECT(args->color_code), "activated", G_CALLBACK(show_dialog_converter), args); args->zoomed_display = gtk_zoomed_new(); if (!dynv_get_bool_wd(args->params, "zoomed_enabled", true)){ gtk_zoomed_set_fade(GTK_ZOOMED(args->zoomed_display), true); } gtk_zoomed_set_size(GTK_ZOOMED(args->zoomed_display), dynv_get_int32_wd(args->params, "zoom_size", 150)); gtk_box_pack_start (GTK_BOX(vbox), args->zoomed_display, false, false, 0); g_signal_connect(G_OBJECT(args->zoomed_display), "activated", G_CALLBACK(on_zoomed_activate), args); scrolled = gtk_scrolled_window_new(0, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX(main_hbox), scrolled, true, true, 0); vbox = gtk_vbox_new(false, 5); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), vbox); expander=gtk_expander_new(_("Settings")); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.settings", false)); args->expanderSettings=expander; gtk_box_pack_start (GTK_BOX(vbox), expander, FALSE, FALSE, 0); table = gtk_table_new(6, 2, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(expander), table); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Oversample:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); widget = gtk_hscale_new_with_range (0,16,1); g_signal_connect (G_OBJECT (widget), "value-changed", G_CALLBACK (on_oversample_value_changed), args); gtk_range_set_value(GTK_RANGE(widget), dynv_get_int32_wd(args->params, "sampler.oversample", 0)); gtk_table_attach(GTK_TABLE(table), widget,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(_("Falloff:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); widget = create_falloff_type_list(); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (on_oversample_falloff_changed), args); gtk_combo_box_set_active(GTK_COMBO_BOX(widget), dynv_get_int32_wd(args->params, "sampler.falloff", NONE)); gtk_table_attach(GTK_TABLE(table), widget,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(_("Zoom:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); widget = gtk_hscale_new_with_range (0, 100, 1); g_signal_connect (G_OBJECT (widget), "value-changed", G_CALLBACK (on_zoom_value_changed), args); gtk_range_set_value(GTK_RANGE(widget), dynv_get_float_wd(args->params, "zoom", 20)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; expander=gtk_expander_new("HSV"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.hsv", false)); args->expanderHSV=expander; gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(hsv); const char *hsv_labels[] = {"H", _("Hue"), "S", _("Saturation"), "V", _("Value"), NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), hsv_labels); args->hsv_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander=gtk_expander_new("HSL"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.hsl", false)); args->expanderHSL = expander; gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(hsl); const char *hsl_labels[] = {"H", _("Hue"), "S", _("Saturation"), "L", _("Lightness"), NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), hsl_labels); args->hsl_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander=gtk_expander_new("RGB"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.rgb", false)); args->expanderRGB = expander; gtk_box_pack_start (GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(rgb); const char *rgb_labels[] = {"R", _("Red"), "G", _("Green"), "B", _("Blue"), NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), rgb_labels); args->rgb_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander=gtk_expander_new("CMYK"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.cmyk", false)); args->expanderCMYK = expander; gtk_box_pack_start(GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(cmyk); const char *cmyk_labels[] = {"C", _("Cyan"), "M", _("Magenta"), "Y", _("Yellow"), "K", _("Key"), NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), cmyk_labels); args->cmyk_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander = gtk_expander_new("Lab"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.lab", false)); args->expanderLAB = expander; gtk_box_pack_start (GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(lab); const char *lab_labels[] = {"L", _("Lightness"), "a", "a", "b", "b", NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), lab_labels); args->lab_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander = gtk_expander_new("LCH"); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.lch", false)); args->expanderLCH = expander; gtk_box_pack_start (GTK_BOX(vbox), expander, FALSE, FALSE, 0); widget = gtk_color_component_new(lch); const char *lch_labels[] = {"L", _("Lightness"), "C", "Chroma", "H", "Hue", NULL}; gtk_color_component_set_label(GTK_COLOR_COMPONENT(widget), lch_labels); args->lch_control = widget; g_signal_connect(G_OBJECT(widget), "color-changed", G_CALLBACK(color_component_change_value), args); g_signal_connect(G_OBJECT(widget), "button_release_event", G_CALLBACK(color_component_key_up_cb), args); g_signal_connect(G_OBJECT(widget), "input-clicked", G_CALLBACK(color_component_input_clicked), args); gtk_container_add(GTK_CONTAINER(expander), widget); expander=gtk_expander_new(_("Info")); gtk_expander_set_expanded(GTK_EXPANDER(expander), dynv_get_bool_wd(args->params, "expander.info", false)); args->expanderInfo=expander; gtk_box_pack_start (GTK_BOX(vbox), expander, FALSE, FALSE, 0); table = gtk_table_new(3, 2, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(expander), table); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Color name:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); widget = gtk_entry_new(); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE); //gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); args->color_name = widget; table_y++; dragdrop_init(&dd, gs); dd.userdata = args; dd.get_color_object = get_color_object_contrast; dd.set_color_object_at = set_color_object_at_contrast; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Contrast:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); widget = gtk_color_new(); Color *c; if ((c = const_cast(dynv_get_color_wd(args->params, "contrast.color", 0)))){ gtk_color_set_color(GTK_COLOR(widget), c, _("Sample")); }else{ Color c; c.rgb.red = 1; c.rgb.green = 1; c.rgb.blue = 1; gtk_color_set_color(GTK_COLOR(widget), &c, _("Sample")); } 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(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); args->contrastCheck = widget; 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 = 0; dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); gtk_table_attach(GTK_TABLE(table), args->contrastCheckMsg = gtk_label_new(""),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,5); table_y++; updateDisplays(args, 0); args->main = main_hbox; gtk_widget_show_all(main_hbox); args->source.widget = main_hbox; return (ColorSource*)args; } int color_picker_source_register(ColorSourceManager *csm){ ColorSource *color_source = new ColorSource; color_source_init(color_source, "color_picker", _("Color picker")); color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement; color_source->single_instance_only = true; color_source->default_accelerator = GDK_c; color_source_manager_add_source(csm, color_source); return 0; } gpick_0.2.5/source/LuaExt.h0000644000175000017500000000377512070605214014271 0ustar zbygzbyg/* * 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 LUAEXT_H_ #define LUAEXT_H_ extern "C"{ #include #include #include #include } #include "Color.h" #include "ColorObject.h" int lua_ext_colors_openlib(lua_State *lua); int lua_pushcolorobject (lua_State *L, struct ColorObject* color_object); struct ColorObject** lua_checkcolorobject (lua_State *L, int index); int lua_pushcolor (lua_State *L, const Color* color); Color *lua_checkcolor (lua_State *L, int index); #endif /* LUAEXT_H_ */ gpick_0.2.5/source/LayoutPreview.cpp0000644000175000017500000006445612070605214016244 0ustar zbygzbyg/* * 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 "LayoutPreview.h" #include "DragDrop.h" #include "uiColorInput.h" #include "CopyPaste.h" #include "uiApp.h" #include "Converter.h" #include "DynvHelpers.h" #include "Internationalisation.h" #include "GlobalStateStruct.h" #include "ToolColorNaming.h" #include "uiUtilities.h" #include "ColorList.h" #include "MathUtil.h" #include #include "gtk/LayoutPreview.h" #include "layout/Layout.h" #include "layout/Style.h" #include #include #include #include #include using namespace std; using namespace layout; typedef struct LayoutPreviewArgs{ ColorSource source; GtkWidget *main; GtkWidget* statusbar; GtkWidget *layout; System* layout_system; Layouts* layouts; string last_filename; struct dynvSystem *params; GlobalState *gs; }LayoutPreviewArgs; class LayoutPreviewColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; const char *m_ident; public: LayoutPreviewColorNameAssigner(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 << _("layout preview") << " " << m_ident << " [" << color_names_get(m_gs->color_names, color, false) << "]"; return m_stream.str(); } }; typedef enum{ LAYOUTLIST_HUMAN_NAME = 0, LAYOUTLIST_PTR, LAYOUTLIST_N_COLUMNS }LayoutListColumns; typedef enum{ STYLELIST_HUMAN_NAME = 0, STYLELIST_CSS_SELECTOR, STYLELIST_PTR, STYLELIST_N_COLUMNS }StyleListColumns; static void style_cell_edited_cb(GtkCellRendererText *cell, gchar *path, gchar *new_text, GtkListStore *store){ GtkTreeIter iter1; gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter1, path ); gtk_list_store_set(store, &iter1, STYLELIST_CSS_SELECTOR, new_text, -1); } static void load_colors(LayoutPreviewArgs* args){ if (args->layout_system){ struct dynvSystem *assignments_params = dynv_get_dynv(args->params, "css_selectors.assignments"); string ident_selector; for (list::iterator i=args->layout_system->styles.begin(); i!=args->layout_system->styles.end(); i++){ ident_selector = (*i)->ident_name + ".color"; const Color *color = dynv_get_color_wd(assignments_params, ident_selector.c_str(), 0); if (color){ color_copy((Color*)color, &(*i)->color); } } dynv_system_release(assignments_params); } } static void save_colors(LayoutPreviewArgs* args){ if (args->layout_system){ struct dynvSystem *assignments_params = dynv_get_dynv(args->params, "css_selectors.assignments"); string ident_selector; for (list::iterator i=args->layout_system->styles.begin(); i!=args->layout_system->styles.end(); i++){ ident_selector = (*i)->ident_name + ".color"; dynv_set_color(assignments_params, ident_selector.c_str(), &(*i)->color); } dynv_system_release(assignments_params); } } static GtkWidget* style_list_new(LayoutPreviewArgs *args){ GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *col; GtkWidget *view; view = gtk_tree_view_new(); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), 1); store = gtk_list_store_new (STYLELIST_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col, true); gtk_tree_view_column_set_title(col, _("Style item")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, true); gtk_tree_view_column_add_attribute(col, renderer, "text", STYLELIST_HUMAN_NAME); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col, true); gtk_tree_view_column_set_title(col, _("CSS selector")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, true); gtk_tree_view_column_add_attribute(col, renderer, "text", STYLELIST_CSS_SELECTOR); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); g_object_set(renderer, "editable", true, NULL); g_signal_connect(renderer, "edited", (GCallback)style_cell_edited_cb, store); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(GTK_TREE_MODEL(store)); /*GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view), TRUE);*/ return view; } static void assign_css_selectors_cb(GtkWidget *widget, LayoutPreviewArgs* args) { GtkWidget *table; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Assign CSS selectors"), GTK_WINDOW(gtk_widget_get_toplevel(args->main)), 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, "css_selectors.window.width", -1), dynv_get_int32_wd(args->params, "css_selectors.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(1, 1, FALSE); table_y=0; GtkWidget* list_widget = style_list_new(args); gtk_widget_set_size_request(list_widget, 100, 100); gtk_table_attach(GTK_TABLE(table), list_widget, 0, 1, table_y, table_y+1, GtkAttachOptions(GTK_FILL|GTK_EXPAND), GtkAttachOptions(GTK_FILL|GTK_EXPAND), 5, 0); table_y++; GtkTreeIter iter1; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_widget)); struct dynvSystem *assignments_params = dynv_get_dynv(args->params, "css_selectors.assignments"); string ident_selector; for (list::iterator i = args->layout_system->styles.begin(); i != args->layout_system->styles.end(); i++){ ident_selector = (*i)->ident_name + ".selector"; const char *css_selector = dynv_get_string_wd(assignments_params, ident_selector.c_str(), (*i)->ident_name.c_str()); gtk_list_store_append(GTK_LIST_STORE(model), &iter1); gtk_list_store_set(GTK_LIST_STORE(model), &iter1, STYLELIST_HUMAN_NAME, (*i)->human_name.c_str(), STYLELIST_CSS_SELECTOR, css_selector, STYLELIST_PTR, (*i), -1); } 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){ gboolean valid; Style *style; char* selector; valid = gtk_tree_model_get_iter_first(model, &iter1); while (valid){ gtk_tree_model_get(model, &iter1, STYLELIST_PTR, &style, STYLELIST_CSS_SELECTOR, &selector, -1); ident_selector = style->ident_name + ".selector"; dynv_set_string(assignments_params, ident_selector.c_str(), selector); g_free(selector); valid = gtk_tree_model_iter_next(model, &iter1); } } dynv_system_release(assignments_params); gint width, height; gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); dynv_set_int32(args->params, "css_selectors.window.width", width); dynv_set_int32(args->params, "css_selectors.window.height", height); gtk_widget_destroy(dialog); } static int source_destroy(LayoutPreviewArgs *args){ save_colors(args); if (args->layout_system) System::unref(args->layout_system); args->layout_system = 0; gtk_widget_destroy(args->main); dynv_system_release(args->params); delete args; return 0; } static int source_get_color(LayoutPreviewArgs *args, struct ColorObject** color){ Style *style = 0; if (gtk_layout_preview_get_current_style(GTK_LAYOUT_PREVIEW(args->layout), &style) == 0){ struct ColorObject *color_object = color_list_new_color_object(args->gs->colors, &style->color); LayoutPreviewColorNameAssigner name_assigner(args->gs); name_assigner.assign(color_object, &style->color, style->ident_name.c_str()); *color = color_object; return 0; } return -1; } static int source_set_color(LayoutPreviewArgs *args, struct ColorObject* color){ Color c; color_object_get_color(color, &c); gtk_layout_preview_set_current_color(GTK_LAYOUT_PREVIEW(args->layout), &c); return -1; } static int source_deactivate(LayoutPreviewArgs *args){ return 0; } static struct ColorObject* get_color_object(struct DragDrop* dd){ LayoutPreviewArgs* args=(LayoutPreviewArgs*)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){ LayoutPreviewArgs* args=(LayoutPreviewArgs*)dd->userdata; Color color; color_object_get_color(colorobject, &color); gtk_layout_preview_set_color_at(GTK_LAYOUT_PREVIEW(args->layout), &color, x, y); return 0; } static bool test_at(struct DragDrop* dd, int x, int y){ LayoutPreviewArgs* args=(LayoutPreviewArgs*)dd->userdata; gtk_layout_preview_set_focus_at(GTK_LAYOUT_PREVIEW(args->layout), x, y); return gtk_layout_preview_is_selected(GTK_LAYOUT_PREVIEW(args->layout)); } static GtkWidget* layout_preview_dropdown_new(LayoutPreviewArgs *args, GtkTreeModel *model){ GtkListStore *store = 0; GtkCellRenderer *renderer; GtkWidget *combo; if (model){ combo = gtk_combo_box_new_with_model(model); }else{ store = gtk_list_store_new (LAYOUTLIST_N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); } renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, true); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", LAYOUTLIST_HUMAN_NAME, NULL); if (store) g_object_unref (store); return combo; } static void edit_cb(GtkWidget *widget, gpointer item) { LayoutPreviewArgs* args=(LayoutPreviewArgs*)item; struct ColorObject *color_object; struct ColorObject* new_color_object = 0; if (source_get_color(args, &color_object)==0){ if (dialog_color_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs, color_object, &new_color_object )==0){ source_set_color(args, new_color_object); color_object_release(new_color_object); } color_object_release(color_object); } } static void paste_cb(GtkWidget *widget, LayoutPreviewArgs* args) { struct ColorObject* color_object; if (copypaste_get_color_object(&color_object, args->gs)==0){ source_set_color(args, color_object); color_object_release(color_object); } } static void add_color_to_palette(Style *style, LayoutPreviewColorNameAssigner &name_assigner, LayoutPreviewArgs *args) { struct ColorObject *color_object; color_object = color_list_new_color_object(args->gs->colors, &style->color); name_assigner.assign(color_object, &style->color, style->ident_name.c_str()); color_list_add_color_object(args->gs->colors, color_object, 1); color_object_release(color_object); } static void add_to_palette_cb(GtkWidget *widget, gpointer item) { LayoutPreviewArgs* args = (LayoutPreviewArgs*)item; LayoutPreviewColorNameAssigner name_assigner(args->gs); Style* style = 0; if (gtk_layout_preview_get_current_style(GTK_LAYOUT_PREVIEW(args->layout), &style) == 0){ add_color_to_palette(style, name_assigner, args); } } static void add_all_to_palette_cb(GtkWidget *widget, LayoutPreviewArgs *args) { LayoutPreviewColorNameAssigner name_assigner(args->gs); for (list::iterator i = args->layout_system->styles.begin(); i != args->layout_system->styles.end(); i++){ add_color_to_palette(*i, name_assigner, args); } } static gboolean button_press_cb (GtkWidget *widget, GdkEventButton *event, LayoutPreviewArgs* args) { GtkWidget *menu; if (event->button == 1 && event->type == GDK_2BUTTON_PRESS){ add_to_palette_cb(widget, args); return true; }else if (event->button == 3 && event->type == GDK_BUTTON_PRESS){ GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); bool selection_avail = gtk_layout_preview_is_selected(GTK_LAYOUT_PREVIEW(args->layout)); 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 (add_to_palette_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); 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 (add_all_to_palette_cb), args); 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); if (selection_avail){ struct ColorObject* color_object; source_get_color(args, &color_object); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (color_object, 0, args->gs)); color_object_release(color_object); }else{ 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 (_("_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 (edit_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); 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 (paste_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); if (copypaste_is_color_object_available(args->gs)!=0){ gtk_widget_set_sensitive(item, false); } gtk_widget_show_all (GTK_WIDGET(menu)); button = event->button; event_time = event->time; gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time); g_object_ref_sink(menu); g_object_unref(menu); return TRUE; } return FALSE; } static void layout_changed_cb(GtkWidget *widget, LayoutPreviewArgs* args) { GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) { GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget)); Layout* layout; gtk_tree_model_get(model, &iter, LAYOUTLIST_PTR, &layout, -1); save_colors(args); System* layout_system = layouts_get(args->layouts, layout->name); gtk_layout_preview_set_system(GTK_LAYOUT_PREVIEW(args->layout), layout_system); if (args->layout_system) System::unref(args->layout_system); args->layout_system = layout_system; dynv_set_string(args->params, "layout_name", layout->name); load_colors(args); } } static int save_css_file(const char* filename, LayoutPreviewArgs* args){ ofstream file(filename, ios::out); if (file.is_open()){ Converters *converters = (Converters*)dynv_get_pointer_wd(args->gs->params, "Converters", 0); Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COPY); struct ColorObject *co_color, *co_background_color; Color t; co_color = color_list_new_color_object(args->gs->colors, &t); co_background_color = color_list_new_color_object(args->gs->colors, &t); char *color; struct dynvSystem *assignments_params = dynv_get_dynv(args->params, "css_selectors.assignments"); string ident_selector; for (list::iterator i=args->layout_system->styles.begin(); i!=args->layout_system->styles.end(); i++){ ident_selector = (*i)->ident_name + ".selector"; const char *css_selector = dynv_get_string_wd(assignments_params, ident_selector.c_str(), (*i)->ident_name.c_str()); if (css_selector[0]!=0){ color_object_set_color(co_color, &(*i)->color); converter_get_text(converter->function_name, co_color, 0, args->gs->params, &color); file << css_selector << " {" << endl; if ((*i)->style_type == Style::TYPE_BACKGROUND){ file << "\tbackground-color: " << color << ";" << endl; }else if ((*i)->style_type == Style::TYPE_COLOR){ file << "\tcolor: " << color << ";" << endl; }else if ((*i)->style_type == Style::TYPE_BORDER){ file << "\tborder-color: " << color << ";" << endl; } file << "}" << endl << endl; } g_free(color); } dynv_system_release(assignments_params); color_object_release(co_color); color_object_release(co_background_color); file.close(); return 0; } return -1; } static void export_css_cb(GtkWidget *widget, LayoutPreviewArgs* args){ if (!args->last_filename.empty()){ if (save_css_file(args->last_filename.c_str(), args)==0){ }else{ GtkWidget* message; message=gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_toplevel(widget)), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be saved")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } return; } GtkWidget *dialog; GtkFileFilter *filter; dialog = gtk_file_chooser_dialog_new(_("Export"), GTK_WINDOW(gtk_widget_get_toplevel(widget)), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); const char* default_path = dynv_get_string_wd(args->params, "export_path", ""); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_path); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("Cascading Style Sheets *.css")); gtk_file_filter_add_pattern(filter, "*.css"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); gboolean finished = false; while (!finished){ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gchar *path; path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); dynv_set_string(args->params, "export_path", path); g_free(path); if (save_css_file(filename, args)==0){ args->last_filename = filename; finished = true; }else{ GtkWidget* message; message=gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be saved")); //gtk_window_set_title(GTK_WINDOW(dialog), "Open"); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } g_free(filename); }else break; } gtk_widget_destroy (dialog); } static void export_css_as_cb(GtkWidget *widget, LayoutPreviewArgs* args){ args->last_filename=""; export_css_cb(widget, args); } static GtkWidget* attach_label(GtkWidget *widget, const char *label){ GtkWidget* hbox = gtk_hbox_new(false, 5); gtk_box_pack_start(GTK_BOX(hbox), gtk_label_aligned_new(label, 0, 0.5, 0, 0), false, true, 0); gtk_box_pack_start(GTK_BOX(hbox), widget, true, true, 0); return hbox; } static int source_activate(LayoutPreviewArgs *args){ transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); gtk_layout_preview_set_transformation_chain(GTK_LAYOUT_PREVIEW(args->layout), chain); gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "empty"), ""); return 0; } static ColorSource* source_implement(ColorSource *source, GlobalState* gs, struct dynvSystem *dynv_namespace){ LayoutPreviewArgs* args = new LayoutPreviewArgs; args->params = dynv_system_ref(dynv_namespace); args->statusbar = (GtkWidget*)dynv_get_pointer_wd(gs->params, "StatusBar", 0); args->layout_system = 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; Layouts* layouts = (Layouts*)dynv_get_pointer_wd(gs->params, "Layouts", 0); args->layouts = layouts; GtkWidget *table, *vbox, *hbox; vbox = gtk_vbox_new(false, 10); hbox = gtk_hbox_new(false, 10); gtk_box_pack_start(GTK_BOX(vbox), hbox, true, true, 5); gint table_y; table = gtk_table_new(4, 4, false); gtk_box_pack_start(GTK_BOX(hbox), table, true, true, 5); table_y = 0; GtkToolItem *tool; GtkWidget *toolbar = gtk_toolbar_new(); gtk_table_attach(GTK_TABLE(table), toolbar, 0, 3, table_y, table_y+1, GtkAttachOptions(GTK_FILL), GTK_FILL, 0, 0); table_y++; tool = gtk_tool_item_new(); gtk_tool_item_set_expand(tool, true); GtkWidget *layout_dropdown = layout_preview_dropdown_new(args, 0); gtk_container_add(GTK_CONTAINER(tool), attach_label(layout_dropdown, _("Layout:"))); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool, -1); g_signal_connect (G_OBJECT(layout_dropdown), "changed", G_CALLBACK(layout_changed_cb), args); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1); tool = gtk_menu_tool_button_new(gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON), _("Export CSS File")); gtk_tool_item_set_tooltip_text(tool, _("Export CSS file")); g_signal_connect(G_OBJECT(tool), "clicked", G_CALLBACK(export_css_cb), args); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool, -1); GtkWidget *menu; GtkWidget* item; menu = gtk_menu_new (); item = gtk_menu_item_new_with_image(_("_Export CSS File As..."), gtk_image_new_from_stock(GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (export_css_as_cb), args); item = gtk_menu_item_new_with_mnemonic(_("_Assign CSS Selectors...")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (assign_css_selectors_cb), args); gtk_widget_show_all(menu); gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(tool), menu); GtkWidget *scrolled = gtk_scrolled_window_new(0, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_table_attach(GTK_TABLE(table), scrolled, 0, 3, table_y, table_y+1 ,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GtkAttachOptions(GTK_FILL | GTK_EXPAND),0,0); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), args->layout = gtk_layout_preview_new()); g_signal_connect_after(G_OBJECT(args->layout), "button-press-event", G_CALLBACK(button_press_cb), args); table_y++; 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; dd.test_at = test_at; dd.handler_map = dynv_system_get_handler_map(gs->colors->params); gtk_drag_dest_set(args->layout, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GDK_ACTION_COPY); gtk_drag_source_set(args->layout, GDK_BUTTON1_MASK, 0, 0, GDK_ACTION_COPY); dragdrop_widget_attach(args->layout, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); args->gs = gs; // Restore settings and fill list const char* layout_name = dynv_get_string_wd(args->params, "layout_name", "std_layout_menu_1"); GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(layout_dropdown)); uint32_t n_layouts; Layout** layout_table = layouts_get_all(layouts, &n_layouts); GtkTreeIter iter1; bool layout_found = false; for (uint32_t i=0; i!=n_layouts; ++i){ if (layout_table[i]->mask != 0) continue; gtk_list_store_append(GTK_LIST_STORE(model), &iter1); gtk_list_store_set(GTK_LIST_STORE(model), &iter1, LAYOUTLIST_HUMAN_NAME, layout_table[i]->human_readable, LAYOUTLIST_PTR, layout_table[i], -1); if (g_strcmp0(layout_name, layout_table[i]->name)==0){ gtk_combo_box_set_active_iter(GTK_COMBO_BOX(layout_dropdown), &iter1); layout_found = true; } } if (!layout_found){ gtk_combo_box_set_active(GTK_COMBO_BOX(layout_dropdown), 0); } gtk_widget_show_all(vbox); //update(0, args); args->main = vbox; args->source.widget =vbox; return (ColorSource*)args; } int layout_preview_source_register(ColorSourceManager *csm){ ColorSource *color_source = new ColorSource; color_source_init(color_source, "layout_preview", _("Layout preview")); color_source->needs_viewport = false; color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement; color_source->default_accelerator = GDK_l; color_source_manager_add_source(csm, color_source); return 0; } gpick_0.2.5/source/uiDialogMix.h0000644000175000017500000000340312070605214015266 0ustar zbygzbyg/* * 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 UIDIALOGMIX_H_ #define UIDIALOGMIX_H_ #include #include "ColorList.h" #include "GlobalState.h" void dialog_mix_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState* gs); #endif /* UIDIALOGMIX_H_ */ gpick_0.2.5/source/FloatingPicker.cpp0000644000175000017500000002520712070605214016315 0ustar zbygzbyg/* * 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 "FloatingPicker.h" #include "gtk/Zoomed.h" #include "gtk/ColorWidget.h" #include "uiUtilities.h" #include "uiApp.h" #include "GlobalStateStruct.h" #include "ColorPicker.h" #include "Converter.h" #include "DynvHelpers.h" #include "ToolColorNaming.h" #include #include #include using namespace math; using namespace std; typedef struct FloatingPickerArgs{ GtkWidget* parent; GtkWidget* window; GtkWidget* zoomed; GtkWidget* color_widget; guint timeout_source_id; ColorSource *color_source; GlobalState* gs; bool release_mode; bool click_mode; }FloatingPickerArgs; class PickerColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; public: PickerColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){ } void assign(struct ColorObject *color_object, Color *color){ 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); return m_stream.str(); } }; static void get_color_sample(FloatingPickerArgs *args, bool updateWidgets, Color* c){ GdkScreen *screen; GdkModifierType state; int x, y; int width, height; gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, &state); width = gdk_screen_get_width(screen); height = gdk_screen_get_height(screen); Vec2 pointer(x,y); Vec2 window_size(width, height); screen_reader_reset_rect(args->gs->screen_reader); Rect2 sampler_rect, zoomed_rect, final_rect; sampler_get_screen_rect(args->gs->sampler, pointer, window_size, &sampler_rect); screen_reader_add_rect(args->gs->screen_reader, screen, sampler_rect); if (updateWidgets){ gtk_zoomed_get_screen_rect(GTK_ZOOMED(args->zoomed), pointer, window_size, &zoomed_rect); screen_reader_add_rect(args->gs->screen_reader, screen, zoomed_rect); } screen_reader_update_pixbuf(args->gs->screen_reader, &final_rect); Vec2 offset; offset = Vec2(sampler_rect.getX()-final_rect.getX(), sampler_rect.getY()-final_rect.getY()); sampler_get_color_sample(args->gs->sampler, pointer, window_size, offset, c); if (updateWidgets){ offset = Vec2(zoomed_rect.getX()-final_rect.getX(), zoomed_rect.getY()-final_rect.getY()); gtk_zoomed_update(GTK_ZOOMED(args->zoomed), pointer, window_size, offset, screen_reader_get_pixbuf(args->gs->screen_reader)); } } static gboolean update_display(FloatingPickerArgs *args){ GdkScreen *screen; GdkModifierType state; int x, y; int width, height; gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, &state); width = gdk_screen_get_width(screen); height = gdk_screen_get_height(screen); gint sx, sy; gtk_window_get_size(GTK_WINDOW(args->window), &sx, &sy); if (x+sx+sx/2 > width){ x -= sx + sx/2; }else{ x += sx/2; } if (y+sy+sy/2 > height){ y -= sy + sy/2; }else{ y += sy/2; } if (gtk_window_get_screen(GTK_WINDOW(args->window)) != screen){ gtk_window_set_screen(GTK_WINDOW(args->window), screen); } gtk_window_move(GTK_WINDOW(args->window), x, y ); Color c; get_color_sample(args, true, &c); struct ColorObject* color_object; color_object = color_list_new_color_object(args->gs->colors, &c); gchar* text = 0; Converters *converters = (Converters*)dynv_get_pointer_wd(args->gs->params, "Converters", 0); Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_DISPLAY); if (converter){ converter_get_text(converter->function_name, color_object, 0, args->gs->params, &text); } color_object_release(color_object); gtk_color_set_color(GTK_COLOR(args->color_widget), &c, text); if (text) g_free(text); return true; } void floating_picker_activate(FloatingPickerArgs *args, bool hide_on_mouse_release){ #ifndef WIN32 //Pointer grabbing in Windows is broken, disabling floating picker for now args->release_mode = hide_on_mouse_release; args->click_mode = true; GdkCursor* cursor; cursor = gdk_cursor_new(GDK_TCROSS); gtk_zoomed_set_zoom(GTK_ZOOMED(args->zoomed), dynv_get_float_wd(args->gs->params, "gpick.picker.zoom", 2)); update_display(args); gtk_widget_show(args->window); //gdk_window_set_cursor(si->fake_window->window, cursor); gdk_pointer_grab(args->window->window, false, GdkEventMask(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK ), NULL, cursor, GDK_CURRENT_TIME); gdk_keyboard_grab(args->window->window, false, GDK_CURRENT_TIME); float refresh_rate = dynv_get_float_wd(args->gs->params, "gpick.picker.refresh_rate", 30); args->timeout_source_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 1000/refresh_rate, (GSourceFunc)update_display, args, (GDestroyNotify)NULL); gdk_cursor_destroy(cursor); #endif } void floating_picker_deactivate(FloatingPickerArgs *args){ gdk_pointer_ungrab(GDK_CURRENT_TIME); gdk_keyboard_ungrab(GDK_CURRENT_TIME); if (args->timeout_source_id > 0){ g_source_remove(args->timeout_source_id); args->timeout_source_id = 0; } gtk_widget_hide(args->window); } static gboolean scroll_event_cb(GtkWidget *widget, GdkEventScroll *event, FloatingPickerArgs *args){ double zoom = gtk_zoomed_get_zoom(GTK_ZOOMED(args->zoomed)); if ((event->direction == GDK_SCROLL_UP) || (event->direction == GDK_SCROLL_RIGHT)){ zoom += 1; }else{ zoom -= 1; } gtk_zoomed_set_zoom(GTK_ZOOMED(args->zoomed), zoom); return TRUE; } static gboolean button_release_cb(GtkWidget *widget, GdkEventButton *event, FloatingPickerArgs *args){ if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 1)) { if (args->release_mode || args->click_mode){ Color c; get_color_sample(args, false, &c); struct ColorObject* color_object; color_object = color_list_new_color_object(args->gs->colors, &c); if (dynv_get_bool_wd(args->gs->params, "gpick.picker.sampler.copy_on_release", false)){ 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); } } if (dynv_get_bool_wd(args->gs->params, "gpick.picker.sampler.add_on_release", false)){ PickerColorNameAssigner name_assigner(args->gs); name_assigner.assign(color_object, &c); color_list_add_color_object(args->gs->colors, color_object, 1); } color_object_release(color_object); } floating_picker_deactivate(args); dynv_set_float(args->gs->params, "gpick.picker.zoom", gtk_zoomed_get_zoom(GTK_ZOOMED(args->zoomed))); } return false; } static gboolean key_up_cb (GtkWidget *widget, GdkEventKey *event, FloatingPickerArgs *args){ GdkEventButton event2; guint modifiers = gtk_accelerator_get_default_mod_mask(); switch(event->keyval){ case GDK_Escape: event2.type = GDK_BUTTON_RELEASE; event2.button = 1; args->release_mode = false; args->click_mode = false; button_release_cb(widget, &event2, args); return TRUE; break; case GDK_m: { int x, y; gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); math::Vec2 position(x, y); if ((event->state&modifiers)==GDK_CONTROL_MASK){ gtk_zoomed_set_mark(GTK_ZOOMED(args->zoomed), 1, position); }else{ gtk_zoomed_set_mark(GTK_ZOOMED(args->zoomed), 0, position); } } break; default: if (color_picker_key_up(args->color_source, event)){ args->release_mode = false; //key pressed and color picked, disable copy on mouse button release return TRUE; } } return FALSE; } static void destroy_cb(GtkWidget *widget, FloatingPickerArgs *args){ delete args; } FloatingPickerArgs* floating_picker_new(GtkWidget *parent, GlobalState *gs, ColorSource* color_source){ FloatingPickerArgs *args = new FloatingPickerArgs; args->gs = gs; args->parent = gtk_widget_get_toplevel(parent); args->window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_skip_pager_hint(GTK_WINDOW(args->window), true); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(args->window), true); gtk_window_set_decorated(GTK_WINDOW(args->window), false); gtk_widget_set_size_request(args->window, -1, -1); GtkWidget* vbox = gtk_vbox_new(0, 0); gtk_container_add (GTK_CONTAINER(args->window), vbox); gtk_widget_show(vbox); args->zoomed = gtk_zoomed_new(); gtk_widget_show(args->zoomed); gtk_box_pack_start(GTK_BOX(vbox), args->zoomed, false, false, 0); args->color_widget = gtk_color_new(); gtk_widget_show(args->color_widget); gtk_box_pack_start(GTK_BOX(vbox), args->color_widget, true, true, 0); g_signal_connect(G_OBJECT(args->window), "scroll_event", G_CALLBACK(scroll_event_cb), args); g_signal_connect(G_OBJECT(args->window), "button-release-event", G_CALLBACK(button_release_cb), args); g_signal_connect(G_OBJECT(args->window), "key_press_event", G_CALLBACK(key_up_cb), args); g_signal_connect(G_OBJECT(args->window), "destroy", G_CALLBACK(destroy_cb), args); args->color_source = color_source; return args; } void floating_picker_free(FloatingPickerArgs *args){ gtk_widget_destroy(args->window); } gpick_0.2.5/source/MathUtil.h0000644000175000017500000000644312070605214014611 0ustar zbygzbyg/* * 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 MATHUTIL_H_ #define MATHUTIL_H_ #define PI 3.14159265 #define MIX(r,a,b,component) r.component = mix_float(a.component, b.component, step_i/(float)(steps-1)) #define MIX_COMPONENTS(r,a,b,ca,cb,cc) MIX(r,a,b,ca); MIX(r,a,b,cb); MIX(r,a,b,cc) float min_float_3(float a, float b, float c); float max_float_3(float a, float b, float c); int min_int(int a, int b); int max_int(int a, int b); int wrap_int(int x, int a, int b); float clamp_float(float x, float a, float b); float wrap_float(float x); float mix_float(float a, float b, float mix); int clamp_int(int x, int a, int b); int abs_int(int a); float abs_float(float a); double mix_double(double a, double b, double mix); typedef struct matrix3x3{ double m[3][3]; }matrix3x3; void matrix3x3_identity(matrix3x3* matrix); void matrix3x3_multiply(const matrix3x3* matrix1, const matrix3x3* matrix2, matrix3x3* result); double matrix3x3_determinant(const matrix3x3* matrix); int matrix3x3_inverse(const matrix3x3* matrix, matrix3x3* result); void matrix3x3_transpose(const matrix3x3* matrix, matrix3x3* result); typedef struct vector2{ float x; float y; }vector2; void vector2_set(vector2* v1, float x, float y); float vector2_length(const vector2* v1); void vector2_normalize(const vector2* v1, vector2* r); float vector2_dot(const vector2* v1, const vector2* v2); typedef struct vector3{ union{ struct{ float x; float y; float z; }; float m[3]; }; }vector3; void vector3_set(vector3* vector, float x, float y, float z); void vector3_copy(const vector3* vector, vector3* result); float vector3_length(const vector3* vector); void vector3_multiply_matrix3x3(const vector3* vector, const matrix3x3* matrix, vector3* result ); void vector3_clamp(vector3* vector, float a, float b); #endif /* MATHUTIL_H_ */ gpick_0.2.5/source/Paths.cpp0000644000175000017500000000526612070605214014476 0ustar zbygzbyg/* * 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 "Paths.h" #include static gchar* get_data_dir(){ static gchar* data_dir=NULL; if (data_dir) return data_dir; GList *paths=NULL, *i=NULL; gchar *tmp; i=g_list_append(i, (gchar*)"share"); paths=i; i=g_list_append(i, (gchar*)g_get_user_data_dir()); const gchar* const *datadirs = g_get_system_data_dirs(); for (gint datadirs_i=0; datadirs[datadirs_i];++datadirs_i){ i=g_list_append(i, (gchar*)datadirs[datadirs_i]); } i=paths; GStatBuf sb; while (i){ tmp = g_build_filename((gchar*)i->data, "gpick", NULL); if (g_stat( tmp, &sb )==0){ data_dir=g_strdup(tmp); g_free(tmp); break; } g_free(tmp); i=g_list_next(i); } g_list_free(paths); if (data_dir==NULL){ data_dir=g_strdup(""); return data_dir; } return data_dir; } gchar* build_filename(const gchar* filename){ if (filename) return g_build_filename(get_data_dir(), filename, NULL); else return g_build_filename(get_data_dir(), NULL); } gchar* build_config_path(const gchar *filename){ if (filename) return g_build_filename(g_get_user_config_dir(), "gpick", filename, NULL); else return g_build_filename(g_get_user_config_dir(), "gpick", NULL); } gpick_0.2.5/source/main.h0000644000175000017500000000311012070605214013772 0ustar zbygzbyg/* * 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 MAIN_H_ #define MAIN_H_ #endif /* MAIN_H_ */ gpick_0.2.5/source/Color.h0000644000175000017500000003646212070605214014144 0ustar zbygzbyg/* * 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_H_ #define COLOR_H_ #include "MathUtil.h" /** \file source/Color.h * \brief Color structure and functions to convert colors from one color space to another. */ /** \struct Color * \brief Color structure is an union of all available color spaces. */ typedef struct Color{ union{ struct{ float red; /**< Red component */ float green; /**< Green component */ float blue; /**< Blue component */ }rgb; struct{ float hue; float saturation; float value; }hsv; struct{ float hue; float saturation; float lightness; }hsl; struct{ float x; float y; float z; }xyz; struct{ float L; float a; float b; }lab; struct{ float L; float C; float h; }lch; struct{ float c; float m; float y; }cmy; struct{ float c; float m; float y; float k; }cmyk; struct{ float m1; float m2; float m3; float m4; }m; /**< General data access structure */ float ma[4]; /**< General data access array */ }; }Color; /** \enum ReferenceIlluminant * \brief Reference illuminants. */ enum ReferenceIlluminant { REFERENCE_ILLUMINANT_A = 0, REFERENCE_ILLUMINANT_C = 1, REFERENCE_ILLUMINANT_D50 = 2, REFERENCE_ILLUMINANT_D55 = 3, REFERENCE_ILLUMINANT_D65 = 4, REFERENCE_ILLUMINANT_D75 = 5, REFERENCE_ILLUMINANT_F2 = 6, REFERENCE_ILLUMINANT_F7 = 7, REFERENCE_ILLUMINANT_F11 = 8, }; /** \enum ReferenceObserver * \brief Reference observers. */ enum ReferenceObserver { REFERENCE_OBSERVER_2 = 0, REFERENCE_OBSERVER_10 = 1, }; /** * Initialize things needed for color conversion functions. Must be called before using any other functions. */ void color_init(); /** * Convert RGB color space to HSL color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in HSL color space. */ void color_rgb_to_hsl(const Color* a, Color* b); /** * Convert HSL color space to RGB color space. * @param[in] a Source color in HSL color space. * @param[out] b Destination color in RGB color space. */ void color_hsl_to_rgb(const Color* a, Color* b); /** * Convert HSL color space to HSV color space. * @param[in] a Source color in HSL color space. * @param[out] b Destination color in HSV color space. */ void color_hsl_to_hsv(const Color *a, Color *b); /** * Convert HSV color space to HSL color space. * @param[in] a Source color in HSV color space. * @param[out] b Destination color in HSL color space. */ void color_hsv_to_hsl(const Color *a, Color *b); /** * Convert RGB color space to HSV color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in HSV color space. */ void color_rgb_to_hsv(const Color* a, Color* b); /** * Convert HSV color space to RGB color space. * @param[in] a Source color in HSV color space. * @param[out] b Destination color in RGB color space. */ void color_hsv_to_rgb(const Color* a, Color* b); /** * Convert RGB color space to XYZ color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in XYZ color space. * @param[in] transformation Transformation matrix for RGB to XYZ conversion. */ void color_rgb_to_xyz(const Color* a, Color* b, const matrix3x3* transformation); /** * Convert XYZ color space to RGB color space. * @param[in] a Source color in XYZ color space. * @param[out] b Destination color in RGB color space. * @param[in] transformation_inverted Transformation matrix for XYZ to RGB conversion. */ void color_xyz_to_rgb(const Color* a, Color* b, const matrix3x3* transformation_inverted); /** * Convert XYZ color space to Lab color space. * @param[in] a Source color in XYZ color space. * @param[out] b Destination color in Lab color space. * @param[in] reference_white Reference white color values. */ void color_xyz_to_lab(const Color* a, Color* b, const vector3* reference_white); /** * Convert Lab color space to XYZ color space. * @param[in] a Source color in Lab color space. * @param[out] b Destination color in XYZ color space. * @param[in] reference_white Reference white color values. */ void color_lab_to_xyz(const Color* a, Color* b, const vector3* reference_white); /** * Convert RGB color space to Lab color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in Lab color space. * @param[in] reference_white Reference white color values. * @param[in] transformation Transformation matrix for RGB to XYZ conversion. * @param[in] adaptation_matrix XYZ chromatic adaptation matrix. */ void color_rgb_to_lab(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation, const matrix3x3* adaptation_matrix); /** * Convert Lab color space to RGB color space. * @param[in] a Source color in Lab color space. * @param[out] b Destination color in RGB color space. * @param[in] reference_white Reference white color values. * @param[in] transformation_inverted Transformation matrix for XYZ to RGB conversion. * @param[in] adaptation_matrix_inverted Inverted XYZ chromatic adaptation matrix. */ void color_lab_to_rgb(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation_inverted, const matrix3x3* adaptation_matrix_inverted); /** * Convert RGB color space to Lab color space with illuminant D50, observer 2, sRGB transformation matrix and D65-D50 adaptation matrix. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in Lab color space. */ void color_rgb_to_lab_d50(const Color* a, Color* b); /** * Convert Lab color space to RGB color space with illuminant D50, observer 2, inverted sRGB transformation matrix and D50-D65 adaptation matrix. * @param[in] a Source color in Lab color space. * @param[out] b Destination color in RGB color space. */ void color_lab_to_rgb_d50(const Color* a, Color* b); /** * Convert Lab color space to LCH color space. * @param[in] a Source color in Lab color space. * @param[out] b Destination color in LCH color space. */ void color_lab_to_lch(const Color* a, Color* b); /** * Convert Lab color space to LCH color space. * @param[in] a Source color in Lab color space. * @param[out] b Destination color in LCH color space. */ void color_lch_to_lab(const Color* a, Color* b); /** * Convert RGB color space to LCH color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in LCH color space. * @param[in] reference_white Reference white color values. * @param[in] transformation Transformation matrix for RGB to XYZ conversion. * @param[in] adaptation_matrix XYZ chromatic adaptation matrix. */ void color_rgb_to_lch(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation, const matrix3x3* adaptation_matrix); /** * Convert LCH color space to RGB color space. * @param[in] a Source color in LCH color space. * @param[out] b Destination color in RGB color space. * @param[in] reference_white Reference white color values. * @param[in] transformation_inverted Transformation matrix for XYZ to RGB conversion. * @param[in] adaptation_matrix_inverted Inverted XYZ chromatic adaptation matrix. */ void color_lch_to_rgb(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation_inverted, const matrix3x3* adaptation_matrix_inverted); /** * Convert RGB color space to LCH color space with illuminant D50, observer 2, sRGB transformation matrix and D65-D50 adaptation matrix. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in LCH color space. */ void color_rgb_to_lch_d50(const Color* a, Color* b); /** * Convert LCH color space to RGB color space with illuminant D50, observer 2, inverted sRGB transformation matrix and D50-D65 adaptation matrix. * @param[in] a Source color in LCH color space. * @param[out] b Destination color in RGB color space. */ void color_lch_to_rgb_d50(const Color* a, Color* b); /** * Convert RGB color space to CMY color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in CMY color space. */ void color_rgb_to_cmy(const Color* a, Color* b); /** * Convert CMY color space to RGB color space. * @param[in] a Source color in CMY color space. * @param[out] b Destination color in RGB color space. */ void color_cmy_to_rgb(const Color* a, Color* b); /** * Convert CMY color space to CMYK color space. * @param[in] a Source color in CMY color space. * @param[out] b Destination color in CMYK color space. */ void color_cmy_to_cmyk(const Color* a, Color* b); /** * Convert CMYK color space to CMY color space. * @param[in] a Source color in CMYK color space. * @param[out] b Destination color in CMY color space. */ void color_cmyk_to_cmy(const Color* a, Color* b); /** * Convert RGB color space to CMYK color space. * @param[in] a Source color in RGB color space. * @param[out] b Destination color in CMYK color space. */ void color_rgb_to_cmyk(const Color* a, Color* b); /** * Convert CMYK color space to RGB color space. * @param[in] a Source color in CMYK color space. * @param[out] b Destination color in RGB color space. */ void color_cmyk_to_rgb(const Color* a, Color* b); /** * Normalize RGB color values. * @param[in,out] a Color in RGB color space. */ void color_rgb_normalize(Color* a); /** * Check whenever the color contains invalid (out of RGB gamut) value. * @param[in] a Color in RGB color space. * @return True, when color is out of RGB gamut. */ bool color_is_rgb_out_of_gamut(const Color* a); /** * Transform RGB color to linear RGB color. * @param[in] a Color in RGB color space. * @param[out] b Linear color in RGB color space. */ void color_rgb_get_linear(const Color* a, Color* b); /** * Transform linear RGB color to RGB color. * @param[in] a Linear color in RGB color space. * @param[out] b Color in RGB color space. */ void color_linear_get_rgb(const Color* a, Color* b); /** * Copy color. * @param[in] a Source color in any color space. * @param[out] b Destination color. */ void color_copy(const Color* a, Color* b); /** * Add color values. * @param[in,out] a Source color in any color space. * @param[in] b Color values. */ void color_add(Color* a, const Color* b); /** * Multiply color values by specified amount. * @param[in,out] a Source color in any color space. * @param[in] b Multiplier. */ void color_multiply(Color* a, float b); /** * Set all color values to zero. * @param[in,out] a Color to be set. */ void color_zero(Color* a); /** * Create new Color structure. * @return Color structure with unspecified values. */ Color* color_new(); /** * Free memory associated with Color structure. * @param[in] a Color to be freed. */ void color_destroy(Color* a); /** * Set all color values to specified value. * @param[in,out] a Color to be set. * @param[in] value Value which is used. */ void color_set(Color* a, float value); /** * Get either black or white color depending on which has more contrast with specified color. * @param[in] a Source color in RGB color space. * @param[out] b Color with most contrast in RGB color space. */ void color_get_contrasting(const Color* a, Color* b); /** * Calculate working space matrix. * @param[in] xr Red primary in x channel. * @param[in] yr Red primary in y channel. * @param[in] xg Green primary in x channel. * @param[in] yg Green primary in y channel. * @param[in] xb Blue primary in x channel. * @param[in] yb Blue primary in y channel. * @param[in] reference_white Reference white vector. * @param[out] result Calculated working space matrix. */ void color_get_working_space_matrix(float xr, float yr, float xg, float yg, float xb, float yb, const vector3* reference_white, matrix3x3* result); /** * Calculate chromatic adaptation matrix from source and destination reference white vectors. * @param[in] source_reference_white Source reference white vector. * @param[in] destination_reference_white Destination reference white vector. * @param[out] result Calculated chromatic adaptation matrix. */ void color_get_chromatic_adaptation_matrix(const vector3* source_reference_white, const vector3* destination_reference_white, matrix3x3* result); /** * Apply chromatic adaptation matrix to the XYZ color. * @param[in] a Source color in XYZ color space. * @param[out] result Pointer to a Color structure where the result is stored in XYZ color space. * @param[in] adaptation Chromatic adaptation matrix. * @see color_get_chromatic_adaptation_matrix. */ void color_xyz_chromatic_adaptation(const Color* a, Color* result, const matrix3x3* adaptation); /** * Get working space matrix for sRGB. * @return Constant reference to sRGB working space matrix. */ const matrix3x3* color_get_sRGB_transformation_matrix(); /** * Get inverted working space matrix for sRGB. * @return Constant reference to inverted sRGB working space matrix. */ const matrix3x3* color_get_inverted_sRGB_transformation_matrix(); /** * Get D65 to D50 chromatic adaptation matrix. * @return Constant reference to chromatic adaptation matrix. */ const matrix3x3* color_get_d65_d50_adaptation_matrix(); /** * Get D50 to D65 chromatic adaptation matrix. * @return Constant reference to chromatic adaptation matrix. */ const matrix3x3* color_get_d50_d65_adaptation_matrix(); /** * Get reference white vector for specified illuminant and observer. * @param[in] illuminant Illuminant. * @param[in] observer Observer. * @return Reference white vector. */ const vector3* color_get_reference(ReferenceIlluminant illuminant, ReferenceObserver observer); /** * Get illuminant by name. * @param[in] illuminant Illuminant name. * @return Reference illuminant. */ const ReferenceIlluminant color_get_illuminant(const char *illuminant); /** * Get observer by name. * @param[in] observer Observer name. * @return Reference observer. */ const ReferenceObserver color_get_observer(const char *observer); #endif /* COLOR_H_ */ gpick_0.2.5/source/cssparser/memory_manager.h0000644000175000017500000000420412070605214020062 0ustar zbygzbyg/* * 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 MEMORY_MANAGER_H #define MEMORY_MANAGER_H #ifndef _MSC_VER #include #endif #include struct MemoryPage; struct MemoryPage{ uint32_t total_size; uint32_t total_free; uint32_t atom_size; struct MemoryPage* next_page; uint8_t *map; uint8_t *raw_memory; }; struct Memory{ struct MemoryPage* pages; }; struct Memory* memory_new(); void memory_destroy(struct Memory* memory); void* memory_alloc(struct Memory* mem, uint32_t size); void memory_free(struct Memory* mem, void* mem_ptr); void* memory_realloc(struct Memory* memory, void* mem_ptr, uint32_t size); #endif /* MEMORY_MANAGER_H */ gpick_0.2.5/source/cssparser/css_parser.h0000644000175000017500000001333112070605214017225 0ustar zbygzbyg/* * 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 CSS_PARSER_H #define CSS_PARSER_H #ifndef _MSC_VER #include #endif #include #include #include #include "memory_manager.h" typedef struct parse_parm_s parse_parm; namespace css_parser { class css_file; class css_base; } typedef struct parse_parm_s{ css_parser::css_file *page; struct Memory* memory; uint32_t first_line; uint32_t first_column; uint32_t last_line; uint32_t last_column; uint32_t position; }parse_parm; int parse(FILE* f, int *result); #define YY_EXTRA_TYPE parse_parm* #ifndef YYSTYPE typedef union css_yystype{ css_parser::css_base *base; char* string; uint32_t number; } css_yystype; # define YYSTYPE css_yystype # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif /* extern YYSTYPE yylval; */ //YYSTYPE yylval; /*#define YY_EXTRA_TYPE parse_parm* */ /* Initialize LOC. */ # define CSS_LOCATION_RESET(Loc) \ (Loc).first_column = (Loc).first_line = 1; \ (Loc).last_column = (Loc).last_line = 1; \ (Loc).position=0; /* Advance of NUM lines. */ # define CSS_LOCATION_LINES(Loc, Num) \ (Loc).last_column = 1; \ (Loc).last_line += Num; /* Restart: move the first cursor to the last position. */ # define CSS_LOCATION_STEP(Loc) \ (Loc).first_column = (Loc).last_column; \ (Loc).first_line = (Loc).last_line; /* Output LOC on the stream OUT. */ # define CSS_LOCATION_PRINT(Out, Loc) \ if ((Loc).first_line != (Loc).last_line) \ fprintf (Out, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ (Loc).last_line, (Loc).last_column - 1); \ else if ((Loc).first_column < (Loc).last_column - 1) \ fprintf (Out, "%d.%d-%d", (Loc).first_line, \ (Loc).first_column, (Loc).last_column - 1); \ else \ fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column) namespace css_parser { class css_base{ public: css_base(); void* operator new(size_t num_bytes, parse_parm* parm); void operator delete(void* base, parse_parm* parm); virtual void polymorphic(); }; class css_property: public css_base{ public: const char* name_; std::list values_; css_property(const char* name); void addValue(css_base* value); }; class css_properties: public css_base{ public: std::list properties_; css_properties(); void addProperty(css_property* property); }; class css_simple_selector: public css_base{ public: const char* name_; css_simple_selector(const char* name); }; class css_selector: public css_base{ public: std::list simple_selectors_; css_selector(); void addSimpleSelector(css_simple_selector* simple_selector); void addSelector(css_selector* selector); void prependSimpleSelector(css_simple_selector* simple_selector); }; class css_selectors: public css_base{ public: std::list selectors_; css_selectors(); void addSelector(css_selector* selector); }; class css_ruleset: public css_base{ public: std::list selectors_; std::list properties_; css_ruleset(); void addSelector(css_selector* selector); void setSelectors(std::list &selectors); void addProperty(css_property* property); void addProperties(css_properties* properties); }; class css_file: public css_base{ public: std::list rulesets_; css_file(); void addRuleset(css_ruleset* ruleset); }; class css_function: public css_base{ public: const char* name_; std::list arguments_; css_function(const char* name); void addArgument(css_base* argument); }; class css_hex: public css_base{ public: uint32_t value_; css_hex(uint32_t value); css_hex(const char *value); }; class css_number: public css_base{ public: double value_; css_number(double value); }; class css_percentage: public css_base{ public: double value_; css_percentage(double value); }; class css_string: public css_base{ public: const char* value_; css_string(const char* value); }; } int parse_file(const char *filename); #endif gpick_0.2.5/source/cssparser/SConscript0000644000175000017500000000122112070605214016715 0ustar zbygzbyg#!/usr/bin/env python import os import sys Import('*') local_env = env.Clone() local_env.PrependUnique(CPPPATH = ['.']) local_env.Append(CPPDEFINES = ['YY_NO_UNISTD_H']) if not env['PREBUILD_GRAMMAR']: parser = local_env.Lemon('css_grammar.y') lexer = local_env.Flex('css_lex.l') else: parser = [File('css_grammar.c'), File('css_grammar.h')] lexer = [File('css_lex.cpp'), File('css_lex.h')] generated_files = Flatten([parser, lexer]) sources = local_env.Glob('*.cpp') objects = local_env.StaticObject( source = [sources]) if not env['PREBUILD_GRAMMAR']: Depends(parser, lexer) Depends(objects, parser) Return('objects', 'generated_files') gpick_0.2.5/source/cssparser/memory_manager.cpp0000644000175000017500000001306512070605214020422 0ustar zbygzbyg/* * 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 "memory_manager.h" #include #include #include static struct MemoryPage* memory_page_new(uint32_t total_size, uint32_t atom_size){ uint32_t atoms = total_size / atom_size; struct MemoryPage* page=(struct MemoryPage*)malloc(sizeof(struct MemoryPage) + atoms + total_size); page->total_size = atoms; page->total_free = atoms; page->atom_size = atom_size; page->map = ((uint8_t*)page) + sizeof(struct MemoryPage); page->raw_memory = ((uint8_t*)page) + sizeof(struct MemoryPage) + atoms; memset(page->map, 1, atoms); page->next_page=0; return page; } static void memory_page_destroy(struct MemoryPage* page){ free(page); } static void* memory_page_alloc(struct MemoryPage* page, uint32_t alloc_size){ register uint32_t size = (alloc_size + sizeof(uint32_t) + (page->atom_size-1))/page->atom_size; if (size>page->total_free) return 0; register uint32_t space=0; for (register uint32_t i=0; itotal_size; ++i){ space=(space+1)*page->map[i]; if (space==size){ memset(page->map+(i+1-size), 0, size); page->total_free-=size; uint8_t *mem_ptr = page->raw_memory+(i+1-size)*page->atom_size; ((uint32_t*)mem_ptr)[0] = alloc_size; return mem_ptr+sizeof(uint32_t); } } return 0; } bool memory_page_free(struct MemoryPage* page, void* mem_ptr){ if ((mem_ptr >= page->raw_memory) && (mem_ptr < page->raw_memory + page->total_size * page->atom_size )){ uint32_t atom_i = (uintptr_t(mem_ptr) - uintptr_t(page->raw_memory) - sizeof(uint32_t)) / page->atom_size; uint32_t atom_count = ((((uint32_t*)mem_ptr)-1)[0] + sizeof(uint32_t) + (page->atom_size-1))/page->atom_size; memset(page->map+atom_i, 1, atom_count); page->total_free+=atom_count; return true; } return false; } static uint32_t high_bit(uint32_t x){ register uint32_t bit=32; register uint32_t mask=(1<<(bit-1)); while (!(x & mask)){ mask>>=1; --bit; if (!mask) break; } return bit; } void* memory_alloc(struct Memory* memory, uint32_t size){ struct MemoryPage* page=memory->pages; void* ptr; struct { int32_t atom_size; int32_t memory_size; }segments[]={ {1<<5, (1<<5)*4096}, // 0 {1<<5, (1<<5)*4096}, // 1 {1<<5, (1<<5)*4096}, // 2 {1<<5, (1<<5)*4096}, // 3 {1<<5, (1<<5)*4096}, // 4 {1<<5, (1<<5)*4096}, // 5 {1<<5, (1<<5)*4096}, // 6 {1<<5, (1<<5)*4096}, // 7 {1<<5, (1<<5)*4096}, // 8 {1<<7, (1<<7)*1024}, // 9 {1<<7, (1<<7)*1024}, // 10 {1<<7, (1<<7)*1024}, // 11 {1<<7, (1<<7)*1024}, // 12 {1<<8, (1<<8)*512}, // 13 {1<<8, (1<<8)*512}, // 14 {1<<8, (1<<8)*512}, // 15 {1<<12, (1<<12)*256}, // 16 {1<<12, (1<<12)*256}, // 17 {1<<12, (1<<12)*256}, // 18 {1<<12, (1<<12)*256}, // 19 // 1MB and more }; uint32_t highbit = high_bit(size); if (page){ do{ if (page->atom_size != segments[highbit].atom_size) continue; if ((ptr = memory_page_alloc(page, size))) return ptr; }while ((page = page->next_page)); } //printf("new page: %d %d %d %d\n", segments[highbit].memory_size, segments[highbit].atom_size, highbit, size); page = memory_page_new( segments[highbit].memory_size, segments[highbit].atom_size); page->next_page = memory->pages; memory->pages = page; if ((ptr = memory_page_alloc(page, size))) return ptr; exit(0); return 0; } void* memory_realloc(struct Memory* memory, void* mem_ptr, uint32_t size){ //printf("r: %d\n", size); void* newptr=memory_alloc(memory, size); memcpy(newptr, mem_ptr, (((uint32_t*)mem_ptr)-1)[0]); memory_free(memory, mem_ptr); return newptr; } void memory_free(struct Memory* memory, void* mem_ptr){ struct MemoryPage* page=memory->pages; if (page){ do{ if (memory_page_free(page, mem_ptr)) return; }while ((page = page->next_page)); } } struct Memory* memory_new(){ struct Memory* memory=(struct Memory*)malloc(sizeof(struct Memory)); memory->pages=0; return memory; } void memory_destroy(struct Memory* memory){ struct MemoryPage* page=memory->pages; struct MemoryPage* tmp; while (page){ tmp=page; page=page->next_page; memory_page_destroy(tmp); } free(memory); } gpick_0.2.5/source/cssparser/css_grammar.y0000644000175000017500000002141712070605214017404 0ustar zbygzbyg %include { #include #include "css_lex.h" #include using namespace css_parser; } %extra_argument { parse_parm_s *parm } %name css_parse %token_prefix CSS_TOKEN_ %token_type {css_yystype} %default_type {css_yystype} %left S. %right IDENT. %left CDO CDC. %left INCLUDES. %left DASHMATCH. %left STRING. %left INVALID. %left HEXCOLOR. %left SEMICOLON COMMA LBRACE RBRACE HASH GREATER PLUS CLPARENTH RBRACK SLASH. %nonassoc DOT COLON LBRACK ASTERISK. %left IMPORT_SYM. %left PAGE_SYM. %left MEDIA_SYM. %left CHARSET_SYM. %left IMPORTANT_SYM. %left FONTFACE_SYM. %left NAMESPACE_SYM. %left EMS EXS LENGTH ANGLE TIME FREQ DIMENSION PERCENTAGE NUMBER. %left FUNCTION. %left URI. %type property {css_property*} %type expr {css_base*} %type term {css_base*} %type hexcolor {css_hex*} %type function {css_function*} %type declaration {css_property*} %type selectors {css_selectors*} %type maybe_declarations {css_properties*} %type ruleset {css_ruleset*} %type declarations {css_properties*} %type declaration_list {css_properties*} %type selector {css_selector*} %type universal_selector {css_simple_selector*} %type type_selector {css_simple_selector*} %type class_selector {css_simple_selector*} %type id_selector {css_simple_selector*} %type simple_selectors {css_selector*} %type pseudo_selector {css_simple_selector*} %type attribute_selector {css_simple_selector*} %type simple_selector {css_selector*} %syntax_error { printf("Error: %s\n", yyTokenName[yymajor]); } %start_symbol stylesheet stylesheet ::= maybe_charset maybe_sgml maybe_rules. maybe_space ::= . maybe_space ::= maybe_space S. space ::= S. space ::= space S. maybe_sgml ::= . maybe_sgml ::= maybe_sgml CDO. maybe_sgml ::= maybe_sgml CDC. maybe_sgml ::= maybe_sgml S. maybe_charset ::= . maybe_charset ::= CHARSET_SYM maybe_space STRING maybe_space SEMICOLON. maybe_rules ::= . maybe_rules ::= maybe_rules rule maybe_sgml. rule ::= import. rule ::= ruleset. rule ::= media. rule ::= page. medium ::= IDENT maybe_space. maybe_medium ::= . maybe_medium ::= medium. maybe_medium ::= maybe_medium COMMA maybe_space medium. uri_or_string ::= URI. uri_or_string ::= STRING. import ::= IMPORT_SYM maybe_space uri_or_string maybe_space maybe_medium SEMICOLON. import ::= IMPORT_SYM error SEMICOLON. ruleset(R) ::= selectors(A) block_start maybe_declarations(B) block_end. { css_ruleset *ruleset = new(parm) css_ruleset(); ruleset->setSelectors(A->selectors_); if (B) ruleset->addProperties(B); R = ruleset; parm->page->addRuleset(ruleset); } ruleset(R) ::= selectors(A) block_start space maybe_declarations(B) block_end. { css_ruleset *ruleset = new(parm) css_ruleset(); ruleset->setSelectors(A->selectors_); if (B) ruleset->addProperties(B); R = ruleset; parm->page->addRuleset(ruleset); } media_list ::= media_list COMMA maybe_space medium. media_list ::= medium. media ::= MEDIA_SYM maybe_space media_list block_start maybe_space maybe_declarations block_end. media ::= MEDIA_SYM maybe_space block_start maybe_space maybe_declarations block_end. page ::= PAGE_SYM maybe_space maybe_pseudo_page block_start maybe_space maybe_declarations block_end. maybe_pseudo_page ::= . maybe_pseudo_page ::= COLON IDENT maybe_space. maybe_declarations(R) ::= . { R = 0; } maybe_declarations(R) ::= declarations(A). { R = A; } universal_selector(R) ::= ASTERISK(A). { R = new(parm) css_simple_selector(A.string); } type_selector(R) ::= IDENT(A). { R = new(parm) css_simple_selector(A.string); } class_selector(R) ::= DOT IDENT(A). { R = new(parm) css_simple_selector(A.string); } id_selector(R) ::= HASH IDENT(A). { R = new(parm) css_simple_selector(A.string); } attribute_selector(R) ::= LBRACK maybe_space IDENT(A) maybe_space RBRACK. { R = new(parm) css_simple_selector(A.string); } pseudo_selector(R) ::= COLON IDENT(A). { R = new(parm) css_simple_selector(A.string); } pseudo_selector ::= COLON FUNCTION maybe_space CLPARENTH. pseudo_selector ::= COLON FUNCTION maybe_space IDENT maybe_space CLPARENTH. pseudo_selector(R) ::= COLON COLON IDENT(A). { R = new(parm) css_simple_selector(A.string); } simple_selectors(R) ::= simple_selectors(A) id_selector(B). { A->addSimpleSelector(B); R = A; } simple_selectors(R) ::= simple_selectors(A) class_selector(B). { A->addSimpleSelector(B); R = A; } simple_selectors(R) ::= simple_selectors(A) attribute_selector(B). { A->addSimpleSelector(B); R = A; } simple_selectors(R) ::= simple_selectors(A) pseudo_selector(B). { A->addSimpleSelector(B); R = A; } simple_selectors(R) ::= id_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selectors(R) ::= class_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selectors(R) ::= attribute_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selectors(R) ::= pseudo_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selector(R) ::= type_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selector(R) ::= type_selector(A) simple_selectors(B). { B->prependSimpleSelector(A); R = B; } simple_selector(R) ::= universal_selector(A). { css_selector* selector = new(parm) css_selector(); selector->addSimpleSelector(A); R = selector; } simple_selector(R) ::= universal_selector(A) simple_selectors(B). { B->prependSimpleSelector(A); R = B; } simple_selector(R) ::= simple_selectors(A). { R = A; } selector(R) ::= simple_selector(A). { R = A; } selector(R) ::= selector(A) combinator simple_selector(B). { A->addSelector(B); R = A; } selector(R) ::= selector(A) space simple_selector(B). { A->addSelector(B); R = A; } selector(R) ::= selector(A) space combinator simple_selector(B). { A->addSelector(B); R = A; } selectors(R) ::= selector(A). { css_selectors* selectors = new(parm) css_selectors(); selectors->addSelector(A); R = selectors; } selectors(R) ::= selector(A) space. { css_selectors* selectors = new(parm) css_selectors(); selectors->addSelector(A); R = selectors; } selectors(R) ::= selectors(A) COMMA maybe_space selector(B). { A->addSelector(B); R = A; } selectors(R) ::= selectors(A) COMMA maybe_space selector(B) space. { A->addSelector(B); R = A; } combinator ::= PLUS maybe_space. combinator ::= GREATER maybe_space. declaration_list(R) ::= declaration(A) SEMICOLON maybe_space. { css_properties* properties = new(parm) css_properties(); if (A) properties->addProperty(A); R = properties; } declaration_list(R) ::= declaration_list(A) declaration(B) SEMICOLON maybe_space. { if (B) A->addProperty(B); R = A; } declarations(R) ::= declaration(A). { css_properties* properties = new(parm) css_properties(); if (A) properties->addProperty(A); R = properties; } declarations(R) ::= declaration_list(A) declaration(B). { if (B) A->addProperty(B); R = A; } declarations(R) ::= declaration_list(A). { R = A; } declaration(R) ::= property(A) COLON maybe_space expr(B) maybe_prio. { if (strcmp(A->name_, "color") == 0 || strcmp(A->name_, "background-color") == 0){ A->addValue(B); R = A; }else{ R = 0; } } property(R) ::= IDENT(A) maybe_space. { R = new(parm) css_property(A.string);} maybe_prio ::= . maybe_prio ::= IMPORTANT_SYM maybe_space. expr(R) ::= term(A). { R = A; } expr(R) ::= expr(A) term(B). { R = A; R = B; } expr(R) ::= expr(A) operator term(C). { R = A; R = C; } unary_operator ::= MINUS. unary_operator ::= PLUS. maybe_unary_operator ::= . maybe_unary_operator ::= unary_operator. operator ::= SLASH maybe_space. operator ::= COMMA maybe_space. term(R) ::= maybe_unary_operator NUMBER(A) maybe_space. { R = new(parm) css_number(A.number); } term(R) ::= maybe_unary_operator PERCENTAGE maybe_space. { R = 0; } term(R) ::= maybe_unary_operator LENGTH maybe_space. { R = 0; } term(R) ::= maybe_unary_operator EMS maybe_space. { R = 0; } term(R) ::= maybe_unary_operator EXS maybe_space. { R = 0; } term(R) ::= maybe_unary_operator ANGLE maybe_space. { R = 0; } term(R) ::= maybe_unary_operator TIME maybe_space. { R = 0; } term(R) ::= maybe_unary_operator FREQ maybe_space. { R = 0; } term(R) ::= STRING(A) maybe_space. { R = new(parm) css_string(A.string); } term(R) ::= IDENT(A) maybe_space. { R = new(parm) css_string(A.string); } term(R) ::= URI maybe_space. { R = 0; } term(R) ::= HEXCOLOR(A) maybe_space. { R = new(parm) css_hex(A.string); } term(R) ::= function(A) maybe_space. { R = A; } function(R) ::= FUNCTION(A) maybe_space expr(B) CLPARENTH maybe_space. { css_function* function = new(parm) css_function(A.string); function->addArgument(B); R = function; } block_start ::= LBRACE. block_end ::= RBRACE. block_end ::= error RBRACE. gpick_0.2.5/source/cssparser/css_parser.cpp0000644000175000017500000001444012070605214017562 0ustar zbygzbyg/* * 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 #include "css_parser.h" #include "css_lex.h" #include using namespace std; namespace css_parser{ css_base::css_base(){ } void css_base::polymorphic(){ } void* css_base::operator new(size_t num_bytes, parse_parm* parm){ return memory_alloc(parm->memory, num_bytes); } void css_base::operator delete(void* base, parse_parm* parm){ memory_free(parm->memory, base); } css_property::css_property(const char* name){ name_ = name; } void css_property::addValue(css_base* value){ values_.push_back(value); } css_simple_selector::css_simple_selector(const char* name){ name_ = name; } css_selector::css_selector(){ } void css_selector::addSimpleSelector(css_simple_selector* simple_selector){ simple_selectors_.push_back(simple_selector); } void css_selector::addSelector(css_selector* selector){ for (list::iterator i = selector->simple_selectors_.begin(); i != selector->simple_selectors_.end(); i++){ simple_selectors_.push_back(*i); } } void css_selector::prependSimpleSelector(css_simple_selector* simple_selector){ simple_selectors_.push_front(simple_selector); } css_selectors::css_selectors(){ } void css_selectors::addSelector(css_selector* selector){ selectors_.push_back(selector); } css_ruleset::css_ruleset(){ } void css_ruleset::addSelector(css_selector* selector){ selectors_.push_back(selector); } void css_ruleset::setSelectors(std::list &selectors){ selectors_ = selectors; } void css_ruleset::addProperty(css_property* property){ properties_.push_back(property); } void css_ruleset::addProperties(css_properties* properties){ for (list::iterator i = properties->properties_.begin(); i != properties->properties_.end(); i++){ properties_.push_back(*i); } } css_file::css_file(){ } void css_file::addRuleset(css_ruleset* ruleset){ rulesets_.push_back(ruleset); } css_function::css_function(const char* name){ name_ = name; } void css_function::addArgument(css_base* argument){ arguments_.push_back(argument); } css_hex::css_hex(uint32_t value){ value_ = value; } css_hex::css_hex(const char *value){ uint32_t x; std::stringstream ss; ss << (value + 1); ss << hex; ss >> x; value_ = x; if (strlen(value) == 4){ value_ = (value_ & 0xf00) << 12 | (value_ & 0xf00) << 8 | (value_ & 0x0f0) << 8 | (value_ & 0x0f0) << 4 | (value_ & 0x00f) << 4 | (value_ & 0x00f) << 0; } } css_number::css_number(double value){ value_ = value; } css_percentage::css_percentage(double value){ value_ = value; } css_string::css_string(const char* value){ value_ = value; } css_properties::css_properties(){ } void css_properties::addProperty(css_property* property){ properties_.push_back(property); } } using namespace css_parser; void *css_parseAlloc(void *(*mallocProc)(size_t)); void css_parseFree(void *p, void (*freeProc)(void*)); void css_parse(void *yyp, int yymajor, css_yystype yyminor, parse_parm*); void print_rec(css_base *node){ css_file *file; css_ruleset *ruleset; css_selector *selector; css_property *property; css_simple_selector *simple_selector; if ((file = dynamic_cast(node))){ printf("file\n"); for (list::iterator i = file->rulesets_.begin(); i != file->rulesets_.end(); i++){ print_rec(*i); } }else if ((ruleset = dynamic_cast(node))){ if (ruleset->properties_.begin() == ruleset->properties_.end()) return; printf("ruleset\n"); for (list::iterator i = ruleset->selectors_.begin(); i != ruleset->selectors_.end(); i++){ print_rec(*i); } for (list::iterator i = ruleset->properties_.begin(); i != ruleset->properties_.end(); i++){ print_rec(*i); } printf("\n"); }else if ((selector = dynamic_cast(node))){ for (list::iterator i = selector->simple_selectors_.begin(); i != selector->simple_selectors_.end(); i++){ print_rec(*i); } printf("-> "); }else if ((simple_selector = dynamic_cast(node))){ printf("%s ", simple_selector->name_); }else if ((property = dynamic_cast(node))){ printf("%s = %06x, ", property->name_, ((css_hex*)*property->values_.begin())->value_); } } int parse_file(const char *filename){ FILE* f = fopen(filename, "rt"); yyscan_t scanner; css_yystype stype; parse_parm pp; struct Memory* memory = memory_new(); pp.memory = memory; pp.page = new(&pp) css_file; css_lex_init_extra(&pp, &scanner); css_set_in(f, scanner); css_restart(f, scanner); void *parser = css_parseAlloc(malloc); int token_id; while( (token_id = css_lex(&stype, scanner)) != 0){ css_parse(parser, token_id, stype, &pp); } css_parseFree(parser, free); css_lex_destroy(scanner); print_rec(pp.page); memory_destroy(memory); fclose(f); printf("\n"); return 1; } gpick_0.2.5/source/cssparser/css_grammar_wrap.cpp0000644000175000017500000000311612070605214020743 0ustar zbygzbyg/* * 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. */ #undef NDEBUG #define NEVER(a) false #include gpick_0.2.5/source/cssparser/css_lex.l0000644000175000017500000001365612070605214016537 0ustar zbygzbyg %option reentrant bison-bridge %option noyywrap nounput batch %option never-interactive %option prefix="css_" %option case-insensitive %option stack %option 8bit %option nounistd %option noyyalloc noyyrealloc noyyfree %{ #include "css_grammar.h" #include #include "memory_manager.h" using namespace std; #define YY_USER_ACTION { yyextra->last_column += yyleng; yyextra->position += yyleng; } char* css_strdup(char* x, void * yyscanner); %} h [0-9a-f] nonascii [\200-\377] unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])? escape {unicode}|\\[^\r\n\f0-9a-f] nmstart [_a-z]|{nonascii}|{escape} nmchar [_a-z0-9-]|{nonascii}|{escape} string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\" string2 \'([^\n\r\f\\']|\\{nl}|{escape})*\' invalid1 \"([^\n\r\f\\"]|\\{nl}|{escape})* invalid2 \'([^\n\r\f\\']|\\{nl}|{escape})* comment_begin "/*" comment_end "*/" ident -?{nmstart}{nmchar}* name {nmchar}+ num [0-9]+|[0-9]*"."[0-9]+ string {string1}|{string2} invalid {invalid1}|{invalid2} url ([!#$%&*-~]|{nonascii}|{escape})* s [ \t\r\n\f]+ w {s}? ws [ \t]+ nl \n|\r\n|\r|\f hexcolor {h}{3}|{h}{6} A a|\\0{0,4}(41|61)(\r\n|[ \t\r\n\f])? B b|\\0{0,4}(42|62)(\r\n|[ \t\r\n\f])? C c|\\0{0,4}(43|63)(\r\n|[ \t\r\n\f])? D d|\\0{0,4}(44|64)(\r\n|[ \t\r\n\f])? E e|\\0{0,4}(45|65)(\r\n|[ \t\r\n\f])? F f|\\0{0,4}(46|66)(\r\n|[ \t\r\n\f])? G g|\\0{0,4}(47|67)(\r\n|[ \t\r\n\f])?|\\g H h|\\0{0,4}(48|68)(\r\n|[ \t\r\n\f])?|\\h I i|\\0{0,4}(49|69)(\r\n|[ \t\r\n\f])?|\\i J j|\\0{0,4}(4a|6a)(\r\n|[ \t\r\n\f])?|\\j K k|\\0{0,4}(4b|6b)(\r\n|[ \t\r\n\f])?|\\k L l|\\0{0,4}(4c|6c)(\r\n|[ \t\r\n\f])?|\\l M m|\\0{0,4}(4d|6d)(\r\n|[ \t\r\n\f])?|\\m N n|\\0{0,4}(4e|6e)(\r\n|[ \t\r\n\f])?|\\n O o|\\0{0,4}(4f|6f)(\r\n|[ \t\r\n\f])?|\\o P p|\\0{0,4}(50|70)(\r\n|[ \t\r\n\f])?|\\p Q q|\\0{0,4}(51|71)(\r\n|[ \t\r\n\f])?|\\q R r|\\0{0,4}(52|72)(\r\n|[ \t\r\n\f])?|\\r S s|\\0{0,4}(53|73)(\r\n|[ \t\r\n\f])?|\\s T t|\\0{0,4}(54|74)(\r\n|[ \t\r\n\f])?|\\t U u|\\0{0,4}(55|75)(\r\n|[ \t\r\n\f])?|\\u V v|\\0{0,4}(56|76)(\r\n|[ \t\r\n\f])?|\\v W w|\\0{0,4}(57|77)(\r\n|[ \t\r\n\f])?|\\w X x|\\0{0,4}(58|78)(\r\n|[ \t\r\n\f])?|\\x Y y|\\0{0,4}(59|79)(\r\n|[ \t\r\n\f])?|\\y Z z|\\0{0,4}(5a|7a)(\r\n|[ \t\r\n\f])?|\\z %x comment %x sgml %% %{ CSS_LOCATION_STEP (*yyextra); %} {nl}+ {CSS_LOCATION_LINES (*yyextra, yyleng); CSS_LOCATION_STEP (*yyextra); return CSS_TOKEN_S;} {ws} {CSS_LOCATION_STEP (*yyextra); return CSS_TOKEN_S;} {comment_begin} { yy_push_state(comment, yyscanner); } {nl}+ {CSS_LOCATION_LINES (*yyextra, yyleng); CSS_LOCATION_STEP (*yyextra); } [^*\n\r\f]* /* eat up comments */ "*"+[^*/\n\r\f]* /* eat up '*'s not followed by '/'s */ {comment_end} { yy_pop_state(yyscanner); } "" { yy_pop_state(yyscanner); } "~=" {return CSS_TOKEN_INCLUDES;} "|=" {return CSS_TOKEN_DASHMATCH;} {string} {yylval->string = css_strdup(yytext, yyscanner); return CSS_TOKEN_STRING;} {invalid} {return CSS_TOKEN_INVALID; /* unclosed string */} {ident} {yylval->string = css_strdup(yytext, yyscanner); return CSS_TOKEN_IDENT; } "#"{hexcolor} {yylval->string = css_strdup(yytext, yyscanner); return CSS_TOKEN_HEXCOLOR;} "@import" {return CSS_TOKEN_IMPORT_SYM;} "@page" {return CSS_TOKEN_PAGE_SYM;} "@media" {return CSS_TOKEN_MEDIA_SYM;} "@font-face" {return CSS_TOKEN_FONTFACE_SYM;} "@charset " {return CSS_TOKEN_CHARSET_SYM;} "@namespace" {return CSS_TOKEN_NAMESPACE_SYM;} "!"({w}|{comment_begin})*{I}{M}{P}{O}{R}{T}{A}{N}{T} {return CSS_TOKEN_IMPORTANT_SYM;} {num}{E}{M} {return CSS_TOKEN_EMS;} {num}{E}{X} {return CSS_TOKEN_EXS;} {num}{P}{X} {return CSS_TOKEN_LENGTH;} {num}{C}{M} {return CSS_TOKEN_LENGTH;} {num}{M}{M} {return CSS_TOKEN_LENGTH;} {num}{I}{N} {return CSS_TOKEN_LENGTH;} {num}{P}{T} {return CSS_TOKEN_LENGTH;} {num}{P}{C} {return CSS_TOKEN_LENGTH;} {num}{D}{E}{G} {return CSS_TOKEN_ANGLE;} {num}{R}{A}{D} {return CSS_TOKEN_ANGLE;} {num}{G}{R}{A}{D} {return CSS_TOKEN_ANGLE;} {num}{M}{S} {return CSS_TOKEN_TIME;} {num}{S} {return CSS_TOKEN_TIME;} {num}{H}{Z} {return CSS_TOKEN_FREQ;} {num}{K}{H}{Z} {return CSS_TOKEN_FREQ;} {num}{ident} {return CSS_TOKEN_DIMENSION;} {num}% {yylval->number = strtod(yytext, 0); return CSS_TOKEN_PERCENTAGE;} {num} {yylval->number = strtod(yytext, 0); return CSS_TOKEN_NUMBER;} {U}{R}{L}"("{w}{string}{w}")" {return CSS_TOKEN_URI;} {U}{R}{L}"("{w}{url}{w}")" {return CSS_TOKEN_URI;} {ident}"(" {yylval->string = css_strdup(yytext, yyscanner); return CSS_TOKEN_FUNCTION;} "-" {return CSS_TOKEN_MINUS;} "+" {return CSS_TOKEN_PLUS;} "/" {return CSS_TOKEN_SLASH;} "*" {return CSS_TOKEN_ASTERISK;} "#" {return CSS_TOKEN_HASH;} "{" {return CSS_TOKEN_LBRACE;} "}" {return CSS_TOKEN_RBRACE;} "[" {return CSS_TOKEN_LBRACK;} "]" {return CSS_TOKEN_RBRACK;} "." {return CSS_TOKEN_DOT;} "," {return CSS_TOKEN_COMMA;} ":" {return CSS_TOKEN_COLON;} ";" {return CSS_TOKEN_SEMICOLON;} ")" {return CSS_TOKEN_CLPARENTH;} ">" {return CSS_TOKEN_GREATER;} . {printf("Unknown char\n"); return *yytext;} %% void * css_alloc (size_t bytes, void* yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return memory_alloc (yyextra->memory, bytes); } void * css_realloc (void * ptr, size_t bytes, void* yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return memory_realloc (yyextra->memory, ptr, bytes); } void css_free (void * ptr, void * yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; memory_free(yyextra->memory, ptr); } char* css_strdup(char* x, void * yyscanner){ uint32_t size=strlen(x)+1; char* r=(char*)css_alloc(size, yyscanner); memcpy(r, x, size); return r; } gpick_0.2.5/source/ColorObject.cpp0000644000175000017500000000647412070605214015626 0ustar zbygzbyg/* * 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 "ColorObject.h" #include "DynvHelpers.h" #include using namespace std; struct ColorObject* color_object_new(struct dynvHandlerMap* handler_map){ struct ColorObject* color_object=new struct ColorObject; color_object->action=NULL; color_object->refcnt=0; color_object->selected=0; color_object->position=~(uint32_t)0; color_object->recalculate=1; if (handler_map){ color_object->params=dynv_system_create(handler_map); }else{ color_object->params=NULL; } return color_object; } int color_object_release(struct ColorObject* color_object){ if (color_object->refcnt){ color_object->refcnt--; return -1; }else{ if (color_object->params) dynv_system_release(color_object->params); delete color_object; return 0; } } struct ColorObject* color_object_ref(struct ColorObject* color_object){ color_object->refcnt++; return color_object; } int color_object_get_color(struct ColorObject* color_object, Color* color){ if (!color_object->action){ const Color* c = dynv_get_color_wd(color_object->params, "color", 0); if (c){ color_copy(const_cast(c), color); return 0; } return -1; }else{ //action } return -1; } int color_object_set_color(struct ColorObject* color_object, Color* color){ if (!color_object->action){ //color_copy(color, &color_object->color); dynv_set_color(color_object->params, "color", color); return 0; }else{ //action } return -1; } struct ColorObject* color_object_copy(struct ColorObject* color_object){ struct ColorObject* new_color_object = color_object_new(0); new_color_object->params = dynv_system_copy(color_object->params); new_color_object->recalculate = color_object->recalculate; new_color_object->selected = color_object->selected; new_color_object->visited = color_object->visited; return new_color_object; } gpick_0.2.5/source/FileFormat.h0000644000175000017500000000340712070605214015107 0ustar zbygzbyg/* * 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 FILEFORMAT_H_ #define FILEFORMAT_H_ #include "ColorList.h" int palette_file_save(const char* filename, struct ColorList* color_list); int palette_file_load(const char* filename, struct ColorList* color_list); #endif /* FILEFORMAT_H_ */ gpick_0.2.5/source/CopyPaste.cpp0000644000175000017500000001460712070605214015325 0ustar zbygzbyg/* * 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 "GlobalStateStruct.h" #include "CopyPaste.h" #include "uiApp.h" #include enum { TARGET_STRING = 1, TARGET_ROOTWIN, TARGET_COLOR, TARGET_COLOR_OBJECT, }; static GtkTargetEntry targets[] = { //{ (char*)"colorobject", GTK_TARGET_SAME_APP, TARGET_COLOR_OBJECT }, { (char*)"application/x-color", 0, TARGET_COLOR }, { (char*)"text/plain", 0, TARGET_STRING }, { (char*)"STRING", 0, TARGET_STRING }, //{ (char*)"application/x-rootwin-drop", 0, TARGET_ROOTWIN } }; static guint n_targets = G_N_ELEMENTS (targets); typedef struct CopyPasteArgs{ struct ColorObject* color_object; GlobalState* gs; }CopyPasteArgs; static void clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint target_type, CopyPasteArgs* args){ g_assert (selection_data != NULL); Color color; switch (target_type){ case TARGET_COLOR_OBJECT: gtk_selection_data_set (selection_data, gdk_atom_intern ("colorobject", false), 8, (guchar *)&args->color_object, sizeof(struct ColorObject*)); break; case TARGET_STRING: { color_object_get_color(args->color_object, &color); char* text = main_get_color_text(args->gs, &color, COLOR_TEXT_TYPE_COPY); if (text){ gtk_selection_data_set_text(selection_data, text, strlen(text)+1); g_free(text); } } break; case TARGET_COLOR: { color_object_get_color(args->color_object, &color); guint16 data_color[4]; data_color[0] = int(color.rgb.red * 0xFFFF); data_color[1] = int(color.rgb.green * 0xFFFF); data_color[2] = int(color.rgb.blue * 0xFFFF); data_color[3] = 0xffff; gtk_selection_data_set (selection_data, gdk_atom_intern ("application/x-color", false), 16, (guchar *)data_color, 8); } break; case TARGET_ROOTWIN: g_print ("Dropped on the root window!\n"); break; default: g_assert_not_reached (); } } static void clipboard_clear(GtkClipboard *clipboard, CopyPasteArgs* args){ color_object_release(args->color_object); delete args; } int copypaste_set_color_object(struct ColorObject* color_object, GlobalState* gs){ CopyPasteArgs* args = new CopyPasteArgs; args->color_object = color_object_ref(color_object); args->gs = gs; if (gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), targets, n_targets, (GtkClipboardGetFunc)clipboard_get, (GtkClipboardClearFunc)clipboard_clear, args)){ return 0; } return -1; } int copypaste_get_color_object(struct ColorObject** out_color_object, GlobalState* gs){ GdkAtom *avail_targets; gint avail_n_targets; GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); if (gtk_clipboard_wait_for_targets(clipboard, &avail_targets, &avail_n_targets)){ for (uint32_t j = 0; j < n_targets; ++j){ for (int32_t i = 0; i < avail_n_targets; ++i){ gchar* atom_name = gdk_atom_name(avail_targets[i]); if (g_strcmp0(targets[j].target, atom_name)==0){ GtkSelectionData *selection_data = gtk_clipboard_wait_for_contents(clipboard, avail_targets[i]); bool success = false; if (selection_data){ switch (targets[j].info){ case TARGET_COLOR_OBJECT: { struct ColorObject* color_object; memcpy(&color_object, selection_data->data, sizeof(struct ColorObject*)); *out_color_object = color_object; success = true; } break; case TARGET_STRING: { gchar* data = (gchar*)selection_data->data; if (data[selection_data->length]!=0) break; //not null terminated struct ColorObject* color_object; if (main_get_color_object_from_text(gs, data, &color_object)==0){ *out_color_object = color_object; success = true; } } break; case TARGET_COLOR: { guint16* data = (guint16*)selection_data->data; Color color; color.rgb.red = data[0] / (double)0xFFFF; color.rgb.green = data[1] / (double)0xFFFF; color.rgb.blue = data[2] / (double)0xFFFF; struct ColorObject* color_object = color_list_new_color_object(gs->colors, &color); *out_color_object = color_object; success = true; } break; default: g_assert_not_reached (); } } if (success){ g_free(atom_name); g_free(avail_targets); return 0; } } g_free(atom_name); } } g_free(avail_targets); } return -1; } int copypaste_is_color_object_available(GlobalState* gs){ GdkAtom *avail_targets; gint avail_n_targets; if (gtk_clipboard_wait_for_targets(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), &avail_targets, &avail_n_targets)){ for (uint32_t j = 0; j < n_targets; ++j){ for (int32_t i = 0; i < avail_n_targets; ++i){ gchar* atom_name = gdk_atom_name(avail_targets[i]); if (g_strcmp0(targets[j].target, atom_name)==0){ g_free(atom_name); g_free(avail_targets); return 0; } g_free(atom_name); } } g_free(avail_targets); } return -1; } gpick_0.2.5/source/ColorSpaceType.h0000644000175000017500000000433012070605214015747 0ustar zbygzbyg/* * 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 COLORSPACETYPE_H_ #define COLORSPACETYPE_H_ #include "gtk/ColorComponent.h" #include "Color.h" #include #include extern "C"{ #include #include #include #include } #include #include typedef struct ColorSpaceType { GtkColorComponentComp comp_type; int8_t n_items; struct { const char *name; double raw_scale; double min_value; double max_value; double step; }items[4]; }ColorSpaceType; const ColorSpaceType* color_space_get_types(); uint32_t color_space_count_types(); std::list color_space_color_to_text(const char *type, const Color *color, lua_State* L); #endif /* COLORSPACETYPE_H_ */ gpick_0.2.5/source/uiDialogGenerate.cpp0000644000175000017500000003023012113713537016622 0ustar zbygzbyg/* * 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 "uiDialogGenerate.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "MathUtil.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "ToolColorNaming.h" #include "ColorRYB.h" #include "Noise.h" #include "GenerateScheme.h" #include "Internationalisation.h" #include #include #include using namespace std; typedef struct DialogGenerateArgs{ GtkWidget *gen_type; GtkWidget *wheel_type; GtkWidget *range_colors; GtkWidget *range_chaos; GtkWidget *range_chaos_seed; GtkWidget *toggle_reverse; struct ColorList *color_list; struct ColorList *selected_color_list; struct ColorList *preview_color_list; struct dynvSystem *params; GlobalState* gs; }DialogGenerateArgs; typedef struct ColorWheelType{ const char *name; void (*hue_to_hsl)(double hue, Color* hsl); void (*rgbhue_to_hue)(double rgbhue, double *hue); }ColorWheelType; class GenerateColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; int32_t m_ident; int32_t m_schemetype; public: GenerateColorNameAssigner(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 void rgb_hue2hue(double hue, Color* hsl){ hsl->hsl.hue = hue; hsl->hsl.saturation = 1; hsl->hsl.lightness = 0.5; } static void rgb_rgbhue2hue(double rgbhue, double *hue){ *hue = rgbhue; } static void ryb1_hue2hue(double hue, Color* hsl){ Color c; color_rybhue_to_rgb(hue, &c); color_rgb_to_hsl(&c, hsl); } static void ryb1_rgbhue2hue(double rgbhue, double *hue){ color_rgbhue_to_rybhue(rgbhue, hue); } static void ryb2_hue2hue(double hue, Color* hsl){ hsl->hsl.hue = color_rybhue_to_rgbhue_f(hue); hsl->hsl.saturation = 1; hsl->hsl.lightness = 0.5; } static void ryb2_rgbhue2hue(double rgbhue, double *hue){ color_rgbhue_to_rybhue_f(rgbhue, hue); } const ColorWheelType color_wheel_types[]={ {"RGB", rgb_hue2hue, rgb_rgbhue2hue}, {"RYB v1", ryb1_hue2hue, ryb1_rgbhue2hue}, {"RYB v2", ryb2_hue2hue, ryb2_rgbhue2hue}, }; static void calc( DialogGenerateArgs *args, bool preview, int limit){ 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)); int32_t color_count = static_cast(gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_colors))); double chaos = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_chaos)); int32_t chaos_seed = static_cast(gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_chaos_seed))); bool reverse = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_reverse)); GenerateColorNameAssigner name_assigner(args->gs); if (!preview){ dynv_set_int32(args->params, "type", type); dynv_set_int32(args->params, "wheel_type", wheel_type); dynv_set_int32(args->params, "colors", color_count); dynv_set_float(args->params, "chaos", chaos); dynv_set_int32(args->params, "chaos_seed", chaos_seed); dynv_set_bool(args->params, "reverse", reverse); } Color r, hsl, hsl_results;; double hue; double hue_step; stringstream s; struct ColorList *color_list; if (preview) color_list = args->preview_color_list; else color_list = args->gs->colors; const ColorWheelType *wheel = &color_wheel_types[wheel_type]; struct Random* random = random_new("SHR3"); unsigned long seed = chaos_seed; random_seed(random, &seed); random_get(random); 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); color_rgb_to_hsl(&in, &hsl); wheel->rgbhue_to_hue(hsl.hsl.hue, &hue); wheel->hue_to_hsl(hue, &hsl_results); double saturation = hsl.hsl.saturation * 1 / hsl_results.hsl.saturation; double lightness = hsl.hsl.lightness - hsl_results.hsl.lightness; for (int32_t i = 0; i < color_count; i++){ if (preview){ if (limit<=0){ random_destroy(random); return; } limit--; } wheel->hue_to_hsl(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_rgb(&hsl, &r); struct ColorObject *color_object=color_list_new_color_object(color_list, &r); name_assigner.assign (color_object, &r, i, type); color_list_add_color_object(color_list, color_object, 1); color_object_release(color_object); hue_step = (generate_scheme_get_scheme_type(type)->turn[i % generate_scheme_get_scheme_type(type)->turn_types]) / (360.0) + chaos*(((random_get(random)&0xFFFFFFFF)/(gdouble)0xFFFFFFFF)-0.5); if (reverse){ hue = wrap_float(hue - hue_step); }else{ hue = wrap_float(hue + hue_step); } } } random_destroy(random); } static void update(GtkWidget *widget, DialogGenerateArgs *args ){ color_list_remove_all(args->preview_color_list); calc(args, true, 100); } void dialog_generate_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState* gs){ DialogGenerateArgs *args = new DialogGenerateArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick.generate"); GtkWidget *table; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Generate colors"), 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(4, 4, FALSE); table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Colors:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->range_colors = gtk_spin_button_new_with_range (1, 72, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->range_colors), dynv_get_int32_wd(args->params, "colors", 1)); gtk_table_attach(GTK_TABLE(table), args->range_colors,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect(G_OBJECT (args->range_colors), "value-changed", G_CALLBACK (update), args); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Type:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,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,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Color wheel:"),0,0.5,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->wheel_type = gtk_combo_box_new_text(); for (uint32_t i=0; iwheel_type), color_wheel_types[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,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,0); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Chaos:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->range_chaos = gtk_spin_button_new_with_range (0,1,0.001); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->range_chaos), dynv_get_float_wd(args->params, "chaos", 0)); gtk_table_attach(GTK_TABLE(table), args->range_chaos,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT (args->range_chaos), "value-changed", G_CALLBACK (update), args); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Seed:"),0,0,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->range_chaos_seed = gtk_spin_button_new_with_range (0, 0xFFFF, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->range_chaos_seed), dynv_get_int32_wd(args->params, "chaos_seed", 0)); gtk_table_attach(GTK_TABLE(table), args->range_chaos_seed,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT (args->range_chaos_seed), "value-changed", G_CALLBACK (update), args); table_y++; args->toggle_reverse = gtk_check_button_new_with_mnemonic (_("_Reverse")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_reverse), dynv_get_bool_wd(args->params, "reverse", false)); gtk_table_attach(GTK_TABLE(table), args->toggle_reverse,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_reverse), "toggled", G_CALLBACK (update), args); table_y++; 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, 4, 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/uiDialogAutonumber.h0000644000175000017500000000341612070605214016656 0ustar zbygzbyg/* * 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 UIDIALOGAUTONUMBER_H_ #define UIDIALOGAUTONUMBER_H_ #include #include #include "GlobalState.h" int dialog_autonumber_show(GtkWindow* parent, uint32_t selected_count, GlobalState* gs); #endif /* UIDIALOGAUTONUMBER_H_ */ gpick_0.2.5/source/BrightnessDarkness.cpp0000644000175000017500000003630712113713537017230 0ustar zbygzbyg/* * 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 "BrightnessDarkness.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/Range2D.h" #include "uiColorInput.h" #include "CopyPaste.h" #include "Converter.h" #include "DynvHelpers.h" #include "Internationalisation.h" #include "gtk/LayoutPreview.h" #include "layout/Layout.h" #include "layout/Style.h" #include "uiApp.h" #include #include #include #include #include #include using namespace std; using namespace layout; typedef struct BrightnessDarknessArgs{ ColorSource source; GtkWidget* main; GtkWidget* statusbar; Color color; GtkWidget *brightness_darkness; GtkWidget *layout_view; System* layout_system; Layouts* layouts; struct dynvSystem *params; GlobalState* gs; }BrightnessDarknessArgs; class BrightnessDarknessColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; const char *m_ident; public: BrightnessDarknessColorNameAssigner(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) << " " << _("brightness darkness") << " " << m_ident; return m_stream.str(); } }; static void calc(BrightnessDarknessArgs *args, bool preview, bool save_settings){ double brightness = gtk_range_2d_get_x(GTK_RANGE_2D(args->brightness_darkness)); double darkness = gtk_range_2d_get_y(GTK_RANGE_2D(args->brightness_darkness)); if (save_settings){ dynv_set_float(args->params, "brightness", brightness); dynv_set_float(args->params, "darkness", brightness); } Color color, hsl_orig, hsl, r; color_copy(&args->color, &color); color_rgb_to_hsl(&color, &hsl_orig); Box* box; string name; for (int i = 1; i <= 4; i++){ color_copy(&hsl_orig, &hsl); hsl.hsl.lightness = mix_float(hsl.hsl.lightness, mix_float(hsl.hsl.lightness, 1, brightness), i / 4.0); //clamp_float(hsl.hsl.lightness + brightness / 8.0 * i, 0, 1); color_hsl_to_rgb(&hsl, &r); name = boost::str(boost::format("b%d") % i); box = args->layout_system->GetNamedBox(name.c_str()); if (box && box->style){ color_copy(&r, &box->style->color); } color_copy(&hsl_orig, &hsl); hsl.hsl.lightness = mix_float(hsl.hsl.lightness, mix_float(hsl.hsl.lightness, 0, darkness), i / 4.0); //clamp_float(hsl.hsl.lightness - darkness / 8.0 * i, 0, 1); color_hsl_to_rgb(&hsl, &r); name = boost::str(boost::format("c%d") % i); box = args->layout_system->GetNamedBox(name.c_str()); if (box && box->style){ color_copy(&r, &box->style->color); } } gtk_widget_queue_draw(GTK_WIDGET(args->layout_view)); } static void update(GtkWidget *widget, BrightnessDarknessArgs *args ){ calc(args, true, false); } static int source_get_color(BrightnessDarknessArgs *args, struct ColorObject** color){ Style* style = 0; Color c; if (gtk_layout_preview_get_current_color(GTK_LAYOUT_PREVIEW(args->layout_view), &c) == 0){ if (gtk_layout_preview_get_current_style(GTK_LAYOUT_PREVIEW(args->layout_view), &style) != 0){ return -1; } *color = color_list_new_color_object(args->gs->colors, &c); BrightnessDarknessColorNameAssigner name_assigner(args->gs); name_assigner.assign(*color, &c, style->human_name.c_str()); return 0; } return -1; } static int source_set_color(BrightnessDarknessArgs *args, struct ColorObject* color){ Color c; color_object_get_color(color, &c); color_copy(&c, &args->color); gtk_layout_preview_set_color_named(GTK_LAYOUT_PREVIEW(args->layout_view), &c, "main"); calc(args, true, false); return 0; } static struct ColorObject* get_color_object(struct DragDrop* dd){ BrightnessDarknessArgs* args = (BrightnessDarknessArgs*)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){ BrightnessDarknessArgs* args=(BrightnessDarknessArgs*)dd->userdata; Color color; color_object_get_color(colorobject, &color); color_copy(&color, &args->color); gtk_layout_preview_set_color_named(GTK_LAYOUT_PREVIEW(args->layout_view), &color, "main"); calc(args, true, false); return 0; } static bool test_at(struct DragDrop* dd, int x, int y){ BrightnessDarknessArgs* args=(BrightnessDarknessArgs*)dd->userdata; gtk_layout_preview_set_focus_named(GTK_LAYOUT_PREVIEW(args->layout_view), "main"); return gtk_layout_preview_is_selected(GTK_LAYOUT_PREVIEW(args->layout_view)); } static void edit_cb(GtkWidget *widget, gpointer item) { BrightnessDarknessArgs* args=(BrightnessDarknessArgs*)item; struct ColorObject *color_object; struct ColorObject* new_color_object = 0; if (source_get_color(args, &color_object)==0){ if (dialog_color_input_show(GTK_WINDOW(gtk_widget_get_toplevel(args->main)), args->gs, color_object, &new_color_object )==0){ source_set_color(args, new_color_object); color_object_release(new_color_object); } color_object_release(color_object); } } static void paste_cb(GtkWidget *widget, BrightnessDarknessArgs* args) { struct ColorObject* color_object; if (copypaste_get_color_object(&color_object, args->gs)==0){ source_set_color(args, color_object); color_object_release(color_object); } } static void add_to_palette_cb(GtkWidget *widget, gpointer item) { BrightnessDarknessArgs* args=(BrightnessDarknessArgs*)item; struct ColorObject *color_object; if (source_get_color(args, &color_object)==0){ color_list_add_color_object(args->gs->colors, color_object, 1); color_object_release(color_object); } } static void add_all_to_palette_cb(GtkWidget *widget, BrightnessDarknessArgs *args) { struct ColorObject *color_object; BrightnessDarknessColorNameAssigner name_assigner(args->gs); for (list::iterator i = args->layout_system->styles.begin(); i != args->layout_system->styles.end(); i++){ color_object = color_list_new_color_object(args->gs->colors, &(*i)->color); name_assigner.assign(color_object, &(*i)->color, (*i)->human_name.c_str()); color_list_add_color_object(args->gs->colors, color_object, 1); color_object_release(color_object); } } static gboolean button_press_cb (GtkWidget *widget, GdkEventButton *event, BrightnessDarknessArgs* args) { GtkWidget *menu; if (event->button == 1 && event->type == GDK_2BUTTON_PRESS){ struct ColorObject *color_object; if (source_get_color(args, &color_object)==0){ color_list_add_color_object(args->gs->colors, color_object, 1); color_object_release(color_object); } return true; }else if (event->button == 3 && event->type == GDK_BUTTON_PRESS){ GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); bool selection_avail = gtk_layout_preview_is_selected(GTK_LAYOUT_PREVIEW(args->layout_view)); bool edit_avail = gtk_layout_preview_is_editable(GTK_LAYOUT_PREVIEW(args->layout_view)); 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 (add_to_palette_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); 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 (add_all_to_palette_cb), args); 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); if (selection_avail){ struct ColorObject* color_object; source_get_color(args, &color_object); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (color_object, 0, args->gs)); color_object_release(color_object); }else{ gtk_widget_set_sensitive(item, false); } if (edit_avail){ 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 (edit_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); 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 (paste_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); if (copypaste_is_color_object_available(args->gs)!=0){ gtk_widget_set_sensitive(item, false); } } gtk_widget_show_all (GTK_WIDGET(menu)); button = event->button; event_time = event->time; gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time); g_object_ref_sink(menu); g_object_unref(menu); return TRUE; } return FALSE; } static int source_destroy(BrightnessDarknessArgs *args){ if (args->layout_system) System::unref(args->layout_system); args->layout_system = 0; dynv_system_release(args->params); gtk_widget_destroy(args->main); delete args; return 0; } static int set_rgb_color(BrightnessDarknessArgs *args, struct ColorObject* color, uint32_t color_index){ color_object_get_color(color, &args->color); update(0, args); return 0; } static int source_activate(BrightnessDarknessArgs *args){ transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); gtk_layout_preview_set_transformation_chain(GTK_LAYOUT_PREVIEW(args->layout_view), chain); gtk_statusbar_push(GTK_STATUSBAR(args->statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(args->statusbar), "empty"), ""); return 0; } static int source_deactivate(BrightnessDarknessArgs *args){ dynv_set_color(args->params, "color", &args->color); calc(args, true, true); return 0; } static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){ BrightnessDarknessArgs* args = new BrightnessDarknessArgs; 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; Layouts* layouts = (Layouts*)dynv_get_pointer_wd(gs->params, "Layouts", 0); args->layouts = layouts; args->layout_system = 0; GtkWidget *hbox, *widget; hbox = gtk_hbox_new(FALSE, 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; dd.test_at = test_at; dd.handler_map = dynv_system_get_handler_map(gs->colors->params); args->brightness_darkness = widget = gtk_range_2d_new(); gtk_range_2d_set_values(GTK_RANGE_2D(widget), dynv_get_float_wd(dynv_namespace, "brightness", 0.5), dynv_get_float_wd(dynv_namespace, "darkness", 0.5)); gtk_range_2d_set_axis(GTK_RANGE_2D(widget), _("Brightness"), _("Darkness")); g_signal_connect(G_OBJECT(widget), "values_changed", G_CALLBACK(update), args); gtk_box_pack_start(GTK_BOX(hbox), widget, false, false, 0); args->layout_view = widget = gtk_layout_preview_new(); g_signal_connect_after(G_OBJECT(widget), "button-press-event", G_CALLBACK(button_press_cb), args); gtk_box_pack_start(GTK_BOX(hbox), widget, false, false, 0); //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); args->gs = gs; System* layout_system = layouts_get(args->layouts, "std_layout_brightness_darkness"); gtk_layout_preview_set_system(GTK_LAYOUT_PREVIEW(args->layout_view), layout_system); if (args->layout_system) System::unref(args->layout_system); args->layout_system = layout_system; Color c; color_set(&c, 0.5); Color *color = dynv_get_color_wdc(dynv_namespace, "color", &c); color_copy(color, &args->color); gtk_layout_preview_set_color_named(GTK_LAYOUT_PREVIEW(args->layout_view), color, "main"); calc(args, true, false); gtk_widget_show_all(hbox); update(0, args); args->main = hbox; args->source.widget = hbox; return (ColorSource*)args; } int brightness_darkness_source_register(ColorSourceManager *csm){ ColorSource *color_source = new ColorSource; color_source_init(color_source, "brightness_darkness", _("Brightness Darkness")); color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement; color_source->default_accelerator = GDK_d; color_source_manager_add_source(csm, color_source); return 0; } gpick_0.2.5/source/uiConverter.h0000644000175000017500000000331312070605214015360 0ustar zbygzbyg/* * 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 UICONVERTER_H_ #define UICONVERTER_H_ #include #include "GlobalState.h" void dialog_converter_show(GtkWindow* parent, GlobalState* gs); #endif /* UICONVERTER_H_ */ gpick_0.2.5/source/uiTransformations.cpp0000644000175000017500000003634412070605214017147 0ustar zbygzbyg/* * 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 "uiTransformations.h" #include "Converter.h" #include "uiUtilities.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "Internationalisation.h" #include "transformation/Chain.h" #include "transformation/Factory.h" #include "transformation/ColorVisionDeficiency.h" #include using namespace std; typedef enum{ TRANSFORMATIONS_HUMAN_NAME = 0, TRANSFORMATIONS_TRANSFORMATION_PTR, TRANSFORMATIONS_N_COLUMNS }TransformationsColumns; typedef enum{ AVAILABLE_TRANSFORMATIONS_HUMAN_NAME = 0, AVAILABLE_TRANSFORMATIONS_NAME, AVAILABLE_TRANSFORMATIONS_N_COLUMNS }AvailableTransformationsColumns; typedef struct TransformationsArgs{ GtkWidget *available_transformations; GtkWidget *list; GtkWidget *config_vbox; GtkWidget *hpaned; GtkWidget *enabled; transformation::Transformation *transformation; boost::shared_ptr configuration; struct dynvSystem *params; struct dynvSystem *transformations_params; GlobalState *gs; }TransformationsArgs; static void configure_transformation(TransformationsArgs *args, transformation::Transformation *transformation); static void tranformations_update_row(GtkTreeModel *model, GtkTreeIter *iter1, transformation::Transformation *transformation, TransformationsArgs *args) { gtk_list_store_set(GTK_LIST_STORE(model), iter1, TRANSFORMATIONS_HUMAN_NAME, transformation->getReadableName().c_str(), TRANSFORMATIONS_TRANSFORMATION_PTR, transformation, -1); } static void available_tranformations_update_row(GtkTreeModel *model, GtkTreeIter *iter1, transformation::Factory::TypeInfo *type_info, TransformationsArgs *args) { gtk_list_store_set(GTK_LIST_STORE(model), iter1, AVAILABLE_TRANSFORMATIONS_HUMAN_NAME, type_info->human_name, AVAILABLE_TRANSFORMATIONS_NAME, type_info->name, -1); } static GtkWidget* available_transformations_list_new(TransformationsArgs *args) { GtkListStore *store; GtkCellRenderer *renderer; GtkWidget *widget; store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); gtk_combo_box_set_add_tearoffs(GTK_COMBO_BOX(widget), 0); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget),renderer,0); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", AVAILABLE_TRANSFORMATIONS_HUMAN_NAME, NULL); g_object_unref(GTK_TREE_MODEL(store)); return widget; } static void add_transformation_cb(GtkWidget *widget, TransformationsArgs *args) { GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(args->available_transformations), &iter)) { GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(args->available_transformations)); gchar *name = 0; gtk_tree_model_get(model, &iter, AVAILABLE_TRANSFORMATIONS_NAME, &name, -1); boost::shared_ptr tran = transformation::Factory::create(name); if (tran){ transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); chain->add(tran); configure_transformation(args, tran.get()); model = gtk_tree_view_get_model(GTK_TREE_VIEW(args->list)); gtk_list_store_append(GTK_LIST_STORE(model), &iter); tranformations_update_row(model, &iter, tran.get(), args); } } } static void remove_transformation_cb(GtkWidget *widget, TransformationsArgs *args) { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(args->list)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(args->list)); GtkTreeIter iter; if (gtk_tree_selection_count_selected_rows(selection) == 0){ return; } configure_transformation(args, NULL); GList *list = gtk_tree_selection_get_selected_rows(selection, 0); GList *ref_list = NULL; GList *i = list; while (i) { ref_list = g_list_prepend(ref_list, gtk_tree_row_reference_new(model, (GtkTreePath*) (i->data))); i = g_list_next(i); } transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); i = ref_list; GtkTreePath *path; while (i) { path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)i->data); if (path) { gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); transformation::Transformation *transformation; gtk_tree_model_get(model, &iter, TRANSFORMATIONS_TRANSFORMATION_PTR, &transformation, -1); chain->remove(transformation); gtk_list_store_remove(GTK_LIST_STORE(model), &iter); } i = g_list_next(i); } g_list_foreach(ref_list, (GFunc)gtk_tree_row_reference_free, NULL); g_list_free(ref_list); g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); } static GtkWidget* transformations_list_new(TransformationsArgs *args) { GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *col; GtkWidget *view; view = gtk_tree_view_new(); args->list = view; gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), 1); store = gtk_list_store_new(TRANSFORMATIONS_N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col, 1); gtk_tree_view_column_set_title(col, _("Name")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, true); gtk_tree_view_column_add_attribute(col, renderer, "text", TRANSFORMATIONS_HUMAN_NAME); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(GTK_TREE_MODEL(store)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view), true); return view; } static void apply_configuration(TransformationsArgs *args){ if (args->configuration && args->transformation){ struct dynvHandlerMap *handler_map = dynv_system_get_handler_map(args->gs->params); struct dynvSystem *dv = dynv_system_create(handler_map); args->configuration->applyConfig(dv); args->transformation->deserialize(dv); dynv_handler_map_release(handler_map); dynv_system_release(dv); } } static void configure_transformation(TransformationsArgs *args, transformation::Transformation *transformation) { if (args->configuration){ gtk_container_remove(GTK_CONTAINER(args->config_vbox), args->configuration->getWidget()); apply_configuration(args); args->configuration = boost::shared_ptr(); } if (transformation){ args->configuration = transformation->getConfig(); args->transformation = transformation; gtk_box_pack_start(GTK_BOX(args->config_vbox), args->configuration->getWidget(), true, true, 0); } } static void transformation_chain_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, TransformationsArgs *args) { GtkTreeModel* model; GtkTreeIter iter; model = gtk_tree_view_get_model(tree_view); gtk_tree_model_get_iter(model, &iter, path); transformation::Transformation *transformation; gtk_tree_model_get(model, &iter, TRANSFORMATIONS_TRANSFORMATION_PTR, &transformation, -1); configure_transformation(args, transformation); } void dialog_transformations_show(GtkWindow* parent, GlobalState* gs) { TransformationsArgs *args = new TransformationsArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick"); args->transformations_params = dynv_get_dynv(args->gs->params, "gpick.transformations"); args->transformation = 0; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Display filters"), 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, "transformations.window.width", -1), dynv_get_int32_wd(args->params, "transformations.window.height", -1)); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); GtkWidget *widget; GtkWidget* vbox = gtk_vbox_new(false, 5); GtkWidget *vbox2 = gtk_vbox_new(false, 5); args->enabled = widget = gtk_check_button_new_with_mnemonic (_("_Enabled")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->transformations_params, "enabled", false)); gtk_box_pack_start(GTK_BOX(vbox), args->enabled, false, false, 0); args->hpaned = gtk_hpaned_new(); gtk_box_pack_start(GTK_BOX(vbox), args->hpaned, true, true, 0); GtkWidget *list, *scrolled; GtkTreeIter iter1; GtkTreeModel *model; args->available_transformations = list = available_transformations_list_new(args); GtkWidget* hbox2 = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox2), hbox2, false, false, 0); gtk_box_pack_start(GTK_BOX(hbox2), list, true, true, 0); GtkWidget *button = gtk_button_new_from_stock(GTK_STOCK_ADD); gtk_box_pack_start(GTK_BOX(hbox2), button, false, false, 0); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(add_transformation_cb), args); button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); gtk_box_pack_start(GTK_BOX(hbox2), button, false, false, 0); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(remove_transformation_cb), args); model = gtk_combo_box_get_model(GTK_COMBO_BOX(list)); vector types = transformation::Factory::getAllTypes(); for (int i = 0; i != types.size(); i++){ gtk_list_store_append(GTK_LIST_STORE(model), &iter1); available_tranformations_update_row(model, &iter1, &types[i], args); } gtk_combo_box_set_active(GTK_COMBO_BOX(list), 0); args->list = list = transformations_list_new(args); g_signal_connect(G_OBJECT(list), "row-activated", G_CALLBACK(transformation_chain_row_activated), args); scrolled = gtk_scrolled_window_new(0, 0); gtk_container_add(GTK_CONTAINER(scrolled), list); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(vbox2), scrolled, true, true, 0); gtk_paned_pack1(GTK_PANED(args->hpaned), vbox2, false, false); args->config_vbox = gtk_vbox_new(false, 5); gtk_paned_pack2(GTK_PANED(args->hpaned), args->config_vbox, false, false); transformation::Chain *chain = static_cast(dynv_get_pointer_wdc(args->gs->params, "TransformationChain", 0)); /*boost::shared_ptr color_vision_deficiency = boost::shared_ptr(new transformation::ColorVisionDeficiency(transformation::ColorVisionDeficiency::DEUTERANOMALY, 0.8)); chain->clear(); chain->add(color_vision_deficiency); */ model = gtk_tree_view_get_model(GTK_TREE_VIEW(list)); for (transformation::Chain::TransformationList::iterator i = chain->getAll().begin(); i != chain->getAll().end(); i++){ gtk_list_store_append(GTK_LIST_STORE(model), &iter1); tranformations_update_row(model, &iter1, (*i).get(), args); } gtk_paned_set_position(GTK_PANED(args->hpaned), dynv_get_int32_wd(args->params, "paned_position", -1)); gtk_widget_show_all(vbox); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, true, true, 5); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { apply_configuration(args); GtkTreeIter iter; GtkListStore *store; gboolean valid; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->enabled)); dynv_set_bool(args->transformations_params, "enabled", enabled); chain->setEnabled(enabled); unsigned int count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); if (count > 0){ struct dynvSystem** config_array = new struct dynvSystem*[count]; unsigned int i = 0; struct dynvHandlerMap *handler_map = dynv_system_get_handler_map(args->gs->params); while (valid){ transformation::Transformation* transformation; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, TRANSFORMATIONS_TRANSFORMATION_PTR, &transformation, -1); struct dynvSystem *dv = dynv_system_create(handler_map); transformation->serialize(dv); config_array[i] = dv; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); ++i; } dynv_handler_map_release(handler_map); dynv_set_dynv_array(args->transformations_params, "items", (const dynvSystem**)config_array, count); for (i = 0; i != count; i++){ dynv_system_release(config_array[i]); } delete [] config_array; }else{ dynv_set_dynv_array(args->transformations_params, "items", 0, 0); } } chain->clear(); chain->setEnabled(dynv_get_bool_wd(gs->params, "gpick.transformations.enabled", false)); struct dynvSystem** config_array; uint32_t config_size; if ((config_array = (struct dynvSystem**)dynv_get_dynv_array_wd(gs->params, "gpick.transformations.items", 0, 0, &config_size))){ for (uint32_t i = 0; i != config_size; i++){ const char *name = dynv_get_string_wd(config_array[i], "name", 0); if (name){ boost::shared_ptr tran = transformation::Factory::create(name); if (tran){ tran->deserialize(config_array[i]); chain->add(tran); } } dynv_system_release(config_array[i]); } delete [] config_array; } gint width, height; gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); dynv_set_int32(args->params, "transformations.window.width", width); dynv_set_int32(args->params, "transformations.window.height", height); dynv_set_int32(args->params, "paned_position", gtk_paned_get_position(GTK_PANED(args->hpaned))); gtk_widget_destroy(dialog); dynv_system_release(args->transformations_params); dynv_system_release(args->params); delete args; } gpick_0.2.5/source/Sampler.h0000644000175000017500000000466412070605214014470 0ustar zbygzbyg/* * 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 SAMPLER_H_ #define SAMPLER_H_ #include "Color.h" #include "Rect2.h" #include "Vector2.h" #include "ScreenReader.h" enum SamplerFalloff{ NONE = 0, LINEAR = 1, QUADRATIC = 2, CUBIC = 3, EXPONENTIAL = 4, }; struct Sampler; struct Sampler* sampler_new(struct ScreenReader* screen_reader); void sampler_set_falloff(struct Sampler *sampler, enum SamplerFalloff falloff); void sampler_set_oversample(struct Sampler *sampler, int oversample); enum SamplerFalloff sampler_get_falloff(struct Sampler *sampler); int sampler_get_oversample(struct Sampler *sampler); void sampler_destroy(struct Sampler *sampler); int sampler_get_color_sample(struct Sampler *sampler, math::Vec2& pointer, math::Vec2& screen_size, math::Vec2& offset, Color* color); void sampler_get_screen_rect(struct Sampler *sampler, math::Vec2& pointer, math::Vec2& screen_size, math::Rect2 *rect); #endif /* SAMPLER_H_ */ gpick_0.2.5/source/color_names/SConscript0000644000175000017500000000074312113713537017227 0ustar zbygzbyg#!/usr/bin/env python import os import sys Import('*') local_env = env.Clone() if not local_env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc': if local_env['DOWNLOAD_RESENE_COLOR_LIST']: local_env.ParseConfig('pkg-config --cflags --libs $CURL_PC') if local_env['DOWNLOAD_RESENE_COLOR_LIST']: local_env.Append( CPPDEFINES = ['DOWNLOAD_RESENE_COLOR_LIST'], ) sources = local_env.Glob('*.cpp') objects = local_env.StaticObject(source = [sources]) Return('objects') gpick_0.2.5/source/color_names/ColorNames.cpp0000644000175000017500000001532212113713537017762 0ustar zbygzbyg/* * 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 "ColorNames.h" #include "../MathUtil.h" #include #include #include #include #include using namespace std; //CIE94 color difference calculation float color_names_distance_lch(const Color* a, const Color* b) { Color al, bl; color_lab_to_lch(a, &al); color_lab_to_lch(b, &bl); return sqrt( pow((bl.lch.L - al.lch.L) / 1, 2) + pow((bl.lch.C - al.lch.C) / (1 + 0.045 * al.lch.C), 2) + pow((pow(a->lab.a - b->lab.a, 2) + pow(a->lab.b - b->lab.b, 2) - (bl.lch.C - al.lch.C)) / (1 + 0.015 * al.lch.C), 2)); } ColorNames* color_names_new() { ColorNames* cnames = new ColorNames; cnames->color_space_convert = color_rgb_to_lab_d50; cnames->color_space_distance = color_names_distance_lch; return cnames; } static void color_names_strip_spaces(string& string_x, string& stripchars){ if(string_x.empty()) return; if (stripchars.empty()) return; size_t startIndex = string_x.find_first_not_of(stripchars); size_t endIndex = string_x.find_last_not_of(stripchars); if ((startIndex==string::npos)||(endIndex==string::npos)){ string_x.erase(); return; } string_x = string_x.substr(startIndex, (endIndex-startIndex)+1 ); } void color_names_get_color_xyz(ColorNames* cnames, Color* c, int* x1, int* y1, int* z1, int* x2, int* y2, int* z2) { *x1=clamp_int(int(c->xyz.x*8-0.5),0,7); *y1=clamp_int(int(c->xyz.y*8-0.5),0,7); *z1=clamp_int(int(c->xyz.z*8-0.5),0,7); *x2=clamp_int(int(c->xyz.x*8+0.5),0,7); *y2=clamp_int(int(c->xyz.y*8+0.5),0,7); *z2=clamp_int(int(c->xyz.z*8+0.5),0,7); } list* color_names_get_color_list(ColorNames* cnames, Color* c) { int x,y,z; x=clamp_int(int(c->xyz.x*8),0,7); y=clamp_int(int(c->xyz.y*8),0,7); z=clamp_int(int(c->xyz.z*8),0,7); return &cnames->colors[x][y][z]; } int color_names_load_from_file(ColorNames* cnames, const char* filename) { ifstream file(filename, ifstream::in); if (file.is_open()) { string line; stringstream rline (ios::in | ios::out); Color color; string name; string strip_chars = " \t,.\n\r"; while (!(file.eof())) { getline(file, line); if (line.empty()) continue; if (line.at(0)=='!') continue; rline.clear(); rline.str(line); rline>>color.rgb.red>>color.rgb.green>>color.rgb.blue; getline(rline, name); color_names_strip_spaces(name, strip_chars); string::iterator i(name.begin()); if (i != name.end()) name[0] = toupper((unsigned char)name[0]); while(++i != name.end()){ *i = tolower((unsigned char)*i); } color_multiply(&color, 1/255.0); ColorNameEntry* name_entry = new ColorNameEntry; name_entry->name=name; cnames->names.push_back(name_entry); ColorEntry* color_entry = new ColorEntry; color_entry->name=name_entry; cnames->color_space_convert(&color, &color_entry->color); color_names_get_color_list(cnames, &color_entry->color)->push_back(color_entry); } file.close(); return 0; } return -1; } void color_names_destroy(ColorNames* cnames) { for (list::iterator i=cnames->names.begin();i!=cnames->names.end();++i){ delete (*i); } for (int x=0;x<8;x++){ for (int y=0;y<8;y++){ for (int z=0;z<8;z++){ for (list::iterator i=cnames->colors[x][y][z].begin();i!=cnames->colors[x][y][z].end();++i){ delete (*i); } } } } delete cnames; } string color_names_get(ColorNames* cnames, Color* color, bool imprecision_postfix) { Color c1; cnames->color_space_convert(color, &c1); int x1,y1,z1,x2,y2,z2; color_names_get_color_xyz(cnames, &c1, &x1, &y1, &z1, &x2, &y2, &z2); float result_delta=1e5; ColorEntry* color_entry=NULL; char skip_mask[8][8][8]; memset(&skip_mask, 0, sizeof(skip_mask)); /* Search expansion should be from 0 to 7, but this would only increase search time and return * wrong color names when no closely matching color is found. Search expansion is only useful * when color name database is very small (16 colors) */ for (int expansion = 0; expansion < 7; ++expansion){ int x_start = std::max(x1 - expansion, 0), x_end = std::min(x2 + expansion, 7); int y_start = std::max(y1 - expansion, 0), y_end = std::min(y2 + expansion, 7); int z_start = std::max(z1 - expansion, 0), z_end = std::min(z2 + expansion, 7); for (int x_i = x_start; x_i <= x_end; ++x_i) { for (int y_i = y_start; y_i <= y_end; ++y_i) { for (int z_i = z_start; z_i <= z_end; ++z_i) { if (skip_mask[x_i][y_i][z_i]) continue; // skip checked items skip_mask[x_i][y_i][z_i] = 1; for (list::iterator i=cnames->colors[x_i][y_i][z_i].begin(); i!=cnames->colors[x_i][y_i][z_i].end();++i){ float delta = cnames->color_space_distance(&(*i)->color, &c1); //float delta = pow((*i)->color.xyz.x-c1.xyz.x,2) + pow((*i)->color.xyz.y-c1.xyz.y,2) + pow((*i)->color.xyz.z-c1.xyz.z,2); if (delta < result_delta) { result_delta=delta; color_entry=*i; } } } } } //no need for further expansion if we have found a match if (color_entry) break; } if (color_entry){ stringstream s; s<name->name;//<<" "<0.1) s<<" ~"; return s.str();//(*result_i)->name; } return string(""); } gpick_0.2.5/source/color_names/ColorNames.h0000644000175000017500000000440612113713537017430 0ustar zbygzbyg/* * 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 COLORNAMES_H_ #define COLORNAMES_H_ #include "../Color.h" #include #include typedef struct ColorNameEntry{ std::string name; }ColorNameEntry; typedef struct ColorEntry{ Color color; ColorNameEntry* name; }ColorEntry; typedef struct ColorNames{ std::list names; std::list colors[8][8][8]; void (*color_space_convert)(const Color* a, Color* b); float (*color_space_distance)(const Color* a, const Color* b); }ColorNames; ColorNames* color_names_new(); int color_names_load_from_file(ColorNames* cnames, const char* filename); void color_names_destroy(ColorNames* cnames); std::string color_names_get(ColorNames* cnames, Color* color, bool imprecision_postfix); #endif /* COLORNAMES_H_ */ gpick_0.2.5/source/color_names/DownloadNameFile.h0000644000175000017500000000023412113713537020531 0ustar zbygzbyg#ifndef HEADER_DOWNLOAD_NAME_FILE_H_ #define HEADER_DOWNLOAD_NAME_FILE_H_ int download_name_file(const char *destination_filename); #endif /* HEADER_ */ gpick_0.2.5/source/color_names/DownloadNameFile.cpp0000644000175000017500000000216112113713537021065 0ustar zbygzbyg#include "DownloadNameFile.h" #include #include using namespace std; #ifdef DOWNLOAD_RESENE_COLOR_LIST #include static size_t data_write_function(void *ptr, size_t size, size_t nmemb, stringstream *data) { (*data).write(reinterpret_cast(ptr), size * nmemb); return size * nmemb; } int download_name_file(const char *destination_filename) { CURL *curl; CURLcode res; curl = curl_easy_init(); if (curl) { stringstream data; curl_easy_setopt(curl, CURLOPT_URL, "http://gpick.googlecode.com/hg/share/gpick/colors.txt"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, data_write_function); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); res = curl_easy_perform(curl); if (res != CURLE_OK){ curl_easy_cleanup(curl); return -1; } ofstream fout(destination_filename); if (fout.is_open()){ string data_str = data.str(); fout.write(data_str.c_str(), data_str.length()); fout.close(); } curl_easy_cleanup(curl); }else return -1; return 0; } #else int download_name_file(const char *destination_filename) { return -1; } #endif gpick_0.2.5/source/ColorSpaceType.cpp0000644000175000017500000000752412070605214016312 0ustar zbygzbyg/* * 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 "ColorSpaceType.h" #include "Internationalisation.h" #include "LuaExt.h" #include using namespace std; const ColorSpaceType color_space_types[] = { {hsv, 3, { {_("Hue"), 360, 0, 360, 0.01}, {_("Saturation"), 100, 0, 100, 0.01}, {_("Value"), 100, 0, 100, 0.01}, }, }, {hsl, 3, { {_("Hue"), 360, 0, 360, 0.01}, {_("Saturation"), 100, 0, 100, 0.01}, {_("Lightness"), 100, 0, 100, 0.01}, }, }, {rgb, 3, { {_("Red"), 255, 0, 255, 0.01}, {_("Green"), 255, 0, 255, 0.01}, {_("Blue"), 255, 0, 255, 0.01}, }, }, {cmyk, 4, { {_("Cyan"), 255, 0, 255, 0.01}, {_("Magenta"), 255, 0, 255, 0.01}, {_("Yellow"), 255, 0, 255, 0.01}, {_("Key"), 255, 0, 255, 0.01} } }, {lab, 3, { {_("Lightness"), 1, 0, 100, 0.0001}, {"a", 1, -145, 145, 0.0001}, {"b", 1, -145, 145, 0.0001} } }, {lch, 3, { {_("Lightness"), 1, 0, 100, 0.0001}, {"Chroma", 1, 0, 100, 0.0001}, {"Hue", 1, 0, 360, 0.0001} } }, }; const ColorSpaceType* color_space_get_types() { return color_space_types; } uint32_t color_space_count_types() { return sizeof(color_space_types) / sizeof(ColorSpaceType); } std::list color_space_color_to_text(const char *type, const Color *color, lua_State* L) { list result; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1) != LUA_TNIL){ lua_pushstring(L, "component_to_text"); lua_gettable(L, gpick_namespace); if (lua_type(L, -1) != LUA_TNIL){ lua_pushstring(L, type); lua_pushcolor(L, color); status = lua_pcall(L, 2, 1, 0); if (status == 0){ if (lua_type(L, -1) == LUA_TTABLE){ for (int i = 0; i < 4; i++){ lua_pushinteger(L, i + 1); lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TSTRING){ const char* converted = lua_tostring(L, -1); result.push_back(string(converted)); } lua_pop(L, 1); } lua_settop(L, stack_top); return result; }else{ cerr << "gpick.component_to_text: returned not a table value, type is \"" << type << "\"" << endl; } }else{ cerr << "gpick.component_to_text: " << lua_tostring (L, -1) << endl; } }else{ cerr << "gpick.component_to_text: no such function" << endl; } } lua_settop(L, stack_top); return result; } gpick_0.2.5/source/uiDialogOptions.h0000644000175000017500000000332512070605214016167 0ustar zbygzbyg/* * 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 UIDIALOGOPTIONS_H_ #define UIDIALOGOPTIONS_H_ #include #include "GlobalState.h" void dialog_options_show(GtkWindow* parent, GlobalState* gs); #endif /* UIDIALOGOPTIONS_H_ */ gpick_0.2.5/source/GlobalStateStruct.h0000644000175000017500000000403412113713537016470 0ustar zbygzbyg/* * 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 GLOBALSTATESTRUCT_H_ #define GLOBALSTATESTRUCT_H_ #include "GlobalState.h" #include "Sampler.h" #include "color_names/ColorNames.h" #include "Random.h" #include "dynv/DynvSystem.h" #include "ColorList.h" #include "LuaExt.h" typedef struct GlobalState{ GlobalStateLevel loaded_levels; ColorNames* color_names; struct Sampler* sampler; struct ScreenReader* screen_reader; struct ColorList* colors; struct dynvSystem* params; lua_State *lua; Random* random; }GlobalState; #endif /* GLOBALSTATESTRUCT_H_ */ gpick_0.2.5/source/ToolColorNaming.cpp0000644000175000017500000000665512070605214016470 0ustar zbygzbyg/* * 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 "ToolColorNaming.h" #include "Internationalisation.h" #include using namespace std; const ToolColorNamingOption options[] = { {TOOL_COLOR_NAMING_EMPTY, "empty", N_("_Empty")}, {TOOL_COLOR_NAMING_AUTOMATIC_NAME, "automatic_name", N_("_Automatic name")}, {TOOL_COLOR_NAMING_TOOL_SPECIFIC, "tool_specific", N_("_Tool specific")}, {TOOL_COLOR_NAMING_UNKNOWN, 0, 0}, }; const ToolColorNamingOption* tool_color_naming_get_options(){ return options; } ToolColorNamingType tool_color_naming_name_to_type(const char *name){ string n = name; int i = 0; while (options[i].name){ if (n.compare(options[i].name) == 0){ return options[i].type; } i++; } return TOOL_COLOR_NAMING_UNKNOWN; } ToolColorNameAssigner::ToolColorNameAssigner(GlobalState *gs):m_gs(gs){ m_color_naming_type = tool_color_naming_name_to_type(dynv_get_string_wd(m_gs->params, "gpick.color_names.tool_color_naming", "tool_specific")); if (m_color_naming_type == TOOL_COLOR_NAMING_AUTOMATIC_NAME){ m_imprecision_postfix = dynv_get_bool_wd(m_gs->params, "gpick.color_names.imprecision_postfix", true); }else{ m_imprecision_postfix = false; } } ToolColorNameAssigner::~ToolColorNameAssigner(){ } void ToolColorNameAssigner::assign(struct ColorObject *color_object, Color *color){ string name; switch (m_color_naming_type){ case TOOL_COLOR_NAMING_UNKNOWN: case TOOL_COLOR_NAMING_EMPTY: dynv_set_string(color_object->params, "name", ""); break; case TOOL_COLOR_NAMING_AUTOMATIC_NAME: name = color_names_get(m_gs->color_names, color, m_imprecision_postfix); dynv_set_string(color_object->params, "name", name.c_str()); break; case TOOL_COLOR_NAMING_TOOL_SPECIFIC: name = getToolSpecificName(color_object, color); dynv_set_string(color_object->params, "name", name.c_str()); break; } } std::string ToolColorNameAssigner::getToolSpecificName(struct ColorObject *color_object, Color *color){ return string(""); } gpick_0.2.5/source/ColorObject.h0000644000175000017500000000457212070605214015270 0ustar zbygzbyg/* * 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 COLOROBJECT_H_ #define COLOROBJECT_H_ #include "Color.h" #include "ColorAction.h" #include "dynv/DynvSystem.h" #include struct ColorObject; struct ColorObject{ uint32_t refcnt; struct dynvSystem* params; struct ColorList* childs; //color objects depending on current object uint32_t position; //Color color; struct ColorAction* action; int recalculate; int selected; int visited; }; struct ColorObject* color_object_new(struct dynvHandlerMap* handler_map); int color_object_release(struct ColorObject* color_object); struct ColorObject* color_object_ref(struct ColorObject* color_object); int color_object_get_color(struct ColorObject* color_object, Color* color); int color_object_set_color(struct ColorObject* color_object, Color* color); struct ColorObject* color_object_copy(struct ColorObject* color_object); #endif /* COLOROBJECT_H_ */ gpick_0.2.5/source/uiColorInput.h0000644000175000017500000000370512070605214015514 0ustar zbygzbyg/* * 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 UICOLORINPUT_H_ #define UICOLORINPUT_H_ #include #include "gtk/ColorComponent.h" #include "GlobalState.h" int dialog_color_input_show(GtkWindow* parent, GlobalState* gs, struct ColorObject* color_object, struct ColorObject** new_color_object); void dialog_color_component_input_show(GtkWindow* parent, GtkColorComponent *color_component, int component_id, struct dynvSystem *params); #endif /* UICOLORINPUT_H_ */ gpick_0.2.5/source/Noise.cpp0000644000175000017500000001125712070605214014471 0ustar zbygzbyg/* * 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 static int permutation[512] = { 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, }; static double fade(double t){ return t * t * t * ( t * (t * 6 - 15) +10); } static double lerp(double t, double a, double b){ return a + t * (b - a); } static double grad(int hash, double x, double y, double z){ int h = hash & 15; double u = h < 8 ? x : y; double v = h < 4 ? y : (h==12 || h==14) ? x : z; return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); } /** * Improved Perlin noise algorithm implemented by using reference Java implementation from. * \see http://mrl.nyu.edu/~perlin/noise/ */ double noise(double x, double y, double z){ int X = (int)floor(x) & 255, Y = (int)floor(y) & 255, Z = (int)floor(z) & 255; x -= floor(x); y -= floor(y); z -= floor(z); double u = fade(x), v = fade(y), w = fade(z); int A = permutation[X ]+Y, AA = permutation[A]+Z, AB = permutation[A+1]+Z, B = permutation[X+1]+Y, BA = permutation[B]+Z, BB = permutation[B+1]+Z; return lerp(w, lerp(v, lerp(u, grad(permutation[AA], x, y, z), grad(permutation[BA ], x-1, y, z)), lerp(u, grad(permutation[AB ], x , y-1, z ), grad(permutation[BB ], x-1, y-1, z ))), lerp(v, lerp(u, grad(permutation[AA+1], x , y , z-1 ), grad(permutation[BA+1], x-1, y , z-1 )), lerp(u, grad(permutation[AB+1], x , y-1, z-1 ), grad(permutation[BB+1], x-1, y-1, z-1 )))); } gpick_0.2.5/source/uiTransformations.h0000644000175000017500000000334712070605214016611 0ustar zbygzbyg/* * 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 UI_TRANSFORMATIONS_H_ #define UI_TRANSFORMATIONS_H_ #include #include "GlobalState.h" void dialog_transformations_show(GtkWindow* parent, GlobalState* gs); #endif /* UI_TRANSFORMATIONS_H_ */ gpick_0.2.5/source/GlobalState.h0000644000175000017500000000410712070605214015256 0ustar zbygzbyg/* * 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 GLOBALSTATE_H_ #define GLOBALSTATE_H_ typedef struct GlobalState GlobalState; enum GlobalStateLevel{ GLOBALSTATE_CONFIGURATION = 1, GLOBALSTATE_SCRIPTING = 2, GLOBALSTATE_COLOR_LIST = 4, GLOBALSTATE_CONVERTERS = 8, GLOBALSTATE_COLOR_NAMES = 16, GLOBALSTATE_OTHER = 32, GLOBALSTATE_TRANSFORMATIONS = 64, GLOBALSTATE_ALL = 0xffffffff, }; int global_state_init(GlobalState *gs, GlobalStateLevel level); int global_state_term(GlobalState *gs); GlobalState *global_state_create(); int global_state_destroy(GlobalState* gs); #endif /* GLOBALSTATE_H_ */ gpick_0.2.5/source/ColorAction.h0000644000175000017500000000405212070605214015270 0ustar zbygzbyg/* * 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 COLORACTION_H_ #define COLORACTION_H_ #include "ColorList.h" #include "dynv/DynvSystem.h" struct ColorAction{ uint32_t refcnt; struct dynvSystem* params; struct ColorList* parents; //color objects which change current action results int (*on_apply)(struct ColorAction* color_action, struct ColorObject* color_object); void* userdata; }; struct ColorAction* color_action_new(struct dynvHandlerMap* handler_map, const char* name); void color_action_destroy(struct ColorAction* color_action); #endif /* COLORACTION_H_ */ gpick_0.2.5/source/GenerateScheme.h0000644000175000017500000000365112070605214015737 0ustar zbygzbyg/* * 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 GENERATESCHEME_H_ #define GENERATESCHEME_H_ #include "ColorSourceManager.h" typedef struct SchemeType{ const char *name; int32_t colors; int32_t turn_types; double turn[4]; }SchemeType; int generate_scheme_source_register(ColorSourceManager *csm); const SchemeType* generate_scheme_get_scheme_type(uint32_t index); uint32_t generate_scheme_get_n_scheme_types(); #endif /* GENERATESCHEME_H_ */ gpick_0.2.5/source/uiApp.h0000644000175000017500000000552212070605214014135 0ustar zbygzbyg/* * 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 UIAPP_H_ #define UIAPP_H_ #include #include "GlobalState.h" #include "Color.h" int main_show_window(GtkWidget* window, struct dynvSystem *main_params); enum ColorTextType{ COLOR_TEXT_TYPE_DISPLAY, COLOR_TEXT_TYPE_COPY, COLOR_TEXT_TYPE_COLOR_LIST, }; char* main_get_color_text(GlobalState* gs, Color* color, ColorTextType text_type); int main_get_color_from_text(GlobalState* gs, char* text, Color* color); int main_get_color_object_from_text(GlobalState* gs, char* text, struct ColorObject** output_color_object); GtkWidget* converter_create_copy_menu (struct ColorObject* color_object, GtkWidget* palette_widget, GlobalState* gs); void converter_get_clipboard(const gchar* function, struct ColorObject* color_object, GtkWidget* palette_widget, struct dynvSystem* params); void converter_get_text(const gchar* function, struct ColorObject* color_object, GtkWidget* palette_widget, struct dynvSystem* params, gchar** text); typedef struct AppArgs AppArgs; typedef struct AppOptions { bool floating_picker_mode; }AppOptions; AppArgs* app_create_main(const AppOptions *options); int app_load_file(AppArgs *args, const char *filename, bool autoload = false); int app_run(AppArgs *args); int app_parse_geometry(AppArgs *args, const char *geometry); bool app_is_autoload_enabled(AppArgs *args); #endif /* UIAPP_H_ */ gpick_0.2.5/source/ScreenReader.h0000644000175000017500000000411212070605214015413 0ustar zbygzbyg/* * 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 SCREENREADER_H_ #define SCREENREADER_H_ #include #include "Rect2.h" struct ScreenReader; struct ScreenReader* screen_reader_new(); void screen_reader_reset_rect(struct ScreenReader *screen); void screen_reader_add_rect(struct ScreenReader *screen, GdkScreen *gdk_screen, math::Rect2& rect); void screen_reader_update_pixbuf(struct ScreenReader *screen, math::Rect2* update_rect); GdkPixbuf* screen_reader_get_pixbuf(struct ScreenReader *screen); void screen_reader_destroy(struct ScreenReader *screen); #endif /* SCREENREADER_H_ */ gpick_0.2.5/source/ColorMixer.h0000644000175000017500000000327112070605214015141 0ustar zbygzbyg/* * 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_MIXER_H_ #define COLOR_MIXER_H_ #include "ColorSourceManager.h" int color_mixer_source_register(ColorSourceManager *csm); #endif /* COLOR_MIXER_H_ */ gpick_0.2.5/source/layout/Layout.h0000644000175000017500000000404212070605214015645 0ustar zbygzbyg/* * 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 LAYOUT_LAYOUT_H_ #define LAYOUT_LAYOUT_H_ #include "../dynv/DynvSystem.h" #ifndef _MSC_VER #include #endif #include #include "System.h" namespace layout{ class Layouts; typedef struct Layout{ char* name; char* human_readable; uint32_t mask; }Layout; Layouts* layouts_init(struct dynvSystem* params); int layouts_term(Layouts *layouts); Layout** layouts_get_all(Layouts *layouts, uint32_t *size); System* layouts_get(Layouts *layouts, const char* name); } #endif /* LAYOUT_LAYOUT_H_ */ gpick_0.2.5/source/layout/SConscript0000644000175000017500000000060312070605214016230 0ustar zbygzbyg#!/usr/bin/env python import os import sys 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') sources = local_env.Glob('*.cpp') objects = local_env.StaticObject( source = [sources]) Return('objects') gpick_0.2.5/source/layout/Box.h0000644000175000017500000000543712070605214015131 0ustar zbygzbyg/* * 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 LAYOUT_BOX_H_ #define LAYOUT_BOX_H_ #include "../Color.h" #include "../Rect2.h" #include "../Vector2.h" #include "ReferenceCounter.h" #include "Style.h" #include "Context.h" #include #include #include namespace layout{ class Box: public ReferenceCounter{ public: std::string name; Style *style; bool helper_only; bool locked; math::Rect2 rect; std::list child; virtual void Draw(Context *context, const math::Rect2& parent_rect ); void DrawChildren(Context *context, const math::Rect2& parent_rect ); void AddChild(Box* box); void SetStyle(Style *style); Box* GetBoxAt(const math::Vec2& point); Box* GetNamedBox(const char *name); Box(const char* name, float x, float y, float width, float height); virtual ~Box(); }; class Text:public Box{ public: std::string text; virtual void Draw(Context *context, const math::Rect2& parent_rect ); Text(const char* name, float x, float y, float width, float height):Box(name,x,y,width,height){ }; }; class Fill:public Box{ public: virtual void Draw(Context *context, const math::Rect2& parent_rect ); Fill(const char* name, float x, float y, float width, float height):Box(name,x,y,width,height){ }; }; } #endif /* LAYOUT_BOX_H_ */ gpick_0.2.5/source/layout/LuaBindings.h0000644000175000017500000000366112070605214016575 0ustar zbygzbyg/* * 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 LAYOUT_LUABINDINGS_H_ #define LAYOUT_LUABINDINGS_H_ #include "../LuaExt.h" #include "Box.h" #include "System.h" namespace layout{ int lua_ext_layout_openlib(lua_State *L); Box* lua_checklbox (lua_State *L, int index); int lua_pushlbox (lua_State *L, Box* box); System* lua_checklsystem (lua_State *L, int index); int lua_pushlsystem (lua_State *L, System* system); } #endif /* LAYOUT_LUABINDINGS_H_ */ gpick_0.2.5/source/layout/Style.cpp0000644000175000017500000000514412070605214016027 0ustar zbygzbyg/* * 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 "Box.h" #include #include using namespace std; using namespace math; namespace layout{ Style::Style(const char* _name, Color* _color, float _font_size){ string name = string(_name); size_t pos = name.find(":"); if (pos != string::npos){ ident_name = name.substr(0, pos); human_name = name.substr(pos+1); }else{ ident_name = name; human_name = name; } style_type = TYPE_UNKNOWN; if ((pos = ident_name.rfind("_")) != string::npos){ string flags = ident_name.substr(pos); if (flags.find("t") != string::npos){ style_type = TYPE_COLOR; }else if (flags.find("b") != string::npos){ style_type = TYPE_BACKGROUND; } } color_copy(_color, &color); font_size = _font_size; dirty = true; highlight = false; selected_box = 0; } Style::~Style(){ } bool Style::IsDirty(){ return dirty; } void Style::SetDirty(bool _dirty){ dirty = _dirty; } bool Style::GetHighlight(){ return highlight; } Box* Style::GetBox(){ return selected_box; } void Style::SetState(bool _highlight, Box *box){ selected_box = box; highlight = _highlight; } } gpick_0.2.5/source/layout/System.h0000644000175000017500000000430312070605214015654 0ustar zbygzbyg/* * 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 LAYOUT_SYSTEM_H_ #define LAYOUT_SYSTEM_H_ #include "../Rect2.h" #include "../Vector2.h" #include "Box.h" #include "Style.h" #include "Context.h" #include "ReferenceCounter.h" #include #ifndef _MSC_VER #include #endif #include #include #include namespace layout{ class System:public ReferenceCounter{ public: std::list styles; Box* box; System(); virtual ~System(); void Draw(Context *context, const math::Rect2& parent_rect ); Box* GetBoxAt(const math::Vec2& point); Box* GetNamedBox(const char *name); void AddStyle(Style *style); void SetBox(Box *box); }; } #endif /* LAYOUT_SYSTEM_H_ */ gpick_0.2.5/source/layout/Style.h0000644000175000017500000000431012070605214015466 0ustar zbygzbyg/* * 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 LAYOUT_STYLE_H_ #define LAYOUT_STYLE_H_ #include "../Color.h" #include "ReferenceCounter.h" #include "Box.h" #include #include namespace layout{ class Box; class Style:public ReferenceCounter{ public: std::string ident_name; std::string human_name; Color color; float font_size; enum{ TYPE_UNKNOWN = 0, TYPE_COLOR, TYPE_BACKGROUND, TYPE_BORDER, }style_type; bool dirty; bool highlight; Box* selected_box; bool IsDirty(); void SetDirty(bool dirty); bool GetHighlight(); Box* GetBox(); void SetState(bool highlight, Box *box); Style(const char* name, Color* color, float font_size); virtual ~Style(); }; } #endif /* LAYOUT_STYLE_H_ */ gpick_0.2.5/source/layout/ReferenceCounter.cpp0000644000175000017500000000367412070605214020173 0ustar zbygzbyg/* * 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 "ReferenceCounter.h" #include using namespace std; namespace layout{ ReferenceCounter::ReferenceCounter(){ refcnt = 0; } ReferenceCounter::~ReferenceCounter(){ } ReferenceCounter* ReferenceCounter::ref(){ refcnt++; return this; } bool ReferenceCounter::unref(ReferenceCounter* rc){ if (rc->refcnt){ rc->refcnt--; return false; }else{ //cout< #include #include #include using namespace std; using namespace math; namespace layout{ void Box::SetStyle(Style *_style){ if (style){ unref(style); style=0; } if (_style){ style = static_cast(_style->ref()); } } void Box::Draw(Context *context, const Rect2& parent_rect ){ DrawChildren(context, parent_rect); } void Box::DrawChildren(Context *context, const math::Rect2& parent_rect ){ Rect2 child_rect = rect.impose( parent_rect ); for (list::iterator i = child.begin(); i!=child.end(); i++){ (*i)->Draw(context, child_rect); } } void Box::AddChild(Box* box){ child.push_back(box); } Box::Box(const char* _name, float x, float y, float width, float height){ style = 0; name = _name; rect = Rect2(x, y, x+width, y+height); helper_only = false; locked = false; } Box::~Box(){ SetStyle(0); for (list::iterator i = child.begin(); i!=child.end(); i++){ unref(*i); } } Box* Box::GetNamedBox(const char *name_){ if (name.compare(name_) == 0){ return this; } Box* r; for (list::iterator i = child.begin(); i!=child.end(); i++){ if ((r = (*i)->GetNamedBox(name_))){ if (!r->helper_only) return r; } } return 0; } Box* Box::GetBoxAt(const Vec2& point){ if (rect.isInside(point.x, point.y)){ Vec2 transformed_point = Vec2((point.x-rect.getX()) / rect.getWidth(), (point.y-rect.getY()) / rect.getHeight()); Box* r; for (list::iterator i = child.begin(); i!=child.end(); i++){ if ((r = (*i)->GetBoxAt(transformed_point))){ if (!r->helper_only) return r; } } if (typeid(*this)==typeid(Box)) //do not match Box, because it is invisible return 0; else return this; }else{ return 0; } } void Text::Draw(Context *context, const Rect2& parent_rect ){ Rect2 draw_rect = rect.impose( parent_rect ); cairo_t *cr = context->getCairo(); if (text!=""){ if (helper_only){ cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL); }else{ cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); } if (style){ cairo_set_font_size(cr, style->font_size * draw_rect.getHeight()); Color color; if (context->getTransformationChain()){ context->getTransformationChain()->apply(&style->color, &color); }else{ color_copy(&style->color, &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); }else{ cairo_set_font_size(cr, draw_rect.getHeight()); cairo_set_source_rgb(cr, 0, 0, 0); } cairo_text_extents_t extents; cairo_text_extents(cr, text.c_str(), &extents); cairo_move_to(cr, draw_rect.getX() + draw_rect.getWidth()/2 - (extents.width/2 + extents.x_bearing), draw_rect.getY() + draw_rect.getHeight()/2 - (extents.height/2 + extents.y_bearing)); cairo_show_text(cr, text.c_str()); if (style && style->GetBox() == this){ cairo_rectangle(cr, draw_rect.getX()+1, draw_rect.getY()+1, draw_rect.getWidth()-2, draw_rect.getHeight()-2); cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_line_width(cr, 2); cairo_stroke(cr); } } DrawChildren(context, parent_rect); } void Fill::Draw(Context *context, const Rect2& parent_rect ){ Rect2 draw_rect = rect.impose( parent_rect ); cairo_t *cr = context->getCairo(); Color color; if (context->getTransformationChain()){ context->getTransformationChain()->apply(&style->color, &color); }else{ color_copy(&style->color, &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); cairo_rectangle(cr, draw_rect.getX(), draw_rect.getY(), draw_rect.getWidth(), draw_rect.getHeight()); cairo_fill(cr); if (style->GetBox() == this){ cairo_rectangle(cr, draw_rect.getX()+1, draw_rect.getY()+1, draw_rect.getWidth()-2, draw_rect.getHeight()-2); cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_line_width(cr, 2); cairo_stroke(cr); } DrawChildren(context, parent_rect); } } gpick_0.2.5/source/layout/Context.cpp0000644000175000017500000000347512070605214016360 0ustar zbygzbyg/* * 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 "Context.h" namespace layout{ Context::Context(cairo_t *cr_, transformation::Chain *chain_) { cr = cr_; chain = chain_; } Context::~Context() { } cairo_t* Context::getCairo() const { return cr; } transformation::Chain* Context::getTransformationChain() const { return chain; } } gpick_0.2.5/source/layout/Layout.cpp0000644000175000017500000001220012070605214016173 0ustar zbygzbyg/* * 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 "Layout.h" #include "LuaBindings.h" #include "../LuaExt.h" #include "../DynvHelpers.h" #include #include #include #include #include #include #include #include #include using namespace std; namespace layout{ class LayoutKeyCompare{ public: bool operator() (const char* const& x, const char* const& y) const { return strcmp(x,y)<0; }; }; class Layouts{ public: typedef std::map LayoutMap; LayoutMap layouts; vector all_layouts; lua_State *L; ~Layouts(); }; Layouts::~Layouts(){ Layouts::LayoutMap::iterator i; for (i=layouts.begin(); i!=layouts.end(); ++i){ g_free(((*i).second)->human_readable); g_free(((*i).second)->name); delete ((*i).second); } layouts.clear(); } Layouts* layouts_init(struct dynvSystem* params){ lua_State* L = static_cast(dynv_get_pointer_wdc(params, "lua_State", 0)); if (L == NULL) return 0; Layouts *layouts = new Layouts; layouts->L = L; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "layouts"); lua_gettable(L, gpick_namespace); int layouts_table = lua_gettop(L); lua_pushstring(L, "layouts_get"); lua_gettable(L, gpick_namespace); if (lua_type(L, -1) != LUA_TNIL){ if ((status=lua_pcall(L, 0, 1, 0))==0){ if (lua_type(L, -1)==LUA_TTABLE){ int table_index = lua_gettop(L); for (int i=1;;i++){ lua_pushinteger(L, i); lua_gettable(L, table_index); if (lua_isnil(L, -1)) break; lua_pushstring(L, lua_tostring(L, -1)); //duplicate, because lua_gettable replaces stack top lua_gettable(L, layouts_table); lua_pushstring(L, "human_readable"); lua_gettable(L, -2); lua_pushstring(L, "mask"); lua_gettable(L, -3); Layout *layout = new Layout; layout->human_readable = g_strdup(lua_tostring(L, -2)); layout->name = g_strdup(lua_tostring(L, -4)); layout->mask = lua_tointeger(L, -1); layouts->layouts[layout->name] = layout; layouts->all_layouts.push_back(layout); //cout<name<all_layouts.size(); return &layouts->all_layouts[0]; } System* layouts_get(Layouts *layouts, const char* name){ Layouts::LayoutMap::iterator i; i=layouts->layouts.find(name); if (i!=layouts->layouts.end()){ //layout name matched, build layout lua_State* L = layouts->L; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "layouts"); lua_gettable(L, gpick_namespace); int layouts_table = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, layouts_table); lua_pushstring(L, "build"); lua_gettable(L, -2); if (!lua_isnil(L, -1)){ System *layout_system = new System; lua_pushlsystem(L, layout_system); if ((status=lua_pcall(L, 1, 1, 0))==0){ if (!lua_isnil(L, -1)){ lua_settop(L, stack_top); return layout_system; } }else{ cerr<<"layouts.build: "< #include using namespace std; namespace layout{ static int lua_lstyle_new (lua_State *L) { size_t st; const char* name = luaL_checklstring(L, 2, &st); Color* color = lua_checkcolor(L, 3); double font_size = luaL_optnumber(L, 4, 1.0); Style** c = static_cast(lua_newuserdata(L, sizeof(Style*))); luaL_getmetatable(L, "layout_style"); lua_setmetatable(L, -2); Style *e = new Style(name, color, font_size); *c = static_cast(e); return 1; } Style* lua_checklstyle (lua_State *L, int index) { Style** c = static_cast(luaL_checkudata(L, index, "layout_style")); luaL_argcheck(L, c != NULL, index, "`layout_style' expected"); return *c; } int lua_pushlstyle (lua_State *L, Style* style) { Style** c = static_cast(lua_newuserdata(L, sizeof(Style*))); luaL_getmetatable(L, "layout_style"); lua_setmetatable(L, -2); *c = style; return 1; } int lua_lstyle_gc (lua_State *L) { Style* style = lua_checklstyle(L, 1); Style::unref(style); return 0; } int lua_lstyle_humanname (lua_State *L) { Style *style = lua_checklstyle(L, 1); if (lua_type(L, 2)==LUA_TSTRING){ size_t st; const char* name = luaL_checklstring(L, 2, &st); style->human_name = name; return 0; }else{ lua_pushstring(L, style->human_name.c_str()); return 1; } } static const struct luaL_Reg lua_lstylelib_f [] = { {"new", lua_lstyle_new}, {NULL, NULL} }; static const struct luaL_Reg lua_lstylelib_m [] = { {"humanname", lua_lstyle_humanname}, {"__gc", lua_lstyle_gc}, {NULL, NULL} }; static int lua_new_box (lua_State *L) { size_t st; const char* name = luaL_checklstring(L, 2, &st); double x = luaL_checknumber(L, 3); double y = luaL_checknumber(L, 4); double w = luaL_checknumber(L, 5); double h = luaL_checknumber(L, 6); Box** c = (Box**)lua_newuserdata(L, sizeof(Box*)); luaL_getmetatable(L, "layout"); lua_setmetatable(L, -2); Box *e = new Box(name, x, y, w, h); *c = static_cast(e); return 1; } static int lua_new_fill (lua_State *L) { size_t st; const char* name = luaL_checklstring(L, 2, &st); double x = luaL_checknumber(L, 3); double y = luaL_checknumber(L, 4); double w = luaL_checknumber(L, 5); double h = luaL_checknumber(L, 6); Style* style = lua_checklstyle(L, 7); Box** c = (Box**)lua_newuserdata(L, sizeof(Box*)); luaL_getmetatable(L, "layout"); lua_setmetatable(L, -2); Fill *e = new Fill(name, x, y, w, h); e->SetStyle(style); *c = static_cast(e); return 1; } static int lua_new_text (lua_State *L) { size_t st; const char* name = luaL_checklstring(L, 2, &st); double x = luaL_checknumber(L, 3); double y = luaL_checknumber(L, 4); double w = luaL_checknumber(L, 5); double h = luaL_checknumber(L, 6); Style* style = 0; if (lua_type(L, 7)!=LUA_TNIL){ style = lua_checklstyle(L, 7); } const char* text = luaL_checklstring(L, 8, &st); Box** c = (Box**)lua_newuserdata(L, sizeof(Box*)); luaL_getmetatable(L, "layout"); lua_setmetatable(L, -2); Text *e = new Text(name, x, y, w, h); if (style) e->SetStyle(style); e->text = text; *c = static_cast(e); return 1; } Box* lua_checklbox (lua_State *L, int index) { Box** c = static_cast(luaL_checkudata(L, index, "layout")); luaL_argcheck(L, c != NULL, index, "`layout' expected"); return *c; } int lua_pushlbox (lua_State *L, Box* box) { Box** c = static_cast(lua_newuserdata(L, sizeof(Box*))); luaL_getmetatable(L, "layout"); lua_setmetatable(L, -2); *c = static_cast(box->ref()); return 1; } int lua_add (lua_State *L) { Box* box = lua_checklbox(L, 1); Box* box2 = lua_checklbox(L, 2); box->AddChild(static_cast(box2->ref())); lua_pushlbox(L, box); return 1; } int lua_box_helper_only (lua_State *L) { Box* box = lua_checklbox(L, 1); if (lua_type(L, 2)==LUA_TBOOLEAN){ int v = lua_toboolean(L, 2); if (v){ box->helper_only = true; }else{ box->helper_only = false; } return 0; }else{ lua_pushboolean(L, box->helper_only); return 1; } } int lua_box_locked (lua_State *L) { Box* box = lua_checklbox(L, 1); if (lua_type(L, 2)==LUA_TBOOLEAN){ int v = lua_toboolean(L, 2); if (v){ box->locked = true; }else{ box->locked = false; } return 0; }else{ lua_pushboolean(L, box->locked); return 1; } } int lua_box_gc(lua_State *L) { Box* box = lua_checklbox(L, 1); Box::unref(box); return 0; } static const struct luaL_Reg lua_lboxlib_f [] = { {"new_box", lua_new_box}, {"new_text", lua_new_text}, {"new_fill", lua_new_fill}, {NULL, NULL} }; static const struct luaL_Reg lua_lboxlib_m [] = { {"add", lua_add}, {"helper_only", lua_box_helper_only}, {"locked", lua_box_locked}, {"__gc", lua_box_gc}, {NULL, NULL} }; System* lua_checklsystem (lua_State *L, int index) { System** c = static_cast(luaL_checkudata(L, index, "layout_system")); luaL_argcheck(L, c != NULL, index, "`layout_system' expected"); return *c; } int lua_pushlsystem (lua_State *L, System* system) { System** c = static_cast(lua_newuserdata(L, sizeof(System*))); luaL_getmetatable(L, "layout_system"); lua_setmetatable(L, -2); *c = static_cast(system); return 1; } int lua_lsystem_addstyle (lua_State *L) { System* system = lua_checklsystem(L, 1); Style* style = lua_checklstyle(L, 2); system->AddStyle(style); return 0; } int lua_lsystem_setbox (lua_State *L) { System* system = lua_checklsystem(L, 1); Box* box = lua_checklbox(L, 2); system->SetBox(box); return 0; } static const struct luaL_Reg lua_systemlib_m [] = { {"addstyle", lua_lsystem_addstyle}, {"setbox", lua_lsystem_setbox}, {NULL, NULL} }; int luaopen_lbox (lua_State *L) { luaL_newmetatable(L, "layout"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_setfuncs(L, lua_lboxlib_m, 0); lua_pop(L, 1); luaL_newlibtable(L, lua_lboxlib_f); luaL_setfuncs(L, lua_lboxlib_f, 0); lua_setglobal(L, "layout"); luaL_newmetatable(L, "layout_style"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_setfuncs(L, lua_lstylelib_m, 0); lua_pop(L, 1); luaL_newlibtable(L, lua_lstylelib_f); luaL_setfuncs(L, lua_lstylelib_f, 0); lua_setglobal(L, "layout_style"); luaL_newmetatable(L, "layout_system"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_setfuncs(L, lua_systemlib_m, 0); lua_pop(L, 1); return 1; } int lua_ext_layout_openlib(lua_State *L){ luaopen_lbox(L); return 0; } } gpick_0.2.5/source/layout/Context.h0000644000175000017500000000400312070605214016011 0ustar zbygzbyg/* * 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 LAYOUT_CONTEXT_H_ #define LAYOUT_CONTEXT_H_ #include "../transformation/Chain.h" #include #ifndef _MSC_VER #include #endif #include #include #include namespace layout{ class Context{ protected: cairo_t *cr; transformation::Chain *chain; public: Context(cairo_t *cr, transformation::Chain *chain); ~Context(); cairo_t* getCairo() const; transformation::Chain* getTransformationChain() const; }; } #endif /* LAYOUT_SYSTEM_H_ */ gpick_0.2.5/source/layout/System.cpp0000644000175000017500000000450112070605214016207 0ustar zbygzbyg/* * 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 "System.h" using namespace std; namespace layout{ System::System(){ box = 0; } System::~System(){ for (list::iterator i=styles.begin(); i!=styles.end(); i++){ Style::unref(*i); } styles.clear(); Box::unref(box); } void System::Draw(Context *context, const math::Rect2& parent_rect ){ if (!box) return; box->Draw(context, parent_rect); } void System::AddStyle(Style *_style){ styles.push_back(static_cast(_style->ref())); } void System::SetBox(Box *_box){ if (box){ Box::unref(box); box = 0; } box = static_cast(_box->ref()); } Box* System::GetBoxAt(const math::Vec2& point){ if (box) return box->GetBoxAt(point); else return 0; } Box* System::GetNamedBox(const char *name){ if (box) return box->GetNamedBox(name); else return 0; } } gpick_0.2.5/source/layout/ReferenceCounter.h0000644000175000017500000000362012070605214017627 0ustar zbygzbyg/* * 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 LAYOUT_REFERENCECOUNTER_H_ #define LAYOUT_REFERENCECOUNTER_H_ #include #ifndef _MSC_VER #include #endif namespace layout{ class ReferenceCounter{ protected: uint32_t refcnt; public: ReferenceCounter(); virtual ~ReferenceCounter(); ReferenceCounter* ref(); static bool unref(ReferenceCounter* rc); }; } #endif /* LAYOUT_REFERENCECOUNTER_H_ */ gpick_0.2.5/source/dynv/DynvMemoryIO.cpp0000644000175000017500000001272412070605214016735 0ustar zbygzbyg/* * 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 "DynvMemoryIO.h" #include #include struct dynvMemoryIO{ char* buffer; uint32_t size; uint32_t eof; uint32_t position; }; static int dynv_io_memory_write(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_written) { struct dynvMemoryIO* mem_io = (struct dynvMemoryIO*) io->userdata; uint32_t data_left = mem_io->size - mem_io->position; if (data_left < size){ //buffer too small uint32_t new_buf = mem_io->size + size + 4096; //while (new_buf - mem_io->position < size) // new_buf *= 2; char *nb; if ((nb = new char[new_buf])){ if (mem_io->buffer){ memcpy(nb, mem_io->buffer, mem_io->position); delete[] mem_io->buffer; } mem_io->buffer = nb; mem_io->size = new_buf; }else{ *data_written = 0; return 0; } } memcpy(mem_io->buffer + mem_io->position, data, size); mem_io->position += size; if (mem_io->position > mem_io->eof) mem_io->eof = mem_io->position; *data_written = size; return 0; } static int dynv_io_memory_read(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_read){ struct dynvMemoryIO* mem_io = (struct dynvMemoryIO*) io->userdata; uint32_t data_left = mem_io->eof - mem_io->position; if (size > data_left) size = data_left; memcpy(data, mem_io->buffer + mem_io->position, size); mem_io->position += size; *data_read=size; return 0; } static int dynv_io_memory_seek(struct dynvIO* io, uint32_t offset, int type, uint32_t* position){ struct dynvMemoryIO* mem_io = (struct dynvMemoryIO*) io->userdata; switch (type){ case SEEK_CUR: mem_io->position+=offset; if (mem_io->position>mem_io->eof) mem_io->position=mem_io->eof; if(position) *position=mem_io->position; return 0; break; case SEEK_SET: mem_io->position=offset; if (mem_io->position>mem_io->eof) mem_io->position=mem_io->eof; if(position) *position=mem_io->position; return 0; break; case SEEK_END: mem_io->position=mem_io->eof-offset; if (mem_io->position>mem_io->eof) mem_io->position=mem_io->eof; if(position) *position=mem_io->position; return 0; break; } return -1; } static int dynv_io_memory_free(struct dynvIO* io){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; if (mem_io->buffer) delete [] mem_io->buffer; delete mem_io; return 0; } static int dynv_io_memory_reset(struct dynvIO* io){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; mem_io->eof=0; mem_io->position=0; return 0; } struct dynvIO* dynv_io_memory_new(){ struct dynvIO* io=new struct dynvIO; struct dynvMemoryIO* mem_io=new struct dynvMemoryIO; mem_io->buffer=0; mem_io->eof=0; mem_io->position=0; mem_io->size=0; io->userdata=mem_io; io->write=dynv_io_memory_write; io->read=dynv_io_memory_read; io->seek=dynv_io_memory_seek; io->free=dynv_io_memory_free; io->reset=dynv_io_memory_reset; return io; } int dynv_io_memory_get_data(struct dynvIO* io, char** data, uint32_t* size){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; if (!mem_io) return -1; if (!mem_io->buffer) return -1; *data=mem_io->buffer; *size=mem_io->eof; return 0; } int dynv_io_memory_set_data(struct dynvIO* io, char* data, uint32_t size){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; if (!mem_io) return -1; dynv_io_memory_reset(io); uint32_t written; dynv_io_memory_write(io, data, size, &written); return 0; } int dynv_io_memory_prepare_size(struct dynvIO* io, uint32_t size){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; if (!mem_io) return -1; mem_io->eof=size; mem_io->position=0; if (mem_io->sizebuffer, mem_io->position); if (mem_io->buffer) delete[] mem_io->buffer; mem_io->buffer = nb; mem_io->size = size; return 0; }else{ return -1; } } return 0; } void* dynv_io_memory_get_buffer(struct dynvIO* io){ struct dynvMemoryIO* mem_io=(struct dynvMemoryIO*)io->userdata; if (!mem_io) return 0; return mem_io->buffer; } gpick_0.2.5/source/dynv/DynvSystem.cpp0000644000175000017500000004376012070605214016525 0ustar zbygzbyg/* * 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 "DynvSystem.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" #include #include #include #include #include using namespace std; bool dynvSystem::dynvKeyCompare::operator() (const char* const& x, const char* const& y) const { return strcmp(x,y)<0; } struct dynvHandlerMap* dynv_system_get_handler_map(struct dynvSystem* dynv_system){ return dynv_handler_map_ref(dynv_system->handler_map); } void dynv_system_set_handler_map(struct dynvSystem* dynv_system, struct dynvHandlerMap* handler_map){ if (dynv_system->handler_map!=NULL){ dynv_handler_map_release(dynv_system->handler_map); dynv_system->handler_map=NULL; } if (handler_map!=NULL){ dynv_system->handler_map=dynv_handler_map_ref(handler_map); } } struct dynvSystem* dynv_system_create(struct dynvHandlerMap* handler_map){ struct dynvSystem* dynv_system=new struct dynvSystem; dynv_system->handler_map=NULL; dynv_system->refcnt=0; dynv_system_set_handler_map(dynv_system, handler_map); return dynv_system; } int dynv_system_release(struct dynvSystem* dynv_system){ if (dynv_system->refcnt){ dynv_system->refcnt--; return -1; }else{ dynvSystem::VariableMap::iterator i; for (i=dynv_system->variables.begin(); i!=dynv_system->variables.end(); ++i){ dynv_variable_destroy((*i).second); } dynv_system->variables.clear(); dynv_handler_map_release(dynv_system->handler_map); delete dynv_system; return 0; } } struct dynvSystem* dynv_system_ref(struct dynvSystem* dynv_system){ dynv_system->refcnt++; return dynv_system; } struct dynvVariable* dynv_system_add_empty(struct dynvSystem* dynv_system, struct dynvHandler* handler, const char* variable_name){ struct dynvVariable* variable=NULL; dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ if (handler==NULL) return 0; variable=dynv_variable_create(variable_name, handler); dynv_system->variables[variable->name]=variable; variable->handler->create(variable); return variable; }else{ variable=(*i).second; } if (variable->flags & dynvVariable::READONLY) return 0; if (variable->handler==handler){ return variable; }else{ if (handler->create!=NULL){ dynv_variable_destroy_data(variable); variable->handler=handler; variable->handler->create(variable); return variable; } } return 0; } int dynv_system_set(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, void* value){ struct dynvVariable* variable=NULL; struct dynvHandler* handler=NULL; if (handler_name!=NULL){ dynvHandlerMap::HandlerMap::iterator j; j=dynv_system->handler_map->handlers.find(handler_name); if (j==dynv_system->handler_map->handlers.end()){ return -3; }else{ handler=(*j).second; } } dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ if (handler==NULL) return -2; variable=dynv_variable_create(variable_name, handler); dynv_system->variables[variable->name]=variable; variable->handler->create(variable); return variable->handler->set(variable, value, false); }else{ variable=(*i).second; } if (variable->flags & dynvVariable::READONLY) return -4; if (variable->handler==handler){ return variable->handler->set(variable, value, false); }else{ if (handler->create!=NULL){ dynv_variable_destroy_data(variable); variable->handler=handler; variable->handler->create(variable); return variable->handler->set(variable, value, false); } } return -1; } void* dynv_system_get_r(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, int* error){ struct dynvVariable* variable=NULL; struct dynvHandler* handler=NULL; int error_redir; if (error == NULL) error = &error_redir; *error = 1; if (handler_name!=NULL){ dynvHandlerMap::HandlerMap::iterator j; j=dynv_system->handler_map->handlers.find(handler_name); if (j==dynv_system->handler_map->handlers.end()){ return 0; }else{ handler=(*j).second; } } dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ return 0; }else{ variable=(*i).second; } if (variable->handler==handler){ if (variable->handler->get!=NULL){ void* value = 0; bool deref = true; if (variable->handler->get(variable, &value, &deref)==0){ *error = 0; return value; }else{ return 0; } } } return 0; } void* dynv_system_get(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name){ return dynv_system_get_r(dynv_system, handler_name, variable_name, 0); } void** dynv_system_get_array_r(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, uint32_t *count, int* error){ struct dynvVariable* variable=NULL; struct dynvHandler* handler=NULL; int error_redir; if (error == NULL) error = &error_redir; *error = 1; if (handler_name!=NULL){ dynvHandlerMap::HandlerMap::iterator j; j=dynv_system->handler_map->handlers.find(handler_name); if (j==dynv_system->handler_map->handlers.end()){ return 0; }else{ handler=(*j).second; } } dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ return 0; }else{ variable=(*i).second; } if (variable->handler==handler){ uint32_t n = 0; struct dynvVariable *i = variable; while (i){ n++; i = i->next; } if (count) *count = n; void** array = (void**)new char [n * handler->data_size]; void** o_array = array; i = variable; for (uint32_t j=0; j!=n; j++){ void *var; bool deref = true; if (i->handler->get && i->handler->get(i, &var, &deref)==0){ if (deref) memcpy(array, var, handler->data_size); else memcpy(array, &var, handler->data_size); }else{ memset(array, 0, handler->data_size); //array[j] = 0; } array = (void**)(((char*)array) + handler->data_size); i = i->next; } *error = 0; return o_array; } return 0; } static int build_linked_list(struct dynvVariable* start_variable, void** values, uint32_t count){ if (count<1) return -1; struct dynvVariable *variable, *v; struct dynvHandler* handler = start_variable->handler; handler->set(start_variable, values, true); values = (void**)(((char*)values) + handler->data_size); v = start_variable; for (uint32_t i=1; ihandler->create(variable); variable->handler->set(variable, values, true); values = (void**)(((char*)values) + handler->data_size); v->next = variable; v = variable; } return 0; } int dynv_system_set_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, void** values, uint32_t count){ struct dynvVariable* variable=NULL; struct dynvHandler* handler=NULL; if (count<1){ return dynv_system_remove(dynv_system, variable_name); } if (handler_name!=NULL){ dynvHandlerMap::HandlerMap::iterator j; j=dynv_system->handler_map->handlers.find(handler_name); if (j==dynv_system->handler_map->handlers.end()){ return -3; }else{ handler=(*j).second; } } dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ if (handler==NULL) return -2; variable=dynv_variable_create(variable_name, handler); dynv_system->variables[variable->name]=variable; variable->handler->create(variable); return build_linked_list(variable, values, count); }else{ variable=(*i).second; } if (variable->flags & dynvVariable::READONLY) return -4; dynv_variable_destroy_data(variable); variable->handler = handler; variable->handler->create(variable); return build_linked_list(variable, values, count); } int dynv_system_remove(struct dynvSystem* dynv_system, const char* variable_name){ dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ return -1; }else{ dynv_variable_destroy((*i).second); dynv_system->variables.erase(i); return 0; } } int dynv_system_remove_all(struct dynvSystem* dynv_system){ dynvSystem::VariableMap::iterator i; for (i=dynv_system->variables.begin(); i!=dynv_system->variables.end(); ++i){ dynv_variable_destroy((*i).second); } dynv_system->variables.clear(); return 0; } struct dynvVariable* dynv_system_get_var(struct dynvSystem* dynv_system, const char* variable_name){ dynvSystem::VariableMap::iterator i; i=dynv_system->variables.find(variable_name); if (i==dynv_system->variables.end()){ return 0; }else{ return (*i).second; } } int dynv_system_serialize(struct dynvSystem* dynv_system, struct dynvIO* io){ dynvSystem::VariableMap::iterator i; uint32_t written, length, id; uint32_t variable_count=dynv_system->variables.size(); variable_count=UINT32_TO_LE(variable_count); dynv_io_write(io, &variable_count, 4, &written); uint32_t handler_count=dynv_system->handler_map->handlers.size(); int_fast32_t handler_bytes; if (handler_count<=0xFF) handler_bytes=1; else if (handler_count<=0xFFFF) handler_bytes=2; else if (handler_count<=0xFFFFFF) handler_bytes=3; else handler_bytes=4; for (i=dynv_system->variables.begin(); i!=dynv_system->variables.end(); ++i){ struct dynvVariable* variable=(*i).second; id=UINT32_TO_LE(variable->handler->id); dynv_io_write(io, &id, handler_bytes, &written); length=strlen(variable->name); uint32_t length_le=UINT32_TO_LE(length); dynv_io_write(io, &length_le, 4, &written); dynv_io_write(io, variable->name, length, &written); variable->handler->serialize(variable, io); } return 0; } int dynv_system_deserialize(struct dynvSystem* dynv_system, dynvHandlerMap::HandlerVec& handler_vec, struct dynvIO* io){ uint32_t read; uint32_t variable_count, handler_id; uint32_t length=0; char* name; struct dynvVariable* variable; if (dynv_io_read(io, &variable_count, 4, &read)==0){ if (read!=4) return -1; }else return -1; variable_count=UINT32_FROM_LE(variable_count); int_fast32_t handler_bytes; if (handler_vec.size()<=0xFF) handler_bytes=1; else if (handler_vec.size()<=0xFFFF) handler_bytes=2; else if (handler_vec.size()<=0xFFFFFF) handler_bytes=3; else handler_bytes=4; for (uint32_t i=0; i!=variable_count; ++i){ handler_id=0; dynv_io_read(io, &handler_id, handler_bytes, &read); handler_id=UINT32_FROM_LE(handler_id); if ((handler_idname<deserialize(variable, io)!=0){ dynv_io_read(io, &length, 4, &read); length=UINT32_FROM_LE(length); dynv_io_seek(io, length, SEEK_CUR, 0); } }else{ //cout<<"Var: skipping val"<write(io, data, size, data_written); } int dynv_io_read(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_read) { return io->read(io, data, size, data_read); } int dynv_io_seek(struct dynvIO* io, uint32_t offset, int type, uint32_t* position) { return io->seek(io, offset, type, position); } int dynv_io_free(struct dynvIO* io) { int r = io->free(io); delete io; return r; } int dynv_io_reset(struct dynvIO* io) { if (io->reset) return io->reset(io); return -1; } struct dynvSystem* dynv_system_copy(struct dynvSystem* dynv_system){ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(dynv_system); struct dynvSystem* new_dynv = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); void* value; struct dynvVariable *variable, *new_variable; struct dynvHandler* handler; dynvSystem::VariableMap::iterator i; for (i=dynv_system->variables.begin(); i!=dynv_system->variables.end(); ++i){ variable = (*i).second; handler = (*i).second->handler; bool deref = true; if (handler->get(variable, &value, &deref)==0){ new_variable = dynv_variable_create(variable->name, handler); new_dynv->variables[new_variable->name] = new_variable; new_variable->handler->create(new_variable); new_variable->handler->set(new_variable, value, false); } } return new_dynv; } int dynv_set(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, const void* value){ string path(variable_path); size_t found; struct dynvSystem* dlevel = dynv_system_ref(dynv_system); for (;;){ found = path.find('.'); if (found != string::npos){ struct dynvSystem* dlevel_new; dlevel_new = (struct dynvSystem*)dynv_system_get(dlevel, "dynv", path.substr(0, found).c_str()); if (dlevel_new){ dynv_system_release(dlevel); dlevel = dlevel_new; }else{ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(dynv_system); struct dynvSystem* dlevel_new = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); dynv_system_set(dlevel, "dynv", path.substr(0, found).c_str(), dlevel_new); dynv_system_release(dlevel); dlevel = dlevel_new; } path = path.substr(found+1); }else break; } int r = dynv_system_set(dlevel, handler_name, path.c_str(), (void*)value); dynv_system_release(dlevel); return r; } int dynv_set_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, const void** values, uint32_t count){ string path(variable_path); size_t found; struct dynvSystem* dlevel = dynv_system_ref(dynv_system); for (;;){ found = path.find('.'); if (found != string::npos){ struct dynvSystem* dlevel_new; dlevel_new = (struct dynvSystem*)dynv_system_get(dlevel, "dynv", path.substr(0, found).c_str()); if (dlevel_new){ dynv_system_release(dlevel); dlevel = dlevel_new; }else{ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(dynv_system); struct dynvSystem* dlevel_new = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); dynv_system_set(dlevel, "dynv", path.substr(0, found).c_str(), dlevel_new); dynv_system_release(dlevel); dlevel = dlevel_new; } path = path.substr(found+1); }else break; } int r = dynv_system_set_array(dlevel, handler_name, path.c_str(), (void**)values, count); dynv_system_release(dlevel); return r; } void* dynv_get(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, int* error){ string path(variable_path); size_t found; int error_redir; if (error == NULL) error = &error_redir; *error = 0; struct dynvSystem* dlevel = dynv_system_ref(dynv_system); for (;;){ found = path.find('.'); if (found != string::npos){ struct dynvSystem* dlevel_new; dlevel_new = (struct dynvSystem*)dynv_system_get(dlevel, "dynv", path.substr(0, found).c_str()); if (dlevel_new){ dynv_system_release(dlevel); dlevel = dlevel_new; }else{ dynv_system_release(dlevel); *error = 1; return 0; } path = path.substr(found+1); }else break; } void* r = dynv_system_get_r(dlevel, handler_name, path.c_str(), error); dynv_system_release(dlevel); return r; } void** dynv_get_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, uint32_t *count, int* error){ string path(variable_path); size_t found; int error_redir; if (error == NULL) error = &error_redir; *error = 0; struct dynvSystem* dlevel = dynv_system_ref(dynv_system); for (;;){ found = path.find('.'); if (found != string::npos){ struct dynvSystem* dlevel_new; dlevel_new = (struct dynvSystem*)dynv_system_get(dlevel, "dynv", path.substr(0, found).c_str()); if (dlevel_new){ dynv_system_release(dlevel); dlevel = dlevel_new; }else{ dynv_system_release(dlevel); *error = 1; return 0; } path = path.substr(found+1); }else break; } void** r = dynv_system_get_array_r(dlevel, handler_name, path.c_str(), count, error); dynv_system_release(dlevel); return r; } gpick_0.2.5/source/dynv/DynvVarString.h0000644000175000017500000000324612070605214016620 0ustar zbygzbyg/* * 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 DYNVVARSTRING_H_ #define DYNVVARSTRING_H_ #include "DynvSystem.h" struct dynvHandler* dynv_var_string_new(); #endif /* DYNVVARSTRING_H_ */ gpick_0.2.5/source/dynv/DynvVarDynv.h0000644000175000017500000000323612070605214016271 0ustar zbygzbyg/* * 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 DYNVVARDYNV_H_ #define DYNVVARDYNV_H_ #include "DynvSystem.h" struct dynvHandler* dynv_var_dynv_new(); #endif /* DYNVVARDYNV_H_ */ gpick_0.2.5/source/dynv/DynvVarBool.h0000644000175000017500000000323712070605214016245 0ustar zbygzbyg/* * 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 DYNVVARBOOL_H_ #define DYNVVARBOOL_H_ #include "DynvHandler.h" struct dynvHandler* dynv_var_bool_new(); #endif /* DYNVVARBOOL_H_ */ gpick_0.2.5/source/dynv/DynvMemoryIO.h0000644000175000017500000000365012070605214016400 0ustar zbygzbyg/* * 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 DYNVMEMORYIO_H_ #define DYNVMEMORYIO_H_ #include "DynvIO.h" struct dynvIO* dynv_io_memory_new(); int dynv_io_memory_get_data(struct dynvIO* io, char** data, uint32_t* size); int dynv_io_memory_set_data(struct dynvIO* io, char* data, uint32_t size); int dynv_io_memory_prepare_size(struct dynvIO* io, uint32_t size); void* dynv_io_memory_get_buffer(struct dynvIO* io); #endif /* DYNVMEMORYIO_H_ */ gpick_0.2.5/source/dynv/DynvVarFloat.h0000644000175000017500000000324212070605214016413 0ustar zbygzbyg/* * 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 DYNVVARFLOAT_H_ #define DYNVVARFLOAT_H_ #include "DynvSystem.h" struct dynvHandler* dynv_var_float_new(); #endif /* DYNVVARFLOAT_H_ */ gpick_0.2.5/source/dynv/DynvVarInt32.h0000644000175000017500000000324212070605214016245 0ustar zbygzbyg/* * 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 DYNVVARINT32_H_ #define DYNVVARINT32_H_ #include "DynvSystem.h" struct dynvHandler* dynv_var_int32_new(); #endif /* DYNVVARINT32_H_ */ gpick_0.2.5/source/dynv/DynvSystem.h0000644000175000017500000001024012070605214016155 0ustar zbygzbyg/* * 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 DYNVSYSTEM_H_ #define DYNVSYSTEM_H_ #include "DynvHandler.h" #include #include #include #include #include struct dynvSystem{ class dynvKeyCompare{ public: bool operator() (const char* const& x, const char* const& y) const; }; typedef std::map VariableMap; uint32_t refcnt; VariableMap variables; dynvHandlerMap* handler_map; }; struct dynvSystem* dynv_system_create(struct dynvHandlerMap* handler_map); int dynv_system_release(struct dynvSystem* dynv_system); struct dynvSystem* dynv_system_ref(struct dynvSystem* dynv_system); struct dynvHandlerMap* dynv_system_get_handler_map(struct dynvSystem* dynv_system); void dynv_system_set_handler_map(struct dynvSystem* dynv_system, struct dynvHandlerMap* handler_map); int dynv_system_set(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, void* value); struct dynvVariable* dynv_system_add_empty(struct dynvSystem* dynv_system, struct dynvHandler* handler, const char* variable_name); void* dynv_system_get(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name); void* dynv_system_get_r(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, int* error); int dynv_system_set_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, void** values, uint32_t count, uint32_t data_size); void** dynv_system_get_array_r(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_name, uint32_t *count, uint32_t data_size, int* error); struct dynvVariable* dynv_system_get_var(struct dynvSystem* dynv_system, const char* variable_name); int dynv_system_remove(struct dynvSystem* dynv_system, const char* variable_name); int dynv_system_remove_all(struct dynvSystem* dynv_system); struct dynvSystem* dynv_system_copy(struct dynvSystem* dynv_system); int dynv_system_serialize(struct dynvSystem* dynv_system, struct dynvIO* io); int dynv_system_deserialize(struct dynvSystem* dynv_system, dynvHandlerMap::HandlerVec& handler_vec, struct dynvIO* io); int dynv_set(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, const void* value); void* dynv_get(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, int* error); void** dynv_get_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, uint32_t *count, int* error); int dynv_set_array(struct dynvSystem* dynv_system, const char* handler_name, const char* variable_path, const void** values, uint32_t count); #endif /* DYNVSYSTEM_H_ */ gpick_0.2.5/source/dynv/DynvHandler.h0000644000175000017500000000654712070605214016265 0ustar zbygzbyg/* * 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 DYNVHANDLER_H_ #define DYNVHANDLER_H_ #include #include #include #include #include #ifndef _MSC_VER #include #endif struct dynvIO; struct dynvHandler{ char* name; int (*set)(struct dynvVariable* variable, void* value, bool deref); int (*create)(struct dynvVariable* variable); int (*destroy)(struct dynvVariable* variable); int (*get)(struct dynvVariable* variable, void** value, bool *deref); int (*serialize)(struct dynvVariable* variable, struct dynvIO* io); int (*deserialize)(struct dynvVariable* variable, struct dynvIO* io); int (*serialize_xml)(struct dynvVariable* variable, std::ostream& out); int (*deserialize_xml)(struct dynvVariable* variable, const char* data); uint32_t id; uint32_t data_size; }; struct dynvHandler* dynv_handler_create(const char* name); void dynv_handler_destroy(struct dynvHandler* handler); struct dynvHandlerMap{ class dynvKeyCompare{ public: bool operator() (const char* const& x, const char* const& y) const; }; typedef std::map HandlerMap; typedef std::vector HandlerVec; uint32_t refcnt; HandlerMap handlers; }; struct dynvHandlerMap* dynv_handler_map_create(); int dynv_handler_map_release(struct dynvHandlerMap* handler_map); struct dynvHandlerMap* dynv_handler_map_ref(struct dynvHandlerMap* handler_map); int dynv_handler_map_add_handler(struct dynvHandlerMap* handler_map, struct dynvHandler* handler); struct dynvHandler* dynv_handler_map_get_handler(struct dynvHandlerMap* handler_map, const char* handler_name); int dynv_handler_map_serialize(struct dynvHandlerMap* handler_map, struct dynvIO* io); int dynv_handler_map_deserialize(struct dynvHandlerMap* handler_map, struct dynvIO* io, dynvHandlerMap::HandlerVec& handler_vec); #endif /* DYNVHANDLER_H_ */ gpick_0.2.5/source/dynv/DynvVarString.cpp0000644000175000017500000001065012070605214017150 0ustar zbygzbyg/* * 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 "DynvVarString.h" #include "DynvVariable.h" #include "DynvIO.h" #include "DynvXml.h" #include "../Endian.h" #include using namespace std; static int dynv_var_string_create(struct dynvVariable* variable){ variable->ptr_value = 0; return -1; } static int dynv_var_string_destroy(struct dynvVariable* variable){ if (variable->ptr_value){ delete [] (char*)variable->ptr_value; return 0; } return -1; } static int dynv_var_string_set(struct dynvVariable* variable, void* value, bool deref){ if (variable->ptr_value){ delete [] (char*)variable->ptr_value; } uint32_t len = strlen(*(char**)value)+1; variable->ptr_value = new char [len]; memcpy(variable->ptr_value, *(void**)value, len); return 0; } static int dynv_var_string_get(struct dynvVariable* variable, void** value, bool *deref){ if (variable->ptr_value){ *value = &variable->ptr_value; return 0; } return -1; } static int dynv_var_string_serialize(struct dynvVariable* variable, struct dynvIO* io){ if (!variable->ptr_value) return -1; uint32_t written; uint32_t length = strlen((char*)variable->ptr_value); uint32_t length_le = UINT32_TO_LE(length); if (dynv_io_write(io, &length_le, 4, &written)==0){ if (written != 4) return -1; }else return -1; if (dynv_io_write(io, variable->ptr_value, length, &written)==0){ if (written != length) return -1; }else return -1; return 0; } static int dynv_var_string_deserialize(struct dynvVariable* variable, struct dynvIO* io){ if (variable->ptr_value){ delete [] (char*)variable->ptr_value; variable->ptr_value = 0; } uint32_t read; uint32_t length; if (dynv_io_read(io, &length, 4, &read)==0){ if (read != 4) return -1; }else return -1; length = UINT32_FROM_LE(length); variable->ptr_value = new char [length+1]; if (dynv_io_read(io, variable->ptr_value, length, &read)==0){ if (read != length) return -1; }else return -1; ((char*)variable->ptr_value)[length] = 0; return 0; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ if (variable->ptr_value){ //out << (char*)variable->value; dynv_xml_escape((char*)variable->ptr_value, out); } return 0; } static int deserialize_xml(struct dynvVariable* variable, const char *data){ if (variable->ptr_value){ delete [] (char*)variable->ptr_value; variable->ptr_value = 0; } uint32_t len = strlen(data)+1; variable->ptr_value = new char [len]; memcpy(variable->ptr_value, data, len); return 0; } struct dynvHandler* dynv_var_string_new(){ struct dynvHandler* handler=dynv_handler_create("string"); handler->create=dynv_var_string_create; handler->destroy=dynv_var_string_destroy; handler->set=dynv_var_string_set; handler->get=dynv_var_string_get; handler->serialize=dynv_var_string_serialize; handler->deserialize=dynv_var_string_deserialize; handler->serialize_xml=serialize_xml; handler->deserialize_xml=deserialize_xml; handler->data_size = sizeof(char*); return handler; } gpick_0.2.5/source/dynv/DynvVarFloat.cpp0000644000175000017500000000724612070605214016756 0ustar zbygzbyg/* * 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 "DynvVarFloat.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" #include using namespace std; static int dynv_var_float_create(struct dynvVariable* variable){ variable->float_value = 0; return 0; } static int dynv_var_float_destroy(struct dynvVariable* variable){ return 0; } static int dynv_var_float_set(struct dynvVariable* variable, void* value, bool deref){ variable->float_value = *((float*)value); return 0; } static int dynv_var_float_get(struct dynvVariable* variable, void** value, bool *deref){ *value = &variable->float_value; return 0; } static int dynv_var_float_serialize(struct dynvVariable* variable, struct dynvIO* io){ uint32_t written; uint32_t length = 4; length = UINT32_TO_LE(length); dynv_io_write(io, &length, 4, &written); union{ uint32_t i32; float f32; }value; value.f32 = variable->float_value; value.i32 = UINT32_TO_LE(value.i32); if (dynv_io_write(io, &value, 4, &written)==0){ if (written == 4) return 0; } return -1; } static int dynv_var_float_deserialize(struct dynvVariable* variable, struct dynvIO* io){ uint32_t read; uint32_t size; dynv_io_read(io, &size, 4, &read); union{ uint32_t i32; float f32; }value; if (dynv_io_read(io, &value, 4, &read)==0){ if (read == 4){ value.i32 = UINT32_FROM_LE(value.i32); variable->float_value = value.f32; return 0; } } return -1; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ out << variable->float_value; return 0; } static int deserialize_xml(struct dynvVariable* variable, const char *data){ stringstream ss(stringstream::in); ss.str(data); ss >> variable->float_value; return 0; } struct dynvHandler* dynv_var_float_new(){ struct dynvHandler* handler=dynv_handler_create("float"); handler->create=dynv_var_float_create; handler->destroy=dynv_var_float_destroy; handler->set=dynv_var_float_set; handler->get=dynv_var_float_get; handler->serialize=dynv_var_float_serialize; handler->deserialize=dynv_var_float_deserialize; handler->serialize_xml = serialize_xml; handler->deserialize_xml = deserialize_xml; handler->data_size = sizeof(float); return handler; } gpick_0.2.5/source/dynv/DynvIO.h0000644000175000017500000000441512070605214015207 0ustar zbygzbyg/* * 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 DYNVIO_H_ #define DYNVIO_H_ #include struct dynvIO{ int (*write)(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_written); int (*read)(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_read); int (*seek)(struct dynvIO* io, uint32_t offset, int type, uint32_t* position); int (*free)(struct dynvIO* io); int (*reset)(struct dynvIO* io); void* userdata; }; int dynv_io_write(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_written); int dynv_io_read(struct dynvIO* io, void* data, uint32_t size, uint32_t* data_read); int dynv_io_seek(struct dynvIO* io, uint32_t offset, int type, uint32_t* position); int dynv_io_free(struct dynvIO* io); int dynv_io_reset(struct dynvIO* io); #endif /* DYNVIO_H_ */ gpick_0.2.5/source/dynv/DynvVariable.cpp0000644000175000017500000000512612070605214016760 0ustar zbygzbyg/* * 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 "DynvVariable.h" #include "DynvHandler.h" #include #include struct dynvVariable* dynv_variable_create(const char* name, struct dynvHandler* handler){ struct dynvVariable* variable = new struct dynvVariable; if (name){ variable->name = strdup(name); }else{ variable->name = NULL; } variable->handler = handler; variable->ptr_value = NULL; variable->next = NULL; variable->prev = NULL; variable->flags = dynvVariable::Flags(0); return variable; } void dynv_variable_destroy_data(struct dynvVariable* variable){ struct dynvVariable *next, *i; i = variable->next; while (i){ next = i->next; if (i->handler->destroy!=NULL) i->handler->destroy(i); if (i->name) free(i->name); delete i; i = next; } variable->next = NULL; variable->ptr_value = NULL; variable->handler = NULL; } void dynv_variable_destroy(struct dynvVariable* variable){ struct dynvVariable *next, *i; i = variable; while (i){ next = i->next; if (i->handler->destroy!=NULL) i->handler->destroy(i); if (i->name) free(i->name); delete i; i = next; } } gpick_0.2.5/source/dynv/DynvVarDynv.cpp0000644000175000017500000000605312070605214016624 0ustar zbygzbyg/* * 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 "DynvSystem.h" #include "DynvVariable.h" #include "DynvIO.h" #include "DynvXml.h" #include "DynvVarDynv.h" #include "../Endian.h" #include using namespace std; static int create(struct dynvVariable* variable){ variable->ptr_value = 0; return 0; } static int destroy(struct dynvVariable* variable){ if (variable->ptr_value){ dynv_system_release((struct dynvSystem*)variable->ptr_value); return 0; } return -1; } static int set(struct dynvVariable* variable, void* value, bool deref){ if (variable->ptr_value) dynv_system_release((struct dynvSystem*)variable->ptr_value); if (deref) variable->ptr_value = dynv_system_ref(*((struct dynvSystem**)value)); else variable->ptr_value = dynv_system_ref((struct dynvSystem*)value); return 0; } static int get(struct dynvVariable* variable, void** value, bool *deref){ if (variable->ptr_value){ *value= dynv_system_ref((struct dynvSystem*)variable->ptr_value); *deref = false; return 0; } return -1; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ if (variable->ptr_value){ out << endl; dynv_xml_serialize((struct dynvSystem*)variable->ptr_value, out); } return 0; } struct dynvHandler* dynv_var_dynv_new(){ struct dynvHandler* handler=dynv_handler_create("dynv"); handler->create=create; handler->destroy=destroy; handler->set=set; handler->get=get; //handler->serialize=serialize; //handler->deserialize=deserialize; handler->serialize_xml = serialize_xml; handler->data_size = sizeof(struct dynvSystem*); return handler; } gpick_0.2.5/source/dynv/DynvXml.cpp0000644000175000017500000002104412070605214015770 0ustar zbygzbyg/* * 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 "DynvXml.h" #include "DynvVariable.h" #include #include #include #include #include #include using namespace std; int dynv_xml_serialize(struct dynvSystem* dynv_system, ostream& out){ struct dynvVariable *variable, *v; for (dynvSystem::VariableMap::iterator i=dynv_system->variables.begin(); i!=dynv_system->variables.end(); ++i){ variable=(*i).second; if (variable->flags & dynvVariable::NO_SAVE) continue; if (variable->handler->serialize_xml){ if (variable->next){ out << "<" << variable->name << " type=\"" << variable->handler->name << "\" list=\"true\">"; v = variable; while (v){ out << "
  • "; v->handler->serialize_xml(v, out); out << "
  • "; v = v->next; } out << "name << ">" << endl; }else{ out << "<" << variable->name << " type=\"" << variable->handler->name << "\">"; variable->handler->serialize_xml(variable, out); out << "name << ">" << endl; } } } return 0; } class XmlEntity{ public: stringstream entity_data; struct dynvVariable *variable; struct dynvSystem* dynv; bool list_expected; struct dynvHandler *list_handler; bool first_item; XmlEntity(struct dynvVariable *_variable, struct dynvSystem* _dynv, bool _list_expected):entity_data(stringstream::out), variable(_variable), dynv(_dynv), list_expected(_list_expected){ list_handler = 0; first_item = true; }; }; class XmlCtx{ public: bool root_found; stack entity; struct dynvHandlerMap *handler_map; XmlCtx(){ root_found = false; handler_map = 0; }; ~XmlCtx(){ if (handler_map) dynv_handler_map_release(handler_map); for (; ! entity.empty(); entity.pop()) if (entity.top()) delete entity.top(); } }; static char* get_attribute(const XML_Char **atts, const char *attribute){ XML_Char **i = (XML_Char**)atts; while (*i){ if (strcmp(attribute, *i)==0){ return *(i+1); } i+=2; } return 0; } static void start_element_handler(XmlCtx *xml, const XML_Char *name, const XML_Char **atts){ if (xml->root_found){ XmlEntity *entity = xml->entity.top(); if (!entity) return; struct dynvVariable *variable; XmlEntity *n; if (entity->list_expected){ if (name && strcmp(name, "li")==0){ if (entity->first_item){ xml->entity.push(n = new XmlEntity(entity->variable, entity->dynv, false)); entity->first_item = false; }else{ variable = dynv_variable_create(0, entity->list_handler); variable->handler->create(variable); if (strcmp(entity->list_handler->name, "dynv") == 0){ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(entity->dynv); struct dynvSystem* dlevel_new = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); entity->list_handler->set(variable, dlevel_new, false); xml->entity.push(n = new XmlEntity(variable, dlevel_new, false)); dynv_system_release(dlevel_new); }else{ xml->entity.push(n = new XmlEntity(variable, entity->dynv, false)); } entity->variable->next = variable; entity->variable = variable; } }else{ xml->entity.push(0); } }else{ char* type = get_attribute(atts, "type"); char* list = get_attribute(atts, "list"); struct dynvHandler *handler = dynv_handler_map_get_handler(xml->handler_map, type); if (handler){ if (strcmp(type, "dynv")==0){ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(entity->dynv); struct dynvSystem* dlevel_new = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); if ((variable = dynv_system_add_empty(entity->dynv, handler, name))){ handler->set(variable, dlevel_new, false); } if (list && strcmp(list, "true")==0){ xml->entity.push(n = new XmlEntity(variable, dlevel_new, true)); n->list_handler = handler; }else{ xml->entity.push(n = new XmlEntity(variable, dlevel_new, false)); } dynv_system_release(dlevel_new); }else if (handler->deserialize_xml){ if (list && strcmp(list, "true")==0){ if ((variable = dynv_system_add_empty(entity->dynv, handler, name))){ xml->entity.push(n = new XmlEntity(variable, entity->dynv, true)); n->list_handler = handler; }else{ xml->entity.push(0); } }else{ if ((variable = dynv_system_add_empty(entity->dynv, handler, name))){ xml->entity.push(new XmlEntity(variable, entity->dynv, false)); }else{ xml->entity.push(0); } } }else{ /* not deserialize'able */ xml->entity.push(0); } }else{ /* unknown type */ xml->entity.push(0); } } //cout << name << "=" << type << endl; }else{ if (strcmp(name, "root")==0){ //XmlEntity *entity = xml->entity.top(); xml->root_found = true; //xml->entity.push(new XmlEntity(0, entity->dynv)); } } } static void end_element_handler(XmlCtx *xml, const XML_Char *name){ if (xml->root_found){ //cout << name << endl; XmlEntity *entity = xml->entity.top(); if (entity){ if (entity->list_expected){ if (entity->first_item){ //entry declared as list, but no list items defined dynv_system_remove(entity->dynv, entity->variable->name); } }else if (entity->variable){ if (entity->variable->handler->deserialize_xml) entity->variable->handler->deserialize_xml(entity->variable, entity->entity_data.str().c_str()); } delete entity; } xml->entity.pop(); } } static void character_data_handler(XmlCtx *xml, const XML_Char *s, int len){ //cout.write(s, len); XmlEntity *entity = xml->entity.top(); if (entity){ entity->entity_data.write(s, len); } } int dynv_xml_deserialize(struct dynvSystem* dynv_system, istream& in){ XML_Parser p = XML_ParserCreate("UTF-8"); XML_SetElementHandler(p, (XML_StartElementHandler)start_element_handler, (XML_EndElementHandler)end_element_handler); XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler)character_data_handler); XmlCtx ctx; ctx.entity.push(new XmlEntity(0, dynv_system, false)); ctx.handler_map = dynv_system_get_handler_map(dynv_system); XML_SetUserData(p, &ctx); for (;;){ void *buffer = XML_GetBuffer(p, 4096); in.read((char*)buffer, 4096); size_t bytes_read = in.gcount(); if (!XML_ParseBuffer(p, bytes_read, bytes_read==0)) { } if (bytes_read == 0) break; } XML_ParserFree(p); return 0; } int dynv_xml_escape(const char* data, std::ostream& out){ char* i = const_cast(data); char* last_esc = i; for (;;){ switch (*i){ case '&': if (last_esc != i) out.write(last_esc, uintptr_t(i)-uintptr_t(last_esc)); out << "&"; last_esc = i+1; break; case '<': if (last_esc != i) out.write(last_esc, uintptr_t(i)-uintptr_t(last_esc)); out << "<"; last_esc = i+1; break; case '>': if (last_esc != i) out.write(last_esc, uintptr_t(i)-uintptr_t(last_esc)); out << ">"; last_esc = i+1; break; case 0: if (last_esc != i) out.write(last_esc, uintptr_t(i)-uintptr_t(last_esc)); return 0; break; } ++i; } return 0; } gpick_0.2.5/source/dynv/DynvVarPtr.h0000644000175000017500000000323212070605214016112 0ustar zbygzbyg/* * 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 DYNVVARPTR_H_ #define DYNVVARPTR_H_ #include "DynvSystem.h" struct dynvHandler* dynv_var_ptr_new(); #endif /* DYNVVARPTR_H_ */ gpick_0.2.5/source/dynv/DynvXml.h0000644000175000017500000000351612070605214015441 0ustar zbygzbyg/* * 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 DYNVXML_H_ #define DYNVXML_H_ #include "DynvSystem.h" #include int dynv_xml_serialize(struct dynvSystem* dynv_system, std::ostream& out); int dynv_xml_deserialize(struct dynvSystem* dynv_system, std::istream& in); int dynv_xml_escape(const char* data, std::ostream& out); #endif /* DYNVXML_H_ */ gpick_0.2.5/source/dynv/DynvVarColor.cpp0000644000175000017500000001102212070605214016752 0ustar zbygzbyg/* * 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 "DynvVarColor.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" #include #include using namespace std; static int dynv_var_color_create(struct dynvVariable* variable){ if ((variable->ptr_value = new float[4])){ return 0; } return -1; } static int dynv_var_color_destroy(struct dynvVariable* variable){ if (variable->ptr_value){ delete [] (float*)variable->ptr_value; return 0; } return -1; } static int dynv_var_color_set(struct dynvVariable* variable, void* value, bool deref){ if (!variable->ptr_value) return -1; memcpy(variable->ptr_value, *(void**)value, sizeof(float[4])); /*((float*)variable->ptr_value)[0] = ((float*)value)[0]; ((float*)variable->ptr_value)[1] = ((float*)value)[1]; ((float*)variable->ptr_value)[2] = ((float*)value)[2]; ((float*)variable->ptr_value)[3] = ((float*)value)[3];*/ return 0; } static int dynv_var_color_get(struct dynvVariable* variable, void** value, bool *deref){ if (variable->ptr_value){ *value = &variable->ptr_value; return 0; } return -1; } static int dynv_var_color_serialize(struct dynvVariable* variable, struct dynvIO* io){ if (!variable->ptr_value) return -1; uint32_t written; uint32_t length=16; length=UINT32_TO_LE(length); dynv_io_write(io, &length, 4, &written); uint32_t value[4]; memcpy(value, variable->ptr_value, 16); value[0]=UINT32_TO_LE(value[0]); value[1]=UINT32_TO_LE(value[1]); value[2]=UINT32_TO_LE(value[2]); value[3]=UINT32_TO_LE(value[3]); if (dynv_io_write(io, value, 16, &written)==0){ if (written!=16) return -1; }else return -1; return 0; } static int dynv_var_color_deserialize(struct dynvVariable* variable, struct dynvIO* io){ if (!variable->ptr_value) return -1; uint32_t read; uint32_t length; uint32_t value[4]; dynv_io_read(io, &length, 4, &read); if (dynv_io_read(io, value, 16, &read)==0){ if (read==16){ value[0]=UINT32_FROM_LE(value[0]); value[1]=UINT32_FROM_LE(value[1]); value[2]=UINT32_FROM_LE(value[2]); value[3]=UINT32_FROM_LE(value[3]); memcpy(variable->ptr_value, value, 16); return 0; } } return -1; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ if (variable->ptr_value){ float* color = (float*)variable->ptr_value; out << color[0] <<" "<< color[1] <<" "<< color[2] <<" "<< color[3]; } return 0; } static int deserialize_xml(struct dynvVariable* variable, const char *data){ stringstream ss(stringstream::in); ss.str(data); float *c = (float*)variable->ptr_value; ss >> c[0] >> c[1] >> c[2] >> c[3]; return 0; } struct dynvHandler* dynv_var_color_new(){ struct dynvHandler* handler=dynv_handler_create("color"); handler->create=dynv_var_color_create; handler->destroy=dynv_var_color_destroy; handler->set=dynv_var_color_set; handler->get=dynv_var_color_get; handler->serialize=dynv_var_color_serialize; handler->deserialize=dynv_var_color_deserialize; handler->serialize_xml=serialize_xml; handler->deserialize_xml=deserialize_xml; handler->data_size = sizeof(float*); return handler; } gpick_0.2.5/source/dynv/DynvHandler.cpp0000644000175000017500000001170312070605214016606 0ustar zbygzbyg/* * 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 "DynvHandler.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" #include #include #include #include #include using namespace std; bool dynvHandlerMap::dynvKeyCompare::operator() (const char* const& x, const char* const& y) const { return strcmp(x,y)<0; } struct dynvHandler* dynv_handler_create(const char* name){ struct dynvHandler* handler=new struct dynvHandler; handler->name=strdup(name); handler->create=NULL; handler->destroy=NULL; handler->set=NULL; handler->serialize=NULL; handler->deserialize=NULL; handler->serialize_xml=NULL; handler->deserialize_xml=NULL; handler->get=NULL; return handler; } void dynv_handler_destroy(struct dynvHandler* handler){ free(handler->name); delete handler; } struct dynvHandlerMap* dynv_handler_map_create(){ struct dynvHandlerMap* handler_map=new struct dynvHandlerMap; handler_map->refcnt=0; return handler_map; } int dynv_handler_map_release(struct dynvHandlerMap* handler_map){ if (handler_map->refcnt){ handler_map->refcnt--; return -1; }else{ dynvHandlerMap::HandlerMap::iterator i; for (i=handler_map->handlers.begin(); i!=handler_map->handlers.end(); ++i){ dynv_handler_destroy((*i).second); } handler_map->handlers.clear(); delete handler_map; return 0; } } struct dynvHandlerMap* dynv_handler_map_ref(struct dynvHandlerMap* handler_map){ handler_map->refcnt++; return handler_map; } int dynv_handler_map_add_handler(struct dynvHandlerMap* handler_map, struct dynvHandler* handler){ dynvHandlerMap::HandlerMap::iterator i; i=handler_map->handlers.find(handler->name); if (i!=handler_map->handlers.end()){ return -1; }else{ handler_map->handlers[handler->name]=handler; return 0; } } struct dynvHandler* dynv_handler_map_get_handler(struct dynvHandlerMap* handler_map, const char* handler_name){ dynvHandlerMap::HandlerMap::iterator i; i=handler_map->handlers.find(handler_name); if (i!=handler_map->handlers.end()){ return (*i).second; }else{ return 0; } } int dynv_handler_map_serialize(struct dynvHandlerMap* handler_map, struct dynvIO* io){ dynvHandlerMap::HandlerMap::iterator i; uint32_t written, length; uint32_t id=0; uint32_t handler_count=handler_map->handlers.size(); handler_count=UINT32_TO_LE(handler_count); dynv_io_write(io, &handler_count, 4, &written); for (i=handler_map->handlers.begin(); i!=handler_map->handlers.end(); ++i){ struct dynvHandler* handler=(*i).second; length=strlen(handler->name); uint32_t length_le=UINT32_TO_LE(length); dynv_io_write(io, &length_le, 4, &written); dynv_io_write(io, handler->name, length, &written); handler->id=id; id++; } return 0; } int dynv_handler_map_deserialize(struct dynvHandlerMap* handler_map, struct dynvIO* io, dynvHandlerMap::HandlerVec& handler_vec){ uint32_t read; uint32_t handler_count; uint32_t length; char* name; struct dynvHandler* handler; if (dynv_io_read(io, &handler_count, 4, &read)==0){ if (read!=4) return -1; }else return -1; handler_count=UINT32_TO_LE(handler_count); handler_vec.resize(handler_count); for (uint32_t i=0; i!=handler_count; ++i){ dynv_io_read(io, &length, 4, &read); length=UINT32_TO_LE(length); name=new char [length+1]; dynv_io_read(io, name, length, &read); name[length]=0; handler=dynv_handler_map_get_handler(handler_map, name); handler_vec[i]=handler; //cout<<"Handler: "<< name< using namespace std; static int dynv_var_int32_create(struct dynvVariable* variable){ variable->int_value = 0; return 0; } static int dynv_var_int32_destroy(struct dynvVariable* variable){ return 0; } static int dynv_var_int32_set(struct dynvVariable* variable, void* value, bool deref){ variable->int_value = *((int32_t*)value); return 0; } static int dynv_var_int32_get(struct dynvVariable* variable, void** value, bool *deref){ *value = &variable->int_value; return 0; } static int dynv_var_int32_serialize(struct dynvVariable* variable, struct dynvIO* io){ uint32_t written; uint32_t length=4; length = UINT32_TO_LE(length); dynv_io_write(io, &length, 4, &written); int32_t value = UINT32_TO_LE(variable->int_value); if (dynv_io_write(io, &value, 4, &written)==0){ if (written == 4) return 0; } return -1; } static int dynv_var_int32_deserialize(struct dynvVariable* variable, struct dynvIO* io){ uint32_t read; int32_t value; dynv_io_read(io, &value, 4, &read); if (dynv_io_read(io, &value, 4, &read)==0){ if (read == 4){ variable->int_value = UINT32_FROM_LE(value); return 0; } } return -1; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ out << variable->int_value; return 0; } static int deserialize_xml(struct dynvVariable* variable, const char *data){ stringstream ss(stringstream::in); ss.str(data); ss >> variable->int_value; return 0; } struct dynvHandler* dynv_var_int32_new(){ struct dynvHandler* handler=dynv_handler_create("int32"); handler->create=dynv_var_int32_create; handler->destroy=dynv_var_int32_destroy; handler->set=dynv_var_int32_set; handler->get=dynv_var_int32_get; handler->serialize=dynv_var_int32_serialize; handler->deserialize=dynv_var_int32_deserialize; handler->serialize_xml = serialize_xml; handler->deserialize_xml = deserialize_xml; handler->data_size = sizeof(int32_t); return handler; } gpick_0.2.5/source/dynv/DynvIO.cpp0000644000175000017500000000304612070605214015541 0ustar zbygzbyg/* * 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 "DynvIO.h" gpick_0.2.5/source/dynv/DynvVarPtr.cpp0000644000175000017500000000461412070605214016452 0ustar zbygzbyg/* * 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 "DynvVarPtr.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" static int dynv_var_ptr_create(struct dynvVariable* variable){ variable->ptr_value = 0; return 0; } static int dynv_var_ptr_destroy(struct dynvVariable* variable){ return 0; } static int dynv_var_ptr_set(struct dynvVariable* variable, void* value, bool deref){ variable->ptr_value = *(void**)value; return 0; } static int dynv_var_ptr_get(struct dynvVariable* variable, void** value, bool *deref){ *value = &variable->ptr_value; return 0; } struct dynvHandler* dynv_var_ptr_new(){ struct dynvHandler* handler=dynv_handler_create("ptr"); handler->create=dynv_var_ptr_create; handler->destroy=dynv_var_ptr_destroy; handler->set=dynv_var_ptr_set; handler->get=dynv_var_ptr_get; handler->serialize=0; handler->deserialize=0; handler->data_size = sizeof(void*); return handler; } gpick_0.2.5/source/dynv/DynvVarBool.cpp0000644000175000017500000000554212070605214016601 0ustar zbygzbyg/* * 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 "DynvVarBool.h" #include "DynvVariable.h" #include "DynvIO.h" #include "../Endian.h" #include #include #include using namespace std; static int create(struct dynvVariable* variable){ variable->bool_value = false; return 0; } static int destroy(struct dynvVariable* variable){ return 0; } static int set(struct dynvVariable* variable, void* value, bool deref){ variable->bool_value = *(bool*)value; return 0; } static int get(struct dynvVariable* variable, void** value, bool *deref){ *value = &variable->bool_value; return 0; } static int serialize_xml(struct dynvVariable* variable, ostream& out){ if (variable->bool_value){ out << "true"; }else{ out << "false"; } return 0; } static int deserialize_xml(struct dynvVariable* variable, const char *data){ if (strcmp(data, "true")==0){ *(bool*)&variable->bool_value = true; }else{ *(bool*)&variable->bool_value = false; } return 0; } struct dynvHandler* dynv_var_bool_new(){ struct dynvHandler* handler=dynv_handler_create("bool"); handler->create=create; handler->destroy=destroy; handler->set=set; handler->get=get; //handler->serialize=serialize; //handler->deserialize=deserialize; handler->serialize_xml = serialize_xml; handler->deserialize_xml = deserialize_xml; handler->data_size = sizeof(bool); return handler; } gpick_0.2.5/source/dynv/DynvVariable.h0000644000175000017500000000424412070605214016425 0ustar zbygzbyg/* * 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 DYNVVARIABLE_H_ #define DYNVVARIABLE_H_ #include #ifndef _MSC_VER #include #endif struct dynvHandler; struct dynvVariable{ char* name; struct dynvHandler* handler; union{ void* ptr_value; bool bool_value; int32_t int_value; float float_value; }; enum Flags{ NO_SAVE = 0x01, READONLY = 0x02, DUMMY = 0xFFFFFFFF }flags; struct dynvVariable *next, *prev; }; struct dynvVariable* dynv_variable_create(const char* name, struct dynvHandler* handler); void dynv_variable_destroy(struct dynvVariable* variable); void dynv_variable_destroy_data(struct dynvVariable* variable); #endif /* DYNVVARIABLE_H_ */ gpick_0.2.5/source/dynv/DynvVarColor.h0000644000175000017500000000324312070605214016425 0ustar zbygzbyg/* * 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 DYNVVARCOLOR_H_ #define DYNVVARCOLOR_H_ #include "DynvHandler.h" struct dynvHandler* dynv_var_color_new(); #endif /* DYNVVARCOLOR_H_ */ gpick_0.2.5/source/uiUtilities.h0000644000175000017500000000403712070605214015370 0ustar zbygzbyg/* * 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 UIUTILITIES_H_ #define UIUTILITIES_H_ #include GtkWidget* gtk_menu_item_new_with_image(const gchar* label, GtkWidget *image); GtkWidget* gtk_label_aligned_new(const gchar* text, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale); GtkWidget* gtk_label_mnemonic_aligned_new(const gchar* text, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale); GtkWidget* gtk_widget_aligned_new(GtkWidget* widget, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale); #endif /* UIUTILITIES_H_ */ gpick_0.2.5/source/version/SConscript0000644000175000017500000000057512072047403016412 0ustar zbygzbyg#!/usr/bin/env python import os import sys Import('*') local_env = env.Clone() local_env.Append(CPPDEFINES = {'BUILD_DATE': env['GPICK_BUILD_DATE'], 'BUILD_REVISION': env['GPICK_BUILD_REVISION'], 'BUILD_PLATFORM': sys.platform, 'BUILD_VERSION': env['GPICK_BUILD_VERSION'], }) sources = local_env.Glob('*.cpp') objects = local_env.StaticObject([sources]) Return('objects') gpick_0.2.5/source/version/Version.h0000644000175000017500000000332412070605214016167 0ustar zbygzbyg/* * 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. */ extern const char* gpick_build_version; extern const char* gpick_build_revision; extern const char* gpick_build_date; extern const char* gpick_build_time; extern const char* gpick_build_platform; gpick_0.2.5/source/version/Version.cpp0000644000175000017500000000345512070605214016527 0ustar zbygzbyg/* * 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 "Version.h" #define TO_STRING(x) #x #define T_(x) TO_STRING(x) const char* gpick_build_version = T_(BUILD_VERSION); const char* gpick_build_revision = T_(BUILD_REVISION); const char* gpick_build_date = T_(BUILD_DATE); const char* gpick_build_platform = T_(BUILD_PLATFORM); gpick_0.2.5/source/ColorSource.h0000644000175000017500000000667312070605214015326 0ustar zbygzbyg/* * 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 COLORSOURCE_H_ #define COLORSOURCE_H_ #include "ColorObject.h" #include "GlobalStateStruct.h" #include typedef struct ColorSourceSlot{ const char *identificator; const char *hr_name; uint32_t id; struct{ bool read; bool write; }supports; }ColorSourceSlot; typedef struct ColorSource{ char *identificator; char *hr_name; int (*set_color)(ColorSource *source, ColorObject *color); int (*get_color)(ColorSource *source, ColorObject **color); int (*set_nth_color)(ColorSource *source, uint32_t color_n, ColorObject *color); int (*get_nth_color)(ColorSource *source, uint32_t color_n, ColorObject **color); int (*activate)(ColorSource *source); int (*deactivate)(ColorSource *source); int (*query_slots)(ColorSource *source, ColorSourceSlot *slot); int (*set_slot_color)(ColorSource *source, uint32_t slot_id, ColorObject *color); ColorSource* (*implement)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace); int (*destroy)(ColorSource *source); bool single_instance_only; bool needs_viewport; int default_accelerator; GtkWidget *widget; void* userdata; }ColorSource; int color_source_init(ColorSource* source, const char *identificator, const char *name); int color_source_activate(ColorSource *source); int color_source_deactivate(ColorSource *source); int color_source_set_color(ColorSource *source, ColorObject *color); int color_source_set_nth_color(ColorSource *source, uint32_t color_n, ColorObject *color); int color_source_get_color(ColorSource *source, ColorObject *color); int color_source_get_nth_color(ColorSource *source, uint32_t color_n, ColorObject **color); int color_source_get_default_accelerator(ColorSource *source); ColorSource* color_source_implement(ColorSource* source, GlobalState *gs, struct dynvSystem *dynv_namespace); GtkWidget* color_source_get_widget(ColorSource* source); int color_source_destroy(ColorSource* source); #endif /* COLORSOURCE_H_ */ gpick_0.2.5/source/Color.cpp0000644000175000017500000004534512070605214014477 0ustar zbygzbyg/* * 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 "Color.h" #include #include "MathUtil.h" #include using namespace std; // Constant used for lab->xyz transform. Should be calculated with maximum accuracy possible. #define EPSILON (216.0 / 24389.0) static vector3 references[][2] = { {{{{109.850, 100.000, 35.585}}}, {{{111.144, 100.000, 35.200}}}}, {{{{ 98.074, 100.000, 118.232}}}, {{{ 97.285, 100.000, 116.145}}}}, {{{{ 96.422, 100.000, 82.521}}}, {{{ 96.720, 100.000, 81.427}}}}, {{{{ 95.682, 100.000, 92.149}}}, {{{ 95.799, 100.000, 90.926}}}}, {{{{ 95.047, 100.000, 108.883}}}, {{{ 94.811, 100.000, 107.304}}}}, {{{{ 94.972, 100.000, 122.638}}}, {{{ 94.416, 100.000, 120.641}}}}, {{{{ 99.187, 100.000, 67.395}}}, {{{103.280, 100.000, 69.026}}}}, {{{{ 95.044, 100.000, 108.755}}}, {{{ 95.792, 100.000, 107.687}}}}, {{{{100.966, 100.000, 64.370}}}, {{{103.866, 100.000, 65.627}}}}, }; static matrix3x3 sRGB_transformation; static matrix3x3 sRGB_transformation_inverted; static matrix3x3 d65_d50_adaptation_matrix; static matrix3x3 d50_d65_adaptation_matrix; void color_init() { // constants used below are sRGB working space red, green and blue primaries for D65 reference white color_get_working_space_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &sRGB_transformation); matrix3x3_inverse(&sRGB_transformation, &sRGB_transformation_inverted); color_get_chromatic_adaptation_matrix(color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &d65_d50_adaptation_matrix); color_get_chromatic_adaptation_matrix(color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &d50_d65_adaptation_matrix); } void color_rgb_to_hsv(const Color* a, Color* b) { float min, max, delta; max = max_float_3(a->rgb.red, a->rgb.green, a->rgb.blue); min = min_float_3(a->rgb.red, a->rgb.green, a->rgb.blue); delta = max - min; b->hsv.value = max; if (max != 0.0f) b->hsv.saturation = delta / max; else b->hsv.saturation = 0.0f; if (b->hsv.saturation == 0.0f) { b->hsv.hue = 0.0f; } else { if (a->rgb.red == max) b->hsv.hue = (a->rgb.green - a->rgb.blue) / delta; else if (a->rgb.green == max) b->hsv.hue = 2.0f + (a->rgb.blue - a->rgb.red) / delta; else if (a->rgb.blue == max) b->hsv.hue = 4.0f + (a->rgb.red - a->rgb.green) / delta; b->hsv.hue /= 6.0f; if (b->hsv.hue < 0.0f) b->hsv.hue += 1.0f; if (b->hsv.hue >= 1.0f) b->hsv.hue -= 1.0f; } } void color_hsv_to_rgb(const Color* a, Color* b) { float h,v, f, x, y, z; int i; v = a->hsv.value; if (a->hsv.saturation == 0.0f) { b->rgb.red = b->rgb.green = b->rgb.blue = a->hsv.value; } else { h = (a->hsv.hue - floor(a->hsv.hue)) * 6.0f; i = int(h); f = h - floor(h); x = v * (1.0f - a->hsv.saturation) ; y = v * (1.0f - (a->hsv.saturation * f)); z = v * (1.0f - (a->hsv.saturation * (1.0f - f))); if (i==0){ b->rgb.red = v; b->rgb.green = z; b->rgb.blue = x; }else if (i==1){ b->rgb.red = y; b->rgb.green = v; b->rgb.blue = x; }else if (i==2){ b->rgb.red = x; b->rgb.green = v; b->rgb.blue = z; }else if (i==3){ b->rgb.red = x; b->rgb.green = y; b->rgb.blue = v; }else if (i==4){ b->rgb.red = z; b->rgb.green = x; b->rgb.blue = v; }else{ b->rgb.red = v; b->rgb.green = x; b->rgb.blue = y; } } } void color_rgb_to_xyz(const Color* a, Color* b, const matrix3x3* transformation) { float R=a->rgb.red, G=a->rgb.green, B=a->rgb.blue; if (R>0.04045){ R=pow(((R+0.055)/1.055),2.4); }else{ R=R/12.92; } if (G>0.04045){ G=pow(((G+0.055)/1.055),2.4); }else{ G=G/12.92; } if (B>0.04045){ B=pow(((B+0.055)/1.055),2.4); }else{ B=B/12.92; } vector3 rgb; rgb.x = R; rgb.y = G; rgb.z = B; vector3_multiply_matrix3x3(&rgb, transformation, &rgb); b->xyz.x = rgb.x; b->xyz.y = rgb.y; b->xyz.z = rgb.z; } void color_xyz_to_rgb(const Color* a, Color* b, const matrix3x3* transformation_inverted) { vector3 rgb; float R,G,B; vector3_multiply_matrix3x3((vector3*)a, transformation_inverted, &rgb); R=rgb.x; G=rgb.y; B=rgb.z; if (R>0.0031308){ R=1.055*(pow(R,1/2.4f))-0.055; }else{ R=12.92*R; } if (G>0.0031308){ G=1.055*(pow(G,1/2.4f))-0.055; }else{ G=12.92*G; } if(B>0.0031308){ B=1.055*(pow(B,1/2.4f))-0.055; }else{ B=12.92*B; } b->rgb.red=R; b->rgb.green=G; b->rgb.blue=B; } void color_rgb_to_lab(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation, const matrix3x3* adaptation_matrix) { Color c; color_rgb_to_xyz(a, &c, transformation); color_xyz_chromatic_adaptation(&c, &c, adaptation_matrix); color_xyz_to_lab(&c, b, reference_white); } void color_lab_to_rgb(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation_inverted, const matrix3x3* adaptation_matrix_inverted) { Color c; color_lab_to_xyz(a, &c, reference_white); color_xyz_chromatic_adaptation(&c, &c, adaptation_matrix_inverted); color_xyz_to_rgb(&c, b, transformation_inverted); } void color_copy(const Color* a, Color* b) { b->m.m1 = a->m.m1; b->m.m2 = a->m.m2; b->m.m3 = a->m.m3; b->m.m4 = a->m.m4; } void color_add(Color* a, const Color* b) { a->m.m1 += b->m.m1; a->m.m2 += b->m.m2; a->m.m3 += b->m.m3; a->m.m4 += b->m.m4; } void color_multiply(Color* a, float b) { a->m.m1 *= b; a->m.m2 *= b; a->m.m3 *= b; a->m.m4 *= b; } void color_zero(Color* a) { a->m.m1 = 0; a->m.m2 = 0; a->m.m3 = 0; a->m.m4 = 0; } void color_get_contrasting(const Color* a, Color* b) { Color t; color_rgb_to_lab(a, &t, color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &sRGB_transformation, &d65_d50_adaptation_matrix); if (t.lab.L > 50){ t.hsv.value=0; }else{ t.hsv.value=1; } t.hsv.saturation=0; t.hsv.hue=0; color_hsv_to_rgb(&t, b); } void color_set(Color* a, float value) { a->rgb.red = a->rgb.green = a->rgb.blue = value; } Color* color_new() { return new Color; } void color_destroy(Color *a) { delete a; } void color_rgb_to_hsl(const Color* a, Color* b) { float min, max, delta; min = min_float_3(a->rgb.red, a->rgb.green, a->rgb.blue); max = max_float_3(a->rgb.red, a->rgb.green, a->rgb.blue); delta = max - min; b->hsl.lightness = (max + min) / 2; if (delta == 0) { b->hsl.hue = 0; b->hsl.saturation = 0; } else { if (b->hsl.lightness < 0.5) { b->hsl.saturation = delta / (max + min); } else { b->hsl.saturation = delta / (2 - max - min); } if (a->rgb.red == max) b->hsv.hue = (a->rgb.green - a->rgb.blue) / delta; else if (a->rgb.green == max) b->hsv.hue = 2.0f + (a->rgb.blue - a->rgb.red) / delta; else if (a->rgb.blue == max) b->hsv.hue = 4.0f + (a->rgb.red - a->rgb.green) / delta; b->hsv.hue /= 6.0f; if (b->hsv.hue < 0.0f) b->hsv.hue += 1.0f; if (b->hsv.hue >= 1.0f) b->hsv.hue -= 1.0f; } } void color_hsl_to_rgb(const Color* a, Color* b) { if (a->hsl.saturation == 0) { b->rgb.red = b->rgb.green = b->rgb.blue = a->hsl.lightness; } else { float q, p, R, G, B; if (a->hsl.lightness < 0.5) q = a->hsl.lightness * (1.0 + a->hsl.saturation); else q = a->hsl.lightness + a->hsl.saturation - a->hsl.lightness * a->hsl.saturation; p = 2 * a->hsl.lightness - q; R = a->hsl.hue+1/3.0; G = a->hsl.hue; B = a->hsl.hue-1/3.0; if (R>1) R-=1; if (B<0) B+=1; if (6.0 * R < 1) b->rgb.red = p + (q - p) * 6.0 * R; else if (2.0 * R < 1) b->rgb.red = q; else if (3.0 * R < 2) b->rgb.red = p + (q - p) * ((2.0 / 3.0) - R) * 6.0; else b->rgb.red = p; if (6.0 * G < 1) b->rgb.green = p + (q - p) * 6.0 * G; else if (2.0 * G < 1) b->rgb.green = q; else if (3.0 * G < 2) b->rgb.green = p + (q - p) * ((2.0 / 3.0) - G) * 6.0; else b->rgb.green = p; if (6.0 * B < 1) b->rgb.blue = p + (q - p) * 6.0 * B; else if (2.0 * B < 1) b->rgb.blue = q; else if (3.0 * B < 2) b->rgb.blue = p + (q - p) * ((2.0 / 3.0) - B) * 6.0; else b->rgb.blue = p; } } void color_lab_to_lch(const Color* a, Color* b) { double H; if (a->lab.a == 0 && a->lab.b == 0){ H = 0; }else{ H = atan2(a->lab.b, a->lab.a); } H *= 180.0 / PI; if (H < 0) H += 360; if (H >= 360) H -= 360; b->lch.L = a->lab.L; b->lch.C = sqrt(a->lab.a * a->lab.a + a->lab.b * a->lab.b); b->lch.h = H; } void color_lch_to_lab(const Color* a, Color* b) { b->lab.L = a->lch.L; b->lab.a = a->lch.C * cos(a->lch.h * PI / 180.0); b->lab.b = a->lch.C * sin(a->lch.h * PI / 180.0); } void color_rgb_to_lch_d50(const Color* a, Color* b) { Color c; color_rgb_to_lab(a, &c, color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &sRGB_transformation, &d65_d50_adaptation_matrix); color_lab_to_lch(&c, b); } void color_lch_to_rgb_d50(const Color* a, Color* b) { Color c; color_lch_to_lab(a, &c); color_lab_to_rgb(&c, b, color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &sRGB_transformation_inverted, &d50_d65_adaptation_matrix); } void color_rgb_to_lch(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation, const matrix3x3* adaptation_matrix) { Color c; color_rgb_to_lab(a, &c, reference_white, transformation, adaptation_matrix); color_lab_to_lch(&c, b); } void color_lch_to_rgb(const Color* a, Color* b, const vector3* reference_white, const matrix3x3* transformation_inverted, const matrix3x3* adaptation_matrix_inverted) { Color c; color_lch_to_lab(a, &c); color_lab_to_rgb(&c, b, reference_white, transformation_inverted, adaptation_matrix_inverted); } void color_rgb_to_lab_d50(const Color* a, Color* b) { color_rgb_to_lab(a, b, color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &sRGB_transformation, &d65_d50_adaptation_matrix); } void color_lab_to_rgb_d50(const Color* a, Color* b) { color_lab_to_rgb(a, b, color_get_reference(REFERENCE_ILLUMINANT_D50, REFERENCE_OBSERVER_2), &sRGB_transformation_inverted, &d50_d65_adaptation_matrix); } #define Kk (24389.0 / 27.0) void color_xyz_to_lab(const Color* a, Color* b, const vector3* reference_white) { float X,Y,Z; X = a->xyz.x / reference_white->x; //95.047f; Y = a->xyz.y / reference_white->y; //100.000f; Z = a->xyz.z / reference_white->z; //108.883f; if (X>EPSILON){ X=pow(X,1.0f/3.0f); }else{ X=(Kk*X+16.0f)/116.0f; } if (Y>EPSILON){ Y=pow(Y,1.0f/3.0f); }else{ Y=(Kk*Y+16.0f)/116.0f; } if (Z>EPSILON){ Z=pow(Z,1.0f/3.0f); }else{ Z=(Kk*Z+16.0f)/116.0f; } b->lab.L=(116*Y)-16; b->lab.a=500*(X-Y); b->lab.b=200*(Y-Z); } void color_lab_to_xyz(const Color* a, Color* b, const vector3* reference_white) { float x, y, z; float fy = (a->lab.L + 16) / 116; float fx = a->lab.a / 500 + fy; float fz = fy - a->lab.b / 200; const double K=(24389.0 / 27.0); if (pow(fx, 3)>EPSILON){ x=pow(fx, 3); }else{ x=(116*fx-16)/K; } if (a->lab.L > K*EPSILON){ y=pow((a->lab.L+16)/116, 3); }else{ y=a->lab.L/K; } if (pow(fz, 3)>EPSILON){ z=pow(fz, 3); }else{ z=(116*fz-16)/K; } b->xyz.x = x * reference_white->x; //95.047f; b->xyz.y = y * reference_white->y; //100.000f; b->xyz.z = z * reference_white->z; //108.883f; } void color_get_working_space_matrix(float xr, float yr, float xg, float yg, float xb, float yb, const vector3* reference_white, matrix3x3* result) { float Xr,Yr,Zr; float Xg,Yg,Zg; float Xb,Yb,Zb; Xr=xr/yr; Yr=1; Zr=(1-xr-yr)/yr; Xg=xg/yg; Yg=1; Zg=(1-xg-yg)/yg; Xb=xb/yb; Yb=1; Zb=(1-xb-yb)/yb; vector3 v; v.x=reference_white->x; v.y=reference_white->y; v.z=reference_white->z; matrix3x3 m_inv; m_inv.m[0][0]=Xr; m_inv.m[1][0]=Yr; m_inv.m[2][0]=Zr; m_inv.m[0][1]=Xg; m_inv.m[1][1]=Yg; m_inv.m[2][1]=Zg; m_inv.m[0][2]=Xb; m_inv.m[1][2]=Yb; m_inv.m[2][2]=Zb; matrix3x3_inverse(&m_inv, &m_inv); vector3_multiply_matrix3x3(&v, &m_inv, &v); result->m[0][0]=Xr*v.x; result->m[1][0]=Yr*v.x; result->m[2][0]=Zr*v.x; result->m[0][1]=Xg*v.y; result->m[1][1]=Yg*v.y; result->m[2][1]=Zg*v.y; result->m[0][2]=Xb*v.z; result->m[1][2]=Yb*v.z; result->m[2][2]=Zb*v.z; } void color_get_chromatic_adaptation_matrix(const vector3* source_reference_white, const vector3* destination_reference_white, matrix3x3* result) { matrix3x3 Ma; //Bradford matrix Ma.m[0][0]= 0.8951; Ma.m[1][0]=-0.7502; Ma.m[2][0]= 0.0389; Ma.m[0][1]= 0.2664; Ma.m[1][1]= 1.7135; Ma.m[2][1]=-0.0685; Ma.m[0][2]=-0.1614; Ma.m[1][2]= 0.0367; Ma.m[2][2]= 1.0296; matrix3x3 Ma_inv; //Bradford inverted matrix Ma_inv.m[0][0]= 0.986993; Ma_inv.m[1][0]= 0.432305; Ma_inv.m[2][0]=-0.008529; Ma_inv.m[0][1]=-0.147054; Ma_inv.m[1][1]= 0.518360; Ma_inv.m[2][1]= 0.040043; Ma_inv.m[0][2]= 0.159963; Ma_inv.m[1][2]= 0.049291; Ma_inv.m[2][2]= 0.968487; vector3 Vs, Vd; vector3_multiply_matrix3x3(source_reference_white, &Ma, &Vs); vector3_multiply_matrix3x3(destination_reference_white, &Ma, &Vd); matrix3x3 M; matrix3x3_identity(&M); M.m[0][0]=Vd.x / Vs.x; M.m[1][1]=Vd.y / Vs.y; M.m[2][2]=Vd.z / Vs.z; matrix3x3_multiply(&Ma, &M, &M); matrix3x3_multiply(&M, &Ma_inv, result); } void color_xyz_chromatic_adaptation(const Color* a, Color* result, const matrix3x3* adaptation) { vector3 x; x.x=a->xyz.x; x.y=a->xyz.y; x.z=a->xyz.z; vector3_multiply_matrix3x3(&x, adaptation, &x); result->xyz.x=x.x; result->xyz.y=x.y; result->xyz.z=x.z; } void color_rgb_to_cmy(const Color* a, Color* b) { b->cmy.c = 1 - a->rgb.red; b->cmy.m = 1 - a->rgb.green; b->cmy.y = 1 - a->rgb.blue; } void color_cmy_to_rgb(const Color* a, Color* b) { b->rgb.red = 1 - a->cmy.c; b->rgb.green = 1 - a->cmy.m; b->rgb.blue = 1 - a->cmy.y; } void color_cmy_to_cmyk(const Color* a, Color* b) { float k = 1; if (a->cmy.c < k) k = a->cmy.c; if (a->cmy.m < k) k = a->cmy.m; if (a->cmy.y < k) k = a->cmy.y; if (k == 1){ b->cmyk.c = b->cmyk.m = b->cmyk.y = 0; }else{ b->cmyk.c = (a->cmy.c - k) / (1 - k); b->cmyk.m = (a->cmy.m - k) / (1 - k); b->cmyk.y = (a->cmy.y - k) / (1 - k); } b->cmyk.k = k; } void color_cmyk_to_cmy(const Color* a, Color* b) { b->cmy.c = (a->cmyk.c * (1 - a->cmyk.k) + a->cmyk.k); b->cmy.m = (a->cmyk.m * (1 - a->cmyk.k) + a->cmyk.k); b->cmy.y = (a->cmyk.y * (1 - a->cmyk.k) + a->cmyk.k); } void color_rgb_to_cmyk(const Color* a, Color* b) { Color c; color_rgb_to_cmy(a, &c); color_cmy_to_cmyk(&c, b); } void color_cmyk_to_rgb(const Color* a, Color* b) { Color c; color_cmyk_to_cmy(a, &c); color_cmy_to_rgb(&c, b); } void color_rgb_normalize(Color* a) { a->rgb.red = clamp_float(a->rgb.red, 0, 1); a->rgb.green = clamp_float(a->rgb.green, 0, 1); a->rgb.blue = clamp_float(a->rgb.blue, 0, 1); } void color_hsl_to_hsv(const Color *a, Color *b) { float l = a->hsl.lightness * 2.0; float s = a->hsl.saturation * ((l <= 1.0) ? (l) : (2.0 - l)); b->hsv.hue = a->hsl.hue; if (l + s == 0){ b->hsv.value = 0; b->hsv.saturation = 1; }else{ b->hsv.value = (l + s) / 2.0; b->hsv.saturation = (2.0 * s) / (l + s); } } void color_hsv_to_hsl(const Color *a, Color *b) { float l = (2.0 - a->hsv.saturation) * a->hsv.value; float s = (a->hsv.saturation * a->hsv.value) / ((l <= 1.0) ? (l) : (2 - l)); if (l == 0) s = 0; b->hsl.hue = a->hsv.hue; b->hsl.saturation = s; b->hsl.lightness = l / 2.0; } void color_rgb_get_linear(const Color* a, Color* b) { b->rgb.red = pow(a->rgb.red, 1.0f / 2.1f); b->rgb.green = pow(a->rgb.green, 1.0f / 2.0f); b->rgb.blue = pow(a->rgb.blue, 1.0f / 2.1f); } void color_linear_get_rgb(const Color* a, Color* b) { b->rgb.red = pow(a->rgb.red, 2.1f); b->rgb.green = pow(a->rgb.green, 2.0f); b->rgb.blue = pow(a->rgb.blue, 2.1f); } const matrix3x3* color_get_sRGB_transformation_matrix() { return &sRGB_transformation; } const matrix3x3* color_get_inverted_sRGB_transformation_matrix() { return &sRGB_transformation_inverted; } const matrix3x3* color_get_d65_d50_adaptation_matrix() { return &d65_d50_adaptation_matrix; } const matrix3x3* color_get_d50_d65_adaptation_matrix() { return &d50_d65_adaptation_matrix; } const vector3* color_get_reference(ReferenceIlluminant illuminant, ReferenceObserver observer) { return &references[illuminant][observer]; } const ReferenceIlluminant color_get_illuminant(const char *illuminant) { const struct{ const char *label; ReferenceIlluminant illuminant; }illuminants[] = { {"A", REFERENCE_ILLUMINANT_A}, {"C", REFERENCE_ILLUMINANT_C}, {"D50", REFERENCE_ILLUMINANT_D50}, {"D55", REFERENCE_ILLUMINANT_D55}, {"D65", REFERENCE_ILLUMINANT_D65}, {"D75", REFERENCE_ILLUMINANT_D75}, {"F2", REFERENCE_ILLUMINANT_F2}, {"F7", REFERENCE_ILLUMINANT_F7}, {"F11", REFERENCE_ILLUMINANT_F11}, {0, REFERENCE_ILLUMINANT_D50}, }; for (int i = 0; illuminants[i].label; i++){ if (string(illuminants[i].label).compare(illuminant) == 0){ return illuminants[i].illuminant; } } return REFERENCE_ILLUMINANT_D50; }; const ReferenceObserver color_get_observer(const char *observer) { const struct{ const char *label; ReferenceObserver observer; }observers[] = { {"2", REFERENCE_OBSERVER_2}, {"10", REFERENCE_OBSERVER_10}, {0, REFERENCE_OBSERVER_2}, }; for (int i = 0; observers[i].label; i++){ if (string(observers[i].label).compare(observer) == 0){ return observers[i].observer; } } return REFERENCE_OBSERVER_2; } bool color_is_rgb_out_of_gamut(const Color* a) { if (a->rgb.red < 0 || a->rgb.red > 1) return true; if (a->rgb.green < 0 || a->rgb.green > 1) return true; if (a->rgb.blue < 0 || a->rgb.blue > 1) return true; return false; } gpick_0.2.5/source/ColorList.h0000644000175000017500000000573412070605214014776 0ustar zbygzbyg/* * 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 COLORLIST_H_ #define COLORLIST_H_ #include "ColorObject.h" #include "dynv/DynvSystem.h" #include struct ColorList{ std::list colors; typedef std::list::iterator iter; struct dynvSystem* params; int (*on_insert)(struct ColorList* color_list, struct ColorObject* color_object); int (*on_delete)(struct ColorList* color_list, struct ColorObject* color_object); int (*on_delete_selected)(struct ColorList* color_list); int (*on_change)(struct ColorList* color_list, struct ColorObject* color_object); int (*on_clear)(struct ColorList* color_list); int (*on_get_positions)(struct ColorList* color_list); void* userdata; }; struct ColorList* color_list_new(struct dynvHandlerMap* handler_map); void color_list_destroy(struct ColorList* color_list); struct ColorObject* color_list_new_color_object(struct ColorList* color_list, Color* color); struct ColorObject* color_list_add_color(struct ColorList* color_list, Color* color); int color_list_add_color_object(struct ColorList* color_list, struct ColorObject* color_object, int add_to_palette); int color_list_remove_color_object(struct ColorList* color_list, struct ColorObject* color_object); int color_list_remove_selected(struct ColorList* color_list); int color_list_remove_all(struct ColorList* color_list); unsigned long color_list_get_count(struct ColorList* color_list); int color_list_get_positions(struct ColorList* color_list); #endif /* COLORLIST_H_ */ gpick_0.2.5/source/uiDialogAutonumber.cpp0000644000175000017500000002045412070605214017212 0ustar zbygzbyg/* * 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 "uiDialogAutonumber.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "MathUtil.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "ColorRYB.h" #include "Noise.h" #include "GenerateScheme.h" #include "Internationalisation.h" #include #include #include using namespace std; typedef struct DialogAutonumberArgs{ GtkWidget *name; GtkWidget *nplaces; GtkWidget *startindex; GtkWidget *toggle_decreasing; GtkWidget *toggle_append; uint32_t selected_count; GtkWidget *sample; struct dynvSystem *params; GlobalState* gs; }DialogAutonumberArgs; static int default_nplaces (uint32_t selected_count){ uint32_t places = 1; uint32_t ncolors = selected_count; // technically this can be implemented as `places = 1 + (int) (trunc(log (ncolors,10)));` // however I don't know the exact function names, and this has minimal dependencies and acceptable speed. while (ncolors > 10) { ncolors = ncolors / 10; places += 1; } return places; } static void update(GtkWidget *widget, DialogAutonumberArgs *args ){ uint32_t nplaces = gtk_spin_button_get_value (GTK_SPIN_BUTTON(args->nplaces)); int startindex = gtk_spin_button_get_value (GTK_SPIN_BUTTON(args->startindex)); const char *name = gtk_entry_get_text(GTK_ENTRY(args->name)); stringstream ss; ss << name << "-"; ss.fill('0'); ss.width(nplaces); ss << right << startindex; gtk_entry_set_text(GTK_ENTRY(args->sample), ss.str().c_str()); dynv_set_string (args->params, "name", name); dynv_set_bool (args->params, "append", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_append))); dynv_set_bool (args->params, "decreasing", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_decreasing))); dynv_set_int32 (args->params, "nplaces", nplaces); dynv_set_int32 (args->params, "startindex", startindex); } static void update_startindex(GtkWidget *widget, DialogAutonumberArgs *args ){ int startindex = gtk_spin_button_get_value (GTK_SPIN_BUTTON(args->startindex)); int newindex; gdouble min, max; gtk_spin_button_get_range(GTK_SPIN_BUTTON(args->startindex), &min, &max); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))){ if (startindex == 0){ newindex = args->selected_count; }else{ newindex = args->selected_count + (startindex - 1); } min = args->selected_count; }else{ newindex = (startindex + 1) - args->selected_count; min = 1; } gtk_spin_button_set_range(GTK_SPIN_BUTTON(args->startindex), min, max); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->startindex), newindex); update(widget, args); } int dialog_autonumber_show(GtkWindow* parent, uint32_t selected_count, GlobalState* gs){ DialogAutonumberArgs *args = new DialogAutonumberArgs; int return_val; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick.autonumber"); args->selected_count = selected_count; GtkWidget *table; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Autonumber colors"), 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(4, 4, FALSE); table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Name:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->name = gtk_entry_new(); // dynv_get_str_wd? gtk_entry_set_text (GTK_ENTRY(args->name), dynv_get_string_wd (args->params, "name", "autonum")); g_signal_connect (G_OBJECT (args->name), "changed", G_CALLBACK(update), args); gtk_table_attach(GTK_TABLE(table), args->name,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(_("Decimal places:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->nplaces = gtk_spin_button_new_with_range (1, 6, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->nplaces), dynv_get_int32_wd(args->params, "nplaces", default_nplaces (selected_count))); gtk_table_attach(GTK_TABLE(table), args->nplaces,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect(G_OBJECT (args->nplaces), "value-changed", G_CALLBACK (update), args); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Starting number:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->startindex = gtk_spin_button_new_with_range (1, 0x7fffffff, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->startindex), dynv_get_int32_wd(args->params, "startindex", 1)); gtk_table_attach(GTK_TABLE(table), args->startindex,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect(G_OBJECT (args->startindex), "value-changed", G_CALLBACK (update), args); table_y++; args->toggle_decreasing = gtk_check_button_new_with_mnemonic (_("_Decreasing")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_decreasing), dynv_get_bool_wd(args->params, "decreasing", false)); gtk_table_attach(GTK_TABLE(table), args->toggle_decreasing,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_decreasing), "toggled", G_CALLBACK (update_startindex), args); table_y++; args->toggle_append = gtk_check_button_new_with_mnemonic (_("_Append")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_append), dynv_get_bool_wd(args->params, "append", false)); gtk_table_attach(GTK_TABLE(table), args->toggle_append,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_append), "toggled", G_CALLBACK (update), args); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Sample:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GtkAttachOptions(GTK_FILL | GTK_EXPAND),5,5); args->sample = gtk_entry_new(); gtk_entry_set_editable (GTK_ENTRY(args->sample), false); gtk_widget_set_sensitive(args->sample, false); gtk_table_attach(GTK_TABLE(table), args->sample,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); update(0, args); gtk_widget_show_all(table); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table); return_val = gtk_dialog_run(GTK_DIALOG(dialog)); 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); gtk_widget_destroy(dialog); dynv_system_release(args->params); delete args; return return_val; } gpick_0.2.5/source/uiListPalette.cpp0000644000175000017500000010516412113713537016213 0ustar zbygzbyg/* * 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 "uiListPalette.h" #include "uiUtilities.h" #include "gtk/ColorCell.h" #include "ColorSource.h" #include "DragDrop.h" #include "GlobalState.h" #include "uiApp.h" #include "GlobalStateStruct.h" #include "DynvHelpers.h" #include "Vector2.h" #include "Internationalisation.h" #include #include #include #include using namespace math; using namespace std; typedef struct ListPaletteArgs{ ColorSource source; GtkWidget *treeview; gint scroll_timeout; Vec2 last_click_position; bool disable_selection; GtkWidget* count_label; GlobalState* gs; }ListPaletteArgs; static void destroy_arguments(gpointer data); static struct ColorObject* get_color_object(struct DragDrop* dd); static struct ColorObject** get_color_object_list(struct DragDrop* dd, uint32_t *colorobject_n); #define SCROLL_EDGE_SIZE 15 //SCROLL_EDGE_SIZE from gtktreeview.c static void add_scroll_timeout(ListPaletteArgs *args); static void remove_scroll_timeout(ListPaletteArgs *args); static gboolean scroll_row_timeout(ListPaletteArgs *args); static void palette_list_vertical_autoscroll(GtkTreeView *treeview); static void update_counts(ListPaletteArgs *args); static gboolean scroll_row_timeout(ListPaletteArgs *args){ palette_list_vertical_autoscroll(GTK_TREE_VIEW(args->treeview)); return true; } static void add_scroll_timeout(ListPaletteArgs *args){ if (!args->scroll_timeout){ args->scroll_timeout = gdk_threads_add_timeout(150, (GSourceFunc)scroll_row_timeout, args); } } static void remove_scroll_timeout(ListPaletteArgs *args){ if (args->scroll_timeout){ g_source_remove(args->scroll_timeout); args->scroll_timeout = 0; } } static bool drag_end(struct DragDrop* dd, GtkWidget *widget, GdkDragContext *context){ remove_scroll_timeout((ListPaletteArgs*)dd->userdata); update_counts((ListPaletteArgs*)dd->userdata); return true; } typedef struct SelectionBoundsArgs{ int min_index; int max_index; int last_index; bool discontinuous; } SelectionBoundsArgs; static void find_selection_bounds(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data){ gint *indices = gtk_tree_path_get_indices(path); SelectionBoundsArgs *args = (SelectionBoundsArgs *) data; int index = indices[0]; // currently indices are all 1d. int diff = index - args->last_index; if ((args->last_index != 0x7fffffff) && (diff != 1) && (diff != -1)){ args->discontinuous = true; } if (index > args->max_index){ args->max_index = index; } if (index < args->min_index){ args->min_index = index; } args->last_index = index; } 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 void update_counts(ListPaletteArgs *args){ stringstream s; GtkTreeSelection *sel; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(args->treeview)); SelectionBoundsArgs bounds; int selected_count; int total_colors; if (!args->count_label){ return; } sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(args->treeview)); selected_count = gtk_tree_selection_count_selected_rows(sel); total_colors = gtk_tree_model_iter_n_children(model, NULL); bounds.discontinuous = false; bounds.min_index = 0x7fffffff; bounds.last_index = 0x7fffffff; bounds.max_index = 0; if (selected_count > 0){ s.str(""); s << "#"; gtk_tree_selection_selected_foreach(sel, &find_selection_bounds, &bounds); if (bounds.min_index < bounds.max_index){ s << bounds.min_index; if (bounds.discontinuous){ s << ".."; }else{ s << "-"; } s << bounds.max_index; }else{ s << bounds.min_index; } #ifdef ENABLE_NLS string selected_color_count; try{ selected_color_count = (format_ignore_arg_errors(ngettext("%d color", "%d colors", selected_count)) % selected_count).str(); }catch(const boost::io::format_error &e){ selected_color_count = ngettext("%d color", "%d colors", selected_count); } s << " (" << selected_color_count << ")"; #else s << " (" << ((selected_count == 1) ? "color" : "colors") << ")"; #endif s << " " << _("selected") << ". "; } #ifdef ENABLE_NLS string total_color_count; try{ total_color_count = (format_ignore_arg_errors(ngettext("Total %d color", "Total %d colors", total_colors)) % total_colors).str(); }catch(const boost::io::format_error &e){ total_color_count = ngettext("Total %d color", "Total %d colors", total_colors); } s << total_color_count; #else s << "Total " << total_colors << " colors."; #endif gtk_label_set_text(GTK_LABEL(args->count_label), s.str().c_str()); } static void palette_list_vertical_autoscroll(GtkTreeView *treeview){ GdkRectangle visible_rect; gint y; gint offset; gdk_window_get_pointer(gtk_tree_view_get_bin_window(treeview), NULL, &y, NULL); gint dy; gtk_tree_view_convert_bin_window_to_tree_coords(treeview, 0, 0, 0, &dy); y += dy; gtk_tree_view_get_visible_rect(treeview, &visible_rect); offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE); if (offset > 0) { offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE); if (offset < 0) return; } GtkAdjustment *adjustment = gtk_tree_view_get_vadjustment(treeview); gtk_adjustment_set_value(adjustment, min(max(gtk_adjustment_get_value(adjustment) + offset, 0.0), gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size (adjustment))); } static void palette_list_entry_fill(GtkListStore* store, GtkTreeIter *iter, struct ColorObject* color_object, ListPaletteArgs* args){ Color color; color_object_get_color(color_object, &color); gchar* text = main_get_color_text(args->gs, &color, COLOR_TEXT_TYPE_COLOR_LIST); const char* name = dynv_get_string_wd(color_object->params, "name", ""); gtk_list_store_set(store, iter, 0, color_object_ref(color_object), 1, text, 2, name, -1); if (text) g_free(text); } static void palette_list_entry_update_row(GtkListStore* store, GtkTreeIter *iter, struct ColorObject* color_object, ListPaletteArgs* args){ Color color; color_object_get_color(color_object, &color); gchar* text = main_get_color_text(args->gs, &color, COLOR_TEXT_TYPE_COLOR_LIST); const char* name = dynv_get_string_wd(color_object->params, "name", ""); gtk_list_store_set(store, iter, 1, text, 2, name, -1); if (text) g_free(text); } static void palette_list_entry_update_name(GtkListStore* store, GtkTreeIter *iter, struct ColorObject* color_object){ const char* name = dynv_get_string_wd(color_object->params, "name", ""); gtk_list_store_set(store, iter, 2, name, -1); } static void palette_list_cell_edited(GtkCellRendererText *cell, gchar *path, gchar *new_text, gpointer user_data) { GtkTreeIter iter; GtkTreeModel *model=GTK_TREE_MODEL(user_data); gtk_tree_model_get_iter_from_string(model, &iter, path ); gtk_list_store_set(GTK_LIST_STORE(model), &iter, 2, new_text, -1); struct ColorObject *color_object; gtk_tree_model_get(model, &iter, 0, &color_object, -1); dynv_set_string(color_object->params, "name", new_text); } static void palette_list_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { ListPaletteArgs* args = (ListPaletteArgs*)user_data; GtkTreeModel* model; GtkTreeIter iter; model=gtk_tree_view_get_model(tree_view); gtk_tree_model_get_iter(model, &iter, path); struct ColorObject *color_object; gtk_tree_model_get(model, &iter, 0, &color_object, -1); ColorSource *color_source = (ColorSource*)dynv_get_pointer_wd(args->gs->params, "CurrentColorSource", 0); color_source_set_color(color_source, color_object); update_counts(args); } static int palette_list_preview_on_insert(struct ColorList* color_list, struct ColorObject* color_object){ palette_list_add_entry(GTK_WIDGET(color_list->userdata), color_object); return 0; } static int palette_list_preview_on_clear(struct ColorList* color_list){ palette_list_remove_all_entries(GTK_WIDGET(color_list->userdata)); return 0; } static void destroy_cb(GtkWidget* widget, ListPaletteArgs *args){ remove_scroll_timeout(args); palette_list_remove_all_entries(widget); } GtkWidget* palette_list_get_widget(struct ColorList *color_list){ return (GtkWidget*)color_list->userdata; } GtkWidget* palette_list_preview_new(GlobalState* gs, bool expander, bool expanded, struct ColorList* color_list, struct ColorList** out_color_list){ ListPaletteArgs* args = new ListPaletteArgs; args->gs = gs; args->scroll_timeout = 0; args->count_label = NULL; GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *col; GtkWidget *view; view = gtk_tree_view_new(); args->treeview = view; gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), 0); store = gtk_list_store_new (3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col, 0); renderer = custom_cell_renderer_color_new(); custom_cell_renderer_color_set_size(renderer, 16, 16); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "color", 0); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), false); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(GTK_TREE_MODEL(store)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); gtk_drag_source_set(view, GDK_BUTTON1_MASK, 0, 0, GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK)); struct DragDrop dd; dragdrop_init(&dd, gs); dd.get_color_object = get_color_object; dd.get_color_object_list = get_color_object_list; dd.drag_end = drag_end; dd.handler_map = dynv_system_get_handler_map(gs->colors->params); dd.userdata = args; dragdrop_widget_attach(view, DragDropFlags(DRAGDROP_SOURCE), &dd); if (out_color_list) { struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(color_list->params); struct ColorList* cl=color_list_new(handler_map); dynv_handler_map_release(handler_map); cl->userdata=view; cl->on_insert=palette_list_preview_on_insert; cl->on_clear=palette_list_preview_on_clear; *out_color_list=cl; } GtkWidget *scrolled_window; scrolled_window=gtk_scrolled_window_new (0,0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(scrolled_window), view); GtkWidget *main_widget = scrolled_window; if (expander){ GtkWidget *expander=gtk_expander_new(_("Preview")); gtk_container_add(GTK_CONTAINER(expander), scrolled_window); gtk_expander_set_expanded(GTK_EXPANDER(expander), expanded); main_widget = expander; } g_object_set_data_full(G_OBJECT(view), "arguments", args, destroy_arguments); g_signal_connect(G_OBJECT(view), "destroy", G_CALLBACK(destroy_cb), args); return main_widget; } static struct ColorObject** get_color_object_list(struct DragDrop* dd, uint32_t *colorobject_n){ GtkTreeIter iter; GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->widget)); GtkTreeModel* model; gint selected = gtk_tree_selection_count_selected_rows(selection); if (selected <= 1){ if (colorobject_n) *colorobject_n = selected; return 0; } GList *list = gtk_tree_selection_get_selected_rows(selection, &model); struct ColorObject** color_objects = new struct ColorObject*[selected]; if (colorobject_n) *colorobject_n = selected; if (list){ GList *i = list; struct ColorObject* color_object; uint32_t j = 0; while (i) { gtk_tree_model_get_iter(model, &iter, (GtkTreePath*) (i->data)); gtk_tree_model_get(model, &iter, 0, &color_object, -1); color_objects[j] = color_object_ref(color_object); i = g_list_next(i); j++; } g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL); g_list_free (list); } return color_objects; } static struct ColorObject* get_color_object(struct DragDrop* dd){ GtkTreeIter iter; GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->widget)); GtkTreeModel* model; GList *list = gtk_tree_selection_get_selected_rows ( selection, &model ); if (list){ GList *i = list; struct ColorObject* color_object; while (i) { gtk_tree_model_get_iter(model, &iter, (GtkTreePath*) (i->data)); gtk_tree_model_get(model, &iter, 0, &color_object, -1); g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL); g_list_free (list); return color_object_ref(color_object); i = g_list_next(i); } g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL); g_list_free (list); } return 0; } static int set_color_object_list_at(struct DragDrop* dd, struct ColorObject** colorobjects, uint32_t colorobject_n, int x, int y, bool move){ ListPaletteArgs* args = (ListPaletteArgs*)dd->userdata; remove_scroll_timeout(args); GtkTreePath* path; GtkTreeViewDropPosition pos; GtkTreeIter iter, iter2; GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(dd->widget)); bool copy = false; bool path_is_valid = false; if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(dd->widget), x, y, &path, &pos)){ gtk_tree_model_get_iter(model, &iter, path); if (pos==GTK_TREE_VIEW_DROP_BEFORE || pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ path_is_valid = true; }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ path_is_valid = true; }else{ return -1; } } for (uint32_t i = 0; i != colorobject_n; i++){ struct ColorObject *colorobject = 0; if (pos==GTK_TREE_VIEW_DROP_BEFORE || pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ colorobject = colorobjects[i]; }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ colorobject = colorobjects[colorobject_n - i - 1]; }else{ colorobject = colorobjects[i]; } if (move){ struct ColorObject *reference_color_object; gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &reference_color_object, -1); if (reference_color_object == colorobject){ // Reference item is going to be removed, so any further inserts // will fail if the same iterator is used. Iterator is moved forward // to avoid that. if (pos==GTK_TREE_VIEW_DROP_BEFORE || pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)){ path_is_valid = false; } }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), &iter); if (gtk_tree_path_prev(path)) { if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path)){ path_is_valid = false; } }else{ path_is_valid = false; } gtk_tree_path_free(path); } } if (colorobject->refcnt != 1){ //only one reference, can't be in palette color_list_remove_color_object(args->gs->colors, colorobject); } }else{ colorobject = color_object_copy(colorobject); copy = true; } if (path_is_valid){ if (pos==GTK_TREE_VIEW_DROP_BEFORE || pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ gtk_list_store_insert_before(GTK_LIST_STORE(model), &iter2, &iter); palette_list_entry_fill(GTK_LIST_STORE(model), &iter2, colorobject, args); color_list_add_color_object(args->gs->colors, colorobject, false); }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ gtk_list_store_insert_after(GTK_LIST_STORE(model), &iter2, &iter); palette_list_entry_fill(GTK_LIST_STORE(model), &iter2, colorobject, args); color_list_add_color_object(args->gs->colors, colorobject, false); }else{ if (copy) color_object_release(colorobject); return -1; } }else{ color_list_add_color_object(args->gs->colors, colorobject, true); if (copy) color_object_release(colorobject); } } update_counts(args); return 0; } static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){ ListPaletteArgs* args = (ListPaletteArgs*)dd->userdata; remove_scroll_timeout((ListPaletteArgs*)dd->userdata); GtkTreePath* path; GtkTreeViewDropPosition pos; GtkTreeIter iter, iter2; GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(dd->widget)); bool copy = false; if (move){ if (colorobject->refcnt != 1){ //only one reference, can't be in palette color_list_remove_color_object(args->gs->colors, colorobject); } }else{ colorobject = color_object_copy(colorobject); copy = true; } if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(dd->widget), x, y, &path, &pos)){ gtk_tree_model_get_iter(model, &iter, path); GdkModifierType mask; gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(dd->widget)), NULL, NULL, &mask); if ((mask & GDK_CONTROL_MASK) && (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)){ Color color; color_object_get_color(colorobject, &color); struct ColorObject* original_color_object; gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &original_color_object, -1); color_object_set_color(original_color_object, &color); palette_list_entry_update_row(GTK_LIST_STORE(model), &iter, original_color_object, args); }else if (pos==GTK_TREE_VIEW_DROP_BEFORE || pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ gtk_list_store_insert_before(GTK_LIST_STORE(model), &iter2, &iter); palette_list_entry_fill(GTK_LIST_STORE(model), &iter2, colorobject, args); color_list_add_color_object(args->gs->colors, colorobject, false); }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ gtk_list_store_insert_after(GTK_LIST_STORE(model), &iter2, &iter); palette_list_entry_fill(GTK_LIST_STORE(model), &iter2, colorobject, args); color_list_add_color_object(args->gs->colors, colorobject, false); }else{ if (copy) color_object_release(colorobject); update_counts(args); return -1; } if (copy) color_object_release(colorobject); }else{ color_list_add_color_object(args->gs->colors, colorobject, true); update_counts(args); if (copy) color_object_release(colorobject); } update_counts(args); return 0; } static bool test_at(struct DragDrop* dd, int x, int y){ GtkTreePath* path; GtkTreeViewDropPosition pos; if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(dd->widget), x, y, &path, &pos)){ GdkModifierType mask; gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(dd->widget)), NULL, NULL, &mask); if ((mask & GDK_CONTROL_MASK) && (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)){ pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; }else if (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE){ pos = GTK_TREE_VIEW_DROP_BEFORE; }else if (pos==GTK_TREE_VIEW_DROP_AFTER || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER){ pos = GTK_TREE_VIEW_DROP_AFTER; } gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(dd->widget), path, pos); add_scroll_timeout((ListPaletteArgs*)dd->userdata); }else{ gtk_tree_view_unset_rows_drag_dest(GTK_TREE_VIEW(dd->widget)); } return true; } static void destroy_arguments(gpointer data){ ListPaletteArgs* args = (ListPaletteArgs*)data; delete args; } static gboolean disable_palette_selection_function(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, ListPaletteArgs *args) { return args->disable_selection; } static void disable_palette_selection(GtkWidget *widget, gboolean disable, int x, int y, ListPaletteArgs *args) { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); args->disable_selection = disable; gtk_tree_selection_set_select_function(selection, (GtkTreeSelectionFunc)disable_palette_selection_function, args, NULL); args->last_click_position.x = x; args->last_click_position.y = y; } static gboolean on_palette_button_press(GtkWidget *widget, GdkEventButton *event, ListPaletteArgs *args) { disable_palette_selection(widget, true, -1, -1, args); if (event->button != 1) return false; if (event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) return false; GtkTreePath *path = NULL; if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), event->x, event->y, &path, NULL, NULL, NULL)) return false; GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); if (gtk_tree_selection_path_is_selected(selection, path)) { disable_palette_selection(widget, false, event->x, event->y, args); } if (path) gtk_tree_path_free(path); update_counts((ListPaletteArgs*)args); return false; } static gboolean on_palette_button_release(GtkWidget *widget, GdkEventButton *event, ListPaletteArgs *args) { if (args->last_click_position != Vec2(-1, -1)) { Vec2 click_pos = args->last_click_position; disable_palette_selection(widget, true, -1, -1, args); if (click_pos.x == event->x && click_pos.y == event->y) { GtkTreePath *path = NULL; GtkTreeViewColumn *column; if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), event->x, event->y, &path, &column, NULL, NULL)) { gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), path, column, FALSE); } if (path) gtk_tree_path_free(path); } } update_counts((ListPaletteArgs*)args); return false; } static void on_palette_cursor_changed(GtkTreeView *treeview, ListPaletteArgs *args){ update_counts(args); } static gboolean on_palette_select_all(GtkTreeView *treeview, ListPaletteArgs *args){ update_counts(args); return FALSE; } static gboolean on_palette_unselect_all(GtkTreeView *treeview, ListPaletteArgs *args){ update_counts(args); return FALSE; } GtkWidget* palette_list_new(GlobalState* gs, GtkWidget* count_label){ ListPaletteArgs* args = new ListPaletteArgs; args->gs = gs; args->count_label = count_label; args->scroll_timeout = 0; GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *col; GtkWidget *view; view = gtk_tree_view_new (); args->treeview = view; gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), 1); store = gtk_list_store_new (3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col,1); gtk_tree_view_column_set_title(col, _("Color")); renderer = custom_cell_renderer_color_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "color", 0); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col,1); gtk_tree_view_column_set_title(col, _("Color")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", 1); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col,1); gtk_tree_view_column_set_title(col, _("Name")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", 2); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); g_object_set(renderer, "editable", TRUE, NULL); g_signal_connect(renderer, "edited", (GCallback) palette_list_cell_edited, store); gtk_tree_view_set_enable_search(GTK_TREE_VIEW(view), false); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(GTK_TREE_MODEL(store)); GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(view) ); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); g_signal_connect(G_OBJECT(view), "row-activated", G_CALLBACK(palette_list_row_activated), args); g_signal_connect(G_OBJECT(view), "button-press-event", G_CALLBACK(on_palette_button_press), args); g_signal_connect(G_OBJECT(view), "button-release-event", G_CALLBACK(on_palette_button_release), args); g_signal_connect(G_OBJECT(view), "cursor-changed", G_CALLBACK(on_palette_cursor_changed), args); g_signal_connect_after(G_OBJECT(view), "select-all", G_CALLBACK(on_palette_select_all), args); g_signal_connect_after(G_OBJECT(view), "unselect-all", G_CALLBACK(on_palette_unselect_all), args); ///gtk_tree_view_set_reorderable(GTK_TREE_VIEW (view), TRUE); gtk_drag_dest_set( view, GtkDestDefaults(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT), 0, 0, GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK)); gtk_drag_source_set( view, GDK_BUTTON1_MASK, 0, 0, GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK)); struct DragDrop dd; dragdrop_init(&dd, gs); dd.get_color_object = get_color_object; dd.get_color_object_list = get_color_object_list; dd.set_color_object_at = set_color_object_at; dd.set_color_object_list_at = set_color_object_list_at; dd.handler_map = dynv_system_get_handler_map(gs->colors->params); dd.test_at = test_at; dd.drag_end = drag_end; dd.userdata = args; dragdrop_widget_attach(view, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); g_object_set_data_full(G_OBJECT(view), "arguments", args, destroy_arguments); g_signal_connect(G_OBJECT(view), "destroy", G_CALLBACK(destroy_cb), args); if (count_label){ update_counts(args); } return view; } void palette_list_remove_all_entries(GtkWidget* widget) { ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeIter iter; GtkListStore *store; gboolean valid; store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid){ struct ColorObject* c; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &c, -1); color_object_release(c); valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } gtk_list_store_clear(GTK_LIST_STORE(store)); update_counts(args); } gint32 palette_list_get_selected_count(GtkWidget* widget) { return gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(widget))); } gint32 palette_list_get_count(GtkWidget* widget){ GtkTreeModel *store; store=gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); return gtk_tree_model_iter_n_children(store, NULL); } gint32 palette_list_get_selected_color(GtkWidget* widget, Color* color) { GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(widget) ); GtkListStore *store; GtkTreeIter iter; if (gtk_tree_selection_count_selected_rows(selection)!=1){ return -1; } store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); GList *list = gtk_tree_selection_get_selected_rows ( selection, 0 ); GList *i=list; struct ColorObject* c; while (i) { gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, (GtkTreePath*)i->data); gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &c, -1); color_object_get_color(c, color); break; i = g_list_next(i); } g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL); g_list_free (list); return 0; } void palette_list_remove_selected_entries(GtkWidget* widget) { ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeIter iter; GtkListStore *store; gboolean valid; store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); struct ColorObject* color_object; while (valid){ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &color_object, -1); if (color_object->selected){ valid = gtk_list_store_remove(GTK_LIST_STORE(store), &iter); color_object_release(color_object); }else{ valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } } update_counts(args); } void palette_list_add_entry(GtkWidget* widget, struct ColorObject* color_object){ ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeIter iter1; GtkListStore *store; store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); gtk_list_store_append(store, &iter1); palette_list_entry_fill(store, &iter1, color_object, args); update_counts(args); } int palette_list_remove_entry(GtkWidget* widget, struct ColorObject* r_color_object){ ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeIter iter; GtkListStore *store; gboolean valid; store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); struct ColorObject* color_object; while (valid){ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &color_object, -1); if (color_object == r_color_object){ valid = gtk_list_store_remove(GTK_LIST_STORE(store), &iter); color_object_release(color_object); return 0; } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } update_counts(args); return -1; } static void execute_callback(GtkListStore *store, GtkTreeIter *iter, ListPaletteArgs* args, PaletteListCallback callback, void *userdata){ struct ColorObject* color_object; gtk_tree_model_get(GTK_TREE_MODEL(store), iter, 0, &color_object, -1); PaletteListCallbackReturn r = callback(color_object, userdata); switch (r){ case PALETTE_LIST_CALLBACK_UPDATE_NAME: palette_list_entry_update_name(store, iter, color_object); break; case PALETTE_LIST_CALLBACK_UPDATE_ROW: palette_list_entry_update_row(store, iter, color_object, args); break; case PALETTE_LIST_CALLBACK_NO_UPDATE: break; } } static void execute_replace_callback(GtkListStore *store, GtkTreeIter *iter, ListPaletteArgs* args, PaletteListReplaceCallback callback, void *userdata){ struct ColorObject *color_object, *orig_color_object; gtk_tree_model_get(GTK_TREE_MODEL(store), iter, 0, &color_object, -1); orig_color_object = color_object; color_object_ref(color_object); PaletteListCallbackReturn r = callback(&color_object, userdata); if (color_object != orig_color_object){ gtk_list_store_set(store, iter, 0, color_object, -1); } switch (r){ case PALETTE_LIST_CALLBACK_UPDATE_NAME: palette_list_entry_update_name(store, iter, color_object); break; case PALETTE_LIST_CALLBACK_UPDATE_ROW: palette_list_entry_update_row(store, iter, color_object, args); break; case PALETTE_LIST_CALLBACK_NO_UPDATE: break; } color_object_release(color_object); } gint32 palette_list_foreach(GtkWidget* widget, PaletteListCallback callback, void *userdata){ ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeIter iter; GtkListStore *store; gboolean valid; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); struct ColorObject* color_object; while (valid){ execute_callback(store, &iter, args, callback, userdata); valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } return 0; } gint32 palette_list_foreach_selected(GtkWidget* widget, PaletteListCallback callback, void *userdata){ ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); GtkListStore *store; GtkTreeIter iter; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); GList *list = gtk_tree_selection_get_selected_rows(selection, 0); GList *i = list; while (i) { gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, (GtkTreePath*) (i->data)); execute_callback(store, &iter, args, callback, userdata); i = g_list_next(i); } g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); return 0; } gint32 palette_list_foreach_selected(GtkWidget* widget, PaletteListReplaceCallback callback, void *userdata){ ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); GtkListStore *store; GtkTreeIter iter; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); GList *list = gtk_tree_selection_get_selected_rows(selection, 0); GList *i = list; while (i) { gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, (GtkTreePath*) (i->data)); execute_replace_callback(store, &iter, args, callback, userdata); i = g_list_next(i); } g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); return 0; } gint32 palette_list_forfirst_selected(GtkWidget* widget, PaletteListCallback callback, void *userdata) { ListPaletteArgs* args = (ListPaletteArgs*)g_object_get_data(G_OBJECT(widget), "arguments"); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); GtkListStore *store; GtkTreeIter iter; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); GList *list = gtk_tree_selection_get_selected_rows(selection, 0); GList *i = list; if (i) { gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, (GtkTreePath*) (i->data)); execute_callback(store, &iter, args, callback, userdata); } g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); return 0; } gpick_0.2.5/source/uiListPalette.h0000644000175000017500000000620312070605214015644 0ustar zbygzbyg/* * 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 UILISTPALETTE_H_ #define UILISTPALETTE_H_ #include #include "ColorObject.h" #include "ColorList.h" #include "GlobalState.h" GtkWidget* palette_list_new(GlobalState* gs, GtkWidget* count_label); void palette_list_add_entry(GtkWidget* widget, struct ColorObject *color_object); GtkWidget* palette_list_preview_new(GlobalState* gs, bool expander, bool expanded, struct ColorList* color_list, struct ColorList** out_color_list); GtkWidget* palette_list_get_widget(struct ColorList *color_list); void palette_list_remove_all_entries(GtkWidget* widget); void palette_list_remove_selected_entries(GtkWidget* widget); int palette_list_remove_entry(GtkWidget* widget, struct ColorObject *color_object); enum PaletteListCallbackReturn{ PALETTE_LIST_CALLBACK_NO_UPDATE = 0, PALETTE_LIST_CALLBACK_UPDATE_ROW = 1, PALETTE_LIST_CALLBACK_UPDATE_NAME = 2, }; typedef PaletteListCallbackReturn (*PaletteListCallback)(struct ColorObject* color_object, void *userdata); typedef PaletteListCallbackReturn (*PaletteListReplaceCallback)(struct ColorObject** color_object, void *userdata); gint32 palette_list_foreach_selected(GtkWidget* widget, PaletteListCallback callback, void *userdata); gint32 palette_list_foreach_selected(GtkWidget* widget, PaletteListReplaceCallback callback, void *userdata); gint32 palette_list_forfirst_selected(GtkWidget* widget, PaletteListCallback callback, void *userdata); gint32 palette_list_foreach(GtkWidget* widget, PaletteListCallback callback, void *userdata); gint32 palette_list_get_selected_count(GtkWidget* widget); gint32 palette_list_get_count(GtkWidget* widget); #endif /* UILISTPALETTE_H_ */ gpick_0.2.5/source/uiAbout.cpp0000644000175000017500000002316312072045012015017 0ustar zbygzbyg/* * 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 "uiAbout.h" #include "version/Version.h" #include "Internationalisation.h" const gchar* program_name = "Gpick"; static GtkWidget* new_page(const char *text){ GtkWidget *text_view = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD); GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); gtk_text_buffer_set_text(buffer, text, -1); gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), false); GtkWidget *scrolled = gtk_scrolled_window_new(0, 0); gtk_container_add(GTK_CONTAINER(scrolled), text_view); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); return scrolled; } void show_about_box(GtkWidget *widget){ const char *license = { "Copyright \xc2\xa9 2009-2013, Albertas Vyšniauskas\n" "\n" "All rights reserved.\n" "\n" "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n" "\n" " * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n" " * 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.\n" " * 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.\n" "\n" "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.\n" }; const char *expat_license = { "Copyright \xc2\xa9 1998, 1999, 2000 Thai Open Source Software Center Ltd and Clark Cooper\n" "Copyright \xc2\xa9 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.\n" "\n" "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" "\n" "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n" "\n" "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" }; const char *lua_license = { "Copyright \xc2\xa9 1994-2008 Lua.org, PUC-Rio.\n" "\n" "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" "\n" "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n" "\n" "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" }; const char *program_authors = { "Albertas Vyšniauskas \n" /* Add yourself here if you helped Gpick project in any way (patch, translation, etc). * Everything is optional, if you do not want, you do not have to disclose your e-mail * address, real name or any other information. * Please keep this list sorted alphabetically. */ }; GtkWidget* dialog = gtk_dialog_new_with_buttons(_("About Gpick"), GTK_WINDOW(gtk_widget_get_toplevel(widget)), GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL); GtkWidget *vbox = gtk_vbox_new(false, 5); GtkWidget *align_box = gtk_hbox_new(false, 5); gtk_box_pack_start(GTK_BOX(vbox), align_box, false, false, 0); gtk_box_pack_start(GTK_BOX(align_box), gtk_vbox_new(false, 0), true, true, 0); gtk_box_pack_end(GTK_BOX(align_box), gtk_vbox_new(false, 0), true, true, 0); GtkWidget *hbox = gtk_hbox_new(false, 5); gtk_box_pack_start(GTK_BOX(align_box), hbox, false, false, 0); GtkWidget *image = gtk_image_new(); gtk_image_set_from_icon_name(GTK_IMAGE(image), "gpick", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start(GTK_BOX(hbox), image, false, false, 0); GtkWidget *vbox2 = gtk_vbox_new(false, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox2, false, false, 0); gchar *tmp_string = g_markup_printf_escaped("%s %s", program_name, gpick_build_version); GtkWidget *name = gtk_label_new(0); gtk_label_set_selectable(GTK_LABEL(name), true); gtk_label_set_justify(GTK_LABEL(name), GTK_JUSTIFY_CENTER); gtk_label_set_markup(GTK_LABEL(name), tmp_string); gtk_box_pack_start(GTK_BOX(vbox2), name, false, false, 0); g_free(tmp_string); GtkWidget *comments = gtk_label_new(_("Advanced color picker")); gtk_label_set_selectable(GTK_LABEL(comments), true); gtk_label_set_justify(GTK_LABEL(comments), GTK_JUSTIFY_CENTER); gtk_box_pack_start(GTK_BOX(vbox2), comments, false, false, 0); tmp_string = g_markup_printf_escaped ("%s", _("Copyrights © 2009-2013, Albertas Vyšniauskas and Gpick development team")); GtkWidget *copyright = gtk_label_new(0); gtk_label_set_selectable(GTK_LABEL(copyright), true); gtk_label_set_justify(GTK_LABEL(copyright), GTK_JUSTIFY_CENTER); gtk_label_set_line_wrap(GTK_LABEL(copyright), true); gtk_label_set_markup(GTK_LABEL(copyright), tmp_string); gtk_box_pack_start(GTK_BOX(vbox2), copyright, false, false, 0); g_free(tmp_string); GtkWidget *website = gtk_link_button_new("http://code.google.com/p/gpick/"); gtk_box_pack_start(GTK_BOX(vbox2), website, false, false, 0); GtkWidget *notebook = gtk_notebook_new(); gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), true); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), new_page(license), gtk_label_new(_("License"))); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), new_page(program_authors), gtk_label_new(_("Credits"))); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), new_page(expat_license), gtk_label_new(_("Expat License"))); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), new_page(lua_license), gtk_label_new(_("Lua License"))); gtk_box_pack_start(GTK_BOX(vbox), notebook, true, true, 0); gtk_widget_show_all(vbox); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, true, true, 5); gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 300); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } gpick_0.2.5/source/uiUtilities.cpp0000644000175000017500000000524612070605214015726 0ustar zbygzbyg/* * 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 "uiUtilities.h" GtkWidget* gtk_menu_item_new_with_image(const gchar* label, GtkWidget *image) { GtkWidget* menu_item = gtk_image_menu_item_new_with_mnemonic(label); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image); return menu_item; } GtkWidget* gtk_label_aligned_new(const gchar* text, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale) { GtkWidget* align = gtk_alignment_new(xalign, yalign, xscale, yscale); GtkWidget* label = gtk_label_new(text); gtk_container_add(GTK_CONTAINER(align), label); return align; } GtkWidget* gtk_label_mnemonic_aligned_new(const gchar* text, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale) { GtkWidget* align = gtk_alignment_new(xalign, yalign, xscale, yscale); GtkWidget* label = gtk_label_new(""); gtk_label_set_text_with_mnemonic(GTK_LABEL(label), text); gtk_container_add(GTK_CONTAINER(align), label); return align; } GtkWidget* gtk_widget_aligned_new(GtkWidget* widget, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale){ GtkWidget* align = gtk_alignment_new(xalign, yalign, xscale, yscale); gtk_container_add(GTK_CONTAINER(align), widget); return align; } gpick_0.2.5/source/ColorAction.cpp0000644000175000017500000000450712070605214015630 0ustar zbygzbyg/* * 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 "ColorAction.h" #include "DynvHelpers.h" using namespace std; struct ColorAction* color_action_new(struct dynvHandlerMap* handler_map, const char* name){ struct ColorAction* color_action = new struct ColorAction; color_action->refcnt = 0; if (handler_map){ color_action->params=dynv_system_create(handler_map); dynv_set_string(color_action->params, "name", name); }else{ color_action->params=NULL; } return color_action; } int color_action_release(struct ColorAction* color_action){ if (color_action->refcnt){ color_action->refcnt--; return -1; }else{ if (color_action->params) dynv_system_release(color_action->params); delete color_action; return 0; } } struct ColorAction* color_action_ref(struct ColorAction* color_action){ color_action->refcnt++; return color_action; } gpick_0.2.5/source/BlendColors.cpp0000644000175000017500000005447012070605214015626 0ustar zbygzbyg/* * 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 "BlendColors.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "MathUtil.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "ToolColorNaming.h" #include "DragDrop.h" #include "ColorList.h" #include "MathUtil.h" #include "ColorRYB.h" #include "gtk/ColorWidget.h" #include "uiColorInput.h" #include "CopyPaste.h" #include "Converter.h" #include "DynvHelpers.h" #include "uiApp.h" #include "ToolColorNaming.h" #include "Internationalisation.h" #include #include #include #include #include #ifndef _MSC_VER #include #endif #include using namespace std; #define STORE_COLOR() struct ColorObject *color_object = color_list_new_color_object(color_list, &r); \ float mixfactor = step_i/(float)(steps-1); \ name_assigner.assign(color_object, &r, start_name.c_str(), end_name.c_str(), (int)((1.0 - mixfactor)*100), (int)(mixfactor*100), (((step_i == 0 || step_i == steps - 1) && stage == 0) || (stage == 1 && step_i == steps - 1))); \ color_list_add_color_object(color_list, color_object, 1); \ color_object_release(color_object) #define STORE_LINEARCOLOR() color_linear_get_rgb(&r, &r); \ STORE_COLOR() typedef struct BlendColorsArgs{ ColorSource source; GtkWidget *main; GtkWidget *mix_type; GtkWidget *steps1; GtkWidget *steps2; GtkWidget *start_color; GtkWidget *middle_color; GtkWidget *end_color; GtkWidget *preview_list; struct ColorList *preview_color_list; struct dynvSystem *params; GlobalState* gs; }BlendColorsArgs; class BlendColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; const char *m_color_start; const char *m_color_end; int m_start_percent; int m_end_percent; bool m_is_color_item; public: BlendColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){ m_is_color_item = false; } void assign(struct ColorObject *color_object, Color *color, const char *start_color_name, const char *end_color_name, int start_percent, int end_percent, bool is_color_item){ m_color_start = start_color_name; m_color_end = end_color_name; m_start_percent = start_percent; m_end_percent = end_percent; m_is_color_item = is_color_item; ToolColorNameAssigner::assign(color_object, color); } void assign(struct ColorObject *color_object, Color *color, const char *item_name){ m_color_start = item_name; m_is_color_item = true; ToolColorNameAssigner::assign(color_object, color); } virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){ m_stream.str(""); if (m_is_color_item){ if (m_end_percent == 100){ m_stream << m_color_end << " " << _("blend node"); }else{ m_stream << m_color_start << " " << _("blend node"); } }else{ m_stream << m_color_start << " " << m_start_percent << " " << _("blend") << " " << m_end_percent << " " << m_color_end; } return m_stream.str(); } }; static int source_get_color(BlendColorsArgs *args, struct ColorObject** color); static void calc( BlendColorsArgs *args, bool preview, int limit){ gint steps1 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->steps1)); gint steps2 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->steps2)); gint type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->mix_type)); Color r; gint step_i; stringstream s; s.precision(0); s.setf(ios::fixed,ios::floatfield); Color a,b; struct ColorList *color_list; color_list = args->preview_color_list; BlendColorNameAssigner name_assigner(args->gs); int steps; for (int stage = 0; stage < 2; stage++){ if (stage == 0){ steps = steps1 + 1; gtk_color_get_color(GTK_COLOR(args->start_color), &a); gtk_color_get_color(GTK_COLOR(args->middle_color), &b); }else{ steps = steps2 + 1; gtk_color_get_color(GTK_COLOR(args->middle_color), &a); gtk_color_get_color(GTK_COLOR(args->end_color), &b); } string start_name = color_names_get(args->gs->color_names, &a, false); string end_name = color_names_get(args->gs->color_names, &b, false); if (type == 0){ color_rgb_get_linear(&a, &a); color_rgb_get_linear(&b, &b); } step_i = stage; switch (type) { case 0: for (; step_i < steps; ++step_i) { MIX_COMPONENTS(r.rgb, a.rgb, b.rgb, red, green, blue); STORE_LINEARCOLOR(); } break; case 1: { Color a_hsv, b_hsv, r_hsv; color_rgb_to_hsv(&a, &a_hsv); color_rgb_to_hsv(&b, &b_hsv); for (; step_i < steps; ++step_i) { MIX_COMPONENTS(r_hsv.hsv, a_hsv.hsv, b_hsv.hsv, hue, saturation, value); color_hsv_to_rgb(&r_hsv, &r); STORE_COLOR(); } } break; case 2: { Color a_hsv, b_hsv, r_hsv; color_rgb_to_hsv(&a, &a_hsv); color_rgb_to_hsv(&b, &b_hsv); if (a_hsv.hsv.hue>b_hsv.hsv.hue){ if (a_hsv.hsv.hue-b_hsv.hsv.hue>0.5) a_hsv.hsv.hue-=1; }else{ if (b_hsv.hsv.hue-a_hsv.hsv.hue>0.5) b_hsv.hsv.hue-=1; } for (; step_i < steps; ++step_i) { MIX_COMPONENTS(r_hsv.hsv, a_hsv.hsv, b_hsv.hsv, hue, saturation, value); if (r_hsv.hsv.hue<0) r_hsv.hsv.hue+=1; color_hsv_to_rgb(&r_hsv, &r); STORE_COLOR(); } } break; case 3: { Color a_lab, b_lab, r_lab; color_rgb_to_lab_d50(&a, &a_lab); color_rgb_to_lab_d50(&b, &b_lab); for (; step_i < steps; ++step_i) { MIX_COMPONENTS(r_lab.lab, a_lab.lab, b_lab.lab, L, a, b); color_lab_to_rgb_d50(&r_lab, &r); color_rgb_normalize(&r); STORE_COLOR(); } } break; } } } static PaletteListCallbackReturn add_to_palette_cb_helper(struct ColorObject* color_object, void *userdata){ BlendColorsArgs *args = (BlendColorsArgs*)userdata; color_list_add_color_object(args->gs->colors, color_object, 1); return PALETTE_LIST_CALLBACK_NO_UPDATE; } static gboolean add_to_palette_cb(GtkWidget *widget, BlendColorsArgs *args) { palette_list_foreach_selected(args->preview_list, add_to_palette_cb_helper, args); return true; } static gboolean add_all_to_palette_cb(GtkWidget *widget, BlendColorsArgs *args) { palette_list_foreach(args->preview_list, add_to_palette_cb_helper, args); return true; } static PaletteListCallbackReturn color_list_selected(struct ColorObject* color_object, void *userdata){ color_list_add_color_object((struct ColorList *)userdata, color_object, 1); return PALETTE_LIST_CALLBACK_NO_UPDATE; } typedef struct CopyMenuItem{ gchar* function_name; struct ColorObject* color_object; GlobalState* gs; GtkWidget* palette_widget; }CopyMenuItem; static void converter_destroy_params(CopyMenuItem* args){ color_object_release(args->color_object); g_free(args->function_name); delete args; } static void converter_callback_copy(GtkWidget *widget, gpointer item) { CopyMenuItem* itemdata=(CopyMenuItem*)g_object_get_data(G_OBJECT(widget), "item_data"); converter_get_clipboard(itemdata->function_name, itemdata->color_object, itemdata->palette_widget, itemdata->gs->params); } static GtkWidget* converter_create_copy_menu_item (GtkWidget *menu, const gchar* function, struct ColorObject* color_object, GtkWidget* palette_widget, GlobalState *gs){ GtkWidget* item=0; gchar* converted; if (converters_color_serialize((Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0), function, color_object, &converted)==0){ item = gtk_menu_item_new_with_image(converted, gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU)); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(converter_callback_copy), 0); CopyMenuItem* itemdata=new CopyMenuItem; itemdata->function_name=g_strdup(function); itemdata->palette_widget=palette_widget; itemdata->color_object=color_object_ref(color_object); itemdata->gs = gs; g_object_set_data_full(G_OBJECT(item), "item_data", itemdata, (GDestroyNotify)converter_destroy_params); g_free(converted); } return item; } static gboolean preview_list_button_press_cb(GtkWidget *widget, GdkEventButton *event, BlendColorsArgs *args) { GtkWidget *menu; if (event->button == 1 && event->type == GDK_2BUTTON_PRESS){ //add_to_palette_cb(widget, args); //return true; }else if (event->button == 3 && event->type == GDK_BUTTON_PRESS){ GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); bool selection_avail = palette_list_get_selected_count(widget) != 0; 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 (add_to_palette_cb), args); if (!selection_avail) gtk_widget_set_sensitive(item, false); 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 (add_all_to_palette_cb), args); 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); if (selection_avail){ struct ColorList *color_list = color_list_new(NULL); palette_list_forfirst_selected(args->preview_list, color_list_selected, color_list); if (color_list_get_count(color_list) != 0){ gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (*color_list->colors.begin(), args->preview_list, args->gs)); } color_list_destroy(color_list); }else{ gtk_widget_set_sensitive(item, false); } gtk_widget_show_all (GTK_WIDGET(menu)); button = event->button; event_time = event->time; gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time); g_object_ref_sink(menu); g_object_unref(menu); return TRUE; } return FALSE; } static void update(GtkWidget *widget, BlendColorsArgs *args ){ color_list_remove_all(args->preview_color_list); calc(args, true, 101); } static void reset_middle_color_cb(GtkWidget *widget, BlendColorsArgs *args){ Color a, b; gtk_color_get_color(GTK_COLOR(args->start_color), &a); gtk_color_get_color(GTK_COLOR(args->end_color), &b); color_multiply(&a, 0.5); color_multiply(&b, 0.5); color_add(&a, &b); gtk_color_set_color(GTK_COLOR(args->middle_color), &a, ""); update(0, args); } static gboolean color_button_press_cb(GtkWidget *widget, GdkEventButton *event, BlendColorsArgs *args) { GtkWidget *menu; if (event->button == 3 && event->type == GDK_BUTTON_PRESS){ GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); item = gtk_menu_item_new_with_mnemonic(_("_Reset")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (reset_middle_color_cb), args); gtk_widget_show_all (GTK_WIDGET(menu)); button = event->button; event_time = event->time; gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time); g_object_ref_sink(menu); g_object_unref(menu); return TRUE; } return FALSE; } static int set_rgb_color(BlendColorsArgs *args, struct ColorObject* color, uint32_t color_index){ Color c; color_object_get_color(color, &c); if (color_index == 1){ gtk_color_set_color(GTK_COLOR(args->start_color), &c, ""); }else if (color_index == 2){ gtk_color_set_color(GTK_COLOR(args->middle_color), &c, ""); }else if (color_index == 3){ gtk_color_set_color(GTK_COLOR(args->end_color), &c, ""); } update(0, args); return 0; } static int get_rgb_color(BlendColorsArgs *args, uint32_t color_index, struct ColorObject** color){ Color c; if (color_index == 1){ gtk_color_get_color(GTK_COLOR(args->start_color), &c); }else if (color_index == 2){ gtk_color_get_color(GTK_COLOR(args->middle_color), &c); }else if (color_index == 3){ gtk_color_get_color(GTK_COLOR(args->end_color), &c); } *color = color_list_new_color_object(args->gs->colors, &c); BlendColorNameAssigner name_assigner(args->gs); const char *item_name[] = { "start", "middle", "end", }; name_assigner.assign(*color, &c, item_name[color_index - 1]); return 0; } static struct ColorObject* get_color_object(struct DragDrop* dd){ BlendColorsArgs* args = (BlendColorsArgs*)dd->userdata; struct ColorObject* colorobject; if (get_rgb_color(args, (uintptr_t)dd->userdata2, &colorobject) == 0){ return colorobject; } return 0; } static int set_color_object_at(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move){ BlendColorsArgs* args = static_cast(dd->userdata); set_rgb_color(args, colorobject, (uintptr_t)dd->userdata2); return 0; } static int source_get_color(BlendColorsArgs *args, struct ColorObject** color){ return -1; } static int source_set_color(BlendColorsArgs *args, struct ColorObject* color){ return -1; } static int source_activate(BlendColorsArgs *args){ update(0, args); return 0; } static int source_deactivate(BlendColorsArgs *args){ return 0; } static int source_destroy(BlendColorsArgs *args){ gint steps1 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->steps1)); gint steps2 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->steps2)); gint type = gtk_combo_box_get_active(GTK_COMBO_BOX(args->mix_type)); dynv_set_int32(args->params, "type", type); dynv_set_int32(args->params, "steps1", steps1); dynv_set_int32(args->params, "steps2", steps2); Color c; gtk_color_get_color(GTK_COLOR(args->start_color), &c); dynv_set_color(args->params, "start_color", &c); gtk_color_get_color(GTK_COLOR(args->middle_color), &c); dynv_set_color(args->params, "middle_color", &c); gtk_color_get_color(GTK_COLOR(args->end_color), &c); dynv_set_color(args->params, "end_color", &c); color_list_destroy(args->preview_color_list); dynv_system_release(args->params); gtk_widget_destroy(args->main); delete args; return 0; } static ColorSource* source_implement(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace){ BlendColorsArgs *args = new BlendColorsArgs; args->params = dynv_system_ref(dynv_namespace); args->gs = gs; 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, *widget; GtkWidget *mix_type, *mix_steps; gint table_y; table = gtk_table_new(6, 2, FALSE); table_y = 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; Color c; color_set(&c, 0.5); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Start:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->start_color = widget = gtk_color_new(); gtk_color_set_color(GTK_COLOR(args->start_color), dynv_get_color_wdc(args->params, "start_color", &c), ""); 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(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); 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); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Middle:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->middle_color = widget = gtk_color_new(); g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(color_button_press_cb), args); gtk_color_set_color(GTK_COLOR(args->middle_color), dynv_get_color_wdc(args->params, "middle_color", &c), ""); 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(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); 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*)2; dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("End:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->end_color = widget = gtk_color_new(); gtk_color_set_color(GTK_COLOR(args->end_color), dynv_get_color_wdc(args->params, "end_color", &c), ""); 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(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); 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*)3; dragdrop_widget_attach(widget, DragDropFlags(DRAGDROP_SOURCE | DRAGDROP_DESTINATION), &dd); table_y = 0; GtkWidget* vbox = gtk_vbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), gtk_label_aligned_new(_("Type:"),0,0,0,0), false, false, 0); args->mix_type = mix_type = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("RGB")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("HSV")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("HSV shortest hue distance")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("LAB")); gtk_combo_box_set_active(GTK_COMBO_BOX(mix_type), dynv_get_int32_wd(args->params, "type", 0)); gtk_box_pack_start(GTK_BOX(vbox), mix_type, false, false, 0); g_signal_connect(G_OBJECT(mix_type), "changed", G_CALLBACK (update), args); gtk_table_attach(GTK_TABLE(table), vbox, 4, 5, table_y, table_y+3, GtkAttachOptions(GTK_FILL),GtkAttachOptions(GTK_FILL),5,0); table_y = 0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Start steps:"),0,0,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); mix_steps = gtk_spin_button_new_with_range (1,255,1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(mix_steps), dynv_get_int32_wd(args->params, "steps1", 3)); gtk_table_attach(GTK_TABLE(table), mix_steps,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; args->steps1 = mix_steps; g_signal_connect(G_OBJECT(mix_steps), "value-changed", G_CALLBACK (update), args); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("End steps:"),0,0,0,0),2,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); mix_steps = gtk_spin_button_new_with_range (1,255,1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(mix_steps), dynv_get_int32_wd(args->params, "steps2", 3)); gtk_table_attach(GTK_TABLE(table), mix_steps,3,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; args->steps2 = mix_steps; g_signal_connect(G_OBJECT(mix_steps), "value-changed", G_CALLBACK (update), args); table_y = 3; GtkWidget* preview; struct ColorList* preview_color_list = NULL; gtk_table_attach(GTK_TABLE(table), preview = palette_list_preview_new(gs, false, false, gs->colors, &preview_color_list), 0, 5, table_y, table_y+1 , GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 5, 5); args->preview_list = palette_list_get_widget(preview_color_list); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(args->preview_list)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); g_signal_connect(G_OBJECT(args->preview_list), "button-press-event", G_CALLBACK(preview_list_button_press_cb), args); table_y++; args->preview_color_list = preview_color_list; update(0, args); gtk_widget_show_all(table); args->main = table; args->source.widget = table; return (ColorSource*)args; } int blend_colors_source_register(ColorSourceManager *csm){ ColorSource *color_source = new ColorSource; color_source_init(color_source, "blend_colors", _("Blend colors")); color_source->implement = (ColorSource* (*)(ColorSource *source, GlobalState *gs, struct dynvSystem *dynv_namespace))source_implement; color_source->default_accelerator = GDK_b; color_source_manager_add_source(csm, color_source); return 0; } gpick_0.2.5/source/transformation/Configuration.h0000644000175000017500000000414212070605214020731 0ustar zbygzbyg/* * 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 TRANSFORMATION_CONFIGURATION_H_ #define TRANSFORMATION_CONFIGURATION_H_ #include "../DynvHelpers.h" #include /** \file source/transformation/Configuration.h * \brief Class for transformation object configuration handling. */ namespace transformation { /** \class Configuration * \brief Transformation object configuration management class. */ class Configuration{ protected: public: Configuration(); virtual ~Configuration(); virtual GtkWidget* getWidget(); virtual void applyConfig(dynvSystem *dynv); }; } #endif /* TRANSFORMATION_CONFIGURATION_H_ */ gpick_0.2.5/source/transformation/GammaModification.cpp0000644000175000017500000001001712070605214022023 0ustar zbygzbyg/* * 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 "GammaModification.h" #include "../MathUtil.h" #include "../uiUtilities.h" #include "../Internationalisation.h" #include #include #include namespace transformation { static const char * transformation_name = "gamma_modification"; const char *GammaModification::getName() { return transformation_name; } const char *GammaModification::getReadableName() { return _("Gamma modification"); } void GammaModification::apply(Color *input, Color *output) { Color linear_input, linear_output; color_rgb_get_linear(input, &linear_input); linear_output.rgb.red = pow(linear_input.rgb.red, value); linear_output.rgb.green= pow(linear_input.rgb.green, value); linear_output.rgb.blue = pow(linear_input.rgb.blue, value); color_linear_get_rgb(&linear_output, output); color_rgb_normalize(output); } GammaModification::GammaModification():Transformation(transformation_name, getReadableName()) { value = 1; } GammaModification::GammaModification(float value_):Transformation(transformation_name, getReadableName()) { value = value_; } GammaModification::~GammaModification() { } void GammaModification::serialize(struct dynvSystem *dynv) { dynv_set_float(dynv, "value", value); Transformation::serialize(dynv); } void GammaModification::deserialize(struct dynvSystem *dynv) { value = dynv_get_float_wd(dynv, "value", 1); } boost::shared_ptr GammaModification::getConfig(){ boost::shared_ptr config = boost::shared_ptr(new GammaModificationConfig(*this)); return config; } GammaModificationConfig::GammaModificationConfig(GammaModification &transformation){ GtkWidget *table = gtk_table_new(2, 2, false); GtkWidget *widget; int table_y = 0; table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Value:"),0, 0.5, 0, 0), 0, 1, table_y, table_y + 1, GTK_FILL, GTK_FILL, 5, 5); value = widget = gtk_spin_button_new_with_range(0, 100, 0.01); gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), transformation.value); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); table_y++; main = table; gtk_widget_show_all(main); g_object_ref(main); } GammaModificationConfig::~GammaModificationConfig(){ g_object_unref(main); } GtkWidget* GammaModificationConfig::getWidget(){ return main; } void GammaModificationConfig::applyConfig(dynvSystem *dynv){ dynv_set_float(dynv, "value", gtk_spin_button_get_value(GTK_SPIN_BUTTON(value))); } } gpick_0.2.5/source/transformation/Chain.h0000644000175000017500000000576012070605214017153 0ustar zbygzbyg/* * 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 TRANSFORMATION_CHAIN_H_ #define TRANSFORMATION_CHAIN_H_ #include "Transformation.h" #include #include /** \file source/transformation/Chain.h * \brief Class for transformation object list handling. */ namespace transformation { /** \class Chain * \brief Transformation object chain management class. */ class Chain{ public: typedef std::list > TransformationList; protected: TransformationList transformation_chain; bool enabled; public: /** * Chain constructor. */ Chain(); /** * Apply transformation chain to color. * @param[in] input Source color in RGB color space. * @param[out] output Destination color in RGB color space. */ void apply(const Color *input, Color *output); /** * Add transformation object into the list. * @param[in] transformation Transformation object. */ void add(boost::shared_ptr transformation); /** * Remove transformation object from the list. * @param[in] transformation Transformation object. */ void remove(const Transformation *transformation); /** * Clear transformation object list. */ void clear(); /** * Enable/disable transformation chain. * @param[in] enabled Enabled. */ void setEnabled(bool enabled); /** * Get the list of transformation objects. * @return Transformation object list. */ TransformationList& getAll(); }; } #endif /* TRANSFORMATION_CHAIN_H_ */ gpick_0.2.5/source/transformation/Invert.h0000644000175000017500000000351112070605214017370 0ustar zbygzbyg/* * 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 TRANSFORMATION_INVERT_H_ #define TRANSFORMATION_INVERT_H_ #include "Transformation.h" namespace transformation { class Invert : public Transformation{ protected: virtual void apply(Color *input, Color *output); public: Invert(); virtual ~Invert(); }; } #endif /* TRANSFORMATION_INVERT_H_ */ gpick_0.2.5/source/transformation/Chain.cpp0000644000175000017500000000523012070605214017476 0ustar zbygzbyg/* * 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 "Chain.h" using namespace std; namespace transformation { Chain::Chain() { enabled = true; } void Chain::apply(const Color *input, Color *output) { if (!enabled) { color_copy(input, output); return; } Color tmp[2]; Color *tmp_p[3]; color_copy(input, &tmp[0]); tmp_p[0] = &tmp[0]; tmp_p[1] = &tmp[1]; for (TransformationList::iterator i = transformation_chain.begin(); i != transformation_chain.end(); i++){ (*i)->apply(tmp_p[0], tmp_p[1]); tmp_p[2] = tmp_p[0]; tmp_p[0] = tmp_p[1]; tmp_p[1] = tmp_p[2]; } color_copy(tmp_p[0], output); } void Chain::add(boost::shared_ptr transformation) { transformation_chain.push_back(transformation); } void Chain::remove(const Transformation *transformation) { for (TransformationList::iterator i = transformation_chain.begin(); i != transformation_chain.end(); i++){ if ((*i).get() == transformation){ transformation_chain.erase(i); return; } } } void Chain::clear() { transformation_chain.clear(); } Chain::TransformationList& Chain::getAll() { return transformation_chain; } void Chain::setEnabled(bool enabled_) { enabled = enabled_; } } gpick_0.2.5/source/transformation/Invert.cpp0000644000175000017500000000350612070605214017727 0ustar zbygzbyg/* * 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 "Invert.h" namespace transformation { void Invert::apply(Color *input, Color *output) { output->rgb.red = 1 - input->rgb.red; output->rgb.green= 1 - input->rgb.green; output->rgb.blue = 1 - input->rgb.blue; } Invert::Invert():Transformation("invert", "Invert") { } Invert::~Invert() { } } gpick_0.2.5/source/transformation/Quantization.cpp0000644000175000017500000001147512070605214021152 0ustar zbygzbyg/* * Copyright (c) 2009-2012, Albertas Vyšniauskas * All rights reserved. * Copyright (c) 2012, David Gowers (Portions regarding adaptation of GammaModification.(cpp|h) to quantise colors instead.) * * 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 "Quantization.h" #include "../MathUtil.h" #include "../uiUtilities.h" #include "../Internationalisation.h" #include #include #include #include namespace transformation { static const char * transformation_name = "quantization"; const char *Quantization::getName() { return transformation_name; } const char *Quantization::getReadableName() { return _("Quantization"); } void Quantization::apply(Color *input, Color *output) { if (clip_top) { float max_intensity = (value - 1) / value; output->rgb.red = MIN(max_intensity, boost::math::round(input->rgb.red * value) / value); output->rgb.green = MIN(max_intensity, boost::math::round(input->rgb.green * value) / value); output->rgb.blue = MIN(max_intensity, boost::math::round(input->rgb.blue * value) / value); }else{ float actualmax = value - 1; output->rgb.red = boost::math::round(input->rgb.red * actualmax) / actualmax; output->rgb.green = boost::math::round(input->rgb.green * actualmax) / actualmax; output->rgb.blue = boost::math::round(input->rgb.blue * actualmax) / actualmax; } } Quantization::Quantization():Transformation(transformation_name, getReadableName()) { value = 16; } Quantization::Quantization(float value_):Transformation(transformation_name, getReadableName()) { value = value_; } Quantization::~Quantization() { } void Quantization::serialize(struct dynvSystem *dynv) { dynv_set_float(dynv, "value", value); dynv_set_bool(dynv, "clip-top", clip_top); Transformation::serialize(dynv); } void Quantization::deserialize(struct dynvSystem *dynv) { value = dynv_get_float_wd(dynv, "value", 16); clip_top = dynv_get_bool_wd(dynv, "clip-top", 0); } boost::shared_ptr Quantization::getConfig(){ boost::shared_ptr config = boost::shared_ptr(new QuantizationConfig(*this)); return config; } QuantizationConfig::QuantizationConfig(Quantization &transformation){ GtkWidget *table = gtk_table_new(2, 3, false); GtkWidget *widget; int table_y = 0; table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Value:"),0, 0.5, 0, 0), 0, 1, table_y, table_y + 1, GTK_FILL, GTK_FILL, 5, 5); value = widget = gtk_spin_button_new_with_range(2, 256, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), transformation.value); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); table_y++; clip_top = widget = gtk_check_button_new_with_label(_("Clip top-end")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), transformation.clip_top); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); main = table; gtk_widget_show_all(main); g_object_ref(main); } QuantizationConfig::~QuantizationConfig(){ g_object_unref(main); } GtkWidget* QuantizationConfig::getWidget(){ return main; } void QuantizationConfig::applyConfig(dynvSystem *dynv){ dynv_set_float(dynv, "value", gtk_spin_button_get_value(GTK_SPIN_BUTTON(value))); dynv_set_bool(dynv, "clip-top", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(clip_top))); } } gpick_0.2.5/source/transformation/ColorVisionDeficiency.cpp0000644000175000017500000004155012070605214022712 0ustar zbygzbyg/* * 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 "ColorVisionDeficiency.h" #include "../MathUtil.h" #include "../uiUtilities.h" #include "../Internationalisation.h" #include #include #include #include using namespace std; namespace transformation { static const char * transformation_name = "color_vision_deficiency"; const char *ColorVisionDeficiency::getName() { return transformation_name; } const char *ColorVisionDeficiency::getReadableName() { return _("Color vision deficiency"); } const char* ColorVisionDeficiency::deficiency_type_string[] = { "protanomaly", "deuteranomaly", "tritanomaly", "protanopia", "deuteranopia", "tritanopia", }; const double protanomaly[11][9] = { {1.000000,0.000000,-0.000000,0.000000,1.000000,0.000000,-0.000000,-0.000000,1.000000}, {0.856167,0.182038,-0.038205,0.029342,0.955115,0.015544,-0.002880,-0.001563,1.004443}, {0.734766,0.334872,-0.069637,0.051840,0.919198,0.028963,-0.004928,-0.004209,1.009137}, {0.630323,0.465641,-0.095964,0.069181,0.890046,0.040773,-0.006308,-0.007724,1.014032}, {0.539009,0.579343,-0.118352,0.082546,0.866121,0.051332,-0.007136,-0.011959,1.019095}, {0.458064,0.679578,-0.137642,0.092785,0.846313,0.060902,-0.007494,-0.016807,1.024301}, {0.385450,0.769005,-0.154455,0.100526,0.829802,0.069673,-0.007442,-0.022190,1.029632}, {0.319627,0.849633,-0.169261,0.106241,0.815969,0.077790,-0.007025,-0.028051,1.035076}, {0.259411,0.923008,-0.182420,0.110296,0.804340,0.085364,-0.006276,-0.034346,1.040622}, {0.203876,0.990338,-0.194214,0.112975,0.794542,0.092483,-0.005222,-0.041043,1.046265}, {0.152286,1.052583,-0.204868,0.114503,0.786281,0.099216,-0.003882,-0.048116,1.051998}, }; const double deuteranomaly[11][9] = { {1.000000,0.000000,-0.000000,0.000000,1.000000,0.000000,-0.000000,-0.000000,1.000000}, {0.866435,0.177704,-0.044139,0.049567,0.939063,0.011370,-0.003453,0.007233,0.996220}, {0.760729,0.319078,-0.079807,0.090568,0.889315,0.020117,-0.006027,0.013325,0.992702}, {0.675425,0.433850,-0.109275,0.125303,0.847755,0.026942,-0.007950,0.018572,0.989378}, {0.605511,0.528560,-0.134071,0.155318,0.812366,0.032316,-0.009376,0.023176,0.986200}, {0.547494,0.607765,-0.155259,0.181692,0.781742,0.036566,-0.010410,0.027275,0.983136}, {0.498864,0.674741,-0.173604,0.205199,0.754872,0.039929,-0.011131,0.030969,0.980162}, {0.457771,0.731899,-0.189670,0.226409,0.731012,0.042579,-0.011595,0.034333,0.977261}, {0.422823,0.781057,-0.203881,0.245752,0.709602,0.044646,-0.011843,0.037423,0.974421}, {0.392952,0.823610,-0.216562,0.263559,0.690210,0.046232,-0.011910,0.040281,0.971630}, {0.367322,0.860646,-0.227968,0.280085,0.672501,0.047413,-0.011820,0.042940,0.968881}, }; const double tritanomaly[11][9] = { {1.000000,0.000000,-0.000000,0.000000,1.000000,0.000000,-0.000000,-0.000000,1.000000}, {0.926670,0.092514,-0.019184,0.021191,0.964503,0.014306,0.008437,0.054813,0.936750}, {0.895720,0.133330,-0.029050,0.029997,0.945400,0.024603,0.013027,0.104707,0.882266}, {0.905871,0.127791,-0.033662,0.026856,0.941251,0.031893,0.013410,0.148296,0.838294}, {0.948035,0.089490,-0.037526,0.014364,0.946792,0.038844,0.010853,0.193991,0.795156}, {1.017277,0.027029,-0.044306,-0.006113,0.958479,0.047634,0.006379,0.248708,0.744913}, {1.104996,-0.046633,-0.058363,-0.032137,0.971635,0.060503,0.001336,0.317922,0.680742}, {1.193214,-0.109812,-0.083402,-0.058496,0.979410,0.079086,-0.002346,0.403492,0.598854}, {1.257728,-0.139648,-0.118081,-0.078003,0.975409,0.102594,-0.003316,0.501214,0.502102}, {1.278864,-0.125333,-0.153531,-0.084748,0.957674,0.127074,-0.000989,0.601151,0.399838}, {1.255528,-0.076749,-0.178779,-0.078411,0.930809,0.147602,0.004733,0.691367,0.303900}, }; const double rgb_to_lms[3][3] = { {0.05059983, 0.08585369, 0.00952420}, {0.01893033, 0.08925308, 0.01370054}, {0.00292202, 0.00975732, 0.07145979}, }; const double lms_to_rgb[3][3] = { {30.830854, -29.832659, 1.610474}, {-6.481468, 17.715578, -2.532642}, {-0.375690, -1.199062, 14.273846}, }; const double anchor[] = { 0.080080, 0.157900, 0.589700, 0.128400, 0.223700, 0.363600, 0.985600, 0.732500, 0.001079, 0.091400, 0.007009, 0.000000, }; const double rgb_anchor[] = { rgb_to_lms[0][0] + rgb_to_lms[0][1] + rgb_to_lms[0][2], rgb_to_lms[1][0] + rgb_to_lms[1][1] + rgb_to_lms[1][2], rgb_to_lms[2][0] + rgb_to_lms[2][1] + rgb_to_lms[2][2], }; const vector3 protanopia_abc[2] = { {{{ rgb_anchor[1] * anchor[8] - rgb_anchor[2] * anchor[7], rgb_anchor[2] * anchor[6] - rgb_anchor[0] * anchor[8], rgb_anchor[0] * anchor[7] - rgb_anchor[1] * anchor[6], }}}, {{{ rgb_anchor[1] * anchor[2] - rgb_anchor[2] * anchor[1], rgb_anchor[2] * anchor[0] - rgb_anchor[0] * anchor[2], rgb_anchor[0] * anchor[1] - rgb_anchor[1] * anchor[0], }}}, }; const vector3 deuteranopia_abc[2] = { {{{ rgb_anchor[1] * anchor[8] - rgb_anchor[2] * anchor[7], rgb_anchor[2] * anchor[6] - rgb_anchor[0] * anchor[8], rgb_anchor[0] * anchor[7] - rgb_anchor[1] * anchor[6], }}}, {{{ rgb_anchor[1] * anchor[2] - rgb_anchor[2] * anchor[1], rgb_anchor[2] * anchor[0] - rgb_anchor[0] * anchor[2], rgb_anchor[0] * anchor[1] - rgb_anchor[1] * anchor[0], }}}, }; const vector3 tritanopia_abc[2] = { {{{ rgb_anchor[1] * anchor[11] - rgb_anchor[2] * anchor[10], rgb_anchor[2] * anchor[9] - rgb_anchor[0] * anchor[11], rgb_anchor[0] * anchor[10] - rgb_anchor[1] * anchor[9], }}}, {{{ rgb_anchor[1] * anchor[5] - rgb_anchor[2] * anchor[4], rgb_anchor[2] * anchor[3] - rgb_anchor[0] * anchor[5], rgb_anchor[0] * anchor[4] - rgb_anchor[1] * anchor[3], }}}, }; static void load_matrix(const double matrix_data[9], matrix3x3 *matrix) { matrix->m[0][0] = matrix_data[0]; matrix->m[1][0] = matrix_data[1]; matrix->m[2][0] = matrix_data[2]; matrix->m[0][1] = matrix_data[3]; matrix->m[1][1] = matrix_data[4]; matrix->m[2][1] = matrix_data[5]; matrix->m[0][2] = matrix_data[6]; matrix->m[1][2] = matrix_data[7]; matrix->m[2][2] = matrix_data[8]; } static void load_matrix(const double matrix_data[3][3], matrix3x3 *matrix) { matrix->m[0][0] = matrix_data[0][0]; matrix->m[1][0] = matrix_data[1][0]; matrix->m[2][0] = matrix_data[2][0]; matrix->m[0][1] = matrix_data[0][1]; matrix->m[1][1] = matrix_data[1][1]; matrix->m[2][1] = matrix_data[2][1]; matrix->m[0][2] = matrix_data[0][2]; matrix->m[1][2] = matrix_data[1][2]; matrix->m[2][2] = matrix_data[2][2]; } static void load_vector(const Color *color, vector3 *vector) { vector->x = color->rgb.red; vector->y = color->rgb.green; vector->z = color->rgb.blue; } void ColorVisionDeficiency::apply(Color *input, Color *output) { Color linear_input, linear_output; color_rgb_get_linear(input, &linear_input); vector3 vi, vo1, vo2; load_vector(&linear_input, &vi); matrix3x3 matrix1, matrix2; int index = floor(strength * 10); int index_secondary = std::min(index + 1, 10); float interpolation_factor = 1 - ((strength * 10) - index); vector3 lms; if ((type == PROTANOPIA) || (type == DEUTERANOPIA) || (type == TRITANOPIA)){ load_matrix(rgb_to_lms, &matrix1); load_matrix(lms_to_rgb, &matrix2); vector3_multiply_matrix3x3(&vi, &matrix1, &lms); } switch (type){ case PROTANOMALY: load_matrix(protanomaly[index], &matrix1); load_matrix(protanomaly[index_secondary], &matrix2); vector3_multiply_matrix3x3(&vi, &matrix1, &vo1); vector3_multiply_matrix3x3(&vi, &matrix2, &vo2); break; case DEUTERANOMALY: load_matrix(deuteranomaly[index], &matrix1); load_matrix(deuteranomaly[index_secondary], &matrix2); vector3_multiply_matrix3x3(&vi, &matrix1, &vo1); vector3_multiply_matrix3x3(&vi, &matrix2, &vo2); break; case TRITANOMALY: load_matrix(tritanomaly[index], &matrix1); load_matrix(tritanomaly[index_secondary], &matrix2); vector3_multiply_matrix3x3(&vi, &matrix1, &vo1); vector3_multiply_matrix3x3(&vi, &matrix2, &vo2); break; case PROTANOPIA: if (lms.z / lms.y < rgb_anchor[2] / rgb_anchor[1]){ lms.x = -(protanopia_abc[0].y * lms.y + protanopia_abc[0].z * lms.z) / protanopia_abc[0].x; }else{ lms.x = -(protanopia_abc[1].y * lms.y + protanopia_abc[1].z * lms.z) / protanopia_abc[1].x; } vector3_multiply_matrix3x3(&lms, &matrix2, &vo1); load_vector(&linear_input, &vo2); interpolation_factor = strength; break; case DEUTERANOPIA: if (lms.z / lms.x < rgb_anchor[2] / rgb_anchor[0]){ lms.y = -(deuteranopia_abc[0].x * lms.x + deuteranopia_abc[0].z * lms.z) / deuteranopia_abc[0].y; }else{ lms.y = -(deuteranopia_abc[1].x * lms.x + deuteranopia_abc[1].z * lms.z) / deuteranopia_abc[1].y; } vector3_multiply_matrix3x3(&lms, &matrix2, &vo1); load_vector(&linear_input, &vo2); interpolation_factor = strength; break; case TRITANOPIA: if (lms.y / lms.x < rgb_anchor[1] / rgb_anchor[0]){ lms.z = -(tritanopia_abc[0].x * lms.x + tritanopia_abc[0].y * lms.y) / tritanopia_abc[0].z; }else{ lms.z = -(tritanopia_abc[1].x * lms.x + tritanopia_abc[1].y * lms.y) / tritanopia_abc[1].z; } vector3_multiply_matrix3x3(&lms, &matrix2, &vo1); load_vector(&linear_input, &vo2); interpolation_factor = strength; break; default: color_copy(input, output); return; } linear_output.rgb.red = vo1.x * interpolation_factor + vo2.x * (1 - interpolation_factor); linear_output.rgb.green = vo1.y * interpolation_factor + vo2.y * (1 - interpolation_factor); linear_output.rgb.blue = vo1.z * interpolation_factor + vo2.z * (1 - interpolation_factor); color_linear_get_rgb(&linear_output, output); color_rgb_normalize(output); } ColorVisionDeficiency::ColorVisionDeficiency():Transformation(transformation_name, getReadableName()) { type = PROTANOMALY; strength = 0.5; } ColorVisionDeficiency::ColorVisionDeficiency(DeficiencyType type_, float strength_):Transformation(transformation_name, getReadableName()) { type = type_; strength = strength_; } ColorVisionDeficiency::~ColorVisionDeficiency() { } void ColorVisionDeficiency::serialize(struct dynvSystem *dynv) { dynv_set_float(dynv, "strength", strength); dynv_set_string(dynv, "type", deficiency_type_string[type]); Transformation::serialize(dynv); } ColorVisionDeficiency::DeficiencyType ColorVisionDeficiency::typeFromString(const char *type_string) { for (int i = 0; i < DEFICIENCY_TYPE_COUNT; i++){ if (strcmp(type_string, deficiency_type_string[i]) == 0){ return (DeficiencyType)i; } } return PROTANOMALY; } void ColorVisionDeficiency::deserialize(struct dynvSystem *dynv) { strength = dynv_get_float_wd(dynv, "strength", 0.5); type = typeFromString(dynv_get_string_wd(dynv, "type", "protanomaly")); } static GtkWidget* create_type_list(void){ GtkListStore *store; GtkCellRenderer *renderer; GtkWidget *widget; store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); gtk_combo_box_set_add_tearoffs(GTK_COMBO_BOX(widget), 0); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, 0); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); g_object_unref(GTK_TREE_MODEL(store)); GtkTreeIter iter1; struct { const char *name; int type; } types[] = { {_("Protanomaly"), ColorVisionDeficiency::PROTANOMALY}, {_("Deuteranomaly"), ColorVisionDeficiency::DEUTERANOMALY}, {_("Tritanomaly"), ColorVisionDeficiency::TRITANOMALY}, {_("Protanopia"), ColorVisionDeficiency::PROTANOPIA}, {_("Deuteranopia"), ColorVisionDeficiency::DEUTERANOPIA}, {_("Tritanopia"), ColorVisionDeficiency::TRITANOPIA}, }; for (int i = 0; i < ColorVisionDeficiency::DEFICIENCY_TYPE_COUNT; ++i){ gtk_list_store_append(store, &iter1); gtk_list_store_set(store, &iter1, 0, types[i].name, 1, types[i].type, -1); } return widget; } boost::shared_ptr ColorVisionDeficiency::getConfig(){ boost::shared_ptr config = boost::shared_ptr(new ColorVisionDeficiencyConfig(*this)); return config; } ColorVisionDeficiencyConfig::ColorVisionDeficiencyConfig(ColorVisionDeficiency &transformation){ GtkWidget *table = gtk_table_new(2, 2, false); GtkWidget *widget; int table_y = 0; 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_FILL, 5, 5); type = widget = create_type_list(); g_signal_connect(G_OBJECT(type), "changed", G_CALLBACK(ColorVisionDeficiencyConfig::type_combobox_change_cb), this); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); table_y++; info_bar = widget = gtk_info_bar_new(); info_label = gtk_label_new(""); gtk_label_set_line_wrap(GTK_LABEL(info_label), true); gtk_label_set_justify(GTK_LABEL(info_label), GTK_JUSTIFY_LEFT); gtk_label_set_single_line_mode(GTK_LABEL(info_label), false); gtk_misc_set_alignment(GTK_MISC(info_label), 0, 0.5); gtk_widget_set_size_request(info_label, 1, -1); GtkWidget *content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar)); gtk_container_add(GTK_CONTAINER(content_area), info_label); gtk_widget_show_all(info_bar); g_signal_connect(G_OBJECT(info_label), "size-allocate", G_CALLBACK(info_label_size_allocate_cb), this); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); table_y++; gtk_combo_box_set_active(GTK_COMBO_BOX(type), transformation.type); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Strength:"), 0, 0.5, 0, 0), 0, 1, table_y, table_y + 1, GTK_FILL, GTK_FILL, 5, 5); strength = widget = gtk_hscale_new_with_range(0, 100, 1); gtk_range_set_value(GTK_RANGE(widget), transformation.strength * 100); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y + 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 5, 0); table_y++; main = table; gtk_widget_show_all(main); g_object_ref(main); } ColorVisionDeficiencyConfig::~ColorVisionDeficiencyConfig(){ g_object_unref(main); } GtkWidget* ColorVisionDeficiencyConfig::getWidget(){ return main; } void ColorVisionDeficiencyConfig::applyConfig(dynvSystem *dynv){ dynv_set_float(dynv, "strength", gtk_range_get_value(GTK_RANGE(strength)) / 100.0f); GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(type), &iter)) { GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(type)); ColorVisionDeficiency::DeficiencyType type_id; gtk_tree_model_get(model, &iter, 1, &type_id, -1); dynv_set_string(dynv, "type", ColorVisionDeficiency::deficiency_type_string[type_id]); } } void ColorVisionDeficiencyConfig::type_combobox_change_cb(GtkWidget *widget, ColorVisionDeficiencyConfig *this_) { const char *descriptions[] = { _("Altered spectral sensitivity of red receptors"), _("Altered spectral sensitivity of green receptors"), _("Altered spectral sensitivity of blue receptors"), _("Absence of red receptors"), _("Absence of green receptors"), _("Absence of blue receptors"), }; GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(this_->type), &iter)) { GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(this_->type)); ColorVisionDeficiency::DeficiencyType type_id; gtk_tree_model_get(model, &iter, 1, &type_id, -1); gtk_label_set_text(GTK_LABEL(this_->info_label), descriptions[type_id]); }else{ gtk_label_set_text(GTK_LABEL(this_->info_label), ""); } gtk_info_bar_set_message_type(GTK_INFO_BAR(this_->info_bar), GTK_MESSAGE_INFO); } void ColorVisionDeficiencyConfig::info_label_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, ColorVisionDeficiencyConfig *this_) { gtk_widget_set_size_request(this_->info_label, allocation->width - 16, -1); } } gpick_0.2.5/source/transformation/ColorVisionDeficiency.h0000644000175000017500000000625412070605214022361 0ustar zbygzbyg/* * 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 TRANSFORMATION_COLOR_VISION_DEFICIENCY_H_ #define TRANSFORMATION_COLOR_VISION_DEFICIENCY_H_ #include "Transformation.h" namespace transformation { class ColorVisionDeficiency; class ColorVisionDeficiencyConfig: public Configuration{ protected: GtkWidget *main; GtkWidget *info_bar; GtkWidget *info_label; GtkWidget *type; GtkWidget *strength; static void type_combobox_change_cb(GtkWidget *widget, ColorVisionDeficiencyConfig *this_); static void info_label_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, ColorVisionDeficiencyConfig *this_); public: ColorVisionDeficiencyConfig(ColorVisionDeficiency &transformation); virtual ~ColorVisionDeficiencyConfig(); virtual GtkWidget* getWidget(); virtual void applyConfig(dynvSystem *dynv); }; class ColorVisionDeficiency: public Transformation{ public: enum DeficiencyType{ PROTANOMALY, DEUTERANOMALY, TRITANOMALY, PROTANOPIA, DEUTERANOPIA, TRITANOPIA, DEFICIENCY_TYPE_COUNT, }; static const char *deficiency_type_string[]; static const char *getName(); static const char *getReadableName(); protected: float strength; DeficiencyType type; virtual void apply(Color *input, Color *output); public: ColorVisionDeficiency(); ColorVisionDeficiency(DeficiencyType type, float strength); virtual ~ColorVisionDeficiency(); virtual void serialize(struct dynvSystem *dynv); virtual void deserialize(struct dynvSystem *dynv); virtual boost::shared_ptr getConfig(); DeficiencyType typeFromString(const char *type_string); friend class ColorVisionDeficiencyConfig; }; } #endif /* TRANSFORMATION_COLOR_VISION_DEFICIENCY_H_ */ gpick_0.2.5/source/transformation/Factory.h0000644000175000017500000000472612070605214017541 0ustar zbygzbyg/* * 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 TRANSFORMATION_FACTORY_H_ #define TRANSFORMATION_FACTORY_H_ #include "Transformation.h" #include #include /** \file source/transformation/Factory.h * \brief Class for transformation object creation. */ namespace transformation { /** \class Factory * \brief Transformation object creation management class. */ class Factory{ public: typedef struct TypeInfo{ const char *name; const char *human_name; TypeInfo(const char *name, const char *human_name); }TypeInfo; /** * Create new transformation object. * @param[in] type Name of transformation object type. * @return New transformation object. */ static boost::shared_ptr create(const char *type); /** * Get all transformation object types. * @return Vector of transformation object type information structures. */ static std::vector getAllTypes(); }; } #endif /* TRANSFORMATION_FACTORY_H_ */ gpick_0.2.5/source/transformation/Configuration.cpp0000644000175000017500000000340112070605214021261 0ustar zbygzbyg/* * 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 "Configuration.h" namespace transformation { Configuration::Configuration() { } Configuration::~Configuration() { } GtkWidget* Configuration::getWidget() { return 0; } void Configuration::applyConfig(dynvSystem *dynv) { } } gpick_0.2.5/source/transformation/Transformation.cpp0000644000175000017500000000437012070605214021466 0ustar zbygzbyg/* * 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 "Transformation.h" namespace transformation { Transformation::Transformation(const char *name_, const char *readable_name_) { name = name_; readable_name = readable_name_; } Transformation::~Transformation() { } void Transformation::apply(Color *input, Color *output) { color_copy(input, output); } std::string Transformation::getName() const { return name; } std::string Transformation::getReadableName() const { return readable_name; } void Transformation::serialize(struct dynvSystem *dynv) { dynv_set_string(dynv, "name", name.c_str()); } void Transformation::deserialize(struct dynvSystem *dynv) { } boost::shared_ptr Transformation::getConfig() { return boost::shared_ptr(); } } gpick_0.2.5/source/transformation/Factory.cpp0000644000175000017500000000525012070605214020065 0ustar zbygzbyg/* * 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 "Factory.h" #include "ColorVisionDeficiency.h" #include "GammaModification.h" #include "Quantization.h" #include namespace transformation { boost::shared_ptr Factory::create(const char *type) { if (strcmp(ColorVisionDeficiency::getName(), type) == 0){ return boost::shared_ptr(new ColorVisionDeficiency()); } if (strcmp(GammaModification::getName(), type) == 0){ return boost::shared_ptr(new GammaModification()); } if (strcmp(Quantization::getName(), type) == 0){ return boost::shared_ptr(new Quantization()); } return boost::shared_ptr(); } std::vector Factory::getAllTypes() { std::vector result; result.push_back(TypeInfo(ColorVisionDeficiency::getName(), ColorVisionDeficiency::getReadableName())); result.push_back(TypeInfo(GammaModification::getName(), GammaModification::getReadableName())); result.push_back(TypeInfo(Quantization::getName(), Quantization::getReadableName())); return result; } Factory::TypeInfo::TypeInfo(const char *name_, const char *human_name_): name(name_), human_name(human_name_) { } } gpick_0.2.5/source/transformation/Quantization.h0000644000175000017500000000501112070605214020604 0ustar zbygzbyg/* * 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 TRANSFORMATION_QUANTIZATION_H_ #define TRANSFORMATION_QUANTIZATION_H_ #include "Transformation.h" namespace transformation { class Quantization; class QuantizationConfig: public Configuration{ protected: GtkWidget *main; GtkWidget *value; GtkWidget *clip_top; public: QuantizationConfig(Quantization &transformation); virtual ~QuantizationConfig(); virtual GtkWidget* getWidget(); virtual void applyConfig(dynvSystem *dynv); }; class Quantization: public Transformation{ public: static const char *getName(); static const char *getReadableName(); protected: float value; bool clip_top; virtual void apply(Color *input, Color *output); public: Quantization(); Quantization(float value); virtual ~Quantization(); virtual void serialize(struct dynvSystem *dynv); virtual void deserialize(struct dynvSystem *dynv); virtual boost::shared_ptr getConfig(); friend class QuantizationConfig; }; } #endif /* TRANSFORMATION_GAMMA_MODIFICATION_H_ */ gpick_0.2.5/source/transformation/GammaModification.h0000644000175000017500000000503712070605214021476 0ustar zbygzbyg/* * 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 TRANSFORMATION_GAMMA_MODIFICATION_H_ #define TRANSFORMATION_GAMMA_MODIFICATION_H_ #include "Transformation.h" namespace transformation { class GammaModification; class GammaModificationConfig: public Configuration{ protected: GtkWidget *main; GtkWidget *value; public: GammaModificationConfig(GammaModification &transformation); virtual ~GammaModificationConfig(); virtual GtkWidget* getWidget(); virtual void applyConfig(dynvSystem *dynv); }; class GammaModification: public Transformation{ public: static const char *getName(); static const char *getReadableName(); protected: float value; virtual void apply(Color *input, Color *output); public: GammaModification(); GammaModification(float value); virtual ~GammaModification(); virtual void serialize(struct dynvSystem *dynv); virtual void deserialize(struct dynvSystem *dynv); virtual boost::shared_ptr getConfig(); friend class GammaModificationConfig; }; } #endif /* TRANSFORMATION_GAMMA_MODIFICATION_H_ */ gpick_0.2.5/source/transformation/Transformation.h0000644000175000017500000000662212070605214021135 0ustar zbygzbyg/* * 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 TRANSFORMATION_H_ #define TRANSFORMATION_H_ #include "../Color.h" #include "Configuration.h" #include "../DynvHelpers.h" #include #include /** \file source/transformation/Transformation.h * \brief Color transformation class. */ namespace transformation { /** \class Transformation * \brief Transformation object class. */ class Transformation{ protected: std::string name; /**< System name */ std::string readable_name; /**< Human readable name */ /** * Apply transformation to color. * @param[in] input Source color in RGB color space. * @param[out] output Destination color in RGB color space. */ virtual void apply(Color *input, Color *output); public: /** * Transformation object constructor. * @param[in] name Transformation object system name. * @param[in] readable_name Transformation object human readable name. */ Transformation(const char *name, const char *readable_name); /** * Transformation object destructor. */ virtual ~Transformation(); /** * Serialize settings into configuration system. * @param[in,out] dynv Configuration system. */ virtual void serialize(struct dynvSystem *dynv); /** * Deserialize settings from configuration system. * @param[in] dynv Configuration system. */ virtual void deserialize(struct dynvSystem *dynv); /** * Get configuration for transformation object. * @return Configuration for transformation object. */ virtual boost::shared_ptr getConfig(); /** * Get transformation object system name. * @return Transformation object system name. */ std::string getName() const; /** * Get transformation object human readable name. * @return Transformation object human readable name. */ std::string getReadableName() const; friend class Chain; }; } #endif /* TRANSFORMATION_H_ */ gpick_0.2.5/source/tools/PaletteFromImage.h0000644000175000017500000000340312070605214017400 0ustar zbygzbyg/* * 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 TOOLS_PALETTE_FROM_IMAGE_H_ #define TOOLS_PALETTE_FROM_IMAGE_H_ #include #include "../GlobalStateStruct.h" void tools_palette_from_image_show(GtkWindow* parent, GlobalState* gs); #endif /* TOOLS_PALETTE_FROM_IMAGE_H_ */ gpick_0.2.5/source/tools/SConscript0000644000175000017500000000104312113713537016060 0ustar zbygzbyg#!/usr/bin/env python 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 local_env['ENABLE_NLS']: local_env.Append( CPPDEFINES = ['ENABLE_NLS'], ) if env['EXPERIMENTAL_CSS_PARSER']: local_env.Append( CPPDEFINES = ['EXPERIMENTAL_CSS_PARSER'], ) sources = local_env.Glob('*.cpp') objects = local_env.StaticObject( source = [sources]) Return('objects') gpick_0.2.5/source/tools/PaletteFromImage.cpp0000644000175000017500000004564712070605214017753 0ustar zbygzbyg/* * 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 "PaletteFromImage.h" #include "../uiUtilities.h" #include "../uiListPalette.h" #include "../GlobalStateStruct.h" #include "../ToolColorNaming.h" #include "../DynvHelpers.h" #include "../Internationalisation.h" #include #include #include #include #include using namespace std; /** \file PaletteFromImage.cpp * \brief */ /** \struct Node * \brief Node is a cube in space with color information * * Each node can b */ typedef struct Node{ uint32_t n_pixels; /**< Number of colors in current Node and its children */ uint32_t n_pixels_in; /**< Number of colors in current Node */ float color[3]; /**< Sum of color values */ float distance; /**< Squared distances from Node center of colors in Node */ Node *child[8]; /**< Pointers to child Nodes */ Node *parent; /**< Pointer to parent Node */ }Node; /** \struct Cube * \brief Cube structure holds all information necessary to define cube size and position in space */ typedef struct Cube{ float x; /**< X position */ float w; /**< Width */ float y; /**< Y position */ float h; /**< Height */ float z; /**< Z position */ float d; /**< Depth */ }Cube; typedef struct PaletteFromImageArgs{ GtkWidget *file_browser; GtkWidget *range_colors; GtkWidget *merge_threshold; GtkWidget *preview_expander; string filename; uint32_t n_colors; string previous_filename; Node *previous_node; struct ColorList *color_list; struct ColorList *preview_color_list; struct dynvSystem *params; GlobalState* gs; }PaletteFromImageArgs; class PaletteColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; const char *m_filename; int m_index; public: PaletteColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){ m_index = 0; } void assign(struct ColorObject *color_object, Color *color, const char *filename, const int index){ m_filename = filename; m_index = index; ToolColorNameAssigner::assign(color_object, color); } virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){ m_stream.str(""); m_stream << m_filename << " #" << m_index; return m_stream.str(); } }; /** * Allocate and initialize a new node with specified parent * @param[in] parent Parent node * @return New node */ static Node* node_new(Node *parent){ Node *n = new Node; n->color[0] = n->color[1] = n->color[2] = 0; n->distance = 0; n->n_pixels = 0; n->n_pixels_in = 0; n->parent = parent; for (int i = 0; i < 8; i++){ n->child[i] = 0; } return n; } /** * Deallocate node and its children * @param[in] node Node to deallocate */ static void node_delete(Node *node){ for (int i = 0; i < 8; i++){ if (node->child[i]){ node_delete(node->child[i]); } } delete node; } /** * Copy node and assing new parent * @param[in] node Node to copy * @param[in] parent Parent of copied node * @return A copy of node */ static Node* node_copy(Node *node, Node *parent){ Node *n = node_new(0); memcpy(n, node, sizeof(Node)); n->parent = parent; for (int i = 0; i < 8; i++){ if (node->child[i]){ n->child[i] = node_copy(node->child[i], n); }else{ n->child[i] = 0; } } return n; } /** * Get the number of nodes with available color information in them * @param[in] node Start from this node * @return Number of nodes with available color information in them */ static uint32_t node_count_leafs(Node *node){ uint32_t r = 0; if (node->n_pixels_in) r++; for (int i = 0; i < 8; i++){ if (node->child[i]) r += node_count_leafs(node->child[i]); } return r; } /** * Call callback on all nodes with available color information in them * @param[in] node Start from this node * @param[in] leaf_cb Callback function * @param[in] userdata User supplied pointer which is passed when calling callback */ static void node_leaf_callback(Node *node, void (*leaf_cb)(Node* node, void* userdata), void* userdata){ if (node->n_pixels_in > 0) leaf_cb(node, userdata); for (int i = 0; i < 8; i++){ if (node->child[i]) node_leaf_callback(node->child[i], leaf_cb, userdata); } } /** * Merge node information into its parent node * @param[in] node Node to merge */ static void node_prune(Node *node){ for (int i = 0; i < 8; i++){ if (node->child[i]){ node_prune(node->child[i]); node->child[i] = 0; } } if (node->parent){ node->parent->n_pixels_in += node->n_pixels_in; node->parent->color[0] += node->color[0]; node->parent->color[1] += node->color[1]; node->parent->color[2] += node->color[2]; } node_delete(node); } typedef struct PruneData{ float threshold; float min_distance; uint32_t n_colors; uint32_t n_colors_target; Node *prune_node; uint32_t distant_nodes; }PruneData; static bool node_prune_threshold(Node *node, PruneData *prune_data){ if (node->distance <= prune_data->threshold){ uint32_t colors_removed = node_count_leafs(node); node_prune(node); prune_data->n_colors -= colors_removed; return true; } if (node->distance < prune_data->min_distance){ prune_data->min_distance = node->distance; } uint32_t n = node->n_pixels_in; for (int i = 0; i < 8; i++){ if (node->child[i]){ if (node_prune_threshold(node->child[i], prune_data)){ node->child[i] = 0; } } } if (node->n_pixels_in > 0 && n == 0) prune_data->n_colors++; return false; } static void node_reduce(Node *node, uint32_t colors){ PruneData prune_data; prune_data.n_colors = node_count_leafs(node); prune_data.n_colors_target = colors; prune_data.threshold = 0; while (prune_data.n_colors > colors){ prune_data.min_distance = node->distance; if (node_prune_threshold(node, &prune_data)) break; prune_data.threshold = prune_data.min_distance; } } static void node_update(Node *node, Color *color, Cube *cube, uint32_t max_depth){ Cube new_cube; new_cube.w = cube->w / 2; new_cube.h = cube->h / 2; new_cube.d = cube->d / 2; node->n_pixels++; node->distance += (color->xyz.x - (cube->x + new_cube.w)) * (color->xyz.x - (cube->x + new_cube.w)) + (color->xyz.y - (cube->y + new_cube.h)) * (color->xyz.y - (cube->y + new_cube.h)) + (color->xyz.z - (cube->z + new_cube.d)) * (color->xyz.z - (cube->z + new_cube.d)); if (!max_depth){ node->n_pixels_in++; node->color[0] += color->xyz.x; node->color[1] += color->xyz.y; node->color[2] += color->xyz.z; }else{ int x, y, z; if (color->xyz.x - cube->x < new_cube.w) x = 0; else x = 1; if (color->xyz.y - cube->y < new_cube.h) y = 0; else y = 1; if (color->xyz.z - cube->z < new_cube.d) z = 0; else z = 1; new_cube.x = cube->x + new_cube.w * x; new_cube.y = cube->y + new_cube.h * y; new_cube.z = cube->z + new_cube.d * z; int i = x | (y<<1) | (z<<2); if (!node->child[i]) node->child[i] = node_new(node); node->n_pixels++; node_update(node->child[x | (y<<1) | (z<<2)], color, &new_cube, max_depth - 1); } } static void leaf_cb(Node *node, void *userdata){ list *l = static_cast*>(userdata); Color c; c.xyz.x = node->color[0] / node->n_pixels_in; c.xyz.y = node->color[1] / node->n_pixels_in; c.xyz.z = node->color[2] / node->n_pixels_in; l->push_back(c); } static Node* process_image(PaletteFromImageArgs *args, const char *filename, Node* node){ if (args->previous_filename == filename){ if (args->previous_node) return node_copy(args->previous_node, 0); else return 0; } args->previous_filename = filename; if (args->previous_node){ node_delete(args->previous_node); args->previous_node = 0; } GError *error = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, &error); if (error){ cout << error->message << endl; g_error_free(error); return 0; } int channels = gdk_pixbuf_get_n_channels(pixbuf); int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); int rowstride = gdk_pixbuf_get_rowstride(pixbuf); guchar *image_data = gdk_pixbuf_get_pixels(pixbuf); guchar *ptr = image_data; Cube cube; cube.x = 0; cube.y = 0; cube.z = 0; cube.w = 1; cube.h = 1; cube.d = 1; Color color; args->previous_node = node_new(0); for (int y = 0; y < height; y++){ ptr = image_data + rowstride * y; for (int x = 0; x < width; x++){ color.xyz.x = ptr[0] / 255.0; color.xyz.y = ptr[1] / 255.0; color.xyz.z = ptr[2] / 255.0; node_update(args->previous_node, &color, &cube, 5); ptr += channels; } } g_object_unref(pixbuf); node_reduce(args->previous_node, 200); return node_copy(args->previous_node, 0); } static void get_settings(PaletteFromImageArgs *args){ gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(args->file_browser)); if (filename){ args->filename = filename; g_free(filename); }else{ args->filename.clear(); } args->n_colors = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->range_colors)); } static void save_settings(PaletteFromImageArgs *args){ dynv_set_int32(args->params, "colors", args->n_colors); gchar *current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(args->file_browser)); if (current_folder){ dynv_set_string(args->params, "current_folder", current_folder); g_free(current_folder); } GtkFileFilter *filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(args->file_browser)); if (filter){ const char *filter_name = static_cast(g_object_get_data(G_OBJECT(filter), "name")); dynv_set_string(args->params, "filter", filter_name); } } static void calc(PaletteFromImageArgs *args, bool preview, int limit){ Node *root_node = 0; int index = 0; gchar *name = g_path_get_basename(args->filename.c_str()); PaletteColorNameAssigner name_assigner(args->gs); if (!args->filename.empty()) root_node = process_image(args, args->filename.c_str(), root_node); struct ColorList *color_list; if (preview) color_list = args->preview_color_list; else color_list = args->gs->colors; list tmp_list; if (root_node){ node_reduce(root_node, args->n_colors); node_leaf_callback(root_node, leaf_cb, &tmp_list); node_delete(root_node); } for (list::iterator i = tmp_list.begin(); i != tmp_list.end(); i++){ struct ColorObject *color_object = color_list_new_color_object(color_list, &(*i)); name_assigner.assign(color_object, &(*i), name, index); color_list_add_color_object(color_list, color_object, 1); color_object_release(color_object); index++; } } static void update(GtkWidget *widget, PaletteFromImageArgs *args ){ color_list_remove_all(args->preview_color_list); get_settings(args); calc(args, true, 100); } static gchar* format_threshold_value_cb(GtkScale *scale, gdouble value){ return g_strdup_printf("%0.01f%%", value); } static void destroy_cb(GtkWidget* widget, PaletteFromImageArgs *args){ if (args->previous_node) node_delete(args->previous_node); color_list_destroy(args->preview_color_list); dynv_system_release(args->params); delete args; } static void response_cb(GtkWidget* widget, gint response_id, PaletteFromImageArgs *args){ get_settings(args); save_settings(args); gint width, height; gtk_window_get_size(GTK_WINDOW(widget), &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(args->preview_expander))); switch (response_id){ case GTK_RESPONSE_APPLY: calc(args, false, 0); break; case GTK_RESPONSE_DELETE_EVENT: break; case GTK_RESPONSE_CLOSE: gtk_widget_destroy(widget); break; } } void tools_palette_from_image_show(GtkWindow* parent, GlobalState* gs){ PaletteFromImageArgs *args = new PaletteFromImageArgs; args->previous_filename = ""; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick.tools.palette_from_image"); args->previous_node = 0; GtkWidget *table, *table_m, *widget; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Palette from image"), parent, GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_ADD, GTK_RESPONSE_APPLY, 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_APPLY, GTK_RESPONSE_CLOSE, -1); GtkWidget *frame; gint table_y, table_m_y; table_m = gtk_table_new(3, 1, FALSE); table_m_y = 0; frame = gtk_frame_new(_("Image")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->file_browser = widget = gtk_file_chooser_button_new(_("Image file"), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(widget), dynv_get_string_wd(args->params, "current_folder", "")); gtk_table_attach(GTK_TABLE(table), widget, 0, 3, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); g_signal_connect(G_OBJECT(args->file_browser), "file-set", G_CALLBACK(update), args); table_y++; const char* selected_filter = dynv_get_string_wd(args->params, "filter", "all_images"); GtkFileFilter *filter; GtkFileFilter *all_image_filter; filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("All files")); gtk_file_filter_add_pattern(filter, "*"); g_object_set_data_full(G_OBJECT(filter), "name", (void*)"all_files", GDestroyNotify(NULL)); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(widget), filter); if (g_strcmp0("all_files", selected_filter) == 0) gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(widget), filter); all_image_filter = gtk_file_filter_new(); gtk_file_filter_set_name(all_image_filter, _("All images")); g_object_set_data_full(G_OBJECT(all_image_filter), "name", (void*)"all_images", GDestroyNotify(NULL)); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(widget), all_image_filter); if (g_strcmp0("all_images", selected_filter) == 0) gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(widget), all_image_filter); stringstream ss; GSList *formats = gdk_pixbuf_get_formats(); GSList *i = formats; while (i){ GdkPixbufFormat *format = static_cast(g_slist_nth_data(i, 0)); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, gdk_pixbuf_format_get_description(format)); gchar **extensions = gdk_pixbuf_format_get_extensions(format); if (extensions){ for (int j = 0; extensions[j]; j++){ ss.str(""); ss << "*." << extensions[j]; gtk_file_filter_add_pattern(filter, ss.str().c_str()); gtk_file_filter_add_pattern(all_image_filter, ss.str().c_str()); } g_strfreev(extensions); } g_object_set_data_full(G_OBJECT(filter), "name", gdk_pixbuf_format_get_name(format), GDestroyNotify(NULL)); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(widget), filter); if (g_strcmp0(gdk_pixbuf_format_get_name(format), selected_filter) == 0) gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(widget), filter); i = g_slist_next(i); } if (formats) g_slist_free(formats); frame = gtk_frame_new(_("Options")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Colors:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->range_colors = widget = gtk_spin_button_new_with_range (1, 100, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->range_colors), dynv_get_int32_wd(args->params, "colors", 3)); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); g_signal_connect(G_OBJECT(args->range_colors), "value-changed", G_CALLBACK(update), args); table_y++; /* gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Threshold:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->merge_threshold = widget = gtk_hscale_new_with_range(0, 100, 0.1); gtk_range_set_value(GTK_RANGE(widget), dynv_get_float_wd(args->params, "merge_threshold", 20)); g_signal_connect(G_OBJECT(widget), "value-changed", G_CALLBACK(update), args); g_signal_connect(G_OBJECT(widget), "format-value", G_CALLBACK(format_threshold_value_cb), args); gtk_scale_set_value_pos(GTK_SCALE(widget), GTK_POS_RIGHT); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; */ struct ColorList* preview_color_list = NULL; gtk_table_attach(GTK_TABLE(table_m), args->preview_expander = palette_list_preview_new(gs, true, dynv_get_bool_wd(args->params, "show_preview", true), gs->colors, &preview_color_list), 0, 1, table_m_y, table_m_y+1 , GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 5, 5); table_m_y++; args->preview_color_list = preview_color_list; gtk_widget_show_all(table_m); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table_m); g_signal_connect(G_OBJECT(dialog), "destroy", G_CALLBACK(destroy_cb), args); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_cb), args); gtk_widget_show(dialog); } gpick_0.2.5/source/tools/PaletteFromCssFile.cpp0000644000175000017500000000357312070605214020251 0ustar zbygzbyg/* * 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 "PaletteFromCssFile.h" /*#include "../uiUtilities.h" #include "../uiListPalette.h" #include "../GlobalStateStruct.h" #include "../DynvHelpers.h" */ using namespace std; int parse_file(const char *filename); void tools_palette_from_css_file_show(GtkWindow* parent, GlobalState* gs) { #ifdef EXPERIMENTAL_CSS_PARSER parse_file("test.css"); #endif } gpick_0.2.5/source/tools/PaletteFromCssFile.h0000644000175000017500000000342012070605214017705 0ustar zbygzbyg/* * 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 TOOLS_PALETTE_FROM_CSS_FILE_H_ #define TOOLS_PALETTE_FROM_CSS_FILE_H_ #include #include "../GlobalStateStruct.h" void tools_palette_from_css_file_show(GtkWindow* parent, GlobalState* gs); #endif /* TOOLS_PALETTE_FROM_CSS_FILE_H_ */ gpick_0.2.5/source/Sampler.cpp0000644000175000017500000001307612070605214015020 0ustar zbygzbyg/* * 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 "Sampler.h" #include "MathUtil.h" #include #include using namespace math; struct Sampler{ int oversample; enum SamplerFalloff falloff; float (*falloff_fnc)(float distance); struct ScreenReader* screen_reader; }; static float sampler_falloff_none(float distance) { return 1; } static float sampler_falloff_linear(float distance) { return 1-distance; } static float sampler_falloff_quadratic(float distance) { return 1-(distance*distance); } static float sampler_falloff_cubic(float distance) { return 1-(distance*distance*distance); } static float sampler_falloff_exponential(float distance) { return 1/exp(5*distance*distance); } struct Sampler* sampler_new(struct ScreenReader* screen_reader) { struct Sampler* sampler = new struct Sampler; sampler->oversample=0; sampler_set_falloff(sampler, NONE); sampler->screen_reader = screen_reader; return sampler; } void sampler_destroy(struct Sampler *sampler) { //g_object_unref (sampler->pixbuf); delete sampler; } void sampler_set_falloff(struct Sampler *sampler, enum SamplerFalloff falloff) { sampler->falloff = falloff; switch (falloff){ case NONE: sampler->falloff_fnc = sampler_falloff_none; break; case LINEAR: sampler->falloff_fnc = sampler_falloff_linear; break; case QUADRATIC: sampler->falloff_fnc = sampler_falloff_quadratic; break; case CUBIC: sampler->falloff_fnc = sampler_falloff_cubic; break; case EXPONENTIAL: sampler->falloff_fnc = sampler_falloff_exponential; break; default: sampler->falloff_fnc = 0; } } void sampler_set_oversample(struct Sampler *sampler, int oversample){ sampler->oversample = oversample; } static void get_pixel(GdkPixbuf *pixbuf, int x, int y, Color* color){ int rowstride; guchar *pixels, *p; rowstride = gdk_pixbuf_get_rowstride(pixbuf); pixels = gdk_pixbuf_get_pixels(pixbuf); p = pixels + y * rowstride + x * 3; color->rgb.red = p[0]/255.0; color->rgb.green = p[1]/255.0; color->rgb.blue = p[2]/255.0; } int sampler_get_color_sample(struct Sampler *sampler, Vec2& pointer, Vec2& screen_size, Vec2& offset, Color* color) { Color sample; Color result; float divider = 0; color_zero(&result); GdkPixbuf* pixbuf = screen_reader_get_pixbuf(sampler->screen_reader); int x = pointer.x, y = pointer.y; int width = screen_size.x, height = screen_size.y; int left, right, top, bottom; left = max_int(0, x - sampler->oversample); right = min_int(width, x + sampler->oversample + 1); top = max_int(0, y - sampler->oversample); bottom = min_int(height, y + sampler->oversample + 1); width = right - left; height = bottom - top; int center_x = x-left; int center_y = y-top; float max_distance = 1 / sqrt(2 * pow((double)sampler->oversample, 2)); for (int x=-sampler->oversample; x <= sampler->oversample; ++x){ for (int y=-sampler->oversample; y <= sampler->oversample; ++y){ if ((center_x+x<0) || (center_y+y<0)) continue; if ((center_x+x>=width) || (center_y+y>=height)) continue; get_pixel(pixbuf, offset.x + center_x+x, offset.y + center_y+y, &sample); float f; if (sampler->oversample){ f = sampler->falloff_fnc(sqrt((double)(x * x + y * y)) * max_distance); }else{ f = 1; } color_multiply(&sample, f); color_add(&result, &sample); divider+=f; } } color_multiply(&result, 1/divider); color_copy(&result, color); return 0; } enum SamplerFalloff sampler_get_falloff(struct Sampler *sampler){ return sampler->falloff; } int sampler_get_oversample(struct Sampler *sampler) { return sampler->oversample; } void sampler_get_screen_rect(struct Sampler *sampler, math::Vec2& pointer, math::Vec2& screen_size, math::Rect2 *rect){ int x=pointer.x, y=pointer.y; int width=screen_size.x, height=screen_size.y; int left, right, top, bottom; left = max_int(0, x - sampler->oversample); right = min_int(width, x + sampler->oversample + 1); top = max_int(0, y - sampler->oversample); bottom = min_int(height, y + sampler->oversample + 1); width = right - left; height = bottom - top; *rect = math::Rect2(left, top, right, bottom); } gpick_0.2.5/source/uiExport.cpp0000644000175000017500000005113712070605214015234 0ustar zbygzbyg/* * 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 "uiExport.h" #include "FileFormat.h" #include "uiUtilities.h" #include "uiListPalette.h" #include "Endian.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "Internationalisation.h" #include #include #include #include #include #include #include using namespace std; static int32_t palette_export_gpl_color(struct ColorObject* color_object, void* userdata){ Color color; color_object_get_color(color_object, &color); const char* name = dynv_get_string_wd(color_object->params, "name", ""); (*(ofstream*)userdata) << boost::math::iround(color.rgb.red*255) << "\t" << boost::math::iround(color.rgb.green*255) << "\t" << boost::math::iround(color.rgb.blue*255) << "\t" << name << endl; return 0; } static vector get_ordered_list(struct ColorList *color_list){ vector ordered(color_list_get_count(color_list)); color_list_get_positions(color_list); uint32_t max_index = ~(uint32_t)0; for (ColorList::iter i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ if ((*i)->position != ~(uint32_t)0){ ordered[(*i)->position] = *i; if (max_index == ~(uint32_t)0){ max_index = (*i)->position; }else if ((*i)->position > max_index){ max_index = (*i)->position; } } } if (max_index == ~(uint32_t)0){ return vector(); }else{ ordered.resize(max_index + 1); return ordered; } } int32_t palette_import_gpa(struct ColorList *color_list, const gchar* filename){ return palette_file_load (filename, color_list); } int32_t palette_export_gpa(struct ColorList *color_list, const gchar* filename, gboolean selected){ return palette_file_save (filename, color_list); } int32_t palette_export_gpl(struct ColorList *color_list, const gchar* filename, gboolean selected){ ofstream f(filename, ios::out | ios::trunc); if (f.is_open()){ gchar* name = g_path_get_basename(filename); f << "GIMP Palette" << endl; f << "Name: " << name << endl; f << "Columns: 1" << endl; f << "#" << endl; g_free(name); vector ordered = get_ordered_list(color_list); for (vector::iterator i=ordered.begin(); i!=ordered.end(); ++i){ palette_export_gpl_color(*i, &f); } f.close(); return 0; } return -1; } static void strip_leading_trailing_chars(string& x, string& stripchars){ if (x.empty()) return; if (stripchars.empty()) return; size_t start = x.find_first_not_of(stripchars); size_t end = x.find_last_not_of(stripchars); if ((start == string::npos) || (end == string::npos)){ x.erase(); return; } x = x.substr(start, end - start + 1); } int32_t palette_import_gpl(struct ColorList *color_list, const gchar* filename){ ifstream f(filename, ios::in); if (f.is_open()){ int r = 0; string line; getline(f, line); if (f.good() && line=="GIMP Palette"){ do{ getline(f, line); }while (f.good() && ((line.size() < 1) || (line[0] > '9') || (line[0] < '0'))); int r, g, b; Color c; struct ColorObject* color_object; string strip_chars = " \t"; for(;;){ if (!f.good()) break; if (line[0]!='#'){ stringstream ss(line); ss >> r >> g >> b; getline(ss, line); if (!f.good()) line = ""; strip_leading_trailing_chars(line, strip_chars); c.rgb.red = r / 255.0; c.rgb.green = g / 255.0; c.rgb.blue = b / 255.0; color_object=color_list_new_color_object(color_list, &c); dynv_set_string(color_object->params, "name", line.c_str()); color_list_add_color_object(color_list, color_object, TRUE); color_object_release(color_object); } getline(f, line); } }else r = -1; f.close(); return r; } return -1; } static int32_t palette_export_mtl_color(struct ColorObject* color_object, void* userdata){ Color color; color_object_get_color(color_object, &color); const char* name = dynv_get_string_wd(color_object->params, "name", ""); (*(ofstream*)userdata) << "newmtl " << name << endl; (*(ofstream*)userdata) << "Ns 90.000000" << endl; (*(ofstream*)userdata) << "Ka 0.000000 0.000000 0.000000" << endl; (*(ofstream*)userdata) << "Kd " << color.rgb.red << " " << color.rgb.green << " " << color.rgb.blue << endl; (*(ofstream*)userdata) << "Ks 0.500000 0.500000 0.500000" << endl << endl; return 0; } static int32_t palette_export_mtl(struct ColorList *color_list, const gchar* filename, gboolean selected){ ofstream f(filename, ios::out | ios::trunc); if (f.is_open()){ vector ordered = get_ordered_list(color_list); for (vector::iterator i=ordered.begin(); i!=ordered.end(); ++i){ palette_export_mtl_color(*i, &f); } f.close(); return 0; } return -1; } typedef union FloatInt{ float f; uint32_t i; }FloatInt; static int32_t palette_export_ase_color(struct ColorObject* color_object, void* userdata){ Color color; color_object_get_color(color_object, &color); const char* name = dynv_get_string_wd(color_object->params, "name", ""); glong name_u16_len=0; gunichar2 *name_u16 = g_utf8_to_utf16(name, -1, 0, &name_u16_len, 0); for (glong i=0; i ordered = get_ordered_list(color_list); for (vector::iterator i=ordered.begin(); i!=ordered.end(); ++i){ palette_export_ase_color(*i, &f); } f.close(); return 0; } return -1; } int32_t palette_import_ase(struct ColorList *color_list, const gchar* filename){ ifstream f(filename, ios::binary); if (f.is_open()){ char magic[4]; f.read(magic, 4); if (memcmp(magic, "ASEF", 4)!=0){ f.close(); return -1; } uint32_t version; f.read((char*)&version, 4); version=UINT32_FROM_BE(version); uint32_t blocks; f.read((char*)&blocks, 4); blocks=UINT32_FROM_BE(blocks); uint16_t block_type; uint32_t block_size; int color_supported; for (uint32_t i=0; iparams, "name", name); color_list_add_color_object(color_list, color_object, TRUE); color_object_release(color_object); } uint16_t color_type; f.read((char*)&color_type, 2); g_free(name); } break; default: f.seekg(block_size, ios::cur); } } f.close(); return 0; } return -1; } static int32_t palette_export_txt_color(struct ColorObject* color_object, void* userdata){ Color color; color_object_get_color(color_object, &color); const char* name = dynv_get_string_wd(color_object->params, "name", 0); (*(ofstream*)userdata)< ordered = get_ordered_list(color_list); for (vector::iterator i=ordered.begin(); i!=ordered.end(); ++i){ palette_export_txt_color(*i, &f); } f.close(); return 0; } return -1; } int dialog_export_show(GtkWindow* parent, struct ColorList *selected_color_list, gboolean selected, GlobalState *gs){ GtkWidget *dialog; GtkFileFilter *filter; dialog = gtk_file_chooser_dialog_new (_("Export"), parent, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); struct export_formats{ const gchar* name; const gchar* pattern; int32_t (*export_function)(struct ColorList *color_list, const gchar* filename, gboolean selected); }; struct export_formats formats[] = { { _("Gpick Palette (*.gpa)"), "*.gpa", palette_export_gpa }, { _("GIMP/Inkscape Palette (*.gpl)"), "*.gpl", palette_export_gpl }, { _("Alias/WaveFront Material (*.mtl)"), "*.mtl", palette_export_mtl }, { _("Adobe Swatch Exchange (*.ase)"), "*.ase", palette_export_ase }, { _("Text file (*.txt)"), "*.txt", palette_export_txt }, }; const char* default_path = dynv_get_string_wd(gs->params, "gpick.export.path", ""); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_path); const char* selected_filter = dynv_get_string_wd(gs->params, "gpick.export.filter", "*.gpl"); for (gint i = 0; i != sizeof(formats) / sizeof(struct export_formats); ++i) { filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, formats[i].name); gtk_file_filter_add_pattern(filter, formats[i].pattern); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (g_strcmp0(formats[i].pattern, selected_filter)==0){ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } } gboolean saved=FALSE; while (!saved){ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gchar *path; path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); dynv_set_string(gs->params, "gpick.import.path", path); g_free(path); const gchar *format_name = gtk_file_filter_get_name(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))); for (gint i = 0; i != sizeof(formats) / sizeof(struct export_formats); ++i) { if (g_strcmp0(formats[i].name, format_name)==0){ struct ColorList *color_list_arg; if (selected){ color_list_arg = selected_color_list; }else{ color_list_arg = gs->colors; } if (formats[i].export_function(color_list_arg, filename, selected)==0){ saved=TRUE; }else{ GtkWidget* message; message=gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be exported")); gtk_window_set_title(GTK_WINDOW(dialog), _("Export")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } dynv_set_string(gs->params, "gpick.export.filter", formats[i].pattern); } } g_free(filename); }else break; } gtk_widget_destroy (dialog); return 0; } enum FileType{ GPA, GPL, ASE, UNKNOWN, }; static FileType get_file_type_from_ext(const char *filename){ const struct{ FileType type; const char *extension; }extensions[] = { {GPA, ".gpa"}, {GPL, ".gpl"}, {ASE, ".ase"}, {UNKNOWN, 0}, }; const char *ext = g_strrstr(filename, "."); if (ext){ for (int i = 0; extensions[i].type != UNKNOWN; ++i){ if (g_ascii_strcasecmp(ext, extensions[i].extension) == 0){ return extensions[i].type; } } } return UNKNOWN; } int dialog_import_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState *gs){ GtkWidget *dialog; GtkWidget* message; GtkFileFilter *filter; dialog = gtk_file_chooser_dialog_new (_("Import"), parent, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); const struct import_formats{ FileType type; const gchar* name; const gchar* pattern; int32_t (*import_function)(struct ColorList *color_list, const gchar* filename); }formats[] = { {GPA, _("Gpick Palette (*.gpa)"), "*.gpa", palette_import_gpa }, {GPL, _("GIMP/Inkscape Palette (*.gpl)"), "*.gpl", palette_import_gpl }, {ASE, _("Adobe Swatch Exchange (*.ase)"), "*.ase", palette_import_ase }, {UNKNOWN, NULL, NULL, NULL}, }; const char* default_path = dynv_get_string_wd(gs->params, "gpick.import.path", ""); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_path); const char* selected_filter = dynv_get_string_wd(gs->params, "gpick.import.filter", "all_supported"); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("All files")); g_object_set_data(G_OBJECT(filter), "identification", (gpointer)"all"); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (g_strcmp0(selected_filter, "all") == 0){ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("All supported formats")); g_object_set_data(G_OBJECT(filter), "identification", (gpointer)"all_supported"); for (gint i = 0; formats[i].name; ++i) { gtk_file_filter_add_pattern(filter, formats[i].pattern); } gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (g_strcmp0(selected_filter, "all_supported") == 0){ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } for (gint i = 0; formats[i].name; ++i) { filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, formats[i].name); g_object_set_data(G_OBJECT(filter), "identification", (gpointer)formats[i].pattern); gtk_file_filter_add_pattern(filter, formats[i].pattern); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (g_strcmp0(formats[i].pattern, selected_filter)==0){ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } } gboolean finished = false; while (!finished){ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gchar *path; path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); dynv_set_string(gs->params, "gpick.import.path", path); g_free(path); FileType type = get_file_type_from_ext(filename); if (type == UNKNOWN){ const gchar *format_name = gtk_file_filter_get_name(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))); for (int i = 0; formats[i].name; ++i) { if (g_strcmp0(formats[i].name, format_name) == 0){ type = formats[i].type; break; } } } if (type == UNKNOWN){ message = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File format is not supported")); gtk_window_set_title(GTK_WINDOW(message), _("Import")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); }else{ for (int i = 0; formats[i].name; ++i) { if (formats[i].type == type){ struct ColorList *color_list_arg; color_list_arg = gs->colors; if (formats[i].import_function(color_list_arg, filename) == 0){ finished = true; }else{ message = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be imported")); gtk_window_set_title(GTK_WINDOW(message), _("Import")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } const char *identification = (const char*)g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))), "identification"); dynv_set_string(gs->params, "gpick.import.filter", identification); break; } } } g_free(filename); }else break; } gtk_widget_destroy (dialog); return 0; } gpick_0.2.5/source/ColorList.cpp0000644000175000017500000001253312070605214015324 0ustar zbygzbyg/* * 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 "ColorList.h" #include using namespace std; struct ColorList* color_list_new(struct dynvHandlerMap* handler_map){ struct ColorList* color_list=new struct ColorList; if (handler_map){ color_list->params=dynv_system_create(handler_map); }else{ color_list->params=NULL; } color_list->on_insert=NULL; color_list->on_change=NULL; color_list->on_delete=NULL; color_list->on_clear=NULL; color_list->on_delete_selected=NULL; color_list->on_get_positions=NULL; color_list->userdata=NULL; return color_list; } void color_list_destroy(struct ColorList* color_list){ ColorList::iter i; for (i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ color_object_release(*i); } color_list->colors.clear(); if (color_list->params) dynv_system_release(color_list->params); delete color_list; } struct ColorObject* color_list_new_color_object(struct ColorList* color_list, Color* color){ struct dynvHandlerMap* handler_map; if (color_list->params){ handler_map=dynv_system_get_handler_map(color_list->params); }else{ handler_map=NULL; } struct ColorObject *color_object=color_object_new(handler_map); if (handler_map) dynv_handler_map_release(handler_map); color_object_set_color(color_object, color); return color_object; } struct ColorObject* color_list_add_color(struct ColorList* color_list, Color* color){ struct dynvHandlerMap* handler_map; if (color_list->params){ handler_map=dynv_system_get_handler_map(color_list->params); }else{ handler_map=NULL; } struct ColorObject *color_object=color_object_new(handler_map); if (handler_map) dynv_handler_map_release(handler_map); color_object_set_color(color_object, color); int r= color_list_add_color_object(color_list, color_object, 1); if (r==0){ color_object_release(color_object); return color_object; }else{ delete color_object; return 0; } } int color_list_add_color_object(struct ColorList* color_list, struct ColorObject* color_object, int add_to_palette){ color_list->colors.push_back(color_object_ref(color_object)); if (add_to_palette) if (color_list->on_insert) color_list->on_insert(color_list, color_object); return 0; } int color_list_remove_color_object(struct ColorList* color_list, struct ColorObject* color_object){ list::iterator i = std::find(color_list->colors.begin(), color_list->colors.end(), color_object); if (i != color_list->colors.end()){ if (color_list->on_delete) color_list->on_delete(color_list, color_object); color_list->colors.erase(i); color_object_release(color_object); return 0; }else return -1; } int color_list_remove_selected(struct ColorList* color_list){ ColorList::iter i=color_list->colors.begin(); while (i!=color_list->colors.end()){ if ((*i)->selected){ color_object_release(*i); i=color_list->colors.erase(i); }else ++i; } color_list->on_delete_selected(color_list); return 0; } int color_list_remove_all(struct ColorList* color_list){ ColorList::iter i; if (color_list->on_clear){ color_list->on_clear(color_list); for (i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ color_object_release(*i); } }else{ for (i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ if (color_list->on_delete) color_list->on_delete(color_list, *i); color_object_release(*i); } } color_list->colors.clear(); return 0; } unsigned long color_list_get_count(struct ColorList* color_list){ return color_list->colors.size(); } int color_list_get_positions(struct ColorList* color_list){ ColorList::iter i; if (color_list->on_get_positions){ for (i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ (*i)->position=~(uint32_t)0; } color_list->on_get_positions(color_list); }else{ uint32_t j = 0; for (i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ (*i)->position = j; j++; } } return 0; } gpick_0.2.5/source/ChangeNotification.cpp0000644000175000017500000000525512070605214017151 0ustar zbygzbyg/* * 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 "ChangeNotification.h" using namespace std; NotificationLink::NotificationLink(const char *source_name_, uint32_t source_slot_id_, const char *destination_name_, uint32_t destination_slot_id_){ source_name = source_name_; destination_name = destination_name_; source_slot_id = source_slot_id_; destination_slot_id = destination_slot_id_; enabled = false; } ChangeNotification::ChangeNotification(){ } ChangeNotification::~ChangeNotification(){ } bool ChangeNotification::registerSource(const char *location, ColorSource *source){ sources[location] = source; return true; } bool ChangeNotification::unregisterSource(const char *location, ColorSource *source){ map::iterator i = sources.find(location); if (i != sources.end()){ sources.erase(i); return true; } return false; } bool ChangeNotification::addLink(boost::shared_ptr notification_link){ links.insert(pair >(notification_link->source_name, notification_link)); return true; } bool ChangeNotification::removeLink(boost::shared_ptr notification_link){ return true; } gpick_0.2.5/source/dbus/SConscript0000644000175000017500000000065712070605214015661 0ustar zbygzbyg#!/usr/bin/env python import os import sys Import('*') local_env = env.Clone() if not local_env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc': local_env.ParseConfig('pkg-config --cflags $GIO_PC') if not env['BUILD_TARGET'] == 'win32': sources = local_env.Glob('*.c') + local_env.Glob('*.cpp') else: sources = local_env.Glob('win32dummy/*.cpp') objects = local_env.StaticObject(source = [sources]) Return('objects') gpick_0.2.5/source/dbus/DbusInterface.h0000644000175000017500000004215012070605214016530 0ustar zbygzbyg/* * Generated by gdbus-codegen 2.32.3. DO NOT EDIT. * * The license of this code is the same as for the source it was derived from. */ #ifndef __DBUSINTERFACE_H__ #define __DBUSINTERFACE_H__ #include G_BEGIN_DECLS /* ------------------------------------------------------------------------ */ /* Declarations for com.google.code.gpick.SingleInstance */ #define GPICK_TYPE_SINGLE_INSTANCE (gpick_single_instance_get_type ()) #define GPICK_SINGLE_INSTANCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_SINGLE_INSTANCE, GpickSingleInstance)) #define GPICK_IS_SINGLE_INSTANCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_SINGLE_INSTANCE)) #define GPICK_SINGLE_INSTANCE_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), GPICK_TYPE_SINGLE_INSTANCE, GpickSingleInstanceIface)) struct _GpickSingleInstance; typedef struct _GpickSingleInstance GpickSingleInstance; typedef struct _GpickSingleInstanceIface GpickSingleInstanceIface; struct _GpickSingleInstanceIface { GTypeInterface parent_iface; gboolean (*handle_activate) ( GpickSingleInstance *object, GDBusMethodInvocation *invocation); }; GType gpick_single_instance_get_type (void) G_GNUC_CONST; GDBusInterfaceInfo *gpick_single_instance_interface_info (void); guint gpick_single_instance_override_properties (GObjectClass *klass, guint property_id_begin); /* D-Bus method call completion functions: */ void gpick_single_instance_complete_activate ( GpickSingleInstance *object, GDBusMethodInvocation *invocation); /* D-Bus method calls: */ void gpick_single_instance_call_activate ( GpickSingleInstance *proxy, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean gpick_single_instance_call_activate_finish ( GpickSingleInstance *proxy, GAsyncResult *res, GError **error); gboolean gpick_single_instance_call_activate_sync ( GpickSingleInstance *proxy, GCancellable *cancellable, GError **error); /* ---- */ #define GPICK_TYPE_SINGLE_INSTANCE_PROXY (gpick_single_instance_proxy_get_type ()) #define GPICK_SINGLE_INSTANCE_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_SINGLE_INSTANCE_PROXY, GpickSingleInstanceProxy)) #define GPICK_SINGLE_INSTANCE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_SINGLE_INSTANCE_PROXY, GpickSingleInstanceProxyClass)) #define GPICK_SINGLE_INSTANCE_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_SINGLE_INSTANCE_PROXY, GpickSingleInstanceProxyClass)) #define GPICK_IS_SINGLE_INSTANCE_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_SINGLE_INSTANCE_PROXY)) #define GPICK_IS_SINGLE_INSTANCE_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_SINGLE_INSTANCE_PROXY)) typedef struct _GpickSingleInstanceProxy GpickSingleInstanceProxy; typedef struct _GpickSingleInstanceProxyClass GpickSingleInstanceProxyClass; typedef struct _GpickSingleInstanceProxyPrivate GpickSingleInstanceProxyPrivate; struct _GpickSingleInstanceProxy { /*< private >*/ GDBusProxy parent_instance; GpickSingleInstanceProxyPrivate *priv; }; struct _GpickSingleInstanceProxyClass { GDBusProxyClass parent_class; }; GType gpick_single_instance_proxy_get_type (void) G_GNUC_CONST; void gpick_single_instance_proxy_new ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GpickSingleInstance *gpick_single_instance_proxy_new_finish ( GAsyncResult *res, GError **error); GpickSingleInstance *gpick_single_instance_proxy_new_sync ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); void gpick_single_instance_proxy_new_for_bus ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GpickSingleInstance *gpick_single_instance_proxy_new_for_bus_finish ( GAsyncResult *res, GError **error); GpickSingleInstance *gpick_single_instance_proxy_new_for_bus_sync ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); /* ---- */ #define GPICK_TYPE_SINGLE_INSTANCE_SKELETON (gpick_single_instance_skeleton_get_type ()) #define GPICK_SINGLE_INSTANCE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_SINGLE_INSTANCE_SKELETON, GpickSingleInstanceSkeleton)) #define GPICK_SINGLE_INSTANCE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_SINGLE_INSTANCE_SKELETON, GpickSingleInstanceSkeletonClass)) #define GPICK_SINGLE_INSTANCE_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_SINGLE_INSTANCE_SKELETON, GpickSingleInstanceSkeletonClass)) #define GPICK_IS_SINGLE_INSTANCE_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_SINGLE_INSTANCE_SKELETON)) #define GPICK_IS_SINGLE_INSTANCE_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_SINGLE_INSTANCE_SKELETON)) typedef struct _GpickSingleInstanceSkeleton GpickSingleInstanceSkeleton; typedef struct _GpickSingleInstanceSkeletonClass GpickSingleInstanceSkeletonClass; typedef struct _GpickSingleInstanceSkeletonPrivate GpickSingleInstanceSkeletonPrivate; struct _GpickSingleInstanceSkeleton { /*< private >*/ GDBusInterfaceSkeleton parent_instance; GpickSingleInstanceSkeletonPrivate *priv; }; struct _GpickSingleInstanceSkeletonClass { GDBusInterfaceSkeletonClass parent_class; }; GType gpick_single_instance_skeleton_get_type (void) G_GNUC_CONST; GpickSingleInstance *gpick_single_instance_skeleton_new (void); /* ------------------------------------------------------------------------ */ /* Declarations for com.google.code.gpick.Control */ #define GPICK_TYPE_CONTROL (gpick_control_get_type ()) #define GPICK_CONTROL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_CONTROL, GpickControl)) #define GPICK_IS_CONTROL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_CONTROL)) #define GPICK_CONTROL_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), GPICK_TYPE_CONTROL, GpickControlIface)) struct _GpickControl; typedef struct _GpickControl GpickControl; typedef struct _GpickControlIface GpickControlIface; struct _GpickControlIface { GTypeInterface parent_iface; gboolean (*handle_activate_floating_picker) ( GpickControl *object, GDBusMethodInvocation *invocation); }; GType gpick_control_get_type (void) G_GNUC_CONST; GDBusInterfaceInfo *gpick_control_interface_info (void); guint gpick_control_override_properties (GObjectClass *klass, guint property_id_begin); /* D-Bus method call completion functions: */ void gpick_control_complete_activate_floating_picker ( GpickControl *object, GDBusMethodInvocation *invocation); /* D-Bus method calls: */ void gpick_control_call_activate_floating_picker ( GpickControl *proxy, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean gpick_control_call_activate_floating_picker_finish ( GpickControl *proxy, GAsyncResult *res, GError **error); gboolean gpick_control_call_activate_floating_picker_sync ( GpickControl *proxy, GCancellable *cancellable, GError **error); /* ---- */ #define GPICK_TYPE_CONTROL_PROXY (gpick_control_proxy_get_type ()) #define GPICK_CONTROL_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_CONTROL_PROXY, GpickControlProxy)) #define GPICK_CONTROL_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_CONTROL_PROXY, GpickControlProxyClass)) #define GPICK_CONTROL_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_CONTROL_PROXY, GpickControlProxyClass)) #define GPICK_IS_CONTROL_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_CONTROL_PROXY)) #define GPICK_IS_CONTROL_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_CONTROL_PROXY)) typedef struct _GpickControlProxy GpickControlProxy; typedef struct _GpickControlProxyClass GpickControlProxyClass; typedef struct _GpickControlProxyPrivate GpickControlProxyPrivate; struct _GpickControlProxy { /*< private >*/ GDBusProxy parent_instance; GpickControlProxyPrivate *priv; }; struct _GpickControlProxyClass { GDBusProxyClass parent_class; }; GType gpick_control_proxy_get_type (void) G_GNUC_CONST; void gpick_control_proxy_new ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GpickControl *gpick_control_proxy_new_finish ( GAsyncResult *res, GError **error); GpickControl *gpick_control_proxy_new_sync ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); void gpick_control_proxy_new_for_bus ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GpickControl *gpick_control_proxy_new_for_bus_finish ( GAsyncResult *res, GError **error); GpickControl *gpick_control_proxy_new_for_bus_sync ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); /* ---- */ #define GPICK_TYPE_CONTROL_SKELETON (gpick_control_skeleton_get_type ()) #define GPICK_CONTROL_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_CONTROL_SKELETON, GpickControlSkeleton)) #define GPICK_CONTROL_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_CONTROL_SKELETON, GpickControlSkeletonClass)) #define GPICK_CONTROL_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_CONTROL_SKELETON, GpickControlSkeletonClass)) #define GPICK_IS_CONTROL_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_CONTROL_SKELETON)) #define GPICK_IS_CONTROL_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_CONTROL_SKELETON)) typedef struct _GpickControlSkeleton GpickControlSkeleton; typedef struct _GpickControlSkeletonClass GpickControlSkeletonClass; typedef struct _GpickControlSkeletonPrivate GpickControlSkeletonPrivate; struct _GpickControlSkeleton { /*< private >*/ GDBusInterfaceSkeleton parent_instance; GpickControlSkeletonPrivate *priv; }; struct _GpickControlSkeletonClass { GDBusInterfaceSkeletonClass parent_class; }; GType gpick_control_skeleton_get_type (void) G_GNUC_CONST; GpickControl *gpick_control_skeleton_new (void); /* ---- */ #define GPICK_TYPE_OBJECT (gpick_object_get_type ()) #define GPICK_OBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_OBJECT, GpickObject)) #define GPICK_IS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_OBJECT)) #define GPICK_OBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), GPICK_TYPE_OBJECT, GpickObject)) struct _GpickObject; typedef struct _GpickObject GpickObject; typedef struct _GpickObjectIface GpickObjectIface; struct _GpickObjectIface { GTypeInterface parent_iface; }; GType gpick_object_get_type (void) G_GNUC_CONST; GpickSingleInstance *gpick_object_get_single_instance (GpickObject *object); GpickControl *gpick_object_get_control (GpickObject *object); GpickSingleInstance *gpick_object_peek_single_instance (GpickObject *object); GpickControl *gpick_object_peek_control (GpickObject *object); #define GPICK_TYPE_OBJECT_PROXY (gpick_object_proxy_get_type ()) #define GPICK_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_OBJECT_PROXY, GpickObjectProxy)) #define GPICK_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_OBJECT_PROXY, GpickObjectProxyClass)) #define GPICK_OBJECT_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_OBJECT_PROXY, GpickObjectProxyClass)) #define GPICK_IS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_OBJECT_PROXY)) #define GPICK_IS_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_OBJECT_PROXY)) typedef struct _GpickObjectProxy GpickObjectProxy; typedef struct _GpickObjectProxyClass GpickObjectProxyClass; typedef struct _GpickObjectProxyPrivate GpickObjectProxyPrivate; struct _GpickObjectProxy { /*< private >*/ GDBusObjectProxy parent_instance; GpickObjectProxyPrivate *priv; }; struct _GpickObjectProxyClass { GDBusObjectProxyClass parent_class; }; GType gpick_object_proxy_get_type (void) G_GNUC_CONST; GpickObjectProxy *gpick_object_proxy_new (GDBusConnection *connection, const gchar *object_path); #define GPICK_TYPE_OBJECT_SKELETON (gpick_object_skeleton_get_type ()) #define GPICK_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_OBJECT_SKELETON, GpickObjectSkeleton)) #define GPICK_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_OBJECT_SKELETON, GpickObjectSkeletonClass)) #define GPICK_OBJECT_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_OBJECT_SKELETON, GpickObjectSkeletonClass)) #define GPICK_IS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_OBJECT_SKELETON)) #define GPICK_IS_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_OBJECT_SKELETON)) typedef struct _GpickObjectSkeleton GpickObjectSkeleton; typedef struct _GpickObjectSkeletonClass GpickObjectSkeletonClass; typedef struct _GpickObjectSkeletonPrivate GpickObjectSkeletonPrivate; struct _GpickObjectSkeleton { /*< private >*/ GDBusObjectSkeleton parent_instance; GpickObjectSkeletonPrivate *priv; }; struct _GpickObjectSkeletonClass { GDBusObjectSkeletonClass parent_class; }; GType gpick_object_skeleton_get_type (void) G_GNUC_CONST; GpickObjectSkeleton *gpick_object_skeleton_new (const gchar *object_path); void gpick_object_skeleton_set_single_instance (GpickObjectSkeleton *object, GpickSingleInstance *interface_); void gpick_object_skeleton_set_control (GpickObjectSkeleton *object, GpickControl *interface_); /* ---- */ #define GPICK_TYPE_OBJECT_MANAGER_CLIENT (gpick_object_manager_client_get_type ()) #define GPICK_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPICK_TYPE_OBJECT_MANAGER_CLIENT, GpickObjectManagerClient)) #define GPICK_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GPICK_TYPE_OBJECT_MANAGER_CLIENT, GpickObjectManagerClientClass)) #define GPICK_OBJECT_MANAGER_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPICK_TYPE_OBJECT_MANAGER_CLIENT, GpickObjectManagerClientClass)) #define GPICK_IS_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPICK_TYPE_OBJECT_MANAGER_CLIENT)) #define GPICK_IS_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPICK_TYPE_OBJECT_MANAGER_CLIENT)) typedef struct _GpickObjectManagerClient GpickObjectManagerClient; typedef struct _GpickObjectManagerClientClass GpickObjectManagerClientClass; typedef struct _GpickObjectManagerClientPrivate GpickObjectManagerClientPrivate; struct _GpickObjectManagerClient { /*< private >*/ GDBusObjectManagerClient parent_instance; GpickObjectManagerClientPrivate *priv; }; struct _GpickObjectManagerClientClass { GDBusObjectManagerClientClass parent_class; }; GType gpick_object_manager_client_get_type (void) G_GNUC_CONST; GType gpick_object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data); void gpick_object_manager_client_new ( GDBusConnection *connection, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GDBusObjectManager *gpick_object_manager_client_new_finish ( GAsyncResult *res, GError **error); GDBusObjectManager *gpick_object_manager_client_new_sync ( GDBusConnection *connection, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); void gpick_object_manager_client_new_for_bus ( GBusType bus_type, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GDBusObjectManager *gpick_object_manager_client_new_for_bus_finish ( GAsyncResult *res, GError **error); GDBusObjectManager *gpick_object_manager_client_new_for_bus_sync ( GBusType bus_type, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error); G_END_DECLS #endif /* __DBUSINTERFACE_H__ */ gpick_0.2.5/source/dbus/Control.h0000644000175000017500000000426712070605214015441 0ustar zbygzbyg/* * 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 UI_DBUS_CONTROL_H_ #define UI_DBUS_CONTROL_H_ #include /** \file source/dbus/Control.h * \brief D-Bus interface and functions. */ /** * Try to get ownership of a bus. */ guint gpick_own_name(bool (*on_control_activate_floating_picker)(void *userdata), bool (*on_single_instance_activate)(void *userdata), void *userdata); /** * Release ownership of a bus. */ void gpick_unown_name(guint bus_id); /** * Activate main window in a remove Gpick instance. */ bool gpick_single_instance_activate(); /** * Activate floating color picker in a remote Gpick instance. */ bool gpick_control_activate_floating_picker(); #endif /* UI_DBUS_CONTROL_H_ */ gpick_0.2.5/source/dbus/DbusInterface.c0000644000175000017500000025044312070605214016531 0ustar zbygzbyg/* * Generated by gdbus-codegen 2.32.3. DO NOT EDIT. * * The license of this code is the same as for the source it was derived from. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "DbusInterface.h" #ifdef G_OS_UNIX # include #endif typedef struct { GDBusArgInfo parent_struct; gboolean use_gvariant; } _ExtendedGDBusArgInfo; typedef struct { GDBusMethodInfo parent_struct; const gchar *signal_name; gboolean pass_fdlist; } _ExtendedGDBusMethodInfo; typedef struct { GDBusSignalInfo parent_struct; const gchar *signal_name; } _ExtendedGDBusSignalInfo; typedef struct { GDBusPropertyInfo parent_struct; const gchar *hyphen_name; gboolean use_gvariant; } _ExtendedGDBusPropertyInfo; typedef struct { GDBusInterfaceInfo parent_struct; const gchar *hyphen_name; } _ExtendedGDBusInterfaceInfo; typedef struct { const _ExtendedGDBusPropertyInfo *info; guint prop_id; GValue orig_value; /* the value before the change */ } ChangedProperty; static void _changed_property_free (ChangedProperty *data) { g_value_unset (&data->orig_value); g_free (data); } static gboolean _g_strv_equal0 (gchar **a, gchar **b) { gboolean ret = FALSE; guint n; if (a == NULL && b == NULL) { ret = TRUE; goto out; } if (a == NULL || b == NULL) goto out; if (g_strv_length (a) != g_strv_length (b)) goto out; for (n = 0; a[n] != NULL; n++) if (g_strcmp0 (a[n], b[n]) != 0) goto out; ret = TRUE; out: return ret; } static gboolean _g_variant_equal0 (GVariant *a, GVariant *b) { gboolean ret = FALSE; if (a == NULL && b == NULL) { ret = TRUE; goto out; } if (a == NULL || b == NULL) goto out; ret = g_variant_equal (a, b); out: return ret; } G_GNUC_UNUSED static gboolean _g_value_equal (const GValue *a, const GValue *b) { gboolean ret = FALSE; g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b)); switch (G_VALUE_TYPE (a)) { case G_TYPE_BOOLEAN: ret = (g_value_get_boolean (a) == g_value_get_boolean (b)); break; case G_TYPE_UCHAR: ret = (g_value_get_uchar (a) == g_value_get_uchar (b)); break; case G_TYPE_INT: ret = (g_value_get_int (a) == g_value_get_int (b)); break; case G_TYPE_UINT: ret = (g_value_get_uint (a) == g_value_get_uint (b)); break; case G_TYPE_INT64: ret = (g_value_get_int64 (a) == g_value_get_int64 (b)); break; case G_TYPE_UINT64: ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b)); break; case G_TYPE_DOUBLE: ret = (g_value_get_double (a) == g_value_get_double (b)); break; case G_TYPE_STRING: ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0); break; case G_TYPE_VARIANT: ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b)); break; default: if (G_VALUE_TYPE (a) == G_TYPE_STRV) ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b)); else g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a))); break; } return ret; } /* ------------------------------------------------------------------------ * Code for interface com.google.code.gpick.SingleInstance * ------------------------------------------------------------------------ */ /** * SECTION:GpickSingleInstance * @title: GpickSingleInstance * @short_description: Generated C code for the com.google.code.gpick.SingleInstance D-Bus interface * * This section contains code for working with the com.google.code.gpick.SingleInstance D-Bus interface in C. */ /* ---- Introspection data for com.google.code.gpick.SingleInstance ---- */ static const _ExtendedGDBusMethodInfo _gpick_single_instance_method_info_activate = { { -1, "Activate", NULL, NULL, NULL }, "handle-activate", FALSE }; static const _ExtendedGDBusMethodInfo * const _gpick_single_instance_method_info_pointers[] = { &_gpick_single_instance_method_info_activate, NULL }; static const _ExtendedGDBusInterfaceInfo _gpick_single_instance_interface_info = { { -1, "com.google.code.gpick.SingleInstance", (GDBusMethodInfo **) &_gpick_single_instance_method_info_pointers, NULL, NULL, NULL }, "single-instance", }; /** * gpick_single_instance_interface_info: * * Gets a machine-readable description of the com.google.code.gpick.SingleInstance D-Bus interface. * * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free. */ GDBusInterfaceInfo * gpick_single_instance_interface_info (void) { return (GDBusInterfaceInfo *) &_gpick_single_instance_interface_info; } /** * gpick_single_instance_override_properties: * @klass: The class structure for a #GObject-derived class. * @property_id_begin: The property id to assign to the first overridden property. * * Overrides all #GObject properties in the #GpickSingleInstance interface for a concrete class. * The properties are overridden in the order they are defined. * * Returns: The last property id. */ guint gpick_single_instance_override_properties (GObjectClass *klass, guint property_id_begin) { return property_id_begin - 1; } /** * GpickSingleInstance: * * Abstract interface type for the D-Bus interface com.google.code.gpick.SingleInstance. */ /** * GpickSingleInstanceIface: * @parent_iface: The parent interface. * @handle_activate: Handler for the #GpickSingleInstance::handle-activate signal. * * Virtual table for the D-Bus interface com.google.code.gpick.SingleInstance. */ static void gpick_single_instance_default_init (GpickSingleInstanceIface *iface) { /* GObject signals for incoming D-Bus method calls: */ /** * GpickSingleInstance::handle-activate: * @object: A #GpickSingleInstance. * @invocation: A #GDBusMethodInvocation. * * Signal emitted when a remote caller is invoking the Activate() D-Bus method. * * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call gpick_single_instance_complete_activate() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. * * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. */ g_signal_new ("handle-activate", G_TYPE_FROM_INTERFACE (iface), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GpickSingleInstanceIface, handle_activate), g_signal_accumulator_true_handled, NULL, g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 1, G_TYPE_DBUS_METHOD_INVOCATION); } typedef GpickSingleInstanceIface GpickSingleInstanceInterface; G_DEFINE_INTERFACE (GpickSingleInstance, gpick_single_instance, G_TYPE_OBJECT); /** * gpick_single_instance_call_activate: * @proxy: A #GpickSingleInstanceProxy. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. * @user_data: User data to pass to @callback. * * Asynchronously invokes the Activate() D-Bus method on @proxy. * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_single_instance_call_activate_finish() to get the result of the operation. * * See gpick_single_instance_call_activate_sync() for the synchronous, blocking version of this method. */ void gpick_single_instance_call_activate ( GpickSingleInstance *proxy, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_dbus_proxy_call (G_DBUS_PROXY (proxy), "Activate", g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, -1, cancellable, callback, user_data); } /** * gpick_single_instance_call_activate_finish: * @proxy: A #GpickSingleInstanceProxy. * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_single_instance_call_activate(). * @error: Return location for error or %NULL. * * Finishes an operation started with gpick_single_instance_call_activate(). * * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. */ gboolean gpick_single_instance_call_activate_finish ( GpickSingleInstance *proxy, GAsyncResult *res, GError **error) { GVariant *_ret; _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); if (_ret == NULL) goto _out; g_variant_get (_ret, "()"); g_variant_unref (_ret); _out: return _ret != NULL; } /** * gpick_single_instance_call_activate_sync: * @proxy: A #GpickSingleInstanceProxy. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL. * * Synchronously invokes the Activate() D-Bus method on @proxy. The calling thread is blocked until a reply is received. * * See gpick_single_instance_call_activate() for the asynchronous version of this method. * * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. */ gboolean gpick_single_instance_call_activate_sync ( GpickSingleInstance *proxy, GCancellable *cancellable, GError **error) { GVariant *_ret; _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), "Activate", g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error); if (_ret == NULL) goto _out; g_variant_get (_ret, "()"); g_variant_unref (_ret); _out: return _ret != NULL; } /** * gpick_single_instance_complete_activate: * @object: A #GpickSingleInstance. * @invocation: (transfer full): A #GDBusMethodInvocation. * * Helper function used in service implementations to finish handling invocations of the Activate() D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. * * This method will free @invocation, you cannot use it afterwards. */ void gpick_single_instance_complete_activate ( GpickSingleInstance *object, GDBusMethodInvocation *invocation) { g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); } /* ------------------------------------------------------------------------ */ /** * GpickSingleInstanceProxy: * * The #GpickSingleInstanceProxy structure contains only private data and should only be accessed using the provided API. */ /** * GpickSingleInstanceProxyClass: * @parent_class: The parent class. * * Class structure for #GpickSingleInstanceProxy. */ struct _GpickSingleInstanceProxyPrivate { GData *qdata; }; static void gpick_single_instance_proxy_iface_init (GpickSingleInstanceIface *iface); G_DEFINE_TYPE_WITH_CODE (GpickSingleInstanceProxy, gpick_single_instance_proxy, G_TYPE_DBUS_PROXY, G_IMPLEMENT_INTERFACE (GPICK_TYPE_SINGLE_INSTANCE, gpick_single_instance_proxy_iface_init)); static void gpick_single_instance_proxy_finalize (GObject *object) { GpickSingleInstanceProxy *proxy = GPICK_SINGLE_INSTANCE_PROXY (object); g_datalist_clear (&proxy->priv->qdata); G_OBJECT_CLASS (gpick_single_instance_proxy_parent_class)->finalize (object); } static void gpick_single_instance_proxy_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { } static void gpick_single_instance_proxy_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { } static void gpick_single_instance_proxy_g_signal (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters) { _ExtendedGDBusSignalInfo *info; GVariantIter iter; GVariant *child; GValue *paramv; guint num_params; guint n; guint signal_id; info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_gpick_single_instance_interface_info, signal_name); if (info == NULL) return; num_params = g_variant_n_children (parameters); paramv = g_new0 (GValue, num_params + 1); g_value_init (¶mv[0], GPICK_TYPE_SINGLE_INSTANCE); g_value_set_object (¶mv[0], proxy); g_variant_iter_init (&iter, parameters); n = 1; while ((child = g_variant_iter_next_value (&iter)) != NULL) { _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1]; if (arg_info->use_gvariant) { g_value_init (¶mv[n], G_TYPE_VARIANT); g_value_set_variant (¶mv[n], child); n++; } else g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); g_variant_unref (child); } signal_id = g_signal_lookup (info->signal_name, GPICK_TYPE_SINGLE_INSTANCE); g_signal_emitv (paramv, signal_id, 0, NULL); for (n = 0; n < num_params + 1; n++) g_value_unset (¶mv[n]); g_free (paramv); } static void gpick_single_instance_proxy_g_properties_changed (GDBusProxy *_proxy, GVariant *changed_properties, const gchar *const *invalidated_properties) { GpickSingleInstanceProxy *proxy = GPICK_SINGLE_INSTANCE_PROXY (_proxy); guint n; const gchar *key; GVariantIter *iter; _ExtendedGDBusPropertyInfo *info; g_variant_get (changed_properties, "a{sv}", &iter); while (g_variant_iter_next (iter, "{&sv}", &key, NULL)) { info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_single_instance_interface_info, key); g_datalist_remove_data (&proxy->priv->qdata, key); if (info != NULL) g_object_notify (G_OBJECT (proxy), info->hyphen_name); } g_variant_iter_free (iter); for (n = 0; invalidated_properties[n] != NULL; n++) { info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_single_instance_interface_info, invalidated_properties[n]); g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]); if (info != NULL) g_object_notify (G_OBJECT (proxy), info->hyphen_name); } } static void gpick_single_instance_proxy_init (GpickSingleInstanceProxy *proxy) { proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, GPICK_TYPE_SINGLE_INSTANCE_PROXY, GpickSingleInstanceProxyPrivate); g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), gpick_single_instance_interface_info ()); } static void gpick_single_instance_proxy_class_init (GpickSingleInstanceProxyClass *klass) { GObjectClass *gobject_class; GDBusProxyClass *proxy_class; g_type_class_add_private (klass, sizeof (GpickSingleInstanceProxyPrivate)); gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gpick_single_instance_proxy_finalize; gobject_class->get_property = gpick_single_instance_proxy_get_property; gobject_class->set_property = gpick_single_instance_proxy_set_property; proxy_class = G_DBUS_PROXY_CLASS (klass); proxy_class->g_signal = gpick_single_instance_proxy_g_signal; proxy_class->g_properties_changed = gpick_single_instance_proxy_g_properties_changed; } static void gpick_single_instance_proxy_iface_init (GpickSingleInstanceIface *iface) { } /** * gpick_single_instance_proxy_new: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Asynchronously creates a proxy for the D-Bus interface com.google.code.gpick.SingleInstance. See g_dbus_proxy_new() for more details. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_single_instance_proxy_new_finish() to get the result of the operation. * * See gpick_single_instance_proxy_new_sync() for the synchronous, blocking version of this constructor. */ void gpick_single_instance_proxy_new ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_SINGLE_INSTANCE_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.SingleInstance", NULL); } /** * gpick_single_instance_proxy_new_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_single_instance_proxy_new(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_single_instance_proxy_new(). * * Returns: (transfer full) (type GpickSingleInstanceProxy): The constructed proxy object or %NULL if @error is set. */ GpickSingleInstance * gpick_single_instance_proxy_new_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return GPICK_SINGLE_INSTANCE (ret); else return NULL; } /** * gpick_single_instance_proxy_new_sync: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Synchronously creates a proxy for the D-Bus interface com.google.code.gpick.SingleInstance. See g_dbus_proxy_new_sync() for more details. * * The calling thread is blocked until a reply is received. * * See gpick_single_instance_proxy_new() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickSingleInstanceProxy): The constructed proxy object or %NULL if @error is set. */ GpickSingleInstance * gpick_single_instance_proxy_new_sync ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_SINGLE_INSTANCE_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.SingleInstance", NULL); if (ret != NULL) return GPICK_SINGLE_INSTANCE (ret); else return NULL; } /** * gpick_single_instance_proxy_new_for_bus: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Like gpick_single_instance_proxy_new() but takes a #GBusType instead of a #GDBusConnection. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_single_instance_proxy_new_for_bus_finish() to get the result of the operation. * * See gpick_single_instance_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor. */ void gpick_single_instance_proxy_new_for_bus ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_SINGLE_INSTANCE_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.SingleInstance", NULL); } /** * gpick_single_instance_proxy_new_for_bus_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_single_instance_proxy_new_for_bus(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_single_instance_proxy_new_for_bus(). * * Returns: (transfer full) (type GpickSingleInstanceProxy): The constructed proxy object or %NULL if @error is set. */ GpickSingleInstance * gpick_single_instance_proxy_new_for_bus_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return GPICK_SINGLE_INSTANCE (ret); else return NULL; } /** * gpick_single_instance_proxy_new_for_bus_sync: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Like gpick_single_instance_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection. * * The calling thread is blocked until a reply is received. * * See gpick_single_instance_proxy_new_for_bus() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickSingleInstanceProxy): The constructed proxy object or %NULL if @error is set. */ GpickSingleInstance * gpick_single_instance_proxy_new_for_bus_sync ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_SINGLE_INSTANCE_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.SingleInstance", NULL); if (ret != NULL) return GPICK_SINGLE_INSTANCE (ret); else return NULL; } /* ------------------------------------------------------------------------ */ /** * GpickSingleInstanceSkeleton: * * The #GpickSingleInstanceSkeleton structure contains only private data and should only be accessed using the provided API. */ /** * GpickSingleInstanceSkeletonClass: * @parent_class: The parent class. * * Class structure for #GpickSingleInstanceSkeleton. */ struct _GpickSingleInstanceSkeletonPrivate { GValue *properties; GList *changed_properties; GSource *changed_properties_idle_source; GMainContext *context; GMutex lock; }; static void _gpick_single_instance_skeleton_handle_method_call ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GpickSingleInstanceSkeleton *skeleton = GPICK_SINGLE_INSTANCE_SKELETON (user_data); _ExtendedGDBusMethodInfo *info; GVariantIter iter; GVariant *child; GValue *paramv; guint num_params; guint num_extra; guint n; guint signal_id; GValue return_value = G_VALUE_INIT; info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation); g_assert (info != NULL); num_params = g_variant_n_children (parameters); num_extra = info->pass_fdlist ? 3 : 2; paramv = g_new0 (GValue, num_params + num_extra); n = 0; g_value_init (¶mv[n], GPICK_TYPE_SINGLE_INSTANCE); g_value_set_object (¶mv[n++], skeleton); g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION); g_value_set_object (¶mv[n++], invocation); if (info->pass_fdlist) { #ifdef G_OS_UNIX g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST); g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation))); #else g_assert_not_reached (); #endif } g_variant_iter_init (&iter, parameters); while ((child = g_variant_iter_next_value (&iter)) != NULL) { _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra]; if (arg_info->use_gvariant) { g_value_init (¶mv[n], G_TYPE_VARIANT); g_value_set_variant (¶mv[n], child); n++; } else g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); g_variant_unref (child); } signal_id = g_signal_lookup (info->signal_name, GPICK_TYPE_SINGLE_INSTANCE); g_value_init (&return_value, G_TYPE_BOOLEAN); g_signal_emitv (paramv, signal_id, 0, &return_value); if (!g_value_get_boolean (&return_value)) g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Method %s is not implemented on interface %s", method_name, interface_name); g_value_unset (&return_value); for (n = 0; n < num_params + num_extra; n++) g_value_unset (¶mv[n]); g_free (paramv); } static GVariant * _gpick_single_instance_skeleton_handle_get_property ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GpickSingleInstanceSkeleton *skeleton = GPICK_SINGLE_INSTANCE_SKELETON (user_data); GValue value = G_VALUE_INIT; GParamSpec *pspec; _ExtendedGDBusPropertyInfo *info; GVariant *ret; ret = NULL; info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_single_instance_interface_info, property_name); g_assert (info != NULL); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); if (pspec == NULL) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); } else { g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value); ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature)); g_value_unset (&value); } return ret; } static gboolean _gpick_single_instance_skeleton_handle_set_property ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *variant, GError **error, gpointer user_data) { GpickSingleInstanceSkeleton *skeleton = GPICK_SINGLE_INSTANCE_SKELETON (user_data); GValue value = G_VALUE_INIT; GParamSpec *pspec; _ExtendedGDBusPropertyInfo *info; gboolean ret; ret = FALSE; info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_single_instance_interface_info, property_name); g_assert (info != NULL); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); if (pspec == NULL) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); } else { if (info->use_gvariant) g_value_set_variant (&value, variant); else g_dbus_gvariant_to_gvalue (variant, &value); g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value); g_value_unset (&value); ret = TRUE; } return ret; } static const GDBusInterfaceVTable _gpick_single_instance_skeleton_vtable = { _gpick_single_instance_skeleton_handle_method_call, _gpick_single_instance_skeleton_handle_get_property, _gpick_single_instance_skeleton_handle_set_property }; static GDBusInterfaceInfo * gpick_single_instance_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton) { return gpick_single_instance_interface_info (); } static GDBusInterfaceVTable * gpick_single_instance_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton) { return (GDBusInterfaceVTable *) &_gpick_single_instance_skeleton_vtable; } static GVariant * gpick_single_instance_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton) { GpickSingleInstanceSkeleton *skeleton = GPICK_SINGLE_INSTANCE_SKELETON (_skeleton); GVariantBuilder builder; guint n; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); if (_gpick_single_instance_interface_info.parent_struct.properties == NULL) goto out; for (n = 0; _gpick_single_instance_interface_info.parent_struct.properties[n] != NULL; n++) { GDBusPropertyInfo *info = _gpick_single_instance_interface_info.parent_struct.properties[n]; if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) { GVariant *value; value = _gpick_single_instance_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "com.google.code.gpick.SingleInstance", info->name, NULL, skeleton); if (value != NULL) { g_variant_take_ref (value); g_variant_builder_add (&builder, "{sv}", info->name, value); g_variant_unref (value); } } } out: return g_variant_builder_end (&builder); } static void gpick_single_instance_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton) { } static void gpick_single_instance_skeleton_iface_init (GpickSingleInstanceIface *iface); G_DEFINE_TYPE_WITH_CODE (GpickSingleInstanceSkeleton, gpick_single_instance_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, G_IMPLEMENT_INTERFACE (GPICK_TYPE_SINGLE_INSTANCE, gpick_single_instance_skeleton_iface_init)); static void gpick_single_instance_skeleton_finalize (GObject *object) { GpickSingleInstanceSkeleton *skeleton = GPICK_SINGLE_INSTANCE_SKELETON (object); g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free); if (skeleton->priv->changed_properties_idle_source != NULL) g_source_destroy (skeleton->priv->changed_properties_idle_source); g_main_context_unref (skeleton->priv->context); g_mutex_clear (&skeleton->priv->lock); G_OBJECT_CLASS (gpick_single_instance_skeleton_parent_class)->finalize (object); } static void gpick_single_instance_skeleton_init (GpickSingleInstanceSkeleton *skeleton) { skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, GPICK_TYPE_SINGLE_INSTANCE_SKELETON, GpickSingleInstanceSkeletonPrivate); g_mutex_init (&skeleton->priv->lock); skeleton->priv->context = g_main_context_ref_thread_default (); } static void gpick_single_instance_skeleton_class_init (GpickSingleInstanceSkeletonClass *klass) { GObjectClass *gobject_class; GDBusInterfaceSkeletonClass *skeleton_class; g_type_class_add_private (klass, sizeof (GpickSingleInstanceSkeletonPrivate)); gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gpick_single_instance_skeleton_finalize; skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); skeleton_class->get_info = gpick_single_instance_skeleton_dbus_interface_get_info; skeleton_class->get_properties = gpick_single_instance_skeleton_dbus_interface_get_properties; skeleton_class->flush = gpick_single_instance_skeleton_dbus_interface_flush; skeleton_class->get_vtable = gpick_single_instance_skeleton_dbus_interface_get_vtable; } static void gpick_single_instance_skeleton_iface_init (GpickSingleInstanceIface *iface) { } /** * gpick_single_instance_skeleton_new: * * Creates a skeleton object for the D-Bus interface com.google.code.gpick.SingleInstance. * * Returns: (transfer full) (type GpickSingleInstanceSkeleton): The skeleton object. */ GpickSingleInstance * gpick_single_instance_skeleton_new (void) { return GPICK_SINGLE_INSTANCE (g_object_new (GPICK_TYPE_SINGLE_INSTANCE_SKELETON, NULL)); } /* ------------------------------------------------------------------------ * Code for interface com.google.code.gpick.Control * ------------------------------------------------------------------------ */ /** * SECTION:GpickControl * @title: GpickControl * @short_description: Generated C code for the com.google.code.gpick.Control D-Bus interface * * This section contains code for working with the com.google.code.gpick.Control D-Bus interface in C. */ /* ---- Introspection data for com.google.code.gpick.Control ---- */ static const _ExtendedGDBusMethodInfo _gpick_control_method_info_activate_floating_picker = { { -1, "ActivateFloatingPicker", NULL, NULL, NULL }, "handle-activate-floating-picker", FALSE }; static const _ExtendedGDBusMethodInfo * const _gpick_control_method_info_pointers[] = { &_gpick_control_method_info_activate_floating_picker, NULL }; static const _ExtendedGDBusInterfaceInfo _gpick_control_interface_info = { { -1, "com.google.code.gpick.Control", (GDBusMethodInfo **) &_gpick_control_method_info_pointers, NULL, NULL, NULL }, "control", }; /** * gpick_control_interface_info: * * Gets a machine-readable description of the com.google.code.gpick.Control D-Bus interface. * * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free. */ GDBusInterfaceInfo * gpick_control_interface_info (void) { return (GDBusInterfaceInfo *) &_gpick_control_interface_info; } /** * gpick_control_override_properties: * @klass: The class structure for a #GObject-derived class. * @property_id_begin: The property id to assign to the first overridden property. * * Overrides all #GObject properties in the #GpickControl interface for a concrete class. * The properties are overridden in the order they are defined. * * Returns: The last property id. */ guint gpick_control_override_properties (GObjectClass *klass, guint property_id_begin) { return property_id_begin - 1; } /** * GpickControl: * * Abstract interface type for the D-Bus interface com.google.code.gpick.Control. */ /** * GpickControlIface: * @parent_iface: The parent interface. * @handle_activate_floating_picker: Handler for the #GpickControl::handle-activate-floating-picker signal. * * Virtual table for the D-Bus interface com.google.code.gpick.Control. */ static void gpick_control_default_init (GpickControlIface *iface) { /* GObject signals for incoming D-Bus method calls: */ /** * GpickControl::handle-activate-floating-picker: * @object: A #GpickControl. * @invocation: A #GDBusMethodInvocation. * * Signal emitted when a remote caller is invoking the ActivateFloatingPicker() D-Bus method. * * If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call gpick_control_complete_activate_floating_picker() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned. * * Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run. */ g_signal_new ("handle-activate-floating-picker", G_TYPE_FROM_INTERFACE (iface), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GpickControlIface, handle_activate_floating_picker), g_signal_accumulator_true_handled, NULL, g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 1, G_TYPE_DBUS_METHOD_INVOCATION); } typedef GpickControlIface GpickControlInterface; G_DEFINE_INTERFACE (GpickControl, gpick_control, G_TYPE_OBJECT); /** * gpick_control_call_activate_floating_picker: * @proxy: A #GpickControlProxy. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. * @user_data: User data to pass to @callback. * * Asynchronously invokes the ActivateFloatingPicker() D-Bus method on @proxy. * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_control_call_activate_floating_picker_finish() to get the result of the operation. * * See gpick_control_call_activate_floating_picker_sync() for the synchronous, blocking version of this method. */ void gpick_control_call_activate_floating_picker ( GpickControl *proxy, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_dbus_proxy_call (G_DBUS_PROXY (proxy), "ActivateFloatingPicker", g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, -1, cancellable, callback, user_data); } /** * gpick_control_call_activate_floating_picker_finish: * @proxy: A #GpickControlProxy. * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_control_call_activate_floating_picker(). * @error: Return location for error or %NULL. * * Finishes an operation started with gpick_control_call_activate_floating_picker(). * * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. */ gboolean gpick_control_call_activate_floating_picker_finish ( GpickControl *proxy, GAsyncResult *res, GError **error) { GVariant *_ret; _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); if (_ret == NULL) goto _out; g_variant_get (_ret, "()"); g_variant_unref (_ret); _out: return _ret != NULL; } /** * gpick_control_call_activate_floating_picker_sync: * @proxy: A #GpickControlProxy. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL. * * Synchronously invokes the ActivateFloatingPicker() D-Bus method on @proxy. The calling thread is blocked until a reply is received. * * See gpick_control_call_activate_floating_picker() for the asynchronous version of this method. * * Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set. */ gboolean gpick_control_call_activate_floating_picker_sync ( GpickControl *proxy, GCancellable *cancellable, GError **error) { GVariant *_ret; _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), "ActivateFloatingPicker", g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error); if (_ret == NULL) goto _out; g_variant_get (_ret, "()"); g_variant_unref (_ret); _out: return _ret != NULL; } /** * gpick_control_complete_activate_floating_picker: * @object: A #GpickControl. * @invocation: (transfer full): A #GDBusMethodInvocation. * * Helper function used in service implementations to finish handling invocations of the ActivateFloatingPicker() D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. * * This method will free @invocation, you cannot use it afterwards. */ void gpick_control_complete_activate_floating_picker ( GpickControl *object, GDBusMethodInvocation *invocation) { g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); } /* ------------------------------------------------------------------------ */ /** * GpickControlProxy: * * The #GpickControlProxy structure contains only private data and should only be accessed using the provided API. */ /** * GpickControlProxyClass: * @parent_class: The parent class. * * Class structure for #GpickControlProxy. */ struct _GpickControlProxyPrivate { GData *qdata; }; static void gpick_control_proxy_iface_init (GpickControlIface *iface); G_DEFINE_TYPE_WITH_CODE (GpickControlProxy, gpick_control_proxy, G_TYPE_DBUS_PROXY, G_IMPLEMENT_INTERFACE (GPICK_TYPE_CONTROL, gpick_control_proxy_iface_init)); static void gpick_control_proxy_finalize (GObject *object) { GpickControlProxy *proxy = GPICK_CONTROL_PROXY (object); g_datalist_clear (&proxy->priv->qdata); G_OBJECT_CLASS (gpick_control_proxy_parent_class)->finalize (object); } static void gpick_control_proxy_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { } static void gpick_control_proxy_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { } static void gpick_control_proxy_g_signal (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters) { _ExtendedGDBusSignalInfo *info; GVariantIter iter; GVariant *child; GValue *paramv; guint num_params; guint n; guint signal_id; info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_gpick_control_interface_info, signal_name); if (info == NULL) return; num_params = g_variant_n_children (parameters); paramv = g_new0 (GValue, num_params + 1); g_value_init (¶mv[0], GPICK_TYPE_CONTROL); g_value_set_object (¶mv[0], proxy); g_variant_iter_init (&iter, parameters); n = 1; while ((child = g_variant_iter_next_value (&iter)) != NULL) { _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1]; if (arg_info->use_gvariant) { g_value_init (¶mv[n], G_TYPE_VARIANT); g_value_set_variant (¶mv[n], child); n++; } else g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); g_variant_unref (child); } signal_id = g_signal_lookup (info->signal_name, GPICK_TYPE_CONTROL); g_signal_emitv (paramv, signal_id, 0, NULL); for (n = 0; n < num_params + 1; n++) g_value_unset (¶mv[n]); g_free (paramv); } static void gpick_control_proxy_g_properties_changed (GDBusProxy *_proxy, GVariant *changed_properties, const gchar *const *invalidated_properties) { GpickControlProxy *proxy = GPICK_CONTROL_PROXY (_proxy); guint n; const gchar *key; GVariantIter *iter; _ExtendedGDBusPropertyInfo *info; g_variant_get (changed_properties, "a{sv}", &iter); while (g_variant_iter_next (iter, "{&sv}", &key, NULL)) { info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_control_interface_info, key); g_datalist_remove_data (&proxy->priv->qdata, key); if (info != NULL) g_object_notify (G_OBJECT (proxy), info->hyphen_name); } g_variant_iter_free (iter); for (n = 0; invalidated_properties[n] != NULL; n++) { info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_control_interface_info, invalidated_properties[n]); g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]); if (info != NULL) g_object_notify (G_OBJECT (proxy), info->hyphen_name); } } static void gpick_control_proxy_init (GpickControlProxy *proxy) { proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, GPICK_TYPE_CONTROL_PROXY, GpickControlProxyPrivate); g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), gpick_control_interface_info ()); } static void gpick_control_proxy_class_init (GpickControlProxyClass *klass) { GObjectClass *gobject_class; GDBusProxyClass *proxy_class; g_type_class_add_private (klass, sizeof (GpickControlProxyPrivate)); gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gpick_control_proxy_finalize; gobject_class->get_property = gpick_control_proxy_get_property; gobject_class->set_property = gpick_control_proxy_set_property; proxy_class = G_DBUS_PROXY_CLASS (klass); proxy_class->g_signal = gpick_control_proxy_g_signal; proxy_class->g_properties_changed = gpick_control_proxy_g_properties_changed; } static void gpick_control_proxy_iface_init (GpickControlIface *iface) { } /** * gpick_control_proxy_new: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Asynchronously creates a proxy for the D-Bus interface com.google.code.gpick.Control. See g_dbus_proxy_new() for more details. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_control_proxy_new_finish() to get the result of the operation. * * See gpick_control_proxy_new_sync() for the synchronous, blocking version of this constructor. */ void gpick_control_proxy_new ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_CONTROL_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.Control", NULL); } /** * gpick_control_proxy_new_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_control_proxy_new(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_control_proxy_new(). * * Returns: (transfer full) (type GpickControlProxy): The constructed proxy object or %NULL if @error is set. */ GpickControl * gpick_control_proxy_new_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return GPICK_CONTROL (ret); else return NULL; } /** * gpick_control_proxy_new_sync: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Synchronously creates a proxy for the D-Bus interface com.google.code.gpick.Control. See g_dbus_proxy_new_sync() for more details. * * The calling thread is blocked until a reply is received. * * See gpick_control_proxy_new() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickControlProxy): The constructed proxy object or %NULL if @error is set. */ GpickControl * gpick_control_proxy_new_sync ( GDBusConnection *connection, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_CONTROL_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.Control", NULL); if (ret != NULL) return GPICK_CONTROL (ret); else return NULL; } /** * gpick_control_proxy_new_for_bus: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Like gpick_control_proxy_new() but takes a #GBusType instead of a #GDBusConnection. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_control_proxy_new_for_bus_finish() to get the result of the operation. * * See gpick_control_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor. */ void gpick_control_proxy_new_for_bus ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_CONTROL_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.Control", NULL); } /** * gpick_control_proxy_new_for_bus_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_control_proxy_new_for_bus(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_control_proxy_new_for_bus(). * * Returns: (transfer full) (type GpickControlProxy): The constructed proxy object or %NULL if @error is set. */ GpickControl * gpick_control_proxy_new_for_bus_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return GPICK_CONTROL (ret); else return NULL; } /** * gpick_control_proxy_new_for_bus_sync: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusProxyFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Like gpick_control_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection. * * The calling thread is blocked until a reply is received. * * See gpick_control_proxy_new_for_bus() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickControlProxy): The constructed proxy object or %NULL if @error is set. */ GpickControl * gpick_control_proxy_new_for_bus_sync ( GBusType bus_type, GDBusProxyFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_CONTROL_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "com.google.code.gpick.Control", NULL); if (ret != NULL) return GPICK_CONTROL (ret); else return NULL; } /* ------------------------------------------------------------------------ */ /** * GpickControlSkeleton: * * The #GpickControlSkeleton structure contains only private data and should only be accessed using the provided API. */ /** * GpickControlSkeletonClass: * @parent_class: The parent class. * * Class structure for #GpickControlSkeleton. */ struct _GpickControlSkeletonPrivate { GValue *properties; GList *changed_properties; GSource *changed_properties_idle_source; GMainContext *context; GMutex lock; }; static void _gpick_control_skeleton_handle_method_call ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GpickControlSkeleton *skeleton = GPICK_CONTROL_SKELETON (user_data); _ExtendedGDBusMethodInfo *info; GVariantIter iter; GVariant *child; GValue *paramv; guint num_params; guint num_extra; guint n; guint signal_id; GValue return_value = G_VALUE_INIT; info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation); g_assert (info != NULL); num_params = g_variant_n_children (parameters); num_extra = info->pass_fdlist ? 3 : 2; paramv = g_new0 (GValue, num_params + num_extra); n = 0; g_value_init (¶mv[n], GPICK_TYPE_CONTROL); g_value_set_object (¶mv[n++], skeleton); g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION); g_value_set_object (¶mv[n++], invocation); if (info->pass_fdlist) { #ifdef G_OS_UNIX g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST); g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation))); #else g_assert_not_reached (); #endif } g_variant_iter_init (&iter, parameters); while ((child = g_variant_iter_next_value (&iter)) != NULL) { _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra]; if (arg_info->use_gvariant) { g_value_init (¶mv[n], G_TYPE_VARIANT); g_value_set_variant (¶mv[n], child); n++; } else g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); g_variant_unref (child); } signal_id = g_signal_lookup (info->signal_name, GPICK_TYPE_CONTROL); g_value_init (&return_value, G_TYPE_BOOLEAN); g_signal_emitv (paramv, signal_id, 0, &return_value); if (!g_value_get_boolean (&return_value)) g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Method %s is not implemented on interface %s", method_name, interface_name); g_value_unset (&return_value); for (n = 0; n < num_params + num_extra; n++) g_value_unset (¶mv[n]); g_free (paramv); } static GVariant * _gpick_control_skeleton_handle_get_property ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GpickControlSkeleton *skeleton = GPICK_CONTROL_SKELETON (user_data); GValue value = G_VALUE_INIT; GParamSpec *pspec; _ExtendedGDBusPropertyInfo *info; GVariant *ret; ret = NULL; info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_control_interface_info, property_name); g_assert (info != NULL); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); if (pspec == NULL) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); } else { g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value); ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature)); g_value_unset (&value); } return ret; } static gboolean _gpick_control_skeleton_handle_set_property ( GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *variant, GError **error, gpointer user_data) { GpickControlSkeleton *skeleton = GPICK_CONTROL_SKELETON (user_data); GValue value = G_VALUE_INIT; GParamSpec *pspec; _ExtendedGDBusPropertyInfo *info; gboolean ret; ret = FALSE; info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_gpick_control_interface_info, property_name); g_assert (info != NULL); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); if (pspec == NULL) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %s", property_name); } else { if (info->use_gvariant) g_value_set_variant (&value, variant); else g_dbus_gvariant_to_gvalue (variant, &value); g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value); g_value_unset (&value); ret = TRUE; } return ret; } static const GDBusInterfaceVTable _gpick_control_skeleton_vtable = { _gpick_control_skeleton_handle_method_call, _gpick_control_skeleton_handle_get_property, _gpick_control_skeleton_handle_set_property }; static GDBusInterfaceInfo * gpick_control_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton) { return gpick_control_interface_info (); } static GDBusInterfaceVTable * gpick_control_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton) { return (GDBusInterfaceVTable *) &_gpick_control_skeleton_vtable; } static GVariant * gpick_control_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton) { GpickControlSkeleton *skeleton = GPICK_CONTROL_SKELETON (_skeleton); GVariantBuilder builder; guint n; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); if (_gpick_control_interface_info.parent_struct.properties == NULL) goto out; for (n = 0; _gpick_control_interface_info.parent_struct.properties[n] != NULL; n++) { GDBusPropertyInfo *info = _gpick_control_interface_info.parent_struct.properties[n]; if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) { GVariant *value; value = _gpick_control_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "com.google.code.gpick.Control", info->name, NULL, skeleton); if (value != NULL) { g_variant_take_ref (value); g_variant_builder_add (&builder, "{sv}", info->name, value); g_variant_unref (value); } } } out: return g_variant_builder_end (&builder); } static void gpick_control_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton) { } static void gpick_control_skeleton_iface_init (GpickControlIface *iface); G_DEFINE_TYPE_WITH_CODE (GpickControlSkeleton, gpick_control_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, G_IMPLEMENT_INTERFACE (GPICK_TYPE_CONTROL, gpick_control_skeleton_iface_init)); static void gpick_control_skeleton_finalize (GObject *object) { GpickControlSkeleton *skeleton = GPICK_CONTROL_SKELETON (object); g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free); if (skeleton->priv->changed_properties_idle_source != NULL) g_source_destroy (skeleton->priv->changed_properties_idle_source); g_main_context_unref (skeleton->priv->context); g_mutex_clear (&skeleton->priv->lock); G_OBJECT_CLASS (gpick_control_skeleton_parent_class)->finalize (object); } static void gpick_control_skeleton_init (GpickControlSkeleton *skeleton) { skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, GPICK_TYPE_CONTROL_SKELETON, GpickControlSkeletonPrivate); g_mutex_init (&skeleton->priv->lock); skeleton->priv->context = g_main_context_ref_thread_default (); } static void gpick_control_skeleton_class_init (GpickControlSkeletonClass *klass) { GObjectClass *gobject_class; GDBusInterfaceSkeletonClass *skeleton_class; g_type_class_add_private (klass, sizeof (GpickControlSkeletonPrivate)); gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gpick_control_skeleton_finalize; skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); skeleton_class->get_info = gpick_control_skeleton_dbus_interface_get_info; skeleton_class->get_properties = gpick_control_skeleton_dbus_interface_get_properties; skeleton_class->flush = gpick_control_skeleton_dbus_interface_flush; skeleton_class->get_vtable = gpick_control_skeleton_dbus_interface_get_vtable; } static void gpick_control_skeleton_iface_init (GpickControlIface *iface) { } /** * gpick_control_skeleton_new: * * Creates a skeleton object for the D-Bus interface com.google.code.gpick.Control. * * Returns: (transfer full) (type GpickControlSkeleton): The skeleton object. */ GpickControl * gpick_control_skeleton_new (void) { return GPICK_CONTROL (g_object_new (GPICK_TYPE_CONTROL_SKELETON, NULL)); } /* ------------------------------------------------------------------------ * Code for Object, ObjectProxy and ObjectSkeleton * ------------------------------------------------------------------------ */ /** * SECTION:GpickObject * @title: GpickObject * @short_description: Specialized GDBusObject types * * This section contains the #GpickObject, #GpickObjectProxy, and #GpickObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces. */ /** * GpickObject: * * The #GpickObject type is a specialized container of interfaces. */ /** * GpickObjectIface: * @parent_iface: The parent interface. * * Virtual table for the #GpickObject interface. */ static void gpick_object_default_init (GpickObjectIface *iface) { /** * GpickObject:single-instance: * * The #GpickSingleInstance instance corresponding to the D-Bus interface com.google.code.gpick.SingleInstance, if any. * * Connect to the #GObject::notify signal to get informed of property changes. */ g_object_interface_install_property (iface, g_param_spec_object ("single-instance", "single-instance", "single-instance", GPICK_TYPE_SINGLE_INSTANCE, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS)); /** * GpickObject:control: * * The #GpickControl instance corresponding to the D-Bus interface com.google.code.gpick.Control, if any. * * Connect to the #GObject::notify signal to get informed of property changes. */ g_object_interface_install_property (iface, g_param_spec_object ("control", "control", "control", GPICK_TYPE_CONTROL, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS)); } typedef GpickObjectIface GpickObjectInterface; G_DEFINE_INTERFACE_WITH_CODE (GpickObject, gpick_object, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT)); /** * gpick_object_get_single_instance: * @object: A #GpickObject. * * Gets the #GpickSingleInstance instance for the D-Bus interface com.google.code.gpick.SingleInstance on @object, if any. * * Returns: (transfer full): A #GpickSingleInstance that must be freed with g_object_unref() or %NULL if @object does not implement the interface. */ GpickSingleInstance *gpick_object_get_single_instance (GpickObject *object) { GDBusInterface *ret; ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.SingleInstance"); if (ret == NULL) return NULL; return GPICK_SINGLE_INSTANCE (ret); } /** * gpick_object_get_control: * @object: A #GpickObject. * * Gets the #GpickControl instance for the D-Bus interface com.google.code.gpick.Control on @object, if any. * * Returns: (transfer full): A #GpickControl that must be freed with g_object_unref() or %NULL if @object does not implement the interface. */ GpickControl *gpick_object_get_control (GpickObject *object) { GDBusInterface *ret; ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.Control"); if (ret == NULL) return NULL; return GPICK_CONTROL (ret); } /** * gpick_object_peek_single_instance: (skip) * @object: A #GpickObject. * * Like gpick_object_get_single_instance() but doesn't increase the reference count on the returned object. * * It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running. * * Returns: (transfer none): A #GpickSingleInstance or %NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object. */ GpickSingleInstance *gpick_object_peek_single_instance (GpickObject *object) { GDBusInterface *ret; ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.SingleInstance"); if (ret == NULL) return NULL; g_object_unref (ret); return GPICK_SINGLE_INSTANCE (ret); } /** * gpick_object_peek_control: (skip) * @object: A #GpickObject. * * Like gpick_object_get_control() but doesn't increase the reference count on the returned object. * * It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running. * * Returns: (transfer none): A #GpickControl or %NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object. */ GpickControl *gpick_object_peek_control (GpickObject *object) { GDBusInterface *ret; ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.Control"); if (ret == NULL) return NULL; g_object_unref (ret); return GPICK_CONTROL (ret); } static void gpick_object_notify (GDBusObject *object, GDBusInterface *interface) { g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name); } /** * GpickObjectProxy: * * The #GpickObjectProxy structure contains only private data and should only be accessed using the provided API. */ /** * GpickObjectProxyClass: * @parent_class: The parent class. * * Class structure for #GpickObjectProxy. */ static void gpick_object_proxy__gpick_object_iface_init (GpickObjectIface *iface) { } static void gpick_object_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface) { iface->interface_added = gpick_object_notify; iface->interface_removed = gpick_object_notify; } G_DEFINE_TYPE_WITH_CODE (GpickObjectProxy, gpick_object_proxy, G_TYPE_DBUS_OBJECT_PROXY, G_IMPLEMENT_INTERFACE (GPICK_TYPE_OBJECT, gpick_object_proxy__gpick_object_iface_init) G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, gpick_object_proxy__g_dbus_object_iface_init)); static void gpick_object_proxy_init (GpickObjectProxy *object) { } static void gpick_object_proxy_set_property (GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec) { G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); } static void gpick_object_proxy_get_property (GObject *gobject, guint prop_id, GValue *value, GParamSpec *pspec) { GpickObjectProxy *object = GPICK_OBJECT_PROXY (gobject); GDBusInterface *interface; switch (prop_id) { case 1: interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.SingleInstance"); g_value_take_object (value, interface); break; case 2: interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.Control"); g_value_take_object (value, interface); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } } static void gpick_object_proxy_class_init (GpickObjectProxyClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->set_property = gpick_object_proxy_set_property; gobject_class->get_property = gpick_object_proxy_get_property; g_object_class_override_property (gobject_class, 1, "single-instance"); g_object_class_override_property (gobject_class, 2, "control"); } /** * gpick_object_proxy_new: * @connection: A #GDBusConnection. * @object_path: An object path. * * Creates a new proxy object. * * Returns: (transfer full): The proxy object. */ GpickObjectProxy * gpick_object_proxy_new (GDBusConnection *connection, const gchar *object_path) { g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); return GPICK_OBJECT_PROXY (g_object_new (GPICK_TYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL)); } /** * GpickObjectSkeleton: * * The #GpickObjectSkeleton structure contains only private data and should only be accessed using the provided API. */ /** * GpickObjectSkeletonClass: * @parent_class: The parent class. * * Class structure for #GpickObjectSkeleton. */ static void gpick_object_skeleton__gpick_object_iface_init (GpickObjectIface *iface) { } static void gpick_object_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface) { iface->interface_added = gpick_object_notify; iface->interface_removed = gpick_object_notify; } G_DEFINE_TYPE_WITH_CODE (GpickObjectSkeleton, gpick_object_skeleton, G_TYPE_DBUS_OBJECT_SKELETON, G_IMPLEMENT_INTERFACE (GPICK_TYPE_OBJECT, gpick_object_skeleton__gpick_object_iface_init) G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, gpick_object_skeleton__g_dbus_object_iface_init)); static void gpick_object_skeleton_init (GpickObjectSkeleton *object) { } static void gpick_object_skeleton_set_property (GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec) { GpickObjectSkeleton *object = GPICK_OBJECT_SKELETON (gobject); GDBusInterfaceSkeleton *interface; switch (prop_id) { case 1: interface = g_value_get_object (value); if (interface != NULL) { g_warn_if_fail (GPICK_IS_SINGLE_INSTANCE (interface)); g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface); } else { g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "com.google.code.gpick.SingleInstance"); } break; case 2: interface = g_value_get_object (value); if (interface != NULL) { g_warn_if_fail (GPICK_IS_CONTROL (interface)); g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface); } else { g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "com.google.code.gpick.Control"); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } } static void gpick_object_skeleton_get_property (GObject *gobject, guint prop_id, GValue *value, GParamSpec *pspec) { GpickObjectSkeleton *object = GPICK_OBJECT_SKELETON (gobject); GDBusInterface *interface; switch (prop_id) { case 1: interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.SingleInstance"); g_value_take_object (value, interface); break; case 2: interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "com.google.code.gpick.Control"); g_value_take_object (value, interface); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } } static void gpick_object_skeleton_class_init (GpickObjectSkeletonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->set_property = gpick_object_skeleton_set_property; gobject_class->get_property = gpick_object_skeleton_get_property; g_object_class_override_property (gobject_class, 1, "single-instance"); g_object_class_override_property (gobject_class, 2, "control"); } /** * gpick_object_skeleton_new: * @object_path: An object path. * * Creates a new skeleton object. * * Returns: (transfer full): The skeleton object. */ GpickObjectSkeleton * gpick_object_skeleton_new (const gchar *object_path) { g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); return GPICK_OBJECT_SKELETON (g_object_new (GPICK_TYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL)); } /** * gpick_object_skeleton_set_single_instance: * @object: A #GpickObjectSkeleton. * @interface_: (allow-none): A #GpickSingleInstance or %NULL to clear the interface. * * Sets the #GpickSingleInstance instance for the D-Bus interface com.google.code.gpick.SingleInstance on @object. */ void gpick_object_skeleton_set_single_instance (GpickObjectSkeleton *object, GpickSingleInstance *interface_) { g_object_set (G_OBJECT (object), "single-instance", interface_, NULL); } /** * gpick_object_skeleton_set_control: * @object: A #GpickObjectSkeleton. * @interface_: (allow-none): A #GpickControl or %NULL to clear the interface. * * Sets the #GpickControl instance for the D-Bus interface com.google.code.gpick.Control on @object. */ void gpick_object_skeleton_set_control (GpickObjectSkeleton *object, GpickControl *interface_) { g_object_set (G_OBJECT (object), "control", interface_, NULL); } /* ------------------------------------------------------------------------ * Code for ObjectManager client * ------------------------------------------------------------------------ */ /** * SECTION:GpickObjectManagerClient * @title: GpickObjectManagerClient * @short_description: Generated GDBusObjectManagerClient type * * This section contains a #GDBusObjectManagerClient that uses gpick_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. */ /** * GpickObjectManagerClient: * * The #GpickObjectManagerClient structure contains only private data and should only be accessed using the provided API. */ /** * GpickObjectManagerClientClass: * @parent_class: The parent class. * * Class structure for #GpickObjectManagerClient. */ G_DEFINE_TYPE (GpickObjectManagerClient, gpick_object_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT); static void gpick_object_manager_client_init (GpickObjectManagerClient *manager) { } static void gpick_object_manager_client_class_init (GpickObjectManagerClientClass *klass) { } /** * gpick_object_manager_client_get_proxy_type: * @manager: A #GDBusObjectManagerClient. * @object_path: The object path of the remote object (unused). * @interface_name: (allow-none): Interface name of the remote object or %NULL to get the object proxy #GType. * @user_data: User data (unused). * * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy- and #GDBusProxy-derived types. * * Returns: A #GDBusProxy-derived #GType if @interface_name is not %NULL, otherwise the #GType for #GpickObjectProxy. */ GType gpick_object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data) { static gsize once_init_value = 0; static GHashTable *lookup_hash; GType ret; if (interface_name == NULL) return GPICK_TYPE_OBJECT_PROXY; if (g_once_init_enter (&once_init_value)) { lookup_hash = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (lookup_hash, "com.google.code.gpick.SingleInstance", GSIZE_TO_POINTER (GPICK_TYPE_SINGLE_INSTANCE_PROXY)); g_hash_table_insert (lookup_hash, "com.google.code.gpick.Control", GSIZE_TO_POINTER (GPICK_TYPE_CONTROL_PROXY)); g_once_init_leave (&once_init_value, 1); } ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name)); if (ret == (GType) 0) ret = G_TYPE_DBUS_PROXY; return ret; } /** * gpick_object_manager_client_new: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Asynchronously creates #GDBusObjectManagerClient using gpick_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_object_manager_client_new_finish() to get the result of the operation. * * See gpick_object_manager_client_new_sync() for the synchronous, blocking version of this constructor. */ void gpick_object_manager_client_new ( GDBusConnection *connection, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", gpick_object_manager_client_get_proxy_type, NULL); } /** * gpick_object_manager_client_new_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_object_manager_client_new(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_object_manager_client_new(). * * Returns: (transfer full) (type GpickObjectManagerClient): The constructed object manager client or %NULL if @error is set. */ GDBusObjectManager * gpick_object_manager_client_new_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return G_DBUS_OBJECT_MANAGER (ret); else return NULL; } /** * gpick_object_manager_client_new_sync: * @connection: A #GDBusConnection. * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Synchronously creates #GDBusObjectManagerClient using gpick_object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details. * * The calling thread is blocked until a reply is received. * * See gpick_object_manager_client_new() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickObjectManagerClient): The constructed object manager client or %NULL if @error is set. */ GDBusObjectManager * gpick_object_manager_client_new_sync ( GDBusConnection *connection, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", gpick_object_manager_client_get_proxy_type, NULL); if (ret != NULL) return G_DBUS_OBJECT_MANAGER (ret); else return NULL; } /** * gpick_object_manager_client_new_for_bus: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied. * @user_data: User data to pass to @callback. * * Like gpick_object_manager_client_new() but takes a #GBusType instead of a #GDBusConnection. * * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from. * You can then call gpick_object_manager_client_new_for_bus_finish() to get the result of the operation. * * See gpick_object_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor. */ void gpick_object_manager_client_new_for_bus ( GBusType bus_type, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (GPICK_TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", gpick_object_manager_client_get_proxy_type, NULL); } /** * gpick_object_manager_client_new_for_bus_finish: * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to gpick_object_manager_client_new_for_bus(). * @error: Return location for error or %NULL * * Finishes an operation started with gpick_object_manager_client_new_for_bus(). * * Returns: (transfer full) (type GpickObjectManagerClient): The constructed object manager client or %NULL if @error is set. */ GDBusObjectManager * gpick_object_manager_client_new_for_bus_finish ( GAsyncResult *res, GError **error) { GObject *ret; GObject *source_object; source_object = g_async_result_get_source_object (res); ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); g_object_unref (source_object); if (ret != NULL) return G_DBUS_OBJECT_MANAGER (ret); else return NULL; } /** * gpick_object_manager_client_new_for_bus_sync: * @bus_type: A #GBusType. * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. * @name: A bus name (well-known or unique). * @object_path: An object path. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL * * Like gpick_object_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection. * * The calling thread is blocked until a reply is received. * * See gpick_object_manager_client_new_for_bus() for the asynchronous version of this constructor. * * Returns: (transfer full) (type GpickObjectManagerClient): The constructed object manager client or %NULL if @error is set. */ GDBusObjectManager * gpick_object_manager_client_new_for_bus_sync ( GBusType bus_type, GDBusObjectManagerClientFlags flags, const gchar *name, const gchar *object_path, GCancellable *cancellable, GError **error) { GInitable *ret; ret = g_initable_new (GPICK_TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", gpick_object_manager_client_get_proxy_type, NULL); if (ret != NULL) return G_DBUS_OBJECT_MANAGER (ret); else return NULL; } gpick_0.2.5/source/dbus/win32dummy/Control.cpp0000644000175000017500000000356212070605214020007 0ustar zbygzbyg/* * 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 guint gpick_own_name(bool (*on_control_activate_floating_picker)(void *userdata), bool (*on_single_instance_activate)(void *userdata), void *userdata) { return 0; } void gpick_unown_name(guint bus_id) { } bool gpick_control_activate_floating_picker() { return false; } bool gpick_single_instance_activate() { return false; } gpick_0.2.5/source/dbus/interface.xml0000644000175000017500000000047012070605214016322 0ustar zbygzbyg gpick_0.2.5/source/dbus/Control.cpp0000644000175000017500000001430212070605214015763 0ustar zbygzbyg/* * 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 "DbusInterface.h" #include using namespace std; static GDBusObjectManagerServer *manager = NULL; typedef struct DbusInterface { bool (*on_control_activate_floating_picker)(void *userdata); bool (*on_single_instance_activate)(void *userdata); void *userdata; }DbusInterface; static DbusInterface dbus_interface; static gboolean on_control_activate_floating_picker(GpickControl *control, GDBusMethodInvocation *invocation, gpointer user_data) { DbusInterface *dbus_interface = reinterpret_cast(user_data); bool result = dbus_interface->on_control_activate_floating_picker(dbus_interface->userdata); gpick_control_complete_activate_floating_picker(control, invocation); return result; } static gboolean on_single_instance_activate(GpickSingleInstance *single_instance, GDBusMethodInvocation *invocation, gpointer user_data) { DbusInterface *dbus_interface = reinterpret_cast(user_data); bool result = dbus_interface->on_single_instance_activate(dbus_interface->userdata); gpick_single_instance_complete_activate(single_instance, invocation); return result; } static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { GpickObjectSkeleton *object; manager = g_dbus_object_manager_server_new ("/gpick"); GpickControl *control; object = gpick_object_skeleton_new("/gpick/Control"); control = gpick_control_skeleton_new(); gpick_object_skeleton_set_control(object, control); g_object_unref(control); g_signal_connect(control, "handle-activate-floating-picker", G_CALLBACK(on_control_activate_floating_picker), user_data); g_dbus_object_manager_server_export(manager, G_DBUS_OBJECT_SKELETON(object)); g_object_unref(object); GpickSingleInstance *single_instance; object = gpick_object_skeleton_new("/gpick/SingleInstance"); single_instance = gpick_single_instance_skeleton_new(); gpick_object_skeleton_set_single_instance(object, single_instance); g_object_unref(single_instance); g_signal_connect(single_instance, "handle-activate", G_CALLBACK(on_single_instance_activate), user_data); g_dbus_object_manager_server_export(manager, G_DBUS_OBJECT_SKELETON(object)); g_object_unref(object); g_dbus_object_manager_server_set_connection(manager, connection); } static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { } static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { } guint gpick_own_name(bool (*on_control_activate_floating_picker)(void *userdata), bool (*on_single_instance_activate)(void *userdata), void *userdata) { dbus_interface.on_control_activate_floating_picker = on_control_activate_floating_picker; dbus_interface.on_single_instance_activate = on_single_instance_activate; dbus_interface.userdata = userdata; return g_bus_own_name(G_BUS_TYPE_SESSION, "com.google.code.gpick", GBusNameOwnerFlags(G_BUS_NAME_OWNER_FLAGS_REPLACE), on_bus_acquired, on_name_acquired, on_name_lost, &dbus_interface, NULL); } void gpick_unown_name(guint bus_id) { g_bus_unown_name(bus_id); } GDBusObjectManager* gpick_get_manager() { GDBusObjectManager *manager; GError *error = NULL; manager = gpick_object_manager_client_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, "com.google.code.gpick", "/gpick", NULL, &error); if (manager == NULL) { cerr << "Error getting object manager client: " << error->message << endl; g_error_free (error); return 0; } return manager; } bool gpick_control_activate_floating_picker() { GDBusObjectManager *manager = gpick_get_manager(); if (!manager) return false; GError *error = NULL; GDBusInterface *interface = g_dbus_object_manager_get_interface(manager, "/gpick/Control", "com.google.code.gpick.Control"); bool result = false; if (interface){ if (!gpick_control_call_activate_floating_picker_sync(GPICK_CONTROL(interface), NULL, &error)){ cerr << "Error calling \"Control.ActivateFloatingPicker\": " << error->message << endl; g_error_free (error); }else result = true; g_object_unref(interface); } g_object_unref(manager); return result; } bool gpick_single_instance_activate() { GDBusObjectManager *manager = gpick_get_manager(); if (!manager) return false; GError *error = NULL; GDBusInterface *interface = g_dbus_object_manager_get_interface(manager, "/gpick/SingleInstance", "com.google.code.gpick.SingleInstance"); bool result = false; if (interface){ if (!gpick_single_instance_call_activate_sync(GPICK_SINGLE_INSTANCE(interface), NULL, &error)){ cerr << "Error calling \"SingleInstance.Activate\": " << error->message << endl; g_error_free (error); }else result = true; g_object_unref(interface); } g_object_unref(manager); return result; } gpick_0.2.5/source/MathUtil.cpp0000644000175000017500000001512512070605214015141 0ustar zbygzbyg/* * 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 "MathUtil.h" #include #include float max_float_3(float a, float b, float c) { if (a > b){ if (a > c){ return a; }else{ return c; } }else{ if (b > c){ return b; }else{ return c; } } } float min_float_3(float a, float b, float c) { if (a < b){ if (a < c){ return a; }else{ return c; } }else{ if (b < c){ return b; }else{ return c; } } } float clamp_float(float x, float a, float b) { if (x < a) return a; if (x > b) return b; return x; } int clamp_int(int x, int a, int b) { if (x < a) return a; if (x > b) return b; return x; } int min_int(int a, int b) { if (a > b) return b; return a; } int max_int(int a, int b) { if (a < b) return b; return a; } int abs_int(int a) { if (a < 0) return -a; return a; } float abs_float(float a) { if (a < 0) return -a; return a; } void matrix3x3_identity(matrix3x3* matrix) { int i,j; for (i=0;i<3;++i){ for (j=0;j<3;++j){ matrix->m[i][j]=((i==j)?1:0); } } } void matrix3x3_copy(const matrix3x3* matrix, matrix3x3* result) { memcpy(result, matrix, sizeof(matrix3x3)); } void matrix3x3_multiply(const matrix3x3* matrix1, const matrix3x3* matrix2, matrix3x3* result){ int i,j,k; matrix3x3 matrix_t; if (matrix1==result){ matrix3x3_copy(matrix1, &matrix_t); matrix1=&matrix_t; }else if (matrix2==result){ matrix3x3_copy(matrix2, &matrix_t); matrix2=&matrix_t; } for (i=0;i<3;++i){ for (j=0;j<3;++j){ result->m[i][j]=0; for (k=0;k<3;++k){ result->m[i][j] += matrix1->m[k][j]*matrix2->m[i][k]; } } } } double matrix3x3_determinant(const matrix3x3* matrix) { double det=0; double t; int i,j; for (i=0;i<3;++i){ t=1; for (j=0;j<3;++j){ t*=matrix->m[(i+j)%3][j]; } det+=t; } for (i=0;i<3;++i){ t=1; for (j=0;j<3;++j){ t*=matrix->m[(i+2-j)%3][j]; } det-=t; } return det; } void matrix3x3_transpose(const matrix3x3* matrix, matrix3x3* result) { int i,j; matrix3x3 matrix_t; if (matrix==result){ matrix3x3_copy(matrix, &matrix_t); matrix=&matrix_t; } for (i=0;i<3;++i){ for (j=0;j<3;++j){ result->m[j][i]=matrix->m[i][j]; } } } int matrix3x3_inverse(const matrix3x3* matrix, matrix3x3* result){ double det = matrix3x3_determinant(matrix); if (det==0) return -1; double invdet=1/det; matrix3x3 matrix_t; if (matrix==result){ matrix3x3_copy(matrix, &matrix_t); matrix=&matrix_t; } result->m[0][0] = (matrix->m[1][1] * matrix->m[2][2] - matrix->m[2][1] * matrix->m[1][2]) * invdet; result->m[0][1] = -(matrix->m[0][1] * matrix->m[2][2] - matrix->m[2][1] * matrix->m[0][2]) * invdet; result->m[0][2] = (matrix->m[0][1] * matrix->m[1][2] - matrix->m[1][1] * matrix->m[0][2]) * invdet; result->m[1][0] = -(matrix->m[1][0] * matrix->m[2][2] - matrix->m[2][0] * matrix->m[1][2]) * invdet; result->m[1][1] = (matrix->m[0][0] * matrix->m[2][2] - matrix->m[2][0] * matrix->m[0][2]) * invdet; result->m[1][2] = -(matrix->m[0][0] * matrix->m[1][2] - matrix->m[1][0] * matrix->m[0][2]) * invdet; result->m[2][0] = (matrix->m[1][0] * matrix->m[2][1] - matrix->m[2][0] * matrix->m[1][1]) * invdet; result->m[2][1] = -(matrix->m[0][0] * matrix->m[2][1] - matrix->m[2][0] * matrix->m[0][1]) * invdet; result->m[2][2] = (matrix->m[0][0] * matrix->m[1][1] - matrix->m[1][0] * matrix->m[0][1]) * invdet; return 0; } void vector2_set(vector2* v1, float x, float y) { v1->x = x; v1->y = y; } float vector2_length(const vector2* v1) { return sqrt(v1->x * v1->x + v1->y * v1->y); } void vector2_normalize(const vector2* v1, vector2* r) { float l = vector2_length(v1); r->x = v1->x / l; r->y = v1->y / l; } float vector2_dot(const vector2* v1, const vector2* v2) { return v1->x * v2->x + v1->y * v2->y; } float mix_float(float a, float b, float mix) { return a * (1 - mix) + b * mix; } double mix_double(double a, double b, double mix){ return a * (1 - mix) + b * mix; } float wrap_float(float x) { return x - floor(x); } int wrap_int(int x, int a, int b) { if (x < a){ return b - (a - x) % (b - a); }else if (x >= b){ return a + (x - b) % (b - a); } return x; } void vector3_multiply_matrix3x3(const vector3* vector, const matrix3x3* matrix, vector3* result) { vector3 vector_t; if (vector==result){ vector3_copy(vector, &vector_t); vector=&vector_t; } result->x = vector->x * matrix->m[0][0] + vector->y * matrix->m[0][1] + vector->z * matrix->m[0][2]; result->y = vector->x * matrix->m[1][0] + vector->y * matrix->m[1][1] + vector->z * matrix->m[1][2]; result->z = vector->x * matrix->m[2][0] + vector->y * matrix->m[2][1] + vector->z * matrix->m[2][2]; } void vector3_set(vector3* vector, float x, float y, float z) { vector->x = x; vector->y = y; vector->z = z; } void vector3_copy(const vector3* vector, vector3* result){ memcpy(result, vector, sizeof(vector3)); } float vector3_length(const vector3* vector) { return sqrt(vector->x * vector->x + vector->y * vector->y + vector->z * vector->z); } void vector3_clamp(vector3* vector, float a, float b){ vector->x = clamp_float(vector->x, a, b); vector->y = clamp_float(vector->y, a, b); vector->z = clamp_float(vector->z, a, b); } gpick_0.2.5/source/ScreenReader.cpp0000644000175000017500000000656112070605214015760 0ustar zbygzbyg/* * 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 "ScreenReader.h" #include "Rect2.h" #include using namespace math; struct ScreenReader{ GdkPixbuf *pixbuf; int max_size; GdkScreen *screen; Rect2 read_area; }; struct ScreenReader* screen_reader_new(){ struct ScreenReader* screen = new struct ScreenReader; screen->max_size = 150; screen->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 150, 150); screen->screen = NULL; return screen; } void screen_reader_destroy(struct ScreenReader *screen) { if (screen->pixbuf) g_object_unref(screen->pixbuf); delete screen; } void screen_reader_add_rect(struct ScreenReader *screen, GdkScreen *gdk_screen, Rect2& rect){ if (screen->screen && (screen->screen == gdk_screen)){ screen->read_area += rect; }else{ screen->read_area += rect; screen->screen = gdk_screen; } } void screen_reader_reset_rect(struct ScreenReader *screen){ screen->read_area = Rect2(); screen->screen = NULL; } void screen_reader_update_pixbuf(struct ScreenReader *screen, Rect2* update_rect){ if (!screen->screen) return; GdkWindow* root_window = gdk_screen_get_root_window(screen->screen); GdkColormap* colormap = gdk_screen_get_system_colormap(screen->screen); int left = screen->read_area.getX(); int top = screen->read_area.getY(); int width = screen->read_area.getWidth(); int height = screen->read_area.getHeight(); if (width > screen->max_size || height > screen->max_size){ if (screen->pixbuf) g_object_unref(screen->pixbuf); screen->max_size = (std::max(width, height) / 150 + 1) * 150; screen->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, screen->max_size, screen->max_size); } gdk_pixbuf_get_from_drawable(screen->pixbuf, root_window, colormap, left, top, 0, 0, width, height); *update_rect = screen->read_area; } GdkPixbuf* screen_reader_get_pixbuf(struct ScreenReader *screen){ return screen->pixbuf; } gpick_0.2.5/source/DragDrop.h0000644000175000017500000000635612070605214014567 0ustar zbygzbyg/* * 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 DRAGDROP_H_ #define DRAGDROP_H_ #include #include "ColorObject.h" #include "GlobalState.h" enum DragDropFlags{ DRAGDROP_SOURCE = 1<<1, DRAGDROP_DESTINATION = 1<<2, }; struct DragDrop{ GtkWidget* widget; void* userdata; struct ColorObject* (*get_color_object)(struct DragDrop* dd); int (*set_color_object_at)(struct DragDrop* dd, struct ColorObject* colorobject, int x, int y, bool move); struct ColorObject** (*get_color_object_list)(struct DragDrop* dd, uint32_t *colorobject_n); int (*set_color_object_list_at)(struct DragDrop* dd, struct ColorObject** colorobject, uint32_t colorobject_n, int x, int y, bool move); bool (*test_at)(struct DragDrop* dd, int x, int y); bool (*data_received)(struct DragDrop* dd, GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time); bool (*data_get)(struct DragDrop* dd, GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint target_type, guint time); bool (*data_delete)(struct DragDrop* dd, GtkWidget *widget, GdkDragContext *context); bool (*drag_end)(struct DragDrop* dd, GtkWidget *widget, GdkDragContext *context); enum DataType{ DATA_TYPE_NONE, DATA_TYPE_COLOR_OBJECT, DATA_TYPE_COLOR_OBJECTS, }; DataType data_type; union{ struct{ struct ColorObject* color_object; }color_object; struct{ struct ColorObject** color_objects; uint32_t color_object_n; }color_objects; }data; struct dynvHandlerMap* handler_map; GtkWidget* dragwidget; GlobalState *gs; void* userdata2; }; int dragdrop_init(struct DragDrop* dd, GlobalState *gs); int dragdrop_widget_attach(GtkWidget* widget, DragDropFlags flags, struct DragDrop *dd); #endif /* DRAGDROP_H_ */ gpick_0.2.5/source/DynvHelpers.h0000644000175000017500000001126412070605214015322 0ustar zbygzbyg/* * 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 DYNVHELPERS_H_ #define DYNVHELPERS_H_ #include "dynv/DynvSystem.h" #include "Color.h" #include #ifndef _MSC_VER #include #endif int32_t dynv_get_int32_wd(struct dynvSystem* dynv_system, const char *path, int32_t default_value); float dynv_get_float_wd(struct dynvSystem* dynv_system, const char *path, float default_value); bool dynv_get_bool_wd(struct dynvSystem* dynv_system, const char *path, bool default_value); const char* dynv_get_string_wd(struct dynvSystem* dynv_system, const char *path, const char* default_value); const Color* dynv_get_color_wd(struct dynvSystem* dynv_system, const char *path, const Color* default_value); Color* dynv_get_color_wdc(struct dynvSystem* dynv_system, const char *path, Color* default_value); const void* dynv_get_pointer_wd(struct dynvSystem* dynv_system, const char *path, const void* default_value); void* dynv_get_pointer_wdc(struct dynvSystem* dynv_system, const char *path, void* default_value); void dynv_set_int32(struct dynvSystem* dynv_system, const char *path, int32_t value); void dynv_set_float(struct dynvSystem* dynv_system, const char *path, float value); void dynv_set_bool(struct dynvSystem* dynv_system, const char *path, bool value); void dynv_set_string(struct dynvSystem* dynv_system, const char *path, const char* value); void dynv_set_color(struct dynvSystem* dynv_system, const char *path, const Color* value); void dynv_set_pointer(struct dynvSystem* dynv_system, const char *path, const void* value); struct dynvSystem* dynv_get_dynv(struct dynvSystem* dynv_system, const char *path); int32_t* dynv_get_int32_array_wd(struct dynvSystem* dynv_system, const char *path, int32_t *default_value, uint32_t default_count, uint32_t *count); float* dynv_get_float_array_wd(struct dynvSystem* dynv_system, const char *path, float *default_value, uint32_t default_count, uint32_t *count); bool* dynv_get_bool_array_wd(struct dynvSystem* dynv_system, const char *path, bool *default_value, uint32_t default_count, uint32_t *count); const char** dynv_get_string_array_wd(struct dynvSystem* dynv_system, const char *path, const char** default_value, uint32_t default_count, uint32_t *count); const Color** dynv_get_color_array_wd(struct dynvSystem* dynv_system, const char *path, const Color** default_value, uint32_t default_count, uint32_t *count); const struct dynvSystem** dynv_get_dynv_array_wd(struct dynvSystem* dynv_system, const char *path, const struct dynvSystem** default_value, uint32_t default_count, uint32_t *count); void dynv_set_int32_array(struct dynvSystem* dynv_system, const char *path, int32_t* values, uint32_t count); void dynv_set_float_array(struct dynvSystem* dynv_system, const char *path, float* values, uint32_t count); void dynv_set_bool_array(struct dynvSystem* dynv_system, const char *path, bool* values, uint32_t count); void dynv_set_string_array(struct dynvSystem* dynv_system, const char *path, const char** values, uint32_t count); void dynv_set_color_array(struct dynvSystem* dynv_system, const char *path, const Color** values, uint32_t count); void dynv_set_dynv_array(struct dynvSystem* dynv_system, const char *path, const struct dynvSystem** values, uint32_t count); #endif /* DYNVHELPERS_H_ */ gpick_0.2.5/source/CopyPaste.h0000644000175000017500000000355212070605214014767 0ustar zbygzbyg/* * 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 COPYPASTE_H_ #define COPYPASTE_H_ #include "ColorObject.h" #include "GlobalState.h" int copypaste_set_color_object(struct ColorObject* color_object, GlobalState* gs); int copypaste_get_color_object(struct ColorObject** color_object, GlobalState* gs); int copypaste_is_color_object_available(GlobalState* gs); #endif /* COPYPASTE_H_ */ gpick_0.2.5/source/uiStatusIcon.cpp0000644000175000017500000001153312070605214016043 0ustar zbygzbyg/* * 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 "uiStatusIcon.h" #include "gtk/Zoomed.h" #include "gtk/ColorWidget.h" #include "uiUtilities.h" #include "uiApp.h" #include "GlobalStateStruct.h" #include "ColorPicker.h" #include "FloatingPicker.h" #include "Converter.h" #include "DynvHelpers.h" #include "Internationalisation.h" #include using namespace math; struct uiStatusIcon{ GtkWidget* parent; GtkStatusIcon* status_icon; FloatingPicker floating_picker; GlobalState* gs; }; static void status_icon_destroy_parent(GtkWidget *widget, gpointer user_data){ struct uiStatusIcon* si = (struct uiStatusIcon*)user_data; gtk_widget_destroy(GTK_WIDGET(si->parent)); } static void status_icon_show_parent(GtkWidget *widget, gpointer user_data){ struct uiStatusIcon* si = (struct uiStatusIcon*)user_data; floating_picker_deactivate(si->floating_picker); status_icon_set_visible(si, false); struct dynvSystem *params = dynv_get_dynv(si->gs->params, "gpick.main"); main_show_window(si->parent, params); dynv_system_release(params); } static void status_icon_popup(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) { struct uiStatusIcon* si = (struct uiStatusIcon*)user_data; GtkMenu* menu; GtkWidget* item; menu = GTK_MENU(gtk_menu_new ()); item = gtk_menu_item_new_with_image (_("_Show Main Window"), gtk_image_new_from_icon_name("gpick", GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (status_icon_show_parent), si); gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new()); item = gtk_menu_item_new_with_image (_("_Quit"), gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (status_icon_destroy_parent), si); gtk_widget_show_all (GTK_WIDGET(menu)); //g_signal_connect (G_OBJECT (menu), "leave-notify-event", G_CALLBACK (tray_popup_leave), menu); gtk_menu_popup (GTK_MENU (menu), NULL, NULL, 0, 0, button, activate_time); g_object_ref_sink(menu); g_object_unref(menu); } static void status_icon_activate(GtkWidget *widget, gpointer user_data){ struct uiStatusIcon* si = (struct uiStatusIcon*)user_data; floating_picker_activate(si->floating_picker, false); } void status_icon_set_visible(struct uiStatusIcon* si, bool visible){ if (visible==false){ floating_picker_deactivate(si->floating_picker); } gtk_status_icon_set_visible(si->status_icon, visible); } struct uiStatusIcon* status_icon_new(GtkWidget* parent, GlobalState* gs, FloatingPicker floating_picker){ struct uiStatusIcon *si = new struct uiStatusIcon; si->gs = gs; si->parent = gtk_widget_get_toplevel(parent); GtkStatusIcon *status_icon = gtk_status_icon_new(); gtk_status_icon_set_visible (status_icon, FALSE); gtk_status_icon_set_from_icon_name(status_icon, "gpick"); g_signal_connect(G_OBJECT(status_icon), "popup-menu", G_CALLBACK(status_icon_popup), si); #ifndef WIN32 g_signal_connect(G_OBJECT(status_icon), "activate", G_CALLBACK(status_icon_activate), si); #endif si->floating_picker = floating_picker; si->status_icon = status_icon; //si->color_source = color_source; return si; } void status_icon_destroy(struct uiStatusIcon* si){ //floating_picker_free(si->floating_picker); delete si; } gpick_0.2.5/source/DynvHelpers.cpp0000644000175000017500000001746012070605214015661 0ustar zbygzbyg/* * 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 "DynvHelpers.h" int32_t dynv_get_int32_wd(struct dynvSystem* dynv_system, const char *path, int32_t default_value){ int error; void* r = dynv_get(dynv_system, "int32", path, &error); if (error){ return default_value; }else return *(int32_t*)r; } float dynv_get_float_wd(struct dynvSystem* dynv_system, const char *path, float default_value){ int error; void* r = dynv_get(dynv_system, "float", path, &error); if (error){ return default_value; }else return *(float*)r; } bool dynv_get_bool_wd(struct dynvSystem* dynv_system, const char *path, bool default_value){ int error; void* r = dynv_get(dynv_system, "bool", path, &error); if (error){ return default_value; }else return *(bool*)r; } const char* dynv_get_string_wd(struct dynvSystem* dynv_system, const char *path, const char* default_value){ int error; void* r = dynv_get(dynv_system, "string", path, &error); if (error){ return default_value; }else return *(const char**)r; } const Color* dynv_get_color_wd(struct dynvSystem* dynv_system, const char *path, const Color* default_value){ int error; void* r = dynv_get(dynv_system, "color", path, &error); if (error){ return default_value; }else return *(const Color**)r; } Color* dynv_get_color_wdc(struct dynvSystem* dynv_system, const char *path, Color* default_value){ int error; void* r = dynv_get(dynv_system, "color", path, &error); if (error){ return default_value; }else return *(Color**)r; } const void* dynv_get_pointer_wd(struct dynvSystem* dynv_system, const char *path, const void* default_value){ int error; void* r = dynv_get(dynv_system, "ptr", path, &error); if (error){ return default_value; }else return *(const void**)r; } void* dynv_get_pointer_wdc(struct dynvSystem* dynv_system, const char *path, void* default_value){ int error; void* r = dynv_get(dynv_system, "ptr", path, &error); if (error){ return default_value; }else return *(void**)r; } void dynv_set_int32(struct dynvSystem* dynv_system, const char *path, int32_t value){ dynv_set(dynv_system, "int32", path, &value); } void dynv_set_float(struct dynvSystem* dynv_system, const char *path, float value){ dynv_set(dynv_system, "float", path, &value); } void dynv_set_bool(struct dynvSystem* dynv_system, const char *path, bool value){ dynv_set(dynv_system, "bool", path, &value); } void dynv_set_string(struct dynvSystem* dynv_system, const char *path, const char* value){ dynv_set(dynv_system, "string", path, &value); } void dynv_set_color(struct dynvSystem* dynv_system, const char *path, const Color* value){ dynv_set(dynv_system, "color", path, &value); } void dynv_set_pointer(struct dynvSystem* dynv_system, const char *path, const void* value){ dynv_set(dynv_system, "ptr", path, &value); } struct dynvSystem* dynv_get_dynv(struct dynvSystem* dynv_system, const char *path){ int error; void* r = dynv_get(dynv_system, "dynv", path, &error); if (error){ struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(dynv_system); struct dynvSystem* dynv = dynv_system_create(handler_map); dynv_handler_map_release(handler_map); dynv_set(dynv_system, "dynv", path, dynv); return dynv; }else return (struct dynvSystem*)r; } int32_t* dynv_get_int32_array_wd(struct dynvSystem* dynv_system, const char *path, int32_t* default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "int32", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (int32_t*)r; } float* dynv_get_float_array_wd(struct dynvSystem* dynv_system, const char *path, float *default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "float", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (float*)r; } bool* dynv_get_bool_array_wd(struct dynvSystem* dynv_system, const char *path, bool *default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "bool", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (bool*)r; } const char** dynv_get_string_array_wd(struct dynvSystem* dynv_system, const char *path, const char** default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "string", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (const char**)r; } const Color** dynv_get_color_array_wd(struct dynvSystem* dynv_system, const char *path, const Color** default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "color", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (const Color**)r; } const struct dynvSystem** dynv_get_dynv_array_wd(struct dynvSystem* dynv_system, const char *path, const struct dynvSystem** default_value, uint32_t default_count, uint32_t *count){ int error; void** r = dynv_get_array(dynv_system, "dynv", path, count, &error); if (error){ if (count) *count = default_count; return default_value; }else return (const struct dynvSystem**)r; } void dynv_set_int32_array(struct dynvSystem* dynv_system, const char *path, int32_t* values, uint32_t count){ dynv_set_array(dynv_system, "int32", path, (const void**)values, count); } void dynv_set_float_array(struct dynvSystem* dynv_system, const char *path, float* values, uint32_t count){ dynv_set_array(dynv_system, "float", path, (const void**)values, count); } void dynv_set_bool_array(struct dynvSystem* dynv_system, const char *path, bool* values, uint32_t count){ dynv_set_array(dynv_system, "bool", path, (const void**)values, count); } void dynv_set_string_array(struct dynvSystem* dynv_system, const char *path, const char** values, uint32_t count){ dynv_set_array(dynv_system, "string", path, (const void**)values, count); } void dynv_set_color_array(struct dynvSystem* dynv_system, const char *path, const Color** values, uint32_t count){ dynv_set_array(dynv_system, "color", path, (const void**)values, count); } void dynv_set_dynv_array(struct dynvSystem* dynv_system, const char *path, const struct dynvSystem** values, uint32_t count){ dynv_set_array(dynv_system, "dynv", path, (const void**)values, count); } gpick_0.2.5/source/FloatingPicker.h0000644000175000017500000000376612070605214015770 0ustar zbygzbyg/* * 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 FLOATINGPICKER_H_ #define FLOATINGPICKER_H_ #include "ColorSource.h" #include "GlobalState.h" #include typedef struct FloatingPickerArgs* FloatingPicker; FloatingPicker floating_picker_new(GtkWidget *parent, GlobalState *gs, ColorSource* color_source); void floating_picker_free(FloatingPicker fp); void floating_picker_activate(FloatingPicker fp, bool hide_on_mouse_release); void floating_picker_deactivate(FloatingPicker fp); #endif /* FLOATINGPICKER_H_ */ gpick_0.2.5/source/uiConverter.cpp0000644000175000017500000003407012070605214015717 0ustar zbygzbyg/* * 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 "uiConverter.h" #include "Converter.h" #include "uiUtilities.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "Internationalisation.h" #include using namespace std; typedef enum{ CONVERTERLIST_HUMAN_NAME = 0, CONVERTERLIST_EXAMPLE, CONVERTERLIST_CONVERTER_PTR, CONVERTERLIST_COPY, CONVERTERLIST_COPY_ENABLED, CONVERTERLIST_PASTE, CONVERTERLIST_PASTE_ENABLED, CONVERTERLIST_N_COLUMNS }ConverterListColumns; typedef struct ConverterArgs{ GtkWidget* list; struct dynvSystem *params; GlobalState *gs; }ConverterArgs; static void converter_update_row(GtkTreeModel *model, GtkTreeIter *iter1, Converter *converter, ConverterArgs *args) { gchar* converted; Color c; c.rgb.red=0.75; c.rgb.green=0.50; c.rgb.blue=0.25; struct ColorObject *color_object=color_list_new_color_object(args->gs->colors, &c); dynv_set_string(color_object->params, "name", _("Test color")); Converters *converters = static_cast(dynv_get_pointer_wdc(args->gs->params, "Converters", 0)); if (converters_color_serialize(converters, converter->function_name, color_object, &converted) == 0) { gtk_list_store_set(GTK_LIST_STORE(model), iter1, CONVERTERLIST_HUMAN_NAME, converter->human_readable, CONVERTERLIST_EXAMPLE, converted, CONVERTERLIST_CONVERTER_PTR, converter, CONVERTERLIST_COPY, converter->copy, CONVERTERLIST_COPY_ENABLED, converter->serialize_available, CONVERTERLIST_PASTE, converter->paste, CONVERTERLIST_PASTE_ENABLED, converter->deserialize_available, -1); g_free(converted); }else{ gtk_list_store_set(GTK_LIST_STORE(model), iter1, CONVERTERLIST_HUMAN_NAME, converter->human_readable, CONVERTERLIST_EXAMPLE, _("error"), CONVERTERLIST_CONVERTER_PTR, converter, CONVERTERLIST_COPY, converter->copy, CONVERTERLIST_COPY_ENABLED, converter->serialize_available, CONVERTERLIST_PASTE, converter->paste, CONVERTERLIST_PASTE_ENABLED, converter->deserialize_available, -1); } color_object_release(color_object); } static void copy_toggled_cb(GtkCellRendererText *cell, gchar *path, ConverterArgs *args) { GtkTreeIter iter1; GtkListStore *store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(args->list))); gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter1, path ); gboolean value; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter1, CONVERTERLIST_COPY, &value, -1); gtk_list_store_set(store, &iter1, CONVERTERLIST_COPY, !value, -1); } static void paste_toggled_cb(GtkCellRendererText *cell, gchar *path, ConverterArgs *args) { GtkTreeIter iter1; GtkListStore *store=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(args->list))); gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter1, path ); gboolean value; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter1, CONVERTERLIST_PASTE, &value, -1); gtk_list_store_set(store, &iter1, CONVERTERLIST_PASTE, !value, -1); } static GtkWidget* converter_dropdown_new(ConverterArgs *args, GtkTreeModel *model){ GtkListStore *store = 0; GtkCellRenderer *renderer; GtkWidget *combo; if (model){ combo = gtk_combo_box_new_with_model(model); }else{ store = gtk_list_store_new (CONVERTERLIST_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); } renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, true); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", CONVERTERLIST_HUMAN_NAME, NULL); if (store) g_object_unref (store); return combo; } static GtkWidget* converter_list_new(ConverterArgs *args){ GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *col; GtkWidget *view; view = gtk_tree_view_new (); args->list=view; gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),1); store = gtk_list_store_new (CONVERTERLIST_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col,1); gtk_tree_view_column_set_title(col, _("Function name")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", CONVERTERLIST_HUMAN_NAME); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable(col,1); gtk_tree_view_column_set_title(col, _("Example")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", CONVERTERLIST_EXAMPLE); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_GROW_ONLY); gtk_tree_view_column_set_title(col, _("Copy")); renderer = gtk_cell_renderer_toggle_new(); gtk_tree_view_column_pack_start(col, renderer, false); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); g_signal_connect(renderer, "toggled", (GCallback) copy_toggled_cb, args); gtk_tree_view_column_set_attributes(col, renderer, "active", CONVERTERLIST_COPY, "activatable", CONVERTERLIST_COPY_ENABLED, (void*)0); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_sizing(col,GTK_TREE_VIEW_COLUMN_GROW_ONLY); gtk_tree_view_column_set_title(col, _("Paste")); renderer = gtk_cell_renderer_toggle_new(); gtk_tree_view_column_pack_start(col, renderer, false); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); g_signal_connect(renderer, "toggled", (GCallback) paste_toggled_cb, args); gtk_tree_view_column_set_attributes(col, renderer, "active", CONVERTERLIST_PASTE, "activatable", CONVERTERLIST_PASTE_ENABLED, (void*)0); gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL(store)); g_object_unref (GTK_TREE_MODEL(store)); GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(view) ); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW (view), TRUE); return view; } void dialog_converter_show(GtkWindow* parent, GlobalState* gs){ ConverterArgs *args = new ConverterArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick"); GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Converters"), 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, "converters.window.width", -1), dynv_get_int32_wd(args->params, "converters.window.height", -1)); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); GtkWidget* vbox = gtk_vbox_new(false, 5); GtkWidget *list; list = converter_list_new(args); GtkWidget *scrolled = gtk_scrolled_window_new(0, 0); gtk_container_add(GTK_CONTAINER(scrolled), list); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX(vbox), scrolled, true, true, 0); gint table_y; GtkWidget* table = gtk_table_new(5, 2, false); gtk_box_pack_start(GTK_BOX(vbox), table, false, false, 0); table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Displays:"),0,0.5,0,0), 0, 1, table_y, table_y+1, GtkAttachOptions(GTK_FILL), GTK_FILL, 0, 0); GtkWidget *display = converter_dropdown_new(args, 0); GtkTreeModel *model2=gtk_combo_box_get_model(GTK_COMBO_BOX(display)); gtk_table_attach(GTK_TABLE(table), display, 1, 2, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Color list:"),0,0.5,0,0), 0, 1, table_y, table_y+1, GtkAttachOptions(GTK_FILL), GTK_FILL, 0, 0); GtkWidget *color_list = converter_dropdown_new(args, model2); gtk_table_attach(GTK_TABLE(table), color_list, 1, 2, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); table_y++; Converters *converters = static_cast(dynv_get_pointer_wdc(args->gs->params, "Converters", 0)); Converter **converter_table; uint32_t total_converters, converter_i; converter_table = converters_get_all(converters, &total_converters); GtkTreeIter iter1; GtkTreeModel *model=gtk_tree_view_get_model(GTK_TREE_VIEW(list)); GtkTreeIter iter2; Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_DISPLAY); bool display_converter_found = false; Converter *list_converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COLOR_LIST); bool color_list_converter_found = false; converter_i = 0; while (converter_iparams, "converters.display", converter->function_name); } if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(color_list), &iter2)){ gtk_tree_model_get(GTK_TREE_MODEL(model2), &iter2, CONVERTERLIST_CONVERTER_PTR, &converter, -1); converters_set(converters, converter, CONVERTERS_ARRAY_TYPE_COLOR_LIST); dynv_set_string(args->params, "converters.color_list", converter->function_name); } store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); unsigned int count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); if (count > 0){ char** name_array = new char*[count]; bool* copy_array = new bool[count]; bool* paste_array = new bool[count]; unsigned int i = 0; while (valid){ Converter* converter; gboolean copy, paste; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, CONVERTERLIST_CONVERTER_PTR, &converter, CONVERTERLIST_COPY, ©, CONVERTERLIST_PASTE, &paste, -1); name_array[i] = converter->function_name; copy_array[i] = copy; paste_array[i] = paste; converter->copy = copy; converter->paste = paste; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); ++i; } converters_reorder(converters, (const char**)name_array, count); dynv_set_string_array(args->params, "converters.names", (const char**)name_array, count); dynv_set_bool_array(args->params, "converters.copy", copy_array, count); dynv_set_bool_array(args->params, "converters.paste", paste_array, count); delete [] name_array; delete [] copy_array; delete [] paste_array; }else{ converters_reorder(converters, 0, 0); dynv_set_string_array(args->params, "converters.names", 0, 0); dynv_set_bool_array(args->params, "converters.copy", 0, 0); dynv_set_bool_array(args->params, "converters.paste", 0, 0); } converters_rebuild_arrays(converters, CONVERTERS_ARRAY_TYPE_COPY); converters_rebuild_arrays(converters, CONVERTERS_ARRAY_TYPE_PASTE); } gint width, height; gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); dynv_set_int32(args->params, "converters.window.width", width); dynv_set_int32(args->params, "converters.window.height", height); gtk_widget_destroy(dialog); dynv_system_release(args->params); delete args; } gpick_0.2.5/source/uiAbout.h0000644000175000017500000000330312070605214014462 0ustar zbygzbyg/* * 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 UIDIALOGABOUT_H_ #define UIDIALOGABOUT_H_ #include void show_about_box(GtkWidget *widget); extern const gchar* program_name; #endif /* UIDIALOGABOUT_H_ */ gpick_0.2.5/source/ChangeNotification.h0000644000175000017500000000507212070605214016613 0ustar zbygzbyg/* * 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 CHANGENOTIFICATION_H_ #define CHANGENOTIFICATION_H_ #include "ColorSource.h" #include #include #include #include class ChangeNotification; class NotificationLink{ protected: std::string source_name; uint32_t source_slot_id; std::string destination_name; uint32_t destination_slot_id; bool enabled; public: NotificationLink(const char *source_name, uint32_t source_slot_id, const char *destination_name, uint32_t destination_slot_id); friend class ChangeNotification; }; class ChangeNotification{ protected: std::map sources; std::multimap > links; public: ChangeNotification(); ~ChangeNotification(); bool registerSource(const char *location, ColorSource *source); bool unregisterSource(const char *location, ColorSource *source); bool addLink(boost::shared_ptr notification_link); bool removeLink(boost::shared_ptr notification_link); }; #endif /* CHANGENOTIFICATION_H_ */ gpick_0.2.5/source/DragDrop.cpp0000644000175000017500000004751612070605214015125 0ustar zbygzbyg/* * 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 "DragDrop.h" #include "gtk/ColorWidget.h" #include "uiApp.h" #include "dynv/DynvXml.h" #include #include #include using namespace std; enum { TARGET_STRING = 1, TARGET_ROOTWIN, TARGET_COLOR, TARGET_COLOR_OBJECT_LIST, TARGET_COLOR_OBJECT_LIST_SERIALIZED, }; static GtkTargetEntry targets[] = { { (char*)"colorobject-list", GTK_TARGET_SAME_APP, TARGET_COLOR_OBJECT_LIST }, { (char*)"application/x-colorobject-list", GTK_TARGET_OTHER_APP, TARGET_COLOR_OBJECT_LIST_SERIALIZED }, { (char*)"application/x-color", 0, TARGET_COLOR }, { (char*)"text/plain", 0, TARGET_STRING }, { (char*)"STRING", 0, TARGET_STRING }, { (char*)"application/x-rootwin-drop", 0, TARGET_ROOTWIN } }; static guint n_targets = G_N_ELEMENTS (targets); static void drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer data); static gboolean drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint t, gpointer user_data); static void drag_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer user_data); static gboolean drag_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data); static void drag_data_delete(GtkWidget *widget, GdkDragContext *context, gpointer user_data); static void drag_data_get(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint target_type, guint time, gpointer user_data); static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer user_data); static void drag_end(GtkWidget *widget, GdkDragContext *context, gpointer user_data); static void drag_destroy(GtkWidget *widget, gpointer user_data); int dragdrop_init(struct DragDrop* dd, GlobalState *gs){ dd->get_color_object = 0; dd->set_color_object_at = 0; dd->test_at = 0; dd->data_received = 0; dd->data_get = 0; dd->data_delete = 0; dd->drag_end = 0; dd->get_color_object_list = 0; dd->set_color_object_list_at = 0; dd->handler_map = 0; dd->data_type = DragDrop::DATA_TYPE_NONE; memset(&dd->data, 0, sizeof(dd->data)); dd->widget = 0; dd->gs = gs; dd->dragwidget = 0; return 0; } int dragdrop_widget_attach(GtkWidget* widget, DragDropFlags flags, struct DragDrop *user_dd){ struct DragDrop* dd=new struct DragDrop; memcpy(dd, user_dd, sizeof(struct DragDrop)); dd->widget = widget; if (flags & DRAGDROP_SOURCE){ GtkTargetList *target_list = gtk_drag_source_get_target_list(widget); if (target_list){ gtk_target_list_add_table(target_list, targets, n_targets); }else{ target_list = gtk_target_list_new(targets, n_targets); gtk_drag_source_set_target_list(widget, target_list); } g_signal_connect (widget, "drag-data-get", G_CALLBACK (drag_data_get), dd); g_signal_connect (widget, "drag-data-delete", G_CALLBACK (drag_data_delete), dd); g_signal_connect (widget, "drag-begin", G_CALLBACK (drag_begin), dd); g_signal_connect (widget, "drag-end", G_CALLBACK (drag_end), dd); } if (flags & DRAGDROP_DESTINATION){ GtkTargetList *target_list = gtk_drag_dest_get_target_list(widget); if (target_list){ gtk_target_list_add_table(target_list, targets, n_targets); }else{ target_list = gtk_target_list_new(targets, n_targets); gtk_drag_dest_set_target_list(widget, target_list); } g_signal_connect (widget, "drag-data-received", G_CALLBACK(drag_data_received), dd); g_signal_connect (widget, "drag-leave", G_CALLBACK (drag_leave), dd); g_signal_connect (widget, "drag-motion", G_CALLBACK (drag_motion), dd); g_signal_connect (widget, "drag-drop", G_CALLBACK (drag_drop), dd); } g_signal_connect (widget, "destroy", G_CALLBACK (drag_destroy), dd); return 0; } static void drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer user_data){ bool success = false; if ((selection_data != NULL) && (selection_data->length >= 0)){ struct DragDrop *dd = (struct DragDrop*)user_data; if (dd->data_received){ success = dd->data_received(dd, widget, context, x, y, selection_data, target_type, time); } if (!success) switch (target_type){ case TARGET_COLOR_OBJECT_LIST: { struct ColorList{ uint64_t color_object_n; struct ColorObject* color_object; }data; memcpy(&data, selection_data->data, sizeof(data)); if (data.color_object_n > 1){ struct ColorObject **color_objects = new struct ColorObject*[data.color_object_n]; memcpy(color_objects, selection_data->data + offsetof(ColorList, color_object), sizeof(struct ColorObject*) * data.color_object_n); if (dd->set_color_object_list_at) dd->set_color_object_list_at(dd, color_objects, data.color_object_n, x, y, context->action & GDK_ACTION_MOVE ); else if (dd->set_color_object_at) dd->set_color_object_at(dd, data.color_object, x, y, context->action & GDK_ACTION_MOVE ); }else{ if (dd->set_color_object_at) dd->set_color_object_at(dd, data.color_object, x, y, context->action & GDK_ACTION_MOVE ); } } success = true; break; case TARGET_COLOR_OBJECT_LIST_SERIALIZED: { char *buffer = new char [selection_data->length + 1]; buffer[selection_data->length] = 0; memcpy(buffer, selection_data->data, selection_data->length); stringstream str(buffer); delete [] buffer; struct dynvSystem *params = dynv_system_create(dd->handler_map); dynv_xml_deserialize(params, str); uint32_t color_n = 0; struct dynvSystem **colors = (struct dynvSystem**)dynv_get_dynv_array_wd(params, "colors", 0, 0, &color_n); if (color_n > 0 && colors){ if (color_n > 1){ if (dd->set_color_object_list_at){ struct ColorObject **color_objects = new struct ColorObject*[color_n]; for (uint32_t i = 0; i < color_n; i++){ color_objects[i] = color_object_new(NULL); color_objects[i]->params = dynv_system_ref(colors[i]); color_objects[i] = color_object_copy(color_objects[i]); } dd->set_color_object_list_at(dd, color_objects, color_n, x, y, false); for (uint32_t i = 0; i < color_n; i++){ color_object_release(color_objects[i]); } delete [] color_objects; }else if (dd->set_color_object_at){ struct ColorObject* color_object = color_object_new(NULL); color_object->params = dynv_system_ref(colors[0]); dd->set_color_object_at(dd, color_object, x, y, false); color_object_release(color_object); } }else{ if (dd->set_color_object_at){ struct ColorObject* color_object = color_object_new(NULL); color_object->params = dynv_system_ref(colors[0]); dd->set_color_object_at(dd, color_object, x, y, false); color_object_release(color_object); } } } if (colors){ for (uint32_t i = 0; i < color_n; i++){ dynv_system_release(colors[i]); } delete [] colors; } /* if (data.color_object_n > 1){ memcpy(color_objects, selection_data->data + offsetof(ColorList, color_object), sizeof(struct ColorObject*) * data.color_object_n); if (dd->set_color_object_list_at) else if (dd->set_color_object_at) dd->set_color_object_at(dd, data.color_object, x, y, context->action & GDK_ACTION_MOVE ); }else{ } */ } success = true; break; case TARGET_STRING: { gchar* data = (gchar*)selection_data->data; if (data[selection_data->length]!=0) break; //not null terminated Color color; if (main_get_color_from_text(dd->gs, data, &color)!=0){ gtk_drag_finish (context, false, false, time); return; } struct ColorObject* color_object = color_object_new(dd->handler_map); color_object_set_color(color_object, &color); dd->set_color_object_at(dd, color_object, x, y, context->action & GDK_ACTION_MOVE ); color_object_release(color_object); } success = true; break; case TARGET_COLOR: { guint16* data = (guint16*)selection_data->data; Color color; color.rgb.red = data[0] / (double)0xFFFF; color.rgb.green = data[1] / (double)0xFFFF; color.rgb.blue = data[2] / (double)0xFFFF; struct ColorObject* color_object = color_object_new(dd->handler_map); color_object_set_color(color_object, &color); dd->set_color_object_at(dd, color_object, x, y, context->action & GDK_ACTION_MOVE ); color_object_release(color_object); } success = true; break; default: g_assert_not_reached (); } } gtk_drag_finish (context, success, (context->action==GDK_ACTION_MOVE), time); } static gboolean drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; if (!dd->test_at){ GdkAtom target = gtk_drag_dest_find_target(widget, context, 0); if (target){ gdk_drag_status(context, context->action, time); }else{ gdk_drag_status(context, GdkDragAction(0), time); } return TRUE; } if (dd->test_at(dd, x, y)){ GdkAtom target = gtk_drag_dest_find_target(widget, context, 0); if (target){ gdk_drag_status(context, context->action, time); }else{ gdk_drag_status(context, GdkDragAction(0), time); } }else{ gdk_drag_status(context, GdkDragAction(0), time); } return TRUE; } static void drag_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer user_data){ } static gboolean drag_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; GdkAtom target = gtk_drag_dest_find_target(widget, context, 0); if (target != GDK_NONE){ gtk_drag_get_data(widget, context, target, time); if (dd->drag_end) dd->drag_end(dd, widget, context); return TRUE; } if (dd->drag_end) dd->drag_end(dd, widget, context); return FALSE; } static void drag_data_delete(GtkWidget *widget, GdkDragContext *context, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; if (dd->data_delete){ dd->data_delete(dd, widget, context); } } static void drag_data_get(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint target_type, guint time, gpointer user_data){ g_assert (selection_data != NULL); struct DragDrop *dd = (struct DragDrop*)user_data; bool success = false; if (dd->data_get){ success = dd->data_get(dd, widget, context, selection_data, target_type, time); } if (!success){ if (dd->data_type == DragDrop::DATA_TYPE_COLOR_OBJECT){ struct ColorObject* color_object = dd->data.color_object.color_object; if (!color_object) return; Color color; switch (target_type){ case TARGET_COLOR_OBJECT_LIST: { struct{ uint64_t color_object_n; struct ColorObject* color_object; }data; data.color_object_n = 1; data.color_object = color_object; gtk_selection_data_set(selection_data, gdk_atom_intern("colorobject", TRUE), 8, (guchar *)&data, sizeof(data)); } break; case TARGET_COLOR_OBJECT_LIST_SERIALIZED: { struct dynvSystem *params = dynv_system_create(dd->handler_map); struct dynvSystem **colors = new struct dynvSystem*[1]; colors[0] = color_object->params; dynv_set_dynv_array(params, "colors", (const dynvSystem**)colors, 1); delete [] colors; stringstream str; str << "" << endl; dynv_xml_serialize(params, str); str << "" << endl; string xml_data = str.str(); gtk_selection_data_set(selection_data, gdk_atom_intern("application/x-colorobject-list", TRUE), 8, (guchar *)xml_data.c_str(), xml_data.length()); } break; case TARGET_STRING: { color_object_get_color(color_object, &color); char* text = main_get_color_text(dd->gs, &color, COLOR_TEXT_TYPE_COPY); if (text){ gtk_selection_data_set_text(selection_data, text, strlen(text)+1); g_free(text); } } break; case TARGET_COLOR: { color_object_get_color(color_object, &color); guint16 data_color[4]; data_color[0] = int(color.rgb.red * 0xFFFF); data_color[1] = int(color.rgb.green * 0xFFFF); data_color[2] = int(color.rgb.blue * 0xFFFF); data_color[3] = 0xffff; gtk_selection_data_set (selection_data, gdk_atom_intern ("application/x-color", TRUE), 16, (guchar *)data_color, 8); } break; case TARGET_ROOTWIN: g_print ("Dropped on the root window!\n"); break; default: g_assert_not_reached (); } }else if (dd->data_type == DragDrop::DATA_TYPE_COLOR_OBJECTS){ struct ColorObject** color_objects = dd->data.color_objects.color_objects; uint32_t color_object_n = dd->data.color_objects.color_object_n; if (!color_objects) return; Color color; switch (target_type){ case TARGET_COLOR_OBJECT_LIST: { struct ColorList{ uint64_t color_object_n; struct ColorObject* color_object[1]; }; uint32_t data_length = sizeof(uint64_t) + sizeof(struct ColorObject*) * color_object_n; struct ColorList *data = (struct ColorList*)new char [data_length]; data->color_object_n = color_object_n; memcpy(&data->color_object[0], color_objects, sizeof(struct ColorObject*) * color_object_n); gtk_selection_data_set(selection_data, gdk_atom_intern("colorobject", TRUE), 8, (guchar *)data, data_length); delete [] (char*)data; } break; case TARGET_COLOR_OBJECT_LIST_SERIALIZED: { struct dynvSystem *params = dynv_system_create(dd->handler_map); if (color_object_n > 0){ struct dynvSystem **colors = new struct dynvSystem*[color_object_n]; for (uint32_t i = 0; i < color_object_n; i++){ colors[i] = color_objects[i]->params; } dynv_set_dynv_array(params, "colors", (const dynvSystem**)colors, color_object_n); delete [] colors; } stringstream str; str << "" << endl; dynv_xml_serialize(params, str); str << "" << endl; string xml_data = str.str(); gtk_selection_data_set(selection_data, gdk_atom_intern("application/x-colorobject-list", TRUE), 8, (guchar *)xml_data.c_str(), xml_data.length()); } break; case TARGET_STRING: { stringstream ss; for (uint32_t i = 0; i != color_object_n; i++){ struct ColorObject *color_object = color_objects[i]; color_object_get_color(color_object, &color); char* text = main_get_color_text(dd->gs, &color, COLOR_TEXT_TYPE_COPY); if (text){ ss << text << endl; g_free(text); } } gtk_selection_data_set_text(selection_data, ss.str().c_str(), ss.str().length() + 1); } break; case TARGET_COLOR: { struct ColorObject *color_object = color_objects[0]; color_object_get_color(color_object, &color); guint16 data_color[4]; data_color[0] = int(color.rgb.red * 0xFFFF); data_color[1] = int(color.rgb.green * 0xFFFF); data_color[2] = int(color.rgb.blue * 0xFFFF); data_color[3] = 0xffff; gtk_selection_data_set (selection_data, gdk_atom_intern ("application/x-color", TRUE), 16, (guchar *)data_color, 8); } break; case TARGET_ROOTWIN: g_print ("Dropped on the root window!\n"); break; default: g_assert_not_reached (); } } } } static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; if (dd->get_color_object_list){ uint32_t color_object_n; struct ColorObject** color_objects = dd->get_color_object_list(dd, &color_object_n); if (color_objects){ dd->data_type = DragDrop::DATA_TYPE_COLOR_OBJECTS; dd->data.color_objects.color_objects = color_objects; dd->data.color_objects.color_object_n = color_object_n; GtkWidget* dragwindow = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget* hbox = gtk_vbox_new(true, 0); gtk_container_add(GTK_CONTAINER(dragwindow), hbox); gtk_window_resize(GTK_WINDOW(dragwindow), 164, 24 * std::min(color_object_n, (uint32_t)5)); for (int i = 0; i < std::min(color_object_n, (uint32_t)5); i++){ Color color; color_object_get_color(color_objects[i], &color); GtkWidget* colorwidget = gtk_color_new(); char* text = main_get_color_text(dd->gs, &color, COLOR_TEXT_TYPE_DISPLAY); gtk_color_set_color(GTK_COLOR(colorwidget), &color, text); g_free(text); gtk_box_pack_start(GTK_BOX(hbox), colorwidget, true, true, 0); } gtk_drag_set_icon_widget(context, dragwindow, 0, 0); gtk_widget_show_all(dragwindow); dd->dragwidget = dragwindow; return; } } if (dd->get_color_object){ struct ColorObject* color_object = dd->get_color_object(dd); if (color_object){ dd->data_type = DragDrop::DATA_TYPE_COLOR_OBJECT; dd->data.color_object.color_object = color_object; GtkWidget* dragwindow = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget* colorwidget = gtk_color_new(); gtk_container_add(GTK_CONTAINER(dragwindow), colorwidget); gtk_window_resize(GTK_WINDOW(dragwindow), 164, 24); Color color; color_object_get_color(color_object, &color); char* text = main_get_color_text(dd->gs, &color, COLOR_TEXT_TYPE_DISPLAY); gtk_color_set_color(GTK_COLOR(colorwidget), &color, text); g_free(text); gtk_drag_set_icon_widget(context, dragwindow, 0, 0); gtk_widget_show_all(dragwindow); dd->dragwidget = dragwindow; return; } } } static void drag_end(GtkWidget *widget, GdkDragContext *context, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; if (dd->data_type == DragDrop::DATA_TYPE_COLOR_OBJECT){ if (dd->data.color_object.color_object){ color_object_release(dd->data.color_object.color_object); memset(&dd->data, 0, sizeof(dd->data)); } dd->data_type = DragDrop::DATA_TYPE_NONE; } if (dd->data_type == DragDrop::DATA_TYPE_COLOR_OBJECTS){ if (dd->data.color_objects.color_objects){ for (uint32_t i = 0; i < dd->data.color_objects.color_object_n; i++){ color_object_release(dd->data.color_objects.color_objects[i]); } delete [] dd->data.color_objects.color_objects; memset(&dd->data, 0, sizeof(dd->data)); } dd->data_type = DragDrop::DATA_TYPE_NONE; } if (dd->dragwidget){ gtk_widget_destroy(dd->dragwidget); dd->dragwidget = 0; } if (dd->drag_end) dd->drag_end(dd, widget, context); } static void drag_destroy(GtkWidget *widget, gpointer user_data){ struct DragDrop *dd = (struct DragDrop*)user_data; dynv_handler_map_release(dd->handler_map); delete dd; } gpick_0.2.5/source/BlendColors.h0000644000175000017500000000327612070605214015271 0ustar zbygzbyg/* * 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 BLEND_COLORS_H_ #define BLEND_COLORS_H_ #include "ColorSourceManager.h" int blend_colors_source_register(ColorSourceManager *csm); #endif /* BLEND_COLORS_H_ */ gpick_0.2.5/source/ColorWheelType.cpp0000644000175000017500000000521412070605214016315 0ustar zbygzbyg/* * 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 "ColorWheelType.h" #include "ColorRYB.h" #include "MathUtil.h" #include "Internationalisation.h" static void rgb_hue2hue(double hue, Color* hsl){ hsl->hsl.hue = hue; hsl->hsl.saturation = 1; hsl->hsl.lightness = 0.5; } static void rgb_rgbhue2hue(double rgbhue, double *hue){ *hue = rgbhue; } static void ryb1_hue2hue(double hue, Color* hsl){ Color c; color_rybhue_to_rgb(hue, &c); color_rgb_to_hsl(&c, hsl); } static void ryb1_rgbhue2hue(double rgbhue, double *hue){ color_rgbhue_to_rybhue(rgbhue, hue); } static void ryb2_hue2hue(double hue, Color* hsl){ hsl->hsl.hue = color_rybhue_to_rgbhue_f(hue); hsl->hsl.saturation = 1; hsl->hsl.lightness = 0.5; } static void ryb2_rgbhue2hue(double rgbhue, double *hue){ color_rgbhue_to_rybhue_f(rgbhue, hue); } const ColorWheelType color_wheel_types[]={ {N_("RGB"), rgb_hue2hue, rgb_rgbhue2hue}, {N_("RYB v1"), ryb1_hue2hue, ryb1_rgbhue2hue}, {N_("RYB v2"), ryb2_hue2hue, ryb2_rgbhue2hue}, }; const ColorWheelType* color_wheel_types_get(){ return color_wheel_types; } const uint32_t color_wheel_types_get_n(){ return sizeof(color_wheel_types)/sizeof(ColorWheelType); } gpick_0.2.5/source/internationalisation/SConscript0000644000175000017500000000052612070605214021155 0ustar zbygzbyg#!/usr/bin/env python import os import sys Import('*') local_env = env.Clone() if not local_env.GetOption('clean'): if local_env['ENABLE_NLS']: local_env.Append( CPPDEFINES = ['ENABLE_NLS', 'LOCALEDIR=' + local_env['LOCALEDIR']], ) sources = local_env.Glob('*.cpp') objects = local_env.StaticObject([sources]) Return('objects') gpick_0.2.5/source/internationalisation/Internationalisation.cpp0000644000175000017500000000365012070605214024046 0ustar zbygzbyg/* * 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. */ #ifdef ENABLE_NLS #include #endif #include #include #include #define TO_STRING(x) #x #define T_(x) TO_STRING(x) void initialize_internationalisation() { #ifdef ENABLE_NLS bindtextdomain("gpick", T_(LOCALEDIR)); char *td = textdomain("gpick"); if (!(td && (strcmp(td, "gpick") == 0))){ fprintf(stderr, "failed to load textdomain \"gpick\"\n"); } #endif } gpick_0.2.5/source/RegisterSources.cpp0000644000175000017500000000405212070605214016537 0ustar zbygzbyg/* * 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 "RegisterSources.h" #include "GenerateScheme.h" #include "ColorPicker.h" #include "LayoutPreview.h" #include "Variations.h" #include "BrightnessDarkness.h" #include "ColorMixer.h" #include "BlendColors.h" int register_sources(ColorSourceManager *csm){ generate_scheme_source_register(csm); color_picker_source_register(csm); layout_preview_source_register(csm); variations_source_register(csm); brightness_darkness_source_register(csm); color_mixer_source_register(csm); blend_colors_source_register(csm); return 0; } gpick_0.2.5/source/Converter.h0000644000175000017500000000612312070605214015024 0ustar zbygzbyg/* * 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 CONVERTER_H_ #define CONVERTER_H_ #include "dynv/DynvSystem.h" #ifndef _MSC_VER #include #endif #include class Converters; enum ConvertersArrayType{ CONVERTERS_ARRAY_TYPE_COPY, CONVERTERS_ARRAY_TYPE_PASTE, CONVERTERS_ARRAY_TYPE_DISPLAY, CONVERTERS_ARRAY_TYPE_COLOR_LIST, }; typedef struct Converter{ char* function_name; char* human_readable; bool copy, serialize_available; bool paste, deserialize_available; }Converter; Converters* converters_init(struct dynvSystem* params); int converters_term(Converters *converters); Converter* converters_get(Converters *converters, const char* name); //Converter** converters_get_all(Converters *converters, const char** priority_names, uint32_t priority_names_size); int converters_set(Converters *converters, Converter* converter, ConvertersArrayType type); Converter* converters_get_first(Converters *converters, ConvertersArrayType type); Converter** converters_get_all_type(Converters *converters, ConvertersArrayType type, uint32_t *size); Converter** converters_get_all(Converters *converters, uint32_t *size); int converters_color_serialize(Converters* converters, const char* function, struct ColorObject* color_object, char** result); int converters_color_deserialize(Converters* converters, const char* function, char* text, struct ColorObject* color_object, float* conversion_quality); int converters_rebuild_arrays(Converters *converters, ConvertersArrayType type); int converters_reorder(Converters *converters, const char** priority_names, uint32_t priority_names_size); #endif /* CONVERTER_H_ */ gpick_0.2.5/source/uiDialogOptions.cpp0000644000175000017500000004552512070605214016532 0ustar zbygzbyg/* * 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 "uiDialogOptions.h" #include "uiUtilities.h" #include "ToolColorNaming.h" #include "GlobalStateStruct.h" #include "Internationalisation.h" #include "DynvHelpers.h" #include using namespace std; static const struct{ const char *label; const char *setting; }available_color_spaces[] = { {"CMYK", "picker.color_space.cmyk"}, {"HSL", "picker.color_space.hsl"}, {"HSV", "picker.color_space.hsv"}, {"LAB", "picker.color_space.lab"}, {"LCH", "picker.color_space.lch"}, {"RGB", "picker.color_space.rgb"}, {0, 0}, }; typedef struct DialogOptionsArgs{ GtkWidget *minimize_to_tray; GtkWidget *close_to_tray; GtkWidget *start_in_tray; GtkWidget *refresh_rate; GtkWidget *single_instance; GtkWidget *save_restore_palette; GtkWidget *add_on_release; GtkWidget *add_to_palette; GtkWidget *copy_to_clipboard; GtkWidget *rotate_swatch; GtkWidget *copy_on_release; GtkWidget *zoom_size; GtkWidget *imprecision_postfix; GtkWidget *tool_color_naming[3]; GtkWidget *color_spaces[6]; GtkWidget *out_of_gamut_mask; GtkWidget *lab_illuminant; GtkWidget *lab_observer; struct dynvSystem *params; GlobalState* gs; }DialogOptionsArgs; static void calc( DialogOptionsArgs *args, bool preview, int limit){ if (preview) return; dynv_set_bool(args->params, "main.minimize_to_tray", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->minimize_to_tray))); dynv_set_bool(args->params, "main.close_to_tray", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->close_to_tray))); dynv_set_bool(args->params, "main.start_in_tray", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->start_in_tray))); dynv_set_bool(args->params, "main.single_instance", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->single_instance))); dynv_set_bool(args->params, "main.save_restore_palette", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->save_restore_palette))); dynv_set_float(args->params, "picker.refresh_rate", gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->refresh_rate))); dynv_set_int32(args->params, "picker.zoom_size", gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->zoom_size))); dynv_set_bool(args->params, "picker.sampler.add_on_release", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->add_on_release))); dynv_set_bool(args->params, "picker.sampler.copy_on_release", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->copy_on_release))); dynv_set_bool(args->params, "picker.sampler.add_to_palette", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->add_to_palette))); dynv_set_bool(args->params, "picker.sampler.copy_to_clipboard", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->copy_to_clipboard))); dynv_set_bool(args->params, "picker.sampler.rotate_swatch_after_sample", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->rotate_swatch))); dynv_set_bool(args->params, "picker.out_of_gamut_mask", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->out_of_gamut_mask))); dynv_set_bool(args->params, "color_names.imprecision_postfix", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->imprecision_postfix))); const ToolColorNamingOption *color_naming_options = tool_color_naming_get_options(); int i = 0; while (color_naming_options[i].name){ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->tool_color_naming[i]))){ dynv_set_string(args->params, "color_names.tool_color_naming", color_naming_options[i].name); break; } i++; } for (int i = 0; available_color_spaces[i].label; i++){ dynv_set_bool(args->params, available_color_spaces[i].setting, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->color_spaces[i]))); } dynv_set_string(args->params, "picker.lab.illuminant", gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(args->lab_illuminant))); dynv_set_string(args->params, "picker.lab.observer", gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(args->lab_observer))); } void dialog_options_show(GtkWindow* parent, GlobalState* gs) { DialogOptionsArgs *args = new DialogOptionsArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick"); GtkWidget *table, *table_m, *widget; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Options"), 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, "options.window.width", -1), dynv_get_int32_wd(args->params, "options.window.height", -1)); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); GtkWidget *frame; GtkWidget* notebook = gtk_notebook_new(); gint table_y, table_m_y; table_m = gtk_table_new(3, 1, FALSE); table_m_y = 0; frame = gtk_frame_new(_("System")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->single_instance = widget = gtk_check_button_new_with_mnemonic (_("_Single instance")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "main.single_instance", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->save_restore_palette = widget = gtk_check_button_new_with_mnemonic (_("Save/_Restore palette")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "main.save_restore_palette", true)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; frame = gtk_frame_new(_("System tray")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->minimize_to_tray = widget = gtk_check_button_new_with_mnemonic (_("_Minimize to system tray")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "main.minimize_to_tray", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->close_to_tray = widget = gtk_check_button_new_with_mnemonic (_("_Close to system tray")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "main.close_to_tray", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->start_in_tray = widget = gtk_check_button_new_with_mnemonic (_("_Start in system tray")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "main.start_in_tray", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table_m, gtk_label_new_with_mnemonic(_("_Main"))); table_m = gtk_table_new(3, 2, FALSE); table_m_y = 0; frame = gtk_frame_new(_("Display")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); gtk_table_attach(GTK_TABLE(table), gtk_label_mnemonic_aligned_new(_("_Refresh rate:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); args->refresh_rate = widget = gtk_spin_button_new_with_range(1, 60, 1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->refresh_rate), dynv_get_float_wd(args->params, "picker.refresh_rate", 30)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,5); gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new("Hz",0,0.5,0,0),2,3,table_y,table_y+1,GTK_FILL,GTK_FILL,5,5); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_mnemonic_aligned_new(_("_Magnified area size:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); args->zoom_size = widget = gtk_spin_button_new_with_range(75, 300, 15); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->zoom_size), dynv_get_int32_wd(args->params, "picker.zoom_size", 150)); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,5); table_y++; frame = gtk_frame_new(_("Floating picker click behaviour")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->add_on_release = widget = gtk_check_button_new_with_mnemonic(_("_Add to palette")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.sampler.add_on_release", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->copy_on_release = widget = gtk_check_button_new_with_mnemonic(_("_Copy to clipboard")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.sampler.copy_on_release", false)); gtk_table_attach(GTK_TABLE(table), widget,0,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; frame = gtk_frame_new(_("'Spacebar' button behaviour")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->add_to_palette = widget = gtk_check_button_new_with_mnemonic(_("_Add to palette")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.sampler.add_to_palette", false)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->copy_to_clipboard = widget = gtk_check_button_new_with_mnemonic(_("_Copy to clipboard")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.sampler.copy_to_clipboard", false)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; args->rotate_swatch = widget = gtk_check_button_new_with_mnemonic(_("_Rotate swatch")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.sampler.rotate_swatch_after_sample", false)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; table_m_y = 0; frame = gtk_frame_new(_("Enabled color spaces")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 1, 2, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); for (int i = 0; available_color_spaces[i].label; i++){ args->color_spaces[i] = widget = gtk_check_button_new_with_label(available_color_spaces[i].label); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, available_color_spaces[i].setting, true)); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 3, 3); table_y++; } frame = gtk_frame_new(_("Lab settings")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 1, 2, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); { int selected; const char *option; gtk_table_attach(GTK_TABLE(table), gtk_label_mnemonic_aligned_new(_("_Illuminant:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); args->lab_illuminant = widget = gtk_combo_box_text_new(); const char *illuminants[] = { "A", "C", "D50", "D55", "D65", "D75", "F2", "F7", "F11", 0, }; selected = 0; option = dynv_get_string_wd(args->params, "picker.lab.illuminant", "D50"); for (int i = 0; illuminants[i]; i++){ if (string(illuminants[i]).compare(option) == 0) selected = i; gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), illuminants[i]); } gtk_combo_box_set_active(GTK_COMBO_BOX(widget), selected); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,5); table_y++; gtk_table_attach(GTK_TABLE(table), gtk_label_mnemonic_aligned_new(_("_Observer:"),0,0.5,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); args->lab_observer = widget = gtk_combo_box_text_new(); const char *observers[] = { "2", "10", 0, }; selected = 0; option = dynv_get_string_wd(args->params, "picker.lab.observer", "2"); for (int i = 0; observers[i]; i++){ if (string(observers[i]).compare(option) == 0) selected = i; gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), observers[i]); } gtk_combo_box_set_active(GTK_COMBO_BOX(widget), selected); gtk_table_attach(GTK_TABLE(table), widget,1,3,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,5); table_y++; } frame = gtk_frame_new(_("Other settings")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 1, 2, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->out_of_gamut_mask = widget = gtk_check_button_new_with_mnemonic(_("_Mask out of gamut colors")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "picker.out_of_gamut_mask", true)); gtk_table_attach(GTK_TABLE(table), widget, 1, 2, table_y, table_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 3, 3); table_y++; gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table_m, gtk_label_new_with_mnemonic(_("_Picker"))); table_m = gtk_table_new(3, 1, FALSE); table_m_y = 0; frame = gtk_frame_new(_("Color name generation")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); args->imprecision_postfix = widget = gtk_check_button_new_with_mnemonic(_("_Imprecision postfix")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dynv_get_bool_wd(args->params, "color_names.imprecision_postfix", true)); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; frame = gtk_frame_new(_("Tool color naming")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); gtk_table_attach(GTK_TABLE(table_m), frame, 0, 1, table_m_y, table_m_y+1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL), 5, 5); table_m_y++; table = gtk_table_new(5, 3, FALSE); table_y=0; gtk_container_add(GTK_CONTAINER(frame), table); GSList *group = NULL; ToolColorNamingType color_naming_type = tool_color_naming_name_to_type(dynv_get_string_wd(args->params, "color_names.tool_color_naming", "tool_specific")); const ToolColorNamingOption *color_naming_options = tool_color_naming_get_options(); int i = 0; while (color_naming_options[i].name){ args->tool_color_naming[i] = widget = gtk_radio_button_new_with_mnemonic(group, _(color_naming_options[i].label)); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(widget)); if (color_naming_type == color_naming_options[i].type) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), true); gtk_table_attach(GTK_TABLE(table), widget,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,3,3); table_y++; i++; } gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table_m, gtk_label_new_with_mnemonic(_("_Color names"))); gtk_widget_show_all(notebook); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), notebook); 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, "options.window.width", width); dynv_set_int32(args->params, "options.window.height", height); dynv_system_release(args->params); gtk_widget_destroy(dialog); delete args; } gpick_0.2.5/source/uiColorInput.cpp0000644000175000017500000001574712070605214016060 0ustar zbygzbyg/* * 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 "uiColorInput.h" #include "Converter.h" #include "DynvHelpers.h" #include "uiApp.h" #include "uiUtilities.h" #include "GlobalStateStruct.h" #include "gtk/ColorWheel.h" #include "Internationalisation.h" #include "gtk/ColorComponent.h" #include "gtk/ColorWidget.h" #include "ColorSpaceType.h" #include int dialog_color_input_show(GtkWindow* parent, GlobalState* gs, struct ColorObject* color_object, struct ColorObject** new_color_object){ gchar* text = 0; Converter *converter; Converters *converters = (Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0); converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_DISPLAY); if (converter){ converter_get_text(converter->function_name, color_object, 0, gs->params, &text); } GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Edit color"), parent, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); GtkWidget* vbox = gtk_vbox_new(false, 5); GtkWidget* hbox = gtk_hbox_new(false, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, true, true, 0); GtkWidget *widget; 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); Color c; color_object_get_color(color_object, &c); gtk_color_set_color(GTK_COLOR(widget), &c, ""); gtk_box_pack_start(GTK_BOX(hbox), widget, false, true, 0); gtk_box_pack_start(GTK_BOX(hbox), gtk_label_aligned_new(_("Color:"),0,0.5,0,0), false, false, 0); GtkWidget* entry = gtk_entry_new(); gtk_entry_set_activates_default(GTK_ENTRY(entry), true); gtk_box_pack_start(GTK_BOX(hbox), entry, true, true, 0); if (text){ gtk_entry_set_text(GTK_ENTRY(entry), text); g_free(text); } gtk_widget_show_all(vbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { struct ColorObject* color_object; if (main_get_color_object_from_text(gs, (char*)gtk_entry_get_text(GTK_ENTRY(entry)), &color_object)==0){ *new_color_object = color_object; gtk_widget_destroy(dialog); return 0; } } gtk_widget_destroy(dialog); return -1; } typedef struct ColorPickerComponentEditArgs{ //ColorPickerArgs *color_picker; GtkWidget* value[4]; GtkColorComponentComp component; int component_id; struct dynvSystem *params; }ColorPickerComponentEditArgs; void dialog_color_component_input_show(GtkWindow* parent, GtkColorComponent *color_component, int component_id, struct dynvSystem *params) { GtkColorComponentComp component = gtk_color_component_get_component(GTK_COLOR_COMPONENT(color_component)); ColorPickerComponentEditArgs *args = new ColorPickerComponentEditArgs; //args->color_picker = color_picker_args; args->params = params; args->component = component; args->component_id = component_id; memset(args->value, 0, sizeof(args->value)); GtkWidget *table; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Edit"), 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); table = gtk_table_new(2, 2, FALSE); Color raw_color; gtk_color_component_get_raw_color(color_component, &raw_color); const ColorSpaceType *color_space_type = 0; for (uint32_t i = 0; i < color_space_count_types(); i++){ if (color_space_get_types()[i].comp_type == component){ color_space_type = &color_space_get_types()[i]; break; } } if (color_space_type){ for (int i = 0; i < color_space_type->n_items; i++){ gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(color_space_type->items[i].name,0,0,0,0),0,1,i,i+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); args->value[i] = gtk_spin_button_new_with_range(color_space_type->items[i].min_value, color_space_type->items[i].max_value, color_space_type->items[i].step); gtk_entry_set_activates_default(GTK_ENTRY(args->value[i]), true); gtk_spin_button_set_value(GTK_SPIN_BUTTON(args->value[i]), raw_color.ma[i] * color_space_type->items[i].raw_scale); gtk_table_attach(GTK_TABLE(table), args->value[i],1,2,i,i+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); if (i == component_id) gtk_widget_grab_focus(args->value[i]); } } gtk_widget_show_all(table); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK){ if (color_space_type){ for (int i = 0; i < color_space_type->n_items; i++){ raw_color.ma[i] = gtk_spin_button_get_value(GTK_SPIN_BUTTON(args->value[i])) / color_space_type->items[i].raw_scale; } gtk_color_component_set_raw_color(color_component, &raw_color); } } 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); gtk_widget_destroy(dialog); dynv_system_release(args->params); delete args; } gpick_0.2.5/source/ColorSourceManager.h0000644000175000017500000000420712070605214016610 0ustar zbygzbyg/* * 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 COLORSOURCEMANAGER_H_ #define COLORSOURCEMANAGER_H_ #include "ColorSource.h" #include #include #include typedef struct ColorSourceManager{ std::map colorsource; }ColorSourceManager; ColorSourceManager* color_source_manager_create(); int color_source_manager_add_source(ColorSourceManager *csm, ColorSource *source); ColorSource* color_source_manager_get(ColorSourceManager *csm, const char *name); std::vector color_source_manager_get_all(ColorSourceManager *csm); int color_source_manager_destroy(ColorSourceManager *csm); #endif /* COLORSOURCE_H_ */ gpick_0.2.5/source/uiDialogGenerate.h0000644000175000017500000000342712070605214016271 0ustar zbygzbyg/* * 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 UIDIALOGGENERATE_H_ #define UIDIALOGGENERATE_H_ #include #include "ColorList.h" #include "GlobalState.h" void dialog_generate_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState* gs); #endif /* UIDIALOGGENERATE_H_ */ gpick_0.2.5/source/Converter.cpp0000644000175000017500000002632212070605214015362 0ustar zbygzbyg/* * 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 "Converter.h" #include "DynvHelpers.h" #include "LuaExt.h" #include #include #include #include #include #include #include #include #include #include using namespace std; class ConverterKeyCompare{ public: bool operator() (const char* const& x, const char* const& y) const; }; bool ConverterKeyCompare::operator() (const char* const& x, const char* const& y) const { return strcmp(x,y)<0; } class Converters{ public: typedef std::map ConverterMap; ConverterMap converters; list all_converters; vector copy_converters; vector paste_converters; Converter* display_converter; Converter* color_list_converter; lua_State *L; ~Converters(); }; Converters::~Converters(){ Converters::ConverterMap::iterator i; for (i=converters.begin(); i!=converters.end(); ++i){ g_free(((*i).second)->human_readable); g_free(((*i).second)->function_name); delete ((*i).second); } converters.clear(); } /*static int get_human_readable_name(lua_State *L, const char* function, char** human_readable){ if (L==NULL) return -1; size_t st; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "converters"); lua_gettable(L, gpick_namespace); int converters_table = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, function); lua_gettable(L, converters_table); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "human_readable"); lua_gettable(L, -2); *human_readable = strdup(lua_tostring(L, -1)); lua_settop(L, stack_top); return 0; } } } lua_settop(L, stack_top); return -1; }*/ int converters_color_deserialize(Converters* converters, const char* function, char* text, struct ColorObject* color_object, float* conversion_quality){ lua_State* L = converters->L; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "color_deserialize"); lua_gettable(L, gpick_namespace); if (lua_type(L, -1) != LUA_TNIL){ lua_pushstring(L, function); lua_pushstring(L, text); lua_pushcolorobject (L, color_object); status=lua_pcall(L, 3, 1, 0); if (status==0){ if (lua_type(L, -1)==LUA_TNUMBER){ double result = luaL_checknumber(L, -1); *conversion_quality = result; lua_settop(L, stack_top); return 0; }else{ cerr<<"gpick.color_deserialize: returned not a number value \""<L; size_t st; int status; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "color_serialize"); lua_gettable(L, gpick_namespace); if (lua_type(L, -1) != LUA_TNIL){ lua_pushstring(L, function); //lua_gettable(L, -2); lua_pushcolorobject (L, color_object); status=lua_pcall(L, 2, 1, 0); if (status==0){ if (lua_type(L, -1)==LUA_TSTRING){ const char* converted = luaL_checklstring(L, -1, &st); *result = g_strdup(converted); lua_settop(L, stack_top); return 0; }else{ cerr<<"gpick.color_serialize: returned not a string value \""<(dynv_get_pointer_wdc(params, "lua_State", 0)); if (L==NULL) return 0; Converters *converters = new Converters; converters->L = L; converters->display_converter = 0; int stack_top = lua_gettop(L); lua_getglobal(L, "gpick"); int gpick_namespace = lua_gettop(L); if (lua_type(L, -1)!=LUA_TNIL){ lua_pushstring(L, "converters"); lua_gettable(L, gpick_namespace); int converters_table = lua_gettop(L); lua_pushnil(L); while (lua_next(L, converters_table) != 0){ if (lua_type(L, -2) == LUA_TSTRING){ Converter *converter = new Converter; converter->function_name = g_strdup(lua_tostring(L, -2)); converters->converters[converter->function_name] = converter; converters->all_converters.push_back(converter); lua_pushstring(L, "human_readable"); lua_gettable(L, -2); converter->human_readable = g_strdup(lua_tostring(L, -1)); lua_pop(L, 1); lua_pushstring(L, "serialize"); lua_gettable(L, -2); converter->serialize_available = !lua_isnil(L, -1); converter->copy = false; lua_pop(L, 1); lua_pushstring(L, "deserialize"); lua_gettable(L, -2); converter->deserialize_available = !lua_isnil(L, -1); converter->paste = false; lua_pop(L, 1); } lua_pop(L, 1); //pop value from stack, but leave key } } lua_settop(L, stack_top); dynv_set_pointer(params, "Converters", converters); return converters; } int converters_term(Converters *converters){ delete converters; return 0; } Converter* converters_get(Converters *converters, const char* name){ Converters::ConverterMap::iterator i; i=converters->converters.find( name); if (i!=converters->converters.end()){ return (*i).second; }else{ return 0; } } Converter* converters_get_first(Converters *converters, ConvertersArrayType type){ switch (type){ case CONVERTERS_ARRAY_TYPE_COPY: if (converters->copy_converters.size()>0) return converters->copy_converters[0]; break; case CONVERTERS_ARRAY_TYPE_PASTE: if (converters->paste_converters.size()>0) return converters->paste_converters[0]; break; case CONVERTERS_ARRAY_TYPE_DISPLAY: return converters->display_converter; break; case CONVERTERS_ARRAY_TYPE_COLOR_LIST: return converters->color_list_converter; break; } return 0; } Converter** converters_get_all_type(Converters *converters, ConvertersArrayType type, uint32_t *size){ switch (type){ case CONVERTERS_ARRAY_TYPE_COPY: if (converters->copy_converters.size()>0){ *size = converters->copy_converters.size(); return &converters->copy_converters[0]; } break; case CONVERTERS_ARRAY_TYPE_PASTE: if (converters->paste_converters.size()>0){ *size = converters->paste_converters.size(); return &converters->paste_converters[0]; } break; case CONVERTERS_ARRAY_TYPE_DISPLAY: *size = 1; return &converters->display_converter; break; case CONVERTERS_ARRAY_TYPE_COLOR_LIST: *size = 1; return &converters->color_list_converter; break; } return 0; } Converter** converters_get_all(Converters *converters, uint32_t *size){ uint32_t total_converters = converters->all_converters.size(); Converter** converter_table = new Converter* [total_converters+1]; uint32_t table_i = 0; for (list::iterator i=converters->all_converters.begin(); i!=converters->all_converters.end(); ++i){ converter_table[table_i] = *i; ++table_i; } if (size) *size = total_converters; return converter_table; } int converters_reorder(Converters *converters, const char** priority_names, uint32_t priority_names_size){ //uint32_t total_converters = converters->converters.size(); //Converter** converter_table = new Converter* [total_converters+1]; //uint32_t table_i = 0; Converter* c; //converter_table[total_converters] = 0; Converters::ConverterMap used_converters; Converters::ConverterMap::iterator used_i; converters->all_converters.clear(); if (priority_names && priority_names_size>0){ for (uint32_t i=0; iall_converters.push_back(c); used_converters[c->function_name] = c; } } } } Converters::ConverterMap::iterator i; for (i=converters->converters.begin(); i!=converters->converters.end(); ++i){ used_i = used_converters.find( ((*i).second)->function_name ); if (used_i==used_converters.end()){ //converter_table[table_i++] = ((*i).second); converters->all_converters.push_back(((*i).second)); used_converters[((*i).second)->function_name] = ((*i).second); } } return 0; } int converters_rebuild_arrays(Converters *converters, ConvertersArrayType type){ list::iterator i; switch (type){ case CONVERTERS_ARRAY_TYPE_COPY: converters->copy_converters.clear(); for (i=converters->all_converters.begin(); i!=converters->all_converters.end(); ++i){ if ((*i)->copy && (*i)->serialize_available){ converters->copy_converters.push_back(*i); } } return 0; break; case CONVERTERS_ARRAY_TYPE_PASTE: converters->paste_converters.clear(); for (i=converters->all_converters.begin(); i!=converters->all_converters.end(); ++i){ if ((*i)->paste && (*i)->deserialize_available){ converters->paste_converters.push_back(*i); } } return 0; break; default: return -1; } return -1; } int converters_set(Converters *converters, Converter* converter, ConvertersArrayType type){ switch (type){ case CONVERTERS_ARRAY_TYPE_DISPLAY: converters->display_converter = converter; break; case CONVERTERS_ARRAY_TYPE_COLOR_LIST: converters->color_list_converter = converter; break; default: return -1; } return 0; } gpick_0.2.5/source/ColorPicker.h0000644000175000017500000000365612070605214015301 0ustar zbygzbyg/* * 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 COLORPICKER_H_ #define COLORPICKER_H_ #include "FloatingPicker.h" #include "ColorSource.h" #include "ColorSourceManager.h" #include int color_picker_source_register(ColorSourceManager *csm); int color_picker_key_up(ColorSource* color_source, GdkEventKey *event); void color_picker_set_floating_picker(ColorSource *color_source, FloatingPicker floating_picker); #endif /* COLORPICKER_H_ */ gpick_0.2.5/source/ColorRYB.h0000644000175000017500000000400212070605214014502 0ustar zbygzbyg/* * 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 COLORRYB_H_ #define COLORRYB_H_ #include "Color.h" #ifndef _MSC_VER #include #endif #include double color_ryb_transform_lightness(double hue1, double hue2); double color_ryb_transform_hue(double hue, bool forward); void color_rybhue_to_rgb(double hue, Color* color); int color_rgbhue_to_rybhue(double rgb_hue, double* ryb_hue); double color_rybhue_to_rgbhue_f(double hue); int color_rgbhue_to_rybhue_f(double rgb_hue, double* ryb_hue); #endif /* COLORRYB_H_ */ gpick_0.2.5/source/uiApp.cpp0000644000175000017500000021464712070605214014502 0ustar zbygzbyg/* * 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 "uiApp.h" #include "GlobalState.h" #include "GlobalStateStruct.h" #include "Paths.h" #include "Converter.h" #include "CopyPaste.h" #include "RegisterSources.h" #include "GenerateScheme.h" #include "ColorPicker.h" #include "LayoutPreview.h" #include "uiAbout.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "uiExport.h" #include "uiDialogMix.h" #include "uiDialogVariations.h" #include "uiDialogGenerate.h" #include "uiDialogAutonumber.h" #include "uiDialogSort.h" #include "uiTransformations.h" #include "tools/PaletteFromImage.h" #include "tools/PaletteFromCssFile.h" #include "dbus/Control.h" #include "uiDialogOptions.h" #include "uiConverter.h" #include "uiStatusIcon.h" #include "DynvHelpers.h" #include "FileFormat.h" #include "MathUtil.h" #include "Internationalisation.h" #include #include #include #include #include #include #include #include #include #include using namespace std; typedef struct AppArgs{ GtkWidget *window; map color_source; vector color_source_index; list recent_files; ColorSourceManager *csm; ColorSource *current_color_source; ColorSource *secondary_color_source; GtkWidget *secondary_source_widget; GtkWidget *secondary_source_scrolled_viewpoint; GtkWidget *secondary_source_container; GtkWidget *color_list; GtkWidget* notebook; GtkWidget* statusbar; GtkWidget* hpaned; GtkWidget* vpaned; uiStatusIcon* statusIcon; FloatingPicker floating_picker; AppOptions options; guint bus_id; struct dynvSystem *params; GlobalState* gs; char* current_filename; bool imported; GtkWidget *precision_loss_icon; gint x, y; gint width, height; }AppArgs; static void updateRecentFileList(AppArgs *args, const char *filename, bool move_up){ list::iterator i = std::find(args->recent_files.begin(), args->recent_files.end(), string(filename)); if (i == args->recent_files.end()){ args->recent_files.push_front(string(filename)); while (args->recent_files.size() > 10){ args->recent_files.pop_back(); } }else{ if (move_up){ args->recent_files.erase(i); args->recent_files.push_front(string(filename)); } } } static gboolean delete_event( GtkWidget *widget, GdkEvent *event, AppArgs *args ){ if (dynv_get_bool_wd(args->params, "close_to_tray", false)){ gtk_widget_hide(args->window); status_icon_set_visible(args->statusIcon, true); return true; } return false; } static gboolean on_window_state_event(GtkWidget *widget, GdkEventWindowState *event, AppArgs *args){ if (dynv_get_bool_wd(args->params, "minimize_to_tray", false)){ if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED){ if (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED){ gtk_widget_hide(args->window); gtk_window_deiconify(GTK_WINDOW(args->window)); status_icon_set_visible(args->statusIcon, true); return true; } } } return false; } static gboolean on_window_configure(GtkWidget *widget, GdkEventConfigure *event, AppArgs *args){ if (GTK_WIDGET_VISIBLE(widget)){ if (gdk_window_get_state(widget->window) & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_ICONIFIED)) { return false; } gint x, y; gtk_window_get_position(GTK_WINDOW(widget), &x, &y); args->x = x; args->y = y; args->width = event->width; args->height = event->height; dynv_set_int32(args->params, "window.x", args->x); dynv_set_int32(args->params, "window.y", args->y); dynv_set_int32(args->params, "window.width", args->width); dynv_set_int32(args->params, "window.height", args->height); } return false; } static void notebook_switch_cb(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, AppArgs *args){ if (args->current_color_source) color_source_deactivate(args->current_color_source); args->current_color_source = NULL; if (page_num >= 0 && page_num <= args->color_source_index.size() && args->color_source_index[page_num]){ color_source_activate(args->color_source_index[page_num]); args->current_color_source = args->color_source_index[page_num]; dynv_set_pointer(args->gs->params, "CurrentColorSource", args->current_color_source); }else{ dynv_set_pointer(args->gs->params, "CurrentColorSource", NULL); } } static void destroy_cb(GtkWidget *widget, AppArgs *args){ g_signal_handlers_disconnect_matched(G_OBJECT(args->notebook), G_SIGNAL_MATCH_FUNC, 0, NULL, NULL, (void*)notebook_switch_cb, 0); //disconnect notebook switch callback, because destroying child widgets triggers it //dynv_set_int32(args->params, "notebook_page", gtk_notebook_get_current_page(GTK_NOTEBOOK(args->notebook))); dynv_set_string(args->params, "color_source", args->color_source_index[gtk_notebook_get_current_page(GTK_NOTEBOOK(args->notebook))]->identificator); dynv_set_int32(args->params, "paned_position", gtk_paned_get_position(GTK_PANED(args->hpaned))); dynv_set_int32(args->params, "vertical_paned_position", gtk_paned_get_position(GTK_PANED(args->vpaned))); if (args->current_color_source){ color_source_deactivate(args->current_color_source); args->current_color_source = 0; } if (args->secondary_color_source){ dynv_set_string(args->params, "secondary_color_source", args->secondary_color_source->identificator); color_source_deactivate(args->secondary_color_source); color_source_destroy(args->secondary_color_source); args->secondary_color_source = 0; args->secondary_source_widget = 0; }else{ dynv_set_string(args->params, "secondary_color_source", ""); } for (map::iterator i = args->color_source.begin(); i != args->color_source.end(); ++i){ color_source_destroy((*i).second); } args->color_source.clear(); args->color_source_index.clear(); dynv_set_int32(args->params, "window.x", args->x); dynv_set_int32(args->params, "window.y", args->y); dynv_set_int32(args->params, "window.width", args->width); dynv_set_int32(args->params, "window.height", args->height); floating_picker_free(args->floating_picker); if (app_is_autoload_enabled(args)){ gchar* autosave_file = build_config_path("autosave.gpa"); palette_file_save(autosave_file, args->gs->colors); g_free(autosave_file); } color_list_remove_all(args->gs->colors); gtk_main_quit(); } int main_get_color_object_from_text(GlobalState* gs, char* text, struct ColorObject** output_color_object){ struct ColorObject* color_object; Color dummy_color; Converters *converters = (Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0); typedef multimap > ValidConverters; ValidConverters valid_converters; Converter *converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_DISPLAY); if (converter){ if (converter->deserialize_available){ color_object = color_list_new_color_object(gs->colors, &dummy_color); float quality; if (converters_color_deserialize(converters, converter->function_name, text, color_object, &quality)==0){ if (quality>0){ valid_converters.insert(make_pair(quality, color_object)); }else{ color_object_release(color_object); } }else{ color_object_release(color_object); } } } uint32_t table_size; Converter **converter_table; if ((converter_table = converters_get_all_type(converters, CONVERTERS_ARRAY_TYPE_PASTE, &table_size))){ for (uint32_t i=0; i!=table_size; ++i){ converter = converter_table[i]; if (converter->deserialize_available){ color_object = color_list_new_color_object(gs->colors, &dummy_color); float quality; if (converters_color_deserialize(converters, converter->function_name, text, color_object, &quality)==0){ if (quality>0){ valid_converters.insert(make_pair(quality, color_object)); }else{ color_object_release(color_object); } }else{ color_object_release(color_object); } } } } bool first = true; for (ValidConverters::iterator i=valid_converters.begin(); i!=valid_converters.end(); ++i){ if (first){ first = false; *output_color_object = (*i).second; }else{ color_object_release((*i).second); } } if (first){ return -1; }else{ return 0; } } int main_get_color_from_text(GlobalState* gs, char* text, Color* color){ struct ColorObject* color_object = 0; if (main_get_color_object_from_text(gs, text, &color_object)==0){ color_object_get_color(color_object, color); color_object_release(color_object); return 0; } return -1; } char* main_get_color_text(GlobalState* gs, Color* color, ColorTextType text_type){ char* text = 0; struct ColorObject* color_object; color_object = color_list_new_color_object(gs->colors, color); Converter *converter; Converters *converters = (Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0); switch (text_type){ case COLOR_TEXT_TYPE_DISPLAY: converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_DISPLAY); if (converter){ converter_get_text(converter->function_name, color_object, 0, gs->params, &text); } break; case COLOR_TEXT_TYPE_COPY: converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COPY); if (converter){ converter_get_text(converter->function_name, color_object, 0, gs->params, &text); } break; case COLOR_TEXT_TYPE_COLOR_LIST: converter = converters_get_first(converters, CONVERTERS_ARRAY_TYPE_COLOR_LIST); if (converter){ converter_get_text(converter->function_name, color_object, 0, gs->params, &text); } break; } color_object_release(color_object); return text; } static void updateProgramName(AppArgs *args){ stringstream prg_name; if (args->current_filename == 0){ prg_name << _("New palette"); if (args->precision_loss_icon) gtk_widget_hide(args->precision_loss_icon); }else{ gchar* filename = g_path_get_basename(args->current_filename); if (args->imported){ prg_name << filename << " " << _("(Imported)"); if (args->precision_loss_icon) gtk_widget_show(args->precision_loss_icon); }else{ prg_name << filename; if (args->precision_loss_icon) gtk_widget_hide(args->precision_loss_icon); } g_free(filename); } prg_name << " - " << program_name; gtk_window_set_title(GTK_WINDOW(args->window), prg_name.str().c_str()); } static void show_dialog_converter(GtkWidget *widget, AppArgs *args){ dialog_converter_show(GTK_WINDOW(args->window), args->gs); return; } static void show_dialog_transformations(GtkWidget *widget, AppArgs *args){ dialog_transformations_show(GTK_WINDOW(args->window), args->gs); return; } static void show_dialog_options(GtkWidget *widget, AppArgs *args){ dialog_options_show(GTK_WINDOW(args->window), args->gs); return; } static void menu_file_new(GtkWidget *widget, AppArgs *args){ if (args->current_filename) g_free(args->current_filename); args->current_filename=0; color_list_remove_all(args->gs->colors); updateProgramName(args); } enum FileType{ GPA, GPL, ASE, UNKNOWN, }; static FileType get_file_type_from_ext(const char *filename){ const struct{ FileType type; const char *extension; }extensions[] = { {GPA, ".gpa"}, {GPL, ".gpl"}, {ASE, ".ase"}, {UNKNOWN, 0}, }; const char *ext = g_strrstr(filename, "."); if (ext){ for (int i = 0; extensions[i].type != UNKNOWN; ++i){ if (g_ascii_strcasecmp(ext, extensions[i].extension) == 0){ return extensions[i].type; } } } return UNKNOWN; } int app_save_file(AppArgs *args, const char *filename){ int return_value = -1; if (filename == NULL){ if (args->current_filename){ filename = args->current_filename; }else{ return -1; } } FileType filetype; switch (filetype = get_file_type_from_ext(filename)){ case GPL: return_value = palette_export_gpl(args->gs->colors, filename, false); break; case ASE: return_value = palette_export_ase(args->gs->colors, filename, false); break; case UNKNOWN: case GPA: return_value = palette_file_save(filename, args->gs->colors); break; } if (return_value == 0){ if (filetype == GPA || filetype == UNKNOWN){ args->imported = false; }else{ args->imported = true; } if (filename != args->current_filename){ // do not touch current_filename if it is assigned to filename if (args->current_filename) g_free(args->current_filename); args->current_filename = g_strdup(filename); } updateProgramName(args); updateRecentFileList(args, filename, true); return 0; }else{ updateProgramName(args); return -1; } return 0; } int app_load_file(AppArgs *args, const char *filename, bool autoload){ int return_value = -1; int index; bool imported = false; switch (get_file_type_from_ext(filename)){ case GPL: return_value = palette_import_gpl(args->gs->colors, filename); imported = true; break; case ASE: return_value = palette_import_ase(args->gs->colors, filename); imported = true; break; case GPA: case UNKNOWN: return_value = palette_file_load(filename, args->gs->colors); break; } if (args->current_filename) g_free(args->current_filename); args->current_filename = NULL; if (return_value == 0){ if (imported){ args->imported = true; }else{ args->imported = false; } if (!autoload){ args->current_filename = g_strdup(filename); updateRecentFileList(args, filename, false); } updateProgramName(args); }else{ updateProgramName(args); return -1; } return 0; } int app_parse_geometry(AppArgs *args, const char *geometry){ gtk_window_parse_geometry(GTK_WINDOW(args->window), geometry); return 0; } static void menu_file_revert(GtkWidget *widget, AppArgs *args){ string filename; if (args->current_filename){ filename = args->current_filename; }else{ return; } color_list_remove_all(args->gs->colors); if (app_load_file(args, filename.c_str()) == 0){ }else{ GtkWidget* message; message = gtk_message_dialog_new(GTK_WINDOW(args->window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be opened")); gtk_window_set_title(GTK_WINDOW(message), _("Open")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } } static void menu_file_open_last(GtkWidget *widget, AppArgs *args){ const char *filename = args->recent_files.begin()->c_str(); color_list_remove_all(args->gs->colors); if (app_load_file(args, filename) == 0){ }else{ GtkWidget* message; message = gtk_message_dialog_new(GTK_WINDOW(args->window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be opened")); gtk_window_set_title(GTK_WINDOW(message), _("Open")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } } static void menu_file_open_nth(GtkWidget *widget, AppArgs *args){ list::iterator i = args->recent_files.begin(); uintptr_t index = (uintptr_t)g_object_get_data(G_OBJECT(widget), "index"); std::advance(i, index); const char *filename = (*i).c_str(); color_list_remove_all(args->gs->colors); if (app_load_file(args, filename) == 0){ }else{ GtkWidget* message; message = gtk_message_dialog_new(GTK_WINDOW(args->window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be opened")); gtk_window_set_title(GTK_WINDOW(message), _("Open")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } } static void add_file_filters (GtkWidget *dialog, FileType preselect){ const struct{ FileType type; const char *label; const char *filter; }filters[] = { {GPA, _("Gpick Palette (*.gpa)"), "*.gpa"}, {GPL, _("GIMP/Inkscape Palette (*.gpl)"), "*.gpl"}, {ASE, _("Adobe Swatch Exchange (*.ase)"), "*.ase"}, {UNKNOWN, 0, 0}, }; GtkFileFilter *filter; filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("All files")); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, _("All supported formats")); for (gint i = 0; filters[i].type != UNKNOWN; ++i) { gtk_file_filter_add_pattern(filter, filters[i].filter); } gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); for (gint i = 0; filters[i].type != UNKNOWN; ++i) { filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, filters[i].label); gtk_file_filter_add_pattern(filter, filters[i].filter); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (preselect == filters[i].type){ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } } } static void menu_file_open(GtkWidget *widget, AppArgs *args){ GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(gtk_widget_get_toplevel(widget)), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); const gchar* default_path = dynv_get_string_wd(args->params, "open.path", ""); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_path); add_file_filters(dialog, UNKNOWN); gboolean finished=FALSE; while (!finished){ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gchar *path; path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); dynv_set_string(args->params, "open.path", path); g_free(path); color_list_remove_all(args->gs->colors); if (app_load_file(args, filename) == 0){ finished = TRUE; }else{ GtkWidget* message; message = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be opened")); gtk_window_set_title(GTK_WINDOW(dialog), _("Open")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } g_free(filename); }else break; } gtk_widget_destroy (dialog); } static void menu_file_save_as(GtkWidget *widget, AppArgs *args){ GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new (_("Save As"), GTK_WINDOW(gtk_widget_get_toplevel(widget)), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); const gchar* default_path = dynv_get_string_wd(args->params, "save.path", ""); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_path); add_file_filters(dialog, UNKNOWN); gboolean finished=FALSE; while (!finished){ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gchar *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gchar *path; path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); dynv_set_string(args->params, "save.path", path); g_free(path); if (app_save_file(args, filename) == 0){ finished=TRUE; }else{ GtkWidget* message; message=gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be saved")); gtk_window_set_title(GTK_WINDOW(message), _("Save As")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } g_free(filename); }else break; } gtk_widget_destroy (dialog); } static void menu_file_save(GtkWidget *widget, AppArgs *args) { // If file has no name, "Save As" dialog is shown instead. if (args->current_filename == 0){ menu_file_save_as(widget, args); }else{ if (app_save_file(args, NULL) == 0){ }else{ GtkWidget* message; message=gtk_message_dialog_new(GTK_WINDOW(args->window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("File could not be saved")); gtk_window_set_title(GTK_WINDOW(message), _("Save")); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); } } } static PaletteListCallbackReturn color_list_selected(struct ColorObject* color_object, void *userdata){ color_list_add_color_object((struct ColorList *)userdata, color_object, 1); return PALETTE_LIST_CALLBACK_NO_UPDATE; } static void menu_file_export_all(GtkWidget *widget, gpointer data) { AppArgs* args=(AppArgs*)data; dialog_export_show(GTK_WINDOW(args->window), 0, false, args->gs); } static void menu_file_import(GtkWidget *widget, gpointer data) { AppArgs* args=(AppArgs*)data; dialog_import_show(GTK_WINDOW(args->window), 0, args->gs); } static void menu_file_export(GtkWidget *widget, gpointer data) { AppArgs* args=(AppArgs*)data; struct dynvHandlerMap* handler_map = dynv_system_get_handler_map(args->gs->params); struct ColorList *color_list = color_list_new(handler_map); dynv_handler_map_release(handler_map); palette_list_foreach_selected(args->color_list, color_list_selected, color_list); dialog_export_show(GTK_WINDOW(args->window), color_list, true, args->gs); color_list_destroy(color_list); } typedef struct FileMenuItems{ GtkWidget *export_all; GtkWidget *export_selected; GtkWidget *recent_files; }FileMenuItems; static void menu_file_activate(GtkWidget *widget, gpointer data) { AppArgs* args=(AppArgs*)data; gint32 selected_count = palette_list_get_selected_count(args->color_list); gint32 total_count = palette_list_get_count(args->color_list); //GtkMenu* menu=GTK_MENU(gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget))); FileMenuItems *items = (FileMenuItems*) g_object_get_data(G_OBJECT(widget), "items"); gtk_widget_set_sensitive(items->export_all, (total_count >= 1)); gtk_widget_set_sensitive(items->export_selected, (selected_count >= 1)); if (args->recent_files.size() > 0){ GtkMenu *menu2 = GTK_MENU(gtk_menu_new()); GtkWidget *item; item = gtk_menu_item_new_with_image (_("Open Last File"), gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu2), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (menu_file_open_last), args); gtk_menu_shell_append (GTK_MENU_SHELL (menu2), gtk_separator_menu_item_new ()); uint32_t j = 0; for (list::iterator i = args->recent_files.begin(); i != args->recent_files.end(); i++){ item = gtk_menu_item_new_with_label ((*i).c_str()); gtk_menu_shell_append (GTK_MENU_SHELL (menu2), item); g_object_set_data_full(G_OBJECT(item), "index", (void*)j, (GDestroyNotify)NULL); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (menu_file_open_nth), args); j++; } gtk_widget_show_all(GTK_WIDGET(menu2)); gtk_menu_item_set_submenu (GTK_MENU_ITEM (items->recent_files), GTK_WIDGET(menu2)); gtk_widget_set_sensitive(items->recent_files, true); }else{ gtk_widget_set_sensitive(items->recent_files, false); } } static void floating_picker_show_cb(GtkWidget *widget, AppArgs* args) { floating_picker_activate(args->floating_picker, false); } static void show_about_box_cb(GtkWidget *widget, AppArgs* args) { show_about_box(args->window); } static void view_palette_cb(GtkWidget *widget, AppArgs* args) { if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))){ g_object_ref(args->vpaned); GtkWidget *vbox = gtk_widget_get_parent(GTK_WIDGET(args->vpaned)); gtk_container_remove(GTK_CONTAINER(vbox), args->vpaned); gtk_paned_pack1(GTK_PANED(args->hpaned), args->vpaned, false, false); g_object_unref(args->vpaned); gtk_widget_show(GTK_WIDGET(args->hpaned)); dynv_set_bool(args->params, "view.palette", true); }else{ gtk_widget_hide(GTK_WIDGET(args->hpaned)); g_object_ref(args->vpaned); gtk_container_remove(GTK_CONTAINER(args->hpaned), args->vpaned); GtkWidget *vbox = gtk_widget_get_parent(GTK_WIDGET(args->hpaned)); gtk_box_pack_start(GTK_BOX(vbox), args->vpaned, TRUE, TRUE, 5); g_object_unref(args->vpaned); dynv_set_bool(args->params, "view.palette", false); } } static void palette_from_image_cb(GtkWidget *widget, AppArgs* args) { tools_palette_from_image_show(GTK_WINDOW(args->window), args->gs); } static void palette_from_css_file_cb(GtkWidget *widget, AppArgs* args) { tools_palette_from_css_file_show(GTK_WINDOW(args->window), args->gs); } static void destroy_file_menu_items(FileMenuItems *items){ delete items; } static void activate_secondary_source(AppArgs *args, ColorSource *source){ if (args->secondary_color_source){ color_source_deactivate(args->secondary_color_source); color_source_destroy(args->secondary_color_source); args->secondary_color_source = 0; args->secondary_source_widget = 0; if (args->secondary_source_scrolled_viewpoint) gtk_container_remove(GTK_CONTAINER(args->secondary_source_container), args->secondary_source_scrolled_viewpoint); args->secondary_source_scrolled_viewpoint= 0; if (!source) gtk_widget_hide(args->secondary_source_container); } if (source){ string namespace_str = "gpick.secondary_view."; namespace_str += source->identificator; struct dynvSystem *dynv_namespace = dynv_get_dynv(args->gs->params, namespace_str.c_str()); source = color_source_implement(source, args->gs, dynv_namespace); GtkWidget *new_widget = color_source_get_widget(source); dynv_system_release(dynv_namespace); args->secondary_color_source = source; args->secondary_source_widget = new_widget; if (source->needs_viewport){ GtkWidget *scrolled_window = gtk_scrolled_window_new(0,0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_NONE); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), new_widget); args->secondary_source_scrolled_viewpoint = scrolled_window; gtk_box_pack_start(GTK_BOX(args->secondary_source_container), args->secondary_source_scrolled_viewpoint, true, true, 0); gtk_widget_show(args->secondary_source_scrolled_viewpoint); }else{ gtk_box_pack_start(GTK_BOX(args->secondary_source_container), new_widget, true, true, 0); gtk_widget_show(new_widget); } gtk_widget_show(args->secondary_source_container); color_source_activate(source); } } static void secondary_view_cb(GtkWidget *widget, AppArgs *args){ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))){ ColorSource *source = static_cast(g_object_get_data(G_OBJECT(widget), "source")); activate_secondary_source(args, source); } } static void createMenu(GtkMenuBar *menu_bar, AppArgs *args, GtkAccelGroup *accel_group) { GtkMenu *menu; GtkWidget *item; GtkWidget* file_item; GtkStockItem stock_item; menu = GTK_MENU(gtk_menu_new()); FileMenuItems *items = new FileMenuItems(); if (gtk_stock_lookup(GTK_STOCK_NEW, &stock_item)){ item = gtk_menu_item_new_with_image(stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator(item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(menu_file_new), args); } if (gtk_stock_lookup(GTK_STOCK_OPEN, &stock_item)){ item = gtk_menu_item_new_with_image(stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (stock_item.keyval) gtk_widget_add_accelerator(item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(menu_file_open), args); } item = gtk_menu_item_new_with_mnemonic(_("Recent _files")); items->recent_files = item; gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (gtk_stock_lookup(GTK_STOCK_REVERT_TO_SAVED, &stock_item)){ item = gtk_menu_item_new_with_image(stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_r, GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F5, GdkModifierType(0), GTK_ACCEL_VISIBLE); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(menu_file_revert), args); } gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new ()); if (gtk_stock_lookup(GTK_STOCK_SAVE, &stock_item)){ item = gtk_menu_item_new_with_image (stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator (item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK(menu_file_save), args); } if (gtk_stock_lookup(GTK_STOCK_SAVE_AS, &stock_item)){ item = gtk_menu_item_new_with_image (stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator (item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK(menu_file_save_as), args); } gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ()); item = gtk_image_menu_item_new_with_mnemonic(_("Ex_port...")); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_e, GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (menu_file_export_all), args); items->export_all = item; //gtk_widget_set_sensitive(item, (total_count >= 1)); item = gtk_image_menu_item_new_with_mnemonic(_("Expo_rt Selected...")); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_e, GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (menu_file_export), args); items->export_selected = item; //gtk_widget_set_sensitive(item, (selected_count >= 1)); item = gtk_image_menu_item_new_with_mnemonic(_("_Import...")); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_i, GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (menu_file_import), args); //gtk_widget_set_sensitive(item, 0); gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ()); if (gtk_stock_lookup(GTK_STOCK_QUIT, &stock_item)){ item = gtk_menu_item_new_with_image (stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator (item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK(destroy_cb), args); } file_item = gtk_menu_item_new_with_mnemonic(_("_File")); g_signal_connect (G_OBJECT (file_item), "activate", G_CALLBACK (menu_file_activate), args); g_object_set_data_full(G_OBJECT(file_item), "items", items, (GDestroyNotify)destroy_file_menu_items); gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item),GTK_WIDGET( menu)); gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), file_item); menu = GTK_MENU(gtk_menu_new()); item = gtk_menu_item_new_with_image(_("Edit _Converters..."), gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (show_dialog_converter), args); item = gtk_menu_item_new_with_image(_("Display _Filters..."), gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (show_dialog_transformations), args); if (gtk_stock_lookup(GTK_STOCK_PREFERENCES, &stock_item)){ item = gtk_menu_item_new_with_image (stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator (item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK(show_dialog_options), args); } file_item = gtk_menu_item_new_with_mnemonic(_("_Edit")); gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item),GTK_WIDGET( menu)); gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), file_item); menu = GTK_MENU(gtk_menu_new()); GtkMenu *menu2 = GTK_MENU(gtk_menu_new()); GSList *group = NULL; ColorSource *source = color_source_manager_get(args->csm, dynv_get_string_wd(args->params, "secondary_color_source", "")); item = gtk_radio_menu_item_new_with_label(group, _("None")); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); if (source == NULL) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), true); g_object_set_data_full(G_OBJECT(item), "source", 0, (GDestroyNotify)NULL); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(secondary_view_cb), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_N, GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append(GTK_MENU_SHELL(menu2), item); vector sources = color_source_manager_get_all(args->csm); for (uint32_t i = 0; i < sources.size(); i++){ if (!(sources[i]->single_instance_only)){ item = gtk_radio_menu_item_new_with_label(group, sources[i]->hr_name); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); if (source == sources[i]) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), true); g_object_set_data_full(G_OBJECT(item), "source", sources[i], (GDestroyNotify)NULL); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(secondary_view_cb), args); if (color_source_get_default_accelerator(sources[i])) gtk_widget_add_accelerator(item, "activate", accel_group, color_source_get_default_accelerator(sources[i]), GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append(GTK_MENU_SHELL(menu2), item); } } item = gtk_menu_item_new_with_mnemonic(_("_Secondary View")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), GTK_WIDGET(menu2)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); item = gtk_check_menu_item_new_with_mnemonic(_("Palette")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), dynv_get_bool_wd(args->params, "view.palette", true)); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_p, GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), GTK_ACCEL_VISIBLE); g_signal_connect(G_OBJECT(item), "toggled", G_CALLBACK(view_palette_cb), args); file_item = gtk_menu_item_new_with_mnemonic (_("_View")); gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item),GTK_WIDGET( menu)); gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), file_item); menu = GTK_MENU(gtk_menu_new()); item = gtk_menu_item_new_with_mnemonic(_("Palette From _Image...")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(palette_from_image_cb), args); //item = gtk_menu_item_new_with_mnemonic(_("Palette From _CSS file...")); //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); //g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(palette_from_css_file_cb), args); file_item = gtk_menu_item_new_with_mnemonic(_("_Tools")); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file_item), GTK_WIDGET(menu)); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file_item); menu = GTK_MENU(gtk_menu_new()); if (gtk_stock_lookup(GTK_STOCK_ABOUT, &stock_item)){ item = gtk_menu_item_new_with_image (stock_item.label, gtk_image_new_from_stock(stock_item.stock_id, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); if (stock_item.keyval) gtk_widget_add_accelerator (item, "activate", accel_group, stock_item.keyval, stock_item.modifier, GTK_ACCEL_VISIBLE); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK(show_about_box_cb), args); } file_item = gtk_menu_item_new_with_mnemonic (_("_Help")); gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item),GTK_WIDGET( menu)); gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), file_item); } typedef struct CopyMenuItem{ gchar* function_name; struct ColorObject* color_object; GlobalState* gs; GtkWidget* palette_widget; }CopyMenuItem; static void converter_destroy_params(CopyMenuItem* args){ color_object_release(args->color_object); g_free(args->function_name); delete args; } static void converter_callback_copy(GtkWidget *widget, gpointer item) { CopyMenuItem* itemdata=(CopyMenuItem*)g_object_get_data(G_OBJECT(widget), "item_data"); converter_get_clipboard(itemdata->function_name, itemdata->color_object, itemdata->palette_widget, itemdata->gs->params); } static GtkWidget* converter_create_copy_menu_item (GtkWidget *menu, const gchar* function, struct ColorObject* color_object, GtkWidget* palette_widget, GlobalState *gs){ GtkWidget* item=0; gchar* converted; if (converters_color_serialize((Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0), function, color_object, &converted)==0){ item = gtk_menu_item_new_with_image(converted, gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU)); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(converter_callback_copy), 0); CopyMenuItem* itemdata=new CopyMenuItem; itemdata->function_name=g_strdup(function); itemdata->palette_widget=palette_widget; itemdata->color_object=color_object_ref(color_object); itemdata->gs = gs; g_object_set_data_full(G_OBJECT(item), "item_data", itemdata, (GDestroyNotify)converter_destroy_params); g_free(converted); } return item; } GtkWidget* converter_create_copy_menu (struct ColorObject* color_object, GtkWidget* palette_widget, GlobalState* gs){ Converters *converters = (Converters*)dynv_get_pointer_wd(gs->params, "Converters", 0); GtkWidget *menu; menu = gtk_menu_new(); uint32_t converter_table_size = 0; Converter** converter_table = converters_get_all_type(converters, CONVERTERS_ARRAY_TYPE_COPY, &converter_table_size); for (uint32_t i=0; ifunction_name, color_object, palette_widget, gs); if (item) gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); } return menu; } void converter_get_text(const gchar* function, struct ColorObject* color_object, GtkWidget* palette_widget, struct dynvSystem *params, gchar** out_text){ stringstream text(ios::out); int first=true; struct ColorList *color_list = color_list_new(NULL); if (palette_widget){ palette_list_foreach_selected(palette_widget, color_list_selected, color_list); }else{ color_list_add_color_object(color_list, color_object, 1); } Converters* converters = (Converters*)dynv_get_pointer_wd(params, "Converters", 0); for (ColorList::iter i=color_list->colors.begin(); i!=color_list->colors.end(); ++i){ gchar* converted; if (converters_color_serialize(converters, function, *i, &converted)==0){ if (first){ text<selected = 1; return PALETTE_LIST_CALLBACK_NO_UPDATE; } static void palette_popup_menu_remove_all(GtkWidget *widget, AppArgs* args) { color_list_remove_all(args->gs->colors); } static void palette_popup_menu_remove_selected(GtkWidget *widget, AppArgs* args) { palette_list_foreach_selected(args->color_list, color_list_mark_selected, 0); color_list_remove_selected(args->gs->colors); } static PaletteListCallbackReturn color_list_clear_names(struct ColorObject* color_object, void *userdata){ dynv_set_string(color_object->params, "name", ""); return PALETTE_LIST_CALLBACK_UPDATE_NAME; } static void palette_popup_menu_clear_names(GtkWidget *widget, AppArgs* args) { palette_list_foreach_selected(args->color_list, color_list_clear_names, NULL); } typedef struct AutonameState{ ColorNames *color_names; bool imprecision_postfix; }AutonameState; static PaletteListCallbackReturn color_list_autoname(struct ColorObject* color_object, void *userdata){ AutonameState *state=(AutonameState *)(userdata); Color c; color_object_get_color (color_object, &c); dynv_set_string(color_object->params, "name", color_names_get(state->color_names, &c, state->imprecision_postfix).c_str()); return PALETTE_LIST_CALLBACK_UPDATE_NAME; } static void palette_popup_menu_autoname(GtkWidget *widget, AppArgs* args) { AutonameState state; state.color_names = args->gs->color_names; state.imprecision_postfix = dynv_get_bool_wd(args->gs->params, "gpick.color_names.imprecision_postfix", true); palette_list_foreach_selected(args->color_list, color_list_autoname, &state); } typedef struct AutonumberState{ std::string name; uint32_t index; uint32_t nplaces; bool decreasing; bool append; }AutonumberState; static PaletteListCallbackReturn color_list_autonumber(struct ColorObject* color_object, void *userdata){ AutonumberState *state = (AutonumberState*)userdata; stringstream ss; if (state->append == true){ ss << dynv_get_string_wd(color_object->params, "name","") << " "; } ss << state->name << "-"; ss.width(state->nplaces); ss.fill('0'); if (state->decreasing){ ss << right << state->index; state->index--; } else{ ss << right << state->index++; } dynv_set_string(color_object->params, "name", ss.str().c_str()); return PALETTE_LIST_CALLBACK_UPDATE_NAME; } static PaletteListCallbackReturn color_list_set_color (struct ColorObject* color_object, void *userdata){ Color *source_color = (Color *)(userdata); color_object_set_color (color_object, source_color); return PALETTE_LIST_CALLBACK_UPDATE_ROW; } static void palette_popup_menu_autonumber(GtkWidget *widget, AppArgs* args) { AutonumberState state; int response; uint32_t selected_count = palette_list_get_selected_count(args->color_list); response = dialog_autonumber_show(GTK_WINDOW(args->window), selected_count, args->gs); if (response == GTK_RESPONSE_OK){ struct dynvSystem *params; params = dynv_get_dynv(args->gs->params, "gpick.autonumber"); state.name = dynv_get_string_wd(params, "name", "autonum"); state.nplaces = dynv_get_int32_wd(params, "nplaces", 1); state.index = dynv_get_int32_wd(params, "startindex", 1); state.decreasing = dynv_get_bool_wd(params, "decreasing", true); state.append = dynv_get_bool_wd(params, "append", true); palette_list_foreach_selected(args->color_list, color_list_autonumber, &state); dynv_system_release(params); } } typedef struct ReplaceState{ std::list::reverse_iterator iter; } ReplaceState; static PaletteListCallbackReturn color_list_reverse_replace(struct ColorObject** color_object, void *userdata) { ReplaceState *state = reinterpret_cast(userdata); *color_object = color_object_ref(*(state->iter)); state->iter++; return PALETTE_LIST_CALLBACK_UPDATE_ROW; } static void palette_popup_menu_reverse(GtkWidget *widget, AppArgs* args) { struct ColorList *color_list = color_list_new(NULL); ReplaceState state; palette_list_foreach_selected(args->color_list, color_list_selected, color_list); state.iter = color_list->colors.rbegin(); palette_list_foreach_selected(args->color_list, color_list_reverse_replace, &state); } gint32 palette_popup_menu_mix_list(Color* color, void *userdata){ *((GList**)userdata) = g_list_append(*((GList**)userdata), color); return 0; } static void palette_popup_menu_mix(GtkWidget *widget, AppArgs* args) { struct ColorList *color_list = color_list_new(NULL); palette_list_foreach_selected(args->color_list, color_list_selected, color_list); dialog_mix_show(GTK_WINDOW(args->window), color_list, args->gs); color_list_destroy(color_list); } static void palette_popup_menu_variations(GtkWidget *widget, AppArgs* args) { struct dynvHandlerMap* handler_map=dynv_system_get_handler_map(args->gs->params); struct ColorList *color_list = color_list_new(handler_map); palette_list_foreach_selected(args->color_list, color_list_selected, color_list); dialog_variations_show(GTK_WINDOW(args->window), color_list, args->gs); color_list_destroy(color_list); dynv_handler_map_release(handler_map); } static void palette_popup_menu_generate(GtkWidget *widget, AppArgs* args) { struct ColorList *color_list = color_list_new(NULL); palette_list_foreach_selected(args->color_list, color_list_selected, color_list); dialog_generate_show(GTK_WINDOW(args->window), color_list, args->gs); color_list_destroy(color_list); } typedef struct GroupAndSortState{ std::list::iterator iter; } GroupAndSortState; static PaletteListCallbackReturn color_list_group_and_sort_replace(struct ColorObject** color_object, void *userdata) { GroupAndSortState *state = reinterpret_cast(userdata); *color_object = color_object_ref(*(state->iter)); state->iter++; return PALETTE_LIST_CALLBACK_UPDATE_ROW; } static void palette_popup_menu_group_and_sort(GtkWidget *widget, AppArgs* args) { struct ColorList *color_list = color_list_new(NULL); struct ColorList *sorted_color_list = color_list_new(NULL); palette_list_foreach_selected(args->color_list, color_list_selected, color_list); if (dialog_sort_show(GTK_WINDOW(args->window), color_list, sorted_color_list, args->gs)){ GroupAndSortState state; state.iter = sorted_color_list->colors.begin(); palette_list_foreach_selected(args->color_list, color_list_group_and_sort_replace, &state); } color_list_destroy(color_list); color_list_destroy(sorted_color_list); } static gboolean palette_popup_menu_show(GtkWidget *widget, GdkEventButton* event, AppArgs *args) { GtkWidget *menu; GtkWidget* item ; gint32 button, event_time; menu = gtk_menu_new (); GtkAccelGroup *accel_group = gtk_accel_group_new(); gtk_menu_set_accel_group(GTK_MENU(menu), accel_group); gint32 selected_count = palette_list_get_selected_count(args->color_list); gint32 total_count = palette_list_get_count(args->color_list); item = gtk_menu_item_new_with_mnemonic(_("_Copy to Clipboard")); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_c, GdkModifierType(GDK_CONTROL_MASK), GTK_ACCEL_VISIBLE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_set_sensitive(item, (selected_count >= 1)); if (total_count>0){ struct ColorList *color_list = color_list_new(NULL); palette_list_forfirst_selected(args->color_list, color_list_selected, color_list); if (color_list_get_count(color_list)!=0){ gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), converter_create_copy_menu (*color_list->colors.begin(), args->color_list, args->gs)); } color_list_destroy(color_list); } gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); item = gtk_menu_item_new_with_image (_("_Mix Colors..."), gtk_image_new_from_stock(GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(palette_popup_menu_mix), args); gtk_widget_set_sensitive(item, (selected_count >= 2)); item = gtk_menu_item_new_with_image (_("_Variations..."), gtk_image_new_from_stock(GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(palette_popup_menu_variations), args); gtk_widget_set_sensitive(item, (selected_count >= 1)); item = gtk_menu_item_new_with_image (_("_Generate..."), gtk_image_new_from_stock(GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK(palette_popup_menu_generate), args); gtk_widget_set_sensitive(item, (selected_count >= 1)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ()); item = gtk_menu_item_new_with_mnemonic (_("C_lear names")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_clear_names), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_E, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 1)); item = gtk_menu_item_new_with_mnemonic (_("Autona_me")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_autoname), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_N, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 1)); item = gtk_menu_item_new_with_mnemonic (_("Auto_number...")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_autonumber), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_a, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 1)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ()); item = gtk_menu_item_new_with_mnemonic(_("R_everse")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_reverse), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_v, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 2)); item = gtk_menu_item_new_with_mnemonic(_("Group and _sort...")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(palette_popup_menu_group_and_sort), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_g, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 2)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ()); item = gtk_menu_item_new_with_image (_("_Remove"), gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_remove_selected), args); gtk_widget_add_accelerator(item, "activate", accel_group, GDK_Delete, GdkModifierType(0), GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive(item, (selected_count >= 1)); item = gtk_menu_item_new_with_image (_("Remove _All"), gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect(G_OBJECT (item), "activate", G_CALLBACK (palette_popup_menu_remove_all), args); gtk_widget_set_sensitive(item, (total_count >= 1)); gtk_widget_show_all (GTK_WIDGET(menu)); 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(G_OBJECT(accel_group)); g_object_unref(G_OBJECT(accel_group)); g_object_ref_sink(menu); g_object_unref(menu); return TRUE; } static void on_palette_popup_menu(GtkWidget *widget, AppArgs *args) { palette_popup_menu_show(widget, 0, args); } static gboolean on_palette_button_press(GtkWidget *widget, GdkEventButton *event, AppArgs *args) { if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { return palette_popup_menu_show(widget, event, args); } return FALSE; } static gboolean on_palette_list_key_press(GtkWidget *widget, GdkEventKey *event, AppArgs *args){ guint modifiers = gtk_accelerator_get_default_mod_mask(); switch(event->keyval) { case GDK_1: case GDK_KP_1: case GDK_2: case GDK_KP_2: case GDK_3: case GDK_KP_3: case GDK_4: case GDK_KP_4: case GDK_5: case GDK_KP_5: case GDK_6: case GDK_KP_6: { struct ColorList *color_list = color_list_new(NULL); palette_list_forfirst_selected(args->color_list, color_list_selected, color_list); if (color_list_get_count(color_list) > 0){ ColorSource *color_source = (ColorSource*)dynv_get_pointer_wd(args->gs->params, "CurrentColorSource", 0); uint32_t color_index = 0; switch(event->keyval) { case GDK_KP_1: case GDK_1: color_index = 0; break; case GDK_KP_2: case GDK_2: color_index = 1; break; case GDK_KP_3: case GDK_3: color_index = 2; break; case GDK_KP_4: case GDK_4: color_index = 3; break; case GDK_KP_5: case GDK_5: color_index = 4; break; case GDK_KP_6: case GDK_6: color_index = 5; break; } if ((event->state&modifiers)==GDK_CONTROL_MASK){ struct ColorObject *source_color_object; Color source_color; color_source_get_nth_color(color_source, color_index, &source_color_object); color_object_get_color (source_color_object, &source_color); palette_list_forfirst_selected (args->color_list, color_list_set_color, &source_color); } else{ color_source_set_nth_color(color_source, color_index, *color_list->colors.begin()); } } color_list_destroy(color_list); return true; } return false; break; case GDK_c: if ((event->state&modifiers)==GDK_CONTROL_MASK){ 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, 0, args->color_list, args->gs->params); } return true; } return false; break; case GDK_v: if ((event->state&modifiers)==GDK_CONTROL_MASK){ struct ColorObject* color_object; if (copypaste_get_color_object(&color_object, args->gs)==0){ color_list_add_color_object(args->gs->colors, color_object, 1); color_object_release(color_object); } return true; }else{ palette_popup_menu_reverse(widget, args); return true; } return false; break; case GDK_g: palette_popup_menu_group_and_sort(widget, args); return true; break; case GDK_Delete: palette_popup_menu_remove_selected(widget, args); break; case GDK_a: if ((event->state & GDK_CONTROL_MASK) == 0){ palette_popup_menu_autonumber(widget, args); return true; } break; case GDK_e: if ((event->state & GDK_CONTROL_MASK) == 0){ palette_popup_menu_clear_names(widget, args); return true; } break; case GDK_n: if ((event->state & GDK_CONTROL_MASK) == 0){ palette_popup_menu_autoname(widget, args); return true; } break; default: return false; break; } return false; } static int color_list_on_insert(struct ColorList* color_list, struct ColorObject* color_object){ palette_list_add_entry(((AppArgs*)color_list->userdata)->color_list, color_object); return 0; } static int color_list_on_delete_selected(struct ColorList* color_list){ palette_list_remove_selected_entries(((AppArgs*)color_list->userdata)->color_list); return 0; } static int color_list_on_delete(struct ColorList* color_list, struct ColorObject* color_object){ palette_list_remove_entry(((AppArgs*)color_list->userdata)->color_list, color_object); return 0; } static int color_list_on_clear(struct ColorList* color_list){ palette_list_remove_all_entries(((AppArgs*)color_list->userdata)->color_list); return 0; } static PaletteListCallbackReturn callback_color_list_on_get_positions(struct ColorObject* color_object, void *userdata){ color_object->position = *((unsigned long*)userdata); (*((unsigned long*)userdata))++; return PALETTE_LIST_CALLBACK_NO_UPDATE; } static int color_list_on_get_positions(struct ColorList* color_list){ unsigned long item = 0; palette_list_foreach(((AppArgs*)color_list->userdata)->color_list, callback_color_list_on_get_positions, &item ); return 0; } int main_show_window(GtkWidget* window, struct dynvSystem *main_params){ if (GTK_WIDGET_VISIBLE(window)){ gtk_window_deiconify(GTK_WINDOW(window)); return -1; //already visible } gint x, y; gint width, height; x = dynv_get_int32_wd(main_params, "window.x", -1); y = dynv_get_int32_wd(main_params, "window.y", -1); width = dynv_get_int32_wd(main_params, "window.width", -1); height = dynv_get_int32_wd(main_params, "window.height", -1); if (x<0 || y<0 || x>gdk_screen_width() || y>gdk_screen_height()){ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); }else{ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE); gtk_window_move(GTK_WINDOW(window), x, y); } if (width>0 && height>0) gtk_window_resize(GTK_WINDOW(window), width, height); gtk_widget_show(window); return 0; } static gboolean on_window_focus_change(GtkWidget *widget, GdkEventFocus *event, AppArgs* args) { if (event->in){ if (args->secondary_color_source) color_source_activate(args->secondary_color_source); if (args->current_color_source) color_source_activate(args->current_color_source); }else{ if (args->secondary_color_source) color_source_deactivate(args->secondary_color_source); if (args->current_color_source) color_source_deactivate(args->current_color_source); } return FALSE; } static void set_main_window_icon() { GList *icons = 0; GtkIconTheme *icon_theme; GError *error = NULL; icon_theme = gtk_icon_theme_get_default(); gint sizes[] = { 16, 32, 48, 128 }; for (guint32 i = 0; i < sizeof(sizes) / sizeof(gint); ++i) { GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(icon_theme, "gpick", sizes[i], GtkIconLookupFlags(0), &error); if (pixbuf && (error == NULL)){ icons = g_list_append(icons, pixbuf); } if (error){ cerr << error->message << endl; g_error_free(error); error = NULL; } } if (icons){ gtk_window_set_default_icon_list(icons); g_list_foreach(icons, (GFunc)g_object_unref, NULL); g_list_free(icons); } } bool app_is_autoload_enabled(AppArgs *args){ return dynv_get_bool_wd(args->params, "main.save_restore_palette", true); } static bool app_on_control_activate_floating_picker(void *userdata) { AppArgs *args = reinterpret_cast(userdata); floating_picker_activate(args->floating_picker, false); return true; } static bool app_on_single_instance_activate(void *userdata) { AppArgs *args = reinterpret_cast(userdata); status_icon_set_visible(args->statusIcon, false); main_show_window(args->window, args->params); return true; } AppArgs* app_create_main(const AppOptions *options){ AppArgs* args=new AppArgs; memcpy(&args->options, options, sizeof(AppOptions)); color_init(); GlobalState *gs = global_state_create(); args->gs = gs; global_state_init(args->gs, GLOBALSTATE_CONFIGURATION); args->bus_id = gpick_own_name(app_on_control_activate_floating_picker, app_on_single_instance_activate, args); bool cancel_startup = false; if (!cancel_startup && args->options.floating_picker_mode){ if (gpick_control_activate_floating_picker()){ cancel_startup = true; } } if (!cancel_startup && dynv_get_bool_wd(gs->params, "gpick.main.single_instance", false)){ if (gpick_single_instance_activate()){ cancel_startup = true; } } if (cancel_startup){ delete args; return 0; } args->current_filename = 0; args->imported = false; args->precision_loss_icon = 0; args->current_color_source = 0; args->secondary_color_source = 0; args->secondary_source_widget = 0; args->secondary_source_scrolled_viewpoint= 0; global_state_init(args->gs, GLOBALSTATE_ALL); args->gs->colors->on_insert = color_list_on_insert; args->gs->colors->on_clear = color_list_on_clear; args->gs->colors->on_delete_selected = color_list_on_delete_selected; args->gs->colors->on_get_positions = color_list_on_get_positions; args->gs->colors->on_delete = color_list_on_delete; args->gs->colors->userdata = args; dynv_set_pointer(args->gs->params, "MainWindowStruct", args); args->params = dynv_get_dynv(args->gs->params, "gpick.main"); args->csm = color_source_manager_create(); register_sources(args->csm); args->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); set_main_window_icon(); updateProgramName(args); g_signal_connect(G_OBJECT(args->window), "delete_event", G_CALLBACK(delete_event), args); g_signal_connect(G_OBJECT(args->window), "destroy", G_CALLBACK(destroy_cb), args); g_signal_connect(G_OBJECT(args->window), "configure-event", G_CALLBACK(on_window_configure), args); g_signal_connect(G_OBJECT(args->window), "window-state-event", G_CALLBACK(on_window_state_event), args); g_signal_connect(G_OBJECT(args->window), "focus-in-event", G_CALLBACK(on_window_focus_change), args); g_signal_connect(G_OBJECT(args->window), "focus-out-event", G_CALLBACK(on_window_focus_change), args); GtkAccelGroup *accel_group=gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(args->window), accel_group); g_object_unref(G_OBJECT (accel_group)); //gtk_accel_group_connect(accel_group, GDK_s, GdkModifierType(GDK_CONTROL_MASK), GtkAccelFlags(GTK_ACCEL_VISIBLE), g_cclosure_new (G_CALLBACK (menu_file_save),window,NULL)); GtkWidget *widget, *statusbar, *notebook, *vpaned, *hpaned; GtkWidget* vbox_main = gtk_vbox_new(false, 0); gtk_container_add (GTK_CONTAINER(args->window), vbox_main); GtkWidget* menu_bar; menu_bar = gtk_menu_bar_new (); gtk_box_pack_start (GTK_BOX(vbox_main), menu_bar, FALSE, FALSE, 0); hpaned = gtk_hpaned_new(); bool color_list_visible = dynv_get_bool_wd(args->params, "view.palette", true); vpaned = gtk_vpaned_new(); args->vpaned = vpaned; if (color_list_visible) gtk_paned_pack1(GTK_PANED(hpaned), vpaned, false, false); else gtk_box_pack_start(GTK_BOX(vbox_main), vpaned, TRUE, TRUE, 5); notebook = gtk_notebook_new(); g_signal_connect(G_OBJECT (notebook), "switch-page", G_CALLBACK(notebook_switch_cb), args); gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), true); statusbar=gtk_statusbar_new(); dynv_set_pointer(args->gs->params, "StatusBar", statusbar); gtk_paned_pack1(GTK_PANED(vpaned), notebook, false, false); if (color_list_visible){ gtk_box_pack_start(GTK_BOX(vbox_main), hpaned, TRUE, TRUE, 5); gtk_widget_show_all(vbox_main); }else{ gtk_widget_show_all(vbox_main); gtk_box_pack_start(GTK_BOX(vbox_main), hpaned, TRUE, TRUE, 5); } ColorSource *source; struct dynvSystem *dynv_namespace; dynv_namespace = dynv_get_dynv(gs->params, "gpick.picker"); source = color_source_implement(color_source_manager_get(args->csm, "color_picker"), args->gs, dynv_namespace); widget = color_source_get_widget(source); dynv_system_release(dynv_namespace); args->color_source[source->identificator] = source; args->color_source_index.push_back(source); args->floating_picker = floating_picker_new(args->window, args->gs, source); color_picker_set_floating_picker(source, args->floating_picker); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), widget, gtk_label_new_with_mnemonic(_("Color pic_ker"))); gtk_widget_show(widget); dynv_namespace = dynv_get_dynv(gs->params, "gpick.generate_scheme"); source = color_source_implement(color_source_manager_get(args->csm, "generate_scheme"), args->gs, dynv_namespace); widget = color_source_get_widget(source); dynv_system_release(dynv_namespace); args->color_source[source->identificator] = source; args->color_source_index.push_back(source); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), widget, gtk_label_new_with_mnemonic(_("Scheme _generation"))); gtk_widget_show(widget); { widget = gtk_vbox_new(false, 0); gtk_paned_pack2(GTK_PANED(vpaned), widget, false, false); args->secondary_source_container = widget; source = color_source_manager_get(args->csm, dynv_get_string_wd(args->params, "secondary_color_source", "")); if (source) activate_secondary_source(args, source); } dynv_namespace = dynv_get_dynv(gs->params, "gpick.layout_preview"); source = color_source_implement(color_source_manager_get(args->csm, "layout_preview"), args->gs, dynv_namespace); widget = color_source_get_widget(source); dynv_system_release(dynv_namespace); args->color_source[source->identificator] = source; args->color_source_index.push_back(source); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), widget, gtk_label_new_with_mnemonic(_("Lay_out preview"))); gtk_widget_show(widget); GtkWidget *count_label = gtk_label_new(""); widget = palette_list_new(args->gs, count_label); args->color_list = widget; gtk_widget_show(widget); g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK (on_palette_popup_menu), args); g_signal_connect(G_OBJECT(widget), "button-press-event",G_CALLBACK (on_palette_button_press), args); g_signal_connect(G_OBJECT(widget), "key_press_event", G_CALLBACK (on_palette_list_key_press), args); GtkWidget *scrolled_window; scrolled_window=gtk_scrolled_window_new (0,0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(scrolled_window), args->color_list ); //gtk_box_pack_start (GTK_BOX(hbox), scrolled_window, TRUE, TRUE, 0); gtk_paned_pack2(GTK_PANED(hpaned), scrolled_window, TRUE, FALSE); gtk_widget_show(scrolled_window); args->hpaned = hpaned; args->notebook = notebook; { const char *tab = dynv_get_string_wd(args->params, "color_source", ""); map::iterator i = args->color_source.find(tab); if (i != args->color_source.end()){ uint32_t tab_index = 0; for (vector::iterator j = args->color_source_index.begin(); j != args->color_source_index.end(); ++j){ if ((*j) == (*i).second){ gtk_notebook_set_current_page(GTK_NOTEBOOK(args->notebook), tab_index); break; } tab_index++; } } } gtk_box_pack_end (GTK_BOX(vbox_main), statusbar, 0, 0, 0); args->statusbar = statusbar; GtkWidget *button = gtk_button_new(); gtk_button_set_focus_on_click(GTK_BUTTON(button), false); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(floating_picker_show_cb), args); gtk_widget_add_accelerator(button, "clicked", accel_group, GDK_p, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); gtk_widget_set_tooltip_text(button, _("Pick colors (Ctrl+P)")); gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_icon_name("gpick", GTK_ICON_SIZE_MENU)); gtk_box_pack_end(GTK_BOX(statusbar), button, false, false, 0); gtk_widget_show_all(button); gtk_box_pack_end(GTK_BOX(statusbar), count_label, false, false, 0); gtk_widget_show_all(count_label); widget = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU); gtk_widget_set_tooltip_text(widget, _("File is currently in a non-native format, possible loss of precision and/or metadata.")); args->precision_loss_icon = widget; if (args->imported) gtk_widget_show(widget); gtk_box_pack_end(GTK_BOX(statusbar), widget, false, false, 0); gtk_widget_show(statusbar); { //Load recent file list char** recent_array; uint32_t recent_array_size; if ((recent_array = (char**)dynv_get_string_array_wd(args->gs->params, "gpick.recent.files", 0, 0, &recent_array_size))){ for (int i = 0; i < recent_array_size; i++){ args->recent_files.push_back(string(recent_array[i])); } delete [] recent_array; } } createMenu(GTK_MENU_BAR(menu_bar), args, accel_group); gtk_widget_show_all(menu_bar); args->statusIcon = status_icon_new(args->window, args->gs, args->floating_picker); return args; } int app_run(AppArgs *args){ gtk_widget_realize(args->window); if (args->options.floating_picker_mode || dynv_get_bool_wd(args->params, "start_in_tray", false)){ status_icon_set_visible (args->statusIcon, true); }else{ main_show_window(args->window, args->params); } gtk_paned_set_position(GTK_PANED(args->hpaned), dynv_get_int32_wd(args->params, "paned_position", -1)); gtk_paned_set_position(GTK_PANED(args->vpaned), dynv_get_int32_wd(args->params, "vertical_paned_position", -1)); if (args->options.floating_picker_mode) floating_picker_activate(args->floating_picker, false); gtk_main(); { //Save recent file list const char** recent_array; uint32_t recent_array_size; recent_array_size = args->recent_files.size(); recent_array = new const char* [recent_array_size]; uint32_t j =0; for (list::iterator i = args->recent_files.begin(); i != args->recent_files.end(); i++){ recent_array[j] = (*i).c_str(); j++; } dynv_set_string_array(args->gs->params, "gpick.recent.files", recent_array, recent_array_size); delete [] recent_array; } gpick_unown_name(args->bus_id); status_icon_destroy(args->statusIcon); global_state_term(args->gs); dynv_system_release(args->params); global_state_destroy(args->gs); if (args->current_filename) g_free(args->current_filename); color_source_manager_destroy(args->csm); delete args; return 0; } gpick_0.2.5/source/Random.h0000644000175000017500000000363112070605214014276 0ustar zbygzbyg/* * 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 RANDOM_H_ #define RANDOM_H_ struct Random { unsigned long (*function)(struct Random* r, unsigned long seed_offset); unsigned long *seed; unsigned long seed_size; }; struct Random* random_new(const char* random_function); unsigned long random_get(struct Random* r); void random_seed(struct Random* r, void* seed); void random_destroy(struct Random* r); #endif /* RANDOM_H_ */ gpick_0.2.5/source/Endian.h0000644000175000017500000000610212070605214014250 0ustar zbygzbyg/* * 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 ENDIAN_H_ #define ENDIAN_H_ #include #define BSWAP_64(x) (((uint64_t)(x) << 56) | \ (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ (((uint64_t)(x) << 8) & 0xff00000000ULL) | \ (((uint64_t)(x) >> 8) & 0xff000000ULL) | \ (((uint64_t)(x) >> 24) & 0xff0000ULL) | \ (((uint64_t)(x) >> 40) & 0xff00ULL) | \ ((uint64_t)(x) >> 56)) #define BSWAP_32(x) (((uint32_t)(x) << 24) | \ (((uint32_t)(x) << 8) & 0xff0000ULL) | \ (((uint32_t)(x) >> 8) & 0xff00ULL) | \ ((uint32_t)(x) >> 24)) #define BSWAP_16(x) (((uint16_t)(x) << 8) | \ ((uint16_t)(x) >> 8)) #ifdef BIG_ENDIAN_P #define UINT16_TO_LE(x) (BSWAP_16(x)) #define UINT16_FROM_LE(x) (BSWAP_16(x)) #define UINT32_TO_LE(x) (BSWAP_32(x)) #define UINT32_FROM_LE(x) (BSWAP_32(x)) #define UINT64_TO_LE(x) (BSWAP_64(x)) #define UINT64_FROM_LE(x) (BSWAP_64(x)) #define UINT16_TO_BE(x) (x) #define UINT16_FROM_BE(x) (x) #define UINT32_TO_BE(x) (x) #define UINT32_FROM_BE(x) (x) #define UINT64_TO_BE(x) (x) #define UINT64_FROM_BE(x) (x) #warning BigEndian #else #define UINT16_TO_LE(x) (x) #define UINT16_FROM_LE(x) (x) #define UINT32_TO_LE(x) (x) #define UINT32_FROM_LE(x) (x) #define UINT64_TO_LE(x) (x) #define UINT64_FROM_LE(x) (x) #define UINT16_TO_BE(x) (BSWAP_16(x)) #define UINT16_FROM_BE(x) (BSWAP_16(x)) #define UINT32_TO_BE(x) (BSWAP_32(x)) #define UINT32_FROM_BE(x) (BSWAP_32(x)) #define UINT64_TO_BE(x) (BSWAP_64(x)) #define UINT64_FROM_BE(x) (BSWAP_64(x)) #endif #endif /* ENDIAN_H_ */ gpick_0.2.5/source/gtk/Swatch.h0000644000175000017500000000725212070605214015077 0ustar zbygzbyg/* * 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 SWATCH_H_ #define SWATCH_H_ #include #include "../Color.h" #include "../transformation/Chain.h" G_BEGIN_DECLS #define GTK_TYPE_SWATCH (gtk_swatch_get_type ()) #define GTK_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SWATCH, GtkSwatch)) #define GTK_SWATCH_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_SWATCH, GtkSwatchClass)) #define GTK_IS_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SWATCH)) #define GTK_IS_SWATCH_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_SWATCH)) #define GTK_SWATCH_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SWATCH, GtkSwatchClass)) typedef struct GtkSwatch GtkSwatch; typedef struct GtkSwatchClass GtkSwatchClass; typedef gpointer GtkSwatchObject; typedef struct GtkSwatch { GtkDrawingArea parent; /* < private > */ }GtkSwatch; typedef struct GtkSwatchClass { GtkDrawingAreaClass parent_class; void (* active_color_changed)(GtkWidget* widget, gint32 active_color, gpointer userdata); void (* color_changed)(GtkWidget* widget, gpointer userdata); void (* color_activated)(GtkWidget* widget, gpointer userdata); void (* center_activated)(GtkWidget* widget, gpointer userdata); }GtkSwatchClass; GtkWidget* gtk_swatch_new (void); void gtk_swatch_set_color(GtkSwatch* swatch, guint32 index, Color* color); void gtk_swatch_set_main_color(GtkSwatch* swatch, Color* color); void gtk_swatch_set_active_index(GtkSwatch* swatch, guint32 index); void gtk_swatch_set_active_color(GtkSwatch* swatch, Color* color); void gtk_swatch_move_active(GtkSwatch* swatch, gint32 direction); void gtk_swatch_set_color_to_main(GtkSwatch* swatch); void gtk_swatch_get_color(GtkSwatch* swatch, guint32 index, Color* color); void gtk_swatch_get_main_color(GtkSwatch* swatch, Color* color); gint32 gtk_swatch_get_active_index(GtkSwatch* swatch); void gtk_swatch_get_active_color(GtkSwatch* swatch, Color* color); void gtk_swatch_set_color_count(GtkSwatch* swatch, gint32 colors); gint gtk_swatch_get_color_at(GtkSwatch* swatch, gint x, gint y); void gtk_swatch_set_transformation_chain(GtkSwatch* widget, transformation::Chain *chain); GType gtk_swatch_get_type(void); G_END_DECLS #endif /* SWATCH_H_ */ gpick_0.2.5/source/gtk/ColorComponent.cpp0000644000175000017500000007430612070605214017146 0ustar zbygzbyg/* * 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 "ColorComponent.h" #include "../uiUtilities.h" #include "../Color.h" #include "../MathUtil.h" #include "../Paths.h" #include #include #include #include using namespace std; #define GTK_COLOR_COMPONENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_COMPONENT, GtkColorComponentPrivate)) G_DEFINE_TYPE (GtkColorComponent, gtk_color_component, GTK_TYPE_DRAWING_AREA); typedef struct GtkColorComponentPrivate GtkColorComponentPrivate; static gboolean gtk_color_component_expose (GtkWidget *widget, GdkEventExpose *event); static gboolean gtk_color_component_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean gtk_color_component_button_press (GtkWidget *node_system, GdkEventButton *event); static gboolean gtk_color_component_motion_notify (GtkWidget *node_system, GdkEventMotion *event); static void update_rgb_color(GtkColorComponentPrivate *ns, Color *c); static void gtk_color_component_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_color_component_finalize(GObject *color_obj); enum{ COLOR_CHANGED, INPUT_CLICKED, LAST_SIGNAL }; static const int MaxNumberOfComponents = 4; static guint gtk_color_component_signals[LAST_SIGNAL] = {0, 0}; typedef struct GtkColorComponentPrivate{ Color orig_color; Color color; GtkColorComponentComp component; int n_components; int capture_on; gint last_event_position; bool changing_color; bool out_of_gamut_mask; ReferenceIlluminant lab_illuminant; ReferenceObserver lab_observer; cairo_surface_t *pattern_surface; cairo_pattern_t *pattern; const char *label[MaxNumberOfComponents][2]; gchar *text[MaxNumberOfComponents]; double range[MaxNumberOfComponents]; double offset[MaxNumberOfComponents]; }GtkColorComponentPrivate; static void gtk_color_component_class_init (GtkColorComponentClass *color_component_class){ GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS (color_component_class); widget_class = GTK_WIDGET_CLASS (color_component_class); /* GtkWidget signals */ widget_class->expose_event = gtk_color_component_expose; widget_class->button_release_event = gtk_color_component_button_release; widget_class->button_press_event = gtk_color_component_button_press; widget_class->motion_notify_event = gtk_color_component_motion_notify; widget_class->size_request = gtk_color_component_size_request; g_type_class_add_private(obj_class, sizeof(GtkColorComponentPrivate)); obj_class->finalize = gtk_color_component_finalize; gtk_color_component_signals[COLOR_CHANGED] = g_signal_new( "color-changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkColorComponentClass, color_changed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); gtk_color_component_signals[INPUT_CLICKED] = g_signal_new( "input-clicked", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkColorComponentClass, input_clicked), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); } static void gtk_color_component_init (GtkColorComponent *color_component){ gtk_widget_add_events (GTK_WIDGET (color_component), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK); } static void gtk_color_component_finalize(GObject *color_obj){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_obj); for (int i = 0; i != sizeof(ns->text) / sizeof(gchar*); i++){ if (ns->text[i]){ g_free(ns->text[i]); ns->text[i] = 0; } } if (ns->pattern_surface) cairo_surface_destroy(ns->pattern_surface); if (ns->pattern) cairo_pattern_destroy(ns->pattern); gpointer parent_class = g_type_class_peek_parent(G_OBJECT_CLASS(GTK_COLOR_COMPONENT_GET_CLASS(color_obj))); G_OBJECT_CLASS(parent_class)->finalize(color_obj); } GtkWidget *gtk_color_component_new (GtkColorComponentComp component){ GtkWidget* widget = (GtkWidget*)g_object_new(GTK_TYPE_COLOR_COMPONENT, NULL); GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); gchar* pattern_filename = build_filename("gpick-gray-pattern.png"); ns->pattern_surface = cairo_image_surface_create_from_png(pattern_filename); g_free(pattern_filename); ns->pattern = cairo_pattern_create_for_surface(ns->pattern_surface); cairo_pattern_set_extend(ns->pattern, CAIRO_EXTEND_REPEAT); ns->component = component; ns->last_event_position = -1; ns->changing_color = false; ns->lab_illuminant = REFERENCE_ILLUMINANT_D50; ns->lab_observer= REFERENCE_OBSERVER_2; ns->out_of_gamut_mask = false; for (int i = 0; i != sizeof(ns->text) / sizeof(gchar*); i++){ ns->text[i] = 0; } for (int i = 0; i != sizeof(ns->label) / sizeof(const char*[2]); i++){ ns->label[i][0] = 0; ns->label[i][1] = 0; } switch (component){ case lab: ns->n_components = 3; ns->range[0] = 100; ns->offset[0] = 0; ns->range[1] = ns->range[2] = 290; ns->offset[1] = ns->offset[2] = -145; break; case lch: ns->n_components = 3; ns->range[0] = 100; ns->offset[0] = 0; ns->range[1] = 136; ns->range[2] = 360; ns->offset[1] = ns->offset[2] = 0; break; case xyz: break; case cmyk: ns->n_components = 4; ns->range[0] = ns->range[1] = ns->range[2] = ns->range[3] = 1; ns->offset[0] = ns->offset[1] = ns->offset[2] = ns->offset[3] = 0; break; default: ns->n_components = 3; ns->range[0] = ns->range[1] = ns->range[2] = ns->range[3] = 1; ns->offset[0] = ns->offset[1] = ns->offset[2] = ns->offset[3] = 0; } gtk_widget_set_size_request(GTK_WIDGET(widget), 242, 16 * ns->n_components); return widget; } void gtk_color_component_get_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(&ns->orig_color, color); } void gtk_color_component_get_transformed_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(&ns->color, color); } void gtk_color_component_set_transformed_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(color, &ns->color); update_rgb_color(ns, &ns->orig_color); gtk_widget_queue_draw(GTK_WIDGET(color_component)); } int gtk_color_component_get_component_id_at(GtkColorComponent* color_component, gint x, gint y){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); int component = y / 16; if (component < 0) component = 0; else if (component >= ns->n_components) component = ns->n_components - 1; return component; } const char* gtk_color_component_get_text(GtkColorComponent* color_component, gint component_id){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); return ns->text[component_id]; } void gtk_color_component_set_text(GtkColorComponent* color_component, const char **text){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); for (int i = 0; i != sizeof(ns->text) / sizeof(gchar*); i++){ if (!text[i]) break; if (ns->text[i]){ g_free(ns->text[i]); } ns->text[i] = g_strdup(text[i]); } gtk_widget_queue_draw(GTK_WIDGET(color_component)); } void gtk_color_component_set_label(GtkColorComponent* color_component, const char **label){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); for (int i = 0; i != MaxNumberOfComponents * 2; i++){ if (!label[i]) break; ns->label[i >> 1][i & 1] = label[i]; } gtk_widget_queue_draw(GTK_WIDGET(color_component)); } void gtk_color_component_set_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(color, &ns->orig_color); switch (ns->component){ case rgb: color_copy(&ns->orig_color, &ns->color); break; case hsl: color_rgb_to_hsl(&ns->orig_color, &ns->color); break; case hsv: color_rgb_to_hsv(&ns->orig_color, &ns->color); break; case cmyk: color_rgb_to_cmyk(&ns->orig_color, &ns->color); break; case lab: { matrix3x3 adaptation_matrix; color_get_chromatic_adaptation_matrix(color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), color_get_reference(ns->lab_illuminant, ns->lab_observer), &adaptation_matrix); color_rgb_to_lab(&ns->orig_color, &ns->color, color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_sRGB_transformation_matrix(), &adaptation_matrix); } break; case xyz: /* todo */ break; case lch: { matrix3x3 adaptation_matrix; color_get_chromatic_adaptation_matrix(color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), color_get_reference(ns->lab_illuminant, ns->lab_observer), &adaptation_matrix); color_rgb_to_lch(&ns->orig_color, &ns->color, color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_sRGB_transformation_matrix(), &adaptation_matrix); } break; } gtk_widget_queue_draw(GTK_WIDGET(color_component)); } static void interpolate_colors(Color *color1, Color *color2, float position, Color *result){ result->rgb.red = color1->rgb.red * (1 - position) + color2->rgb.red * position; result->rgb.green= color1->rgb.green * (1 - position) + color2->rgb.green * position; result->rgb.blue = color1->rgb.blue * (1 - position) + color2->rgb.blue * position; } static void gtk_color_component_size_request (GtkWidget *widget, GtkRequisition *requisition){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); gint width = 240 + widget->style->xthickness * 2; gint height = ns->n_components * 16 + widget->style->ythickness * 2; requisition->width = width; requisition->height = height; } static gboolean gtk_color_component_expose (GtkWidget *widget, GdkEventExpose *event){ cairo_t *cr; GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); Color c[MaxNumberOfComponents]; double pointer_pos[MaxNumberOfComponents]; float steps; int i, j; for (int i = 0; i < ns->n_components; ++i){ pointer_pos[i] = (ns->color.ma[i] - ns->offset[i]) / ns->range[i]; } cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, ns->n_components * 16); unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_image_surface_get_stride(surface); int surface_width = cairo_image_surface_get_width(surface); unsigned char *col_ptr; Color *rgb_points = new Color[ns->n_components * 200]; double int_part; matrix3x3 adaptation_matrix; vector > out_of_gamut(MaxNumberOfComponents, vector(false, 1)); switch (ns->component) { case rgb: steps = 1; for (i = 0; i < 3; ++i){ color_copy(&ns->color, &c[i]); } for (i = 0; i < surface_width; ++i){ c[0].rgb.red = c[1].rgb.green = c[2].rgb.blue = (float)i / (float)(surface_width - 1); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; case hsv: steps = 100; for (i = 0; i < 3; ++i){ color_copy(&ns->color, &c[i]); } for (i = 0; i <= steps; ++i){ c[0].hsv.hue = c[1].hsv.saturation = c[2].hsv.value = i / steps; for (j = 0; j < 3; ++j){ color_hsv_to_rgb(&c[j], &rgb_points[j * (int(steps) + 1) + i]); } } for (i = 0; i < surface_width; ++i){ float position = modf(i * steps / surface_width, &int_part); int index = i * int(steps) / surface_width; interpolate_colors(&rgb_points[0 * (int(steps) + 1) + index], &rgb_points[0 * (int(steps) + 1) + index + 1], position, &c[0]); interpolate_colors(&rgb_points[1 * (int(steps) + 1) + index], &rgb_points[1 * (int(steps) + 1) + index + 1], position, &c[1]); interpolate_colors(&rgb_points[2 * (int(steps) + 1) + index], &rgb_points[2 * (int(steps) + 1) + index + 1], position, &c[2]); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; case hsl: steps = 100; for (i = 0; i < 3; ++i){ color_copy(&ns->color, &c[i]); } for (i = 0; i <= steps; ++i){ c[0].hsl.hue = c[1].hsl.saturation = c[2].hsl.lightness = i / steps; for (j = 0; j < 3; ++j){ color_hsl_to_rgb(&c[j], &rgb_points[j * (int(steps) + 1) + i]); } } for (i = 0; i < surface_width; ++i){ float position = modf(i * steps / surface_width, &int_part); int index = i * int(steps) / surface_width; interpolate_colors(&rgb_points[0 * (int(steps) + 1) + index], &rgb_points[0 * (int(steps) + 1) + index + 1], position, &c[0]); interpolate_colors(&rgb_points[1 * (int(steps) + 1) + index], &rgb_points[1 * (int(steps) + 1) + index + 1], position, &c[1]); interpolate_colors(&rgb_points[2 * (int(steps) + 1) + index], &rgb_points[2 * (int(steps) + 1) + index + 1], position, &c[2]); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; case cmyk: steps = 100; for (i = 0; i < 4; ++i){ color_copy(&ns->color, &c[i]); } for (i = 0; i <= steps; ++i){ c[0].cmyk.c = c[1].cmyk.m = c[2].cmyk.y = c[3].cmyk.k = i / steps; for (j = 0; j < 4; ++j){ color_cmyk_to_rgb(&c[j], &rgb_points[j * (int(steps) + 1) + i]); } } for (i = 0; i < surface_width; ++i){ float position = modf(i * steps / surface_width, &int_part); int index = i * int(steps) / surface_width; interpolate_colors(&rgb_points[0 * (int(steps) + 1) + index], &rgb_points[0 * (int(steps) + 1) + index + 1], position, &c[0]); interpolate_colors(&rgb_points[1 * (int(steps) + 1) + index], &rgb_points[1 * (int(steps) + 1) + index + 1], position, &c[1]); interpolate_colors(&rgb_points[2 * (int(steps) + 1) + index], &rgb_points[2 * (int(steps) + 1) + index + 1], position, &c[2]); interpolate_colors(&rgb_points[3 * (int(steps) + 1) + index], &rgb_points[3 * (int(steps) + 1) + index + 1], position, &c[3]); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; case lab: steps = 100; color_get_chromatic_adaptation_matrix(color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &adaptation_matrix); for (j = 0; j < 3; ++j){ color_copy(&ns->color, &c[j]); out_of_gamut[j] = vector(steps + 1, false); for (i = 0; i <= steps; ++i){ c[j].ma[j] = (i / steps) * ns->range[j] + ns->offset[j]; color_lab_to_rgb(&c[j], &rgb_points[j * (int(steps) + 1) + i], color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_inverted_sRGB_transformation_matrix(), &adaptation_matrix); if (color_is_rgb_out_of_gamut(&rgb_points[j * (int(steps) + 1) + i])){ out_of_gamut[j][i] = true; } color_rgb_normalize(&rgb_points[j * (int(steps) + 1) + i]); } } for (i = 0; i < surface_width; ++i){ float position = modf(i * steps / surface_width, &int_part); int index = i * int(steps) / surface_width; interpolate_colors(&rgb_points[0 * (int(steps) + 1) + index], &rgb_points[0 * (int(steps) + 1) + index + 1], position, &c[0]); interpolate_colors(&rgb_points[1 * (int(steps) + 1) + index], &rgb_points[1 * (int(steps) + 1) + index + 1], position, &c[1]); interpolate_colors(&rgb_points[2 * (int(steps) + 1) + index], &rgb_points[2 * (int(steps) + 1) + index + 1], position, &c[2]); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; case lch: steps = 100; color_get_chromatic_adaptation_matrix(color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &adaptation_matrix); for (j = 0; j < 3; ++j){ color_copy(&ns->color, &c[j]); out_of_gamut[j] = vector(steps + 1, false); for (i = 0; i <= steps; ++i){ c[j].ma[j] = (i / steps) * ns->range[j] + ns->offset[j]; color_lch_to_rgb(&c[j], &rgb_points[j * (int(steps) + 1) + i], color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_inverted_sRGB_transformation_matrix(), &adaptation_matrix); if (color_is_rgb_out_of_gamut(&rgb_points[j * (int(steps) + 1) + i])){ out_of_gamut[j][i] = true; } color_rgb_normalize(&rgb_points[j * (int(steps) + 1) + i]); } } for (i = 0; i < surface_width; ++i){ float position = modf(i * steps / surface_width, &int_part); int index = i * int(steps) / surface_width; interpolate_colors(&rgb_points[0 * (int(steps) + 1) + index], &rgb_points[0 * (int(steps) + 1) + index + 1], position, &c[0]); interpolate_colors(&rgb_points[1 * (int(steps) + 1) + index], &rgb_points[1 * (int(steps) + 1) + index + 1], position, &c[1]); interpolate_colors(&rgb_points[2 * (int(steps) + 1) + index], &rgb_points[2 * (int(steps) + 1) + index + 1], position, &c[2]); col_ptr = data + i * 4; for (int y = 0; y < ns->n_components * 16; ++y){ if ((y & 0x0f) != 0x0f){ col_ptr[2] = (unsigned char)(c[y / 16].rgb.red * 255); col_ptr[1] = (unsigned char)(c[y / 16].rgb.green * 255); col_ptr[0] = (unsigned char)(c[y / 16].rgb.blue * 255); col_ptr[3] = 0xff; }else{ col_ptr[0] = 0x00; col_ptr[1] = 0x00; col_ptr[2] = 0x00; col_ptr[3] = 0x00; } col_ptr += stride; } } break; default: break; } delete [] rgb_points; cairo_surface_mark_dirty(surface); cairo_save(cr); int offset_x = widget->allocation.width - widget->style->xthickness * 2 - 240; cairo_set_source_surface(cr, surface, offset_x, 0); cairo_surface_destroy(surface); for (i = 0; i < ns->n_components; ++i){ cairo_rectangle(cr, offset_x, 16 * i, 200, 15); cairo_fill(cr); } cairo_restore(cr); for (i = 0; i < ns->n_components; ++i){ cairo_matrix_t matrix; cairo_matrix_init_translate(&matrix, -offset_x - 64, -64 + 5 * i); cairo_pattern_set_matrix(ns->pattern, &matrix); if (ns->out_of_gamut_mask){ int first_out_of_gamut = 0; bool out_of_gamut_found = false; cairo_matrix_t matrix; cairo_set_source(cr, ns->pattern); for (int j = 0; j < out_of_gamut[i].size(); j++){ if (out_of_gamut[i][j]){ if (!out_of_gamut_found){ out_of_gamut_found = true; first_out_of_gamut = j; } }else{ if (out_of_gamut_found){ cairo_rectangle(cr, offset_x + (first_out_of_gamut * 200.0 / out_of_gamut[i].size()), 16 * i, (j - first_out_of_gamut) * 200.0 / out_of_gamut[i].size(), 15); cairo_fill(cr); out_of_gamut_found = false; } } } if (out_of_gamut_found){ cairo_rectangle(cr, offset_x + (first_out_of_gamut * 200.0 / out_of_gamut[i].size()), 16 * i, (out_of_gamut[i].size() - first_out_of_gamut) * 200.0 / out_of_gamut[i].size(), 15); cairo_fill(cr); } } cairo_move_to(cr, offset_x + 200 * pointer_pos[i], 16 * i + 9); cairo_line_to(cr, offset_x + 200 * pointer_pos[i] + 3, 16 * i + 16); cairo_line_to(cr, offset_x + 200 * pointer_pos[i] - 3, 16 * i + 16); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill_preserve(cr); cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 1); cairo_stroke(cr); if (ns->text[i] || ns->label[i]){ PangoLayout *layout; PangoFontDescription *font_description; font_description = pango_font_description_new(); layout = pango_cairo_create_layout(cr); pango_font_description_set_family(font_description, "sans"); pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_absolute_size(font_description, 12 * PANGO_SCALE); pango_layout_set_font_description(layout, font_description); pango_layout_set_wrap(layout, PANGO_WRAP_WORD); pango_layout_set_single_paragraph_mode(layout, true); gdk_cairo_set_source_color(cr, &widget->style->text[0]); int width, height; if (ns->text[i]){ pango_layout_set_text(layout, ns->text[i], -1); pango_layout_set_width(layout, 40 * PANGO_SCALE); pango_layout_set_height(layout, 16 * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); pango_cairo_update_layout(cr, layout); pango_layout_get_pixel_size(layout, &width, &height); cairo_move_to(cr, 200 + offset_x, i * 16); pango_cairo_show_layout(cr, layout); } if (ns->label[i] && offset_x > 10){ if (offset_x > 50){ pango_layout_set_text(layout, ns->label[i][1], -1); }else{ pango_layout_set_text(layout, ns->label[i][0], -1); } pango_layout_set_width(layout, (offset_x - 10) * PANGO_SCALE); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); pango_layout_set_height(layout, 16 * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); pango_cairo_update_layout(cr, layout); pango_layout_get_pixel_size(layout, &width, &height); cairo_move_to(cr, 5, i * 16); pango_cairo_show_layout(cr, layout); } g_object_unref(layout); pango_font_description_free(font_description); } } cairo_destroy(cr); return TRUE; } GtkColorComponentComp gtk_color_component_get_component(GtkColorComponent* color_component){ return GTK_COLOR_COMPONENT_GET_PRIVATE(color_component)->component; } static void update_rgb_color(GtkColorComponentPrivate *ns, Color *c){ switch (ns->component) { case rgb: color_copy(&ns->color, c); color_rgb_normalize(c); break; case hsv: color_hsv_to_rgb(&ns->color, c); color_rgb_normalize(c); break; case hsl: color_hsl_to_rgb(&ns->color, c); color_rgb_normalize(c); break; case cmyk: color_cmyk_to_rgb(&ns->color, c); color_rgb_normalize(c); break; case lab: { matrix3x3 adaptation_matrix; color_get_chromatic_adaptation_matrix(color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &adaptation_matrix); color_lab_to_rgb(&ns->color, c, color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_inverted_sRGB_transformation_matrix(), &adaptation_matrix); color_rgb_normalize(c); } break; case xyz: /* TODO */ break; case lch: { matrix3x3 adaptation_matrix; color_get_chromatic_adaptation_matrix(color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_reference(REFERENCE_ILLUMINANT_D65, REFERENCE_OBSERVER_2), &adaptation_matrix); color_lch_to_rgb(&ns->color, c, color_get_reference(ns->lab_illuminant, ns->lab_observer), color_get_inverted_sRGB_transformation_matrix(), &adaptation_matrix); color_rgb_normalize(c); } break; } } void gtk_color_component_get_raw_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(&ns->color, color); } void gtk_color_component_set_raw_color(GtkColorComponent* color_component, Color* color){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); color_copy(color, &ns->color); Color c; update_rgb_color(ns, &c); color_copy(&c, &ns->orig_color); gtk_widget_queue_draw(GTK_WIDGET(color_component)); g_signal_emit(GTK_WIDGET(color_component), gtk_color_component_signals[COLOR_CHANGED], 0, &c); } static void gtk_color_component_emit_color_change(GtkWidget *widget, int component, double value){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); Color c; ns->color.ma[component] = value * ns->range[component] + ns->offset[component]; update_rgb_color(ns, &c); g_signal_emit(widget, gtk_color_component_signals[COLOR_CHANGED], 0, &c); } static gboolean gtk_color_component_button_release (GtkWidget *widget, GdkEventButton *event){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); gdk_pointer_ungrab(GDK_CURRENT_TIME); ns->changing_color = false; return false; } static gboolean gtk_color_component_button_press (GtkWidget *widget, GdkEventButton *event){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); if ((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){ int component = event->y / 16; if (component < 0) component = 0; else if (component >= ns->n_components) component = ns->n_components - 1; int offset_x = widget->allocation.width - widget->style->xthickness * 2 - 240; if (event->x < offset_x || event->x > 200 + offset_x) { g_signal_emit(widget, gtk_color_component_signals[INPUT_CLICKED], 0, component); return FALSE; } ns->changing_color = true; ns->last_event_position = event->x; double value; value = (event->x - offset_x) / 200.0; if (value < 0) value = 0; else if (value > 1) value = 1; ns->capture_on = component; gdk_pointer_grab(gtk_widget_get_window(widget), false, GdkEventMask(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, NULL, GDK_CURRENT_TIME); gtk_color_component_emit_color_change(widget, component, value); gtk_widget_queue_draw(widget); return TRUE; } return FALSE; } static gboolean gtk_color_component_motion_notify (GtkWidget *widget, GdkEventMotion *event){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(widget); if (ns->changing_color && (event->state & GDK_BUTTON1_MASK)){ int offset_x = widget->allocation.width - widget->style->xthickness * 2 - 240; if ((event->x < offset_x && ns->last_event_position < offset_x) || ((event->x > 200 + offset_x) && (ns->last_event_position > 200 + offset_x))) return FALSE; ns->last_event_position = event->x; double value; value = (event->x - offset_x) / 200.0; if (value < 0) value = 0; else if (value > 1) value = 1; /*int component = event->y / 16; if (component < 0) component = 0; else if (component >= ns->n_components) component = ns->n_components - 1;*/ gtk_color_component_emit_color_change(widget, ns->capture_on, value); gtk_widget_queue_draw(widget); return TRUE; } return FALSE; } void gtk_color_component_set_lab_illuminant(GtkColorComponent* color_component, ReferenceIlluminant illuminant){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); ns->lab_illuminant = illuminant; gtk_color_component_set_color(color_component, &ns->orig_color); gtk_widget_queue_draw(GTK_WIDGET(color_component)); } void gtk_color_component_set_lab_observer(GtkColorComponent* color_component, ReferenceObserver observer){ GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); ns->lab_observer = observer; gtk_color_component_set_color(color_component, &ns->orig_color); gtk_widget_queue_draw(GTK_WIDGET(color_component)); } void gtk_color_component_set_out_of_gamut_mask(GtkColorComponent* color_component, bool mask_enabled) { GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); ns->out_of_gamut_mask = mask_enabled; gtk_widget_queue_draw(GTK_WIDGET(color_component)); } bool gtk_color_component_get_out_of_gamut_mask(GtkColorComponent* color_component) { GtkColorComponentPrivate *ns = GTK_COLOR_COMPONENT_GET_PRIVATE(color_component); return ns->out_of_gamut_mask; } gpick_0.2.5/source/gtk/SConscript0000644000175000017500000000060412070605214015501 0ustar zbygzbyg#!/usr/bin/env python import os import sys 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') sources = local_env.Glob('*.cpp') objects = local_env.StaticObject( source = [sources]) Return('objects') gpick_0.2.5/source/gtk/ColorWheel.cpp0000644000175000017500000004212312070605214016240 0ustar zbygzbyg/* * 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 "ColorWheel.h" #include "../Color.h" #include "../ColorWheelType.h" #include "../MathUtil.h" #include #ifdef _MSC_VER #define M_PI 3.14159265359 #endif #include #include #include using namespace std; #define GTK_COLOR_WHEEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_WHEEL, GtkColorWheelPrivate)) G_DEFINE_TYPE (GtkColorWheel, gtk_color_wheel, GTK_TYPE_DRAWING_AREA); static GtkWindowClass *parent_class = NULL; static gboolean gtk_color_wheel_expose(GtkWidget *color_wheel, GdkEventExpose *event); static gboolean gtk_color_wheel_button_release(GtkWidget *color_wheel, GdkEventButton *event); static gboolean gtk_color_wheel_button_press(GtkWidget *color_wheel, GdkEventButton *event); static gboolean gtk_color_wheel_motion_notify(GtkWidget *widget, GdkEventMotion *event); enum { HUE_CHANGED, SATURATION_VALUE_CHANGED, LAST_SIGNAL }; static guint gtk_color_wheel_signals[LAST_SIGNAL] = { 0 }; typedef struct ColorPoint{ double hue; double lightness; double saturation; }ColorPoint; typedef struct GtkColorWheelPrivate{ ColorPoint cpoint[10]; uint32_t n_cpoint; ColorPoint *grab_active; bool grab_block; ColorPoint *selected; int active_color; double radius; double circle_width; double block_size; bool block_editable; const ColorWheelType *color_wheel_type; cairo_surface_t *cache_color_wheel; }GtkColorWheelPrivate; static uint32_t get_color_index(GtkColorWheelPrivate *ns, ColorPoint *cp); static void gtk_color_wheel_finalize(GObject *color_wheel_obj){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel_obj); if (ns->cache_color_wheel){ cairo_surface_destroy(ns->cache_color_wheel); ns->cache_color_wheel = 0; } G_OBJECT_CLASS(parent_class)->finalize(color_wheel_obj); } static void gtk_color_wheel_class_init(GtkColorWheelClass *color_wheel_class) { GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS(color_wheel_class); widget_class = GTK_WIDGET_CLASS(color_wheel_class); /* GtkWidget signals */ widget_class->expose_event = gtk_color_wheel_expose; widget_class->button_release_event = gtk_color_wheel_button_release; widget_class->button_press_event = gtk_color_wheel_button_press; widget_class->motion_notify_event = gtk_color_wheel_motion_notify; parent_class = (GtkWindowClass*)g_type_class_peek_parent(G_OBJECT_CLASS(color_wheel_class)); obj_class->finalize = gtk_color_wheel_finalize; g_type_class_add_private(obj_class, sizeof(GtkColorWheelPrivate)); gtk_color_wheel_signals[HUE_CHANGED] = g_signal_new("hue_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkColorWheelClass, hue_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); gtk_color_wheel_signals[SATURATION_VALUE_CHANGED] = g_signal_new("saturation_value_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkColorWheelClass, saturation_value_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); } static void gtk_color_wheel_init(GtkColorWheel *color_wheel){ gtk_widget_add_events(GTK_WIDGET(color_wheel), GDK_2BUTTON_PRESS | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); } GtkWidget* gtk_color_wheel_new(){ GtkWidget* widget = (GtkWidget*) g_object_new(GTK_TYPE_COLOR_WHEEL, NULL); GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(widget); ns->active_color = 1; ns->radius = 80; ns->circle_width = 14; ns->block_size = 2 * (ns->radius - ns->circle_width) * sin(M_PI / 4) - 8; gtk_widget_set_size_request(GTK_WIDGET(widget), ns->radius * 2 + widget->style->xthickness*2, ns->radius * 2 + widget->style->ythickness*2); ns->n_cpoint = 0; ns->grab_active = 0; ns->grab_block = false; ns->selected = &ns->cpoint[0]; ns->block_editable = true; ns->color_wheel_type = &color_wheel_types_get()[0]; ns->cache_color_wheel = 0; GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS); return widget; } void gtk_color_wheel_set_color_wheel_type(GtkColorWheel *color_wheel, const ColorWheelType *color_wheel_type){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (ns->color_wheel_type != color_wheel_type){ ns->color_wheel_type = color_wheel_type; if (ns->cache_color_wheel){ cairo_surface_destroy(ns->cache_color_wheel); ns->cache_color_wheel = 0; } gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } void gtk_color_wheel_set_block_editable(GtkColorWheel* color_wheel, bool editable){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); ns->block_editable = editable; } bool gtk_color_wheel_get_block_editable(GtkColorWheel* color_wheel){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); return ns->block_editable; } void gtk_color_wheel_set_selected(GtkColorWheel* color_wheel, guint32 index){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ ns->selected = &ns->cpoint[index]; gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } void gtk_color_wheel_set_n_colors(GtkColorWheel* color_wheel, guint32 number_of_colors){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (number_of_colors <= 10){ if (ns->n_cpoint != number_of_colors){ ns->n_cpoint = number_of_colors; if (ns->selected){ uint32_t index = get_color_index(ns, ns->selected); if (index >= number_of_colors){ ns->selected = &ns->cpoint[0]; } } gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } } void gtk_color_wheel_set_hue(GtkColorWheel* color_wheel, guint32 index, double hue){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ ns->cpoint[index].hue = hue; gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } void gtk_color_wheel_set_saturation(GtkColorWheel* color_wheel, guint32 index, double saturation){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ ns->cpoint[index].saturation = saturation; if (&ns->cpoint[index] == ns->selected) gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } void gtk_color_wheel_set_value(GtkColorWheel* color_wheel, guint32 index, double value){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ ns->cpoint[index].lightness = value; if (&ns->cpoint[index] == ns->selected) gtk_widget_queue_draw(GTK_WIDGET(color_wheel)); } } double gtk_color_wheel_get_hue(GtkColorWheel* color_wheel, guint32 index){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ return ns->cpoint[index].hue; } return 0; } double gtk_color_wheel_get_saturation(GtkColorWheel* color_wheel, guint32 index){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ return ns->cpoint[index].saturation; } return 0; } double gtk_color_wheel_get_value(GtkColorWheel* color_wheel, guint32 index){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); if (index < 10){ return ns->cpoint[index].lightness; } return 0; } static void draw_dot(cairo_t *cr, double x, double y, double size){ cairo_arc(cr, x, y, size - 1, 0, 2 * M_PI); cairo_set_source_rgba(cr, 1, 1, 1, 0.5); cairo_set_line_width(cr, 2); cairo_stroke(cr); cairo_arc(cr, x, y, size, 0, 2 * M_PI); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_set_line_width(cr, 1); cairo_stroke(cr); } static void draw_sat_val_block(cairo_t *cr, double pos_x, double pos_y, double size, double hue){ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(size), ceil(size)); unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_image_surface_get_stride(surface); int surface_width = cairo_image_surface_get_width(surface); int surface_height = cairo_image_surface_get_height(surface); Color c; unsigned char *line_data; for (int y = 0; y < surface_height; ++y){ line_data = data + stride * y; for (int x = 0; x < surface_width; ++x){ c.hsv.hue = hue; c.hsv.saturation = x / size; c.hsv.value = y / size; color_hsv_to_rgb(&c, &c); line_data[2] = c.rgb.red * 255; line_data[1] = c.rgb.green * 255; line_data[0] = c.rgb.blue * 255; line_data[3] = 0xFF; line_data += 4; } } cairo_surface_mark_dirty(surface); cairo_save(cr); cairo_set_source_surface(cr, surface, pos_x - size / 2, pos_y - size / 2); cairo_surface_destroy(surface); cairo_rectangle(cr, pos_x - size / 2, pos_y - size / 2, size, size); cairo_fill(cr); cairo_restore(cr); } static void draw_wheel(GtkColorWheelPrivate *ns, cairo_t *cr, double radius, double width, const ColorWheelType *wheel){ cairo_surface_t *surface; double inner_radius = radius - width; if (ns->cache_color_wheel){ surface = ns->cache_color_wheel; }else{ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(radius * 2), ceil(radius * 2)); if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS){ cerr << "ColorWheel image surface allocation failed" << endl; return; } unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_image_surface_get_stride(surface); int surface_width = cairo_image_surface_get_width(surface); int surface_height = cairo_image_surface_get_height(surface); double radius_sq = radius * radius + 2 * radius + 1; double inner_radius_sq = inner_radius * inner_radius - 2 * inner_radius + 1; Color c; unsigned char *line_data; for (int y = 0; y < surface_height; ++y){ line_data = data + stride * y; for (int x = 0; x < surface_width; ++x){ int dx = -(x - surface_width / 2); int dy = y - surface_height / 2; int dist = dx * dx + dy * dy; if ((dist >= inner_radius_sq) && (dist <= radius_sq)){ double angle = atan2((double)dx, (double)dy) + M_PI; wheel->hue_to_hsl(angle / (M_PI * 2), &c); color_hsl_to_rgb(&c, &c); line_data[2] = c.rgb.red * 255; line_data[1] = c.rgb.green * 255; line_data[0] = c.rgb.blue * 255; line_data[3] = 0xFF; } line_data += 4; } } ns->cache_color_wheel = surface; } cairo_surface_mark_dirty(surface); cairo_save(cr); cairo_set_source_surface(cr, surface, 0, 0); //cairo_surface_destroy(surface); cairo_set_line_width(cr, width); cairo_new_path(cr); cairo_arc(cr, radius, radius, (inner_radius + radius) / 2, 0, M_PI * 2); cairo_stroke(cr); cairo_restore(cr); } static bool is_inside_block(GtkColorWheelPrivate *ns, gint x, gint y){ double size = ns->block_size; if ((x >= ns->radius - size / 2) && (x <= ns->radius + size / 2)){ if ((y >= ns->radius - size / 2) && (y <= ns->radius + size / 2)){ return true; } } return false; } static ColorPoint* get_cpoint_at(GtkColorWheelPrivate *ns, gint x, gint y){ double dx, dy; for (uint32_t i = 0; i != ns->n_cpoint; i++){ dx = ns->radius + (ns->radius - ns->circle_width / 2) * sin(ns->cpoint[i].hue * M_PI * 2) - x; dy = ns->radius - (ns->radius - ns->circle_width / 2) * cos(ns->cpoint[i].hue * M_PI * 2) - y; if (sqrt(dx * dx + dy * dy) < 16){ return &ns->cpoint[i]; } } return 0; } static uint32_t get_color_index(GtkColorWheelPrivate *ns, ColorPoint *cp){ return (uint64_t(cp) - uint64_t(ns)) / sizeof(ColorPoint); } int gtk_color_wheel_get_at(GtkColorWheel *color_wheel, int x, int y){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(color_wheel); ColorPoint *cp = get_cpoint_at(ns, x, y); if (cp){ return get_color_index(ns, cp); } if (is_inside_block(ns, x, y)) return -1; return -2; } static gboolean gtk_color_wheel_motion_notify(GtkWidget *widget, GdkEventMotion *event){ GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(widget); if (ns->grab_active){ double dx = -((event->x - widget->style->xthickness) - ns->radius); double dy = (event->y - widget->style->ythickness) - ns->radius; double angle = atan2(dx, dy) + M_PI; ns->grab_active->hue = angle / (M_PI * 2); g_signal_emit(widget, gtk_color_wheel_signals[HUE_CHANGED], 0, get_color_index(ns, ns->grab_active)); gtk_widget_queue_draw(widget); return true; }else if (ns->grab_block){ double dx = (event->x - widget->style->xthickness) - ns->radius + ns->block_size / 2; double dy = (event->y - widget->style->ythickness) - ns->radius + ns->block_size / 2; ns->selected->saturation = clamp_float(dx / ns->block_size, 0, 1); ns->selected->lightness = clamp_float(dy / ns->block_size, 0, 1); g_signal_emit(widget, gtk_color_wheel_signals[SATURATION_VALUE_CHANGED], 0, get_color_index(ns, ns->selected)); gtk_widget_queue_draw(widget); return true; } /* ColorPoint *p = get_cpoint_at(ns, event->x, event->y); if (p){ GdkCursor *grab = gdk_cursor_new(GDK_HAND2); gdk_window_set_cursor(gtk_widget_get_window(widget), grab); gdk_cursor_destroy(grab); } */ return false; } static gboolean gtk_color_wheel_expose(GtkWidget *widget, GdkEventExpose *event){ GtkStateType state; if (GTK_WIDGET_HAS_FOCUS (widget)) state = GTK_STATE_SELECTED; else state = GTK_STATE_ACTIVE; cairo_t *cr; GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(widget); /* if (GTK_WIDGET_HAS_FOCUS(widget)){ gtk_paint_focus(widget->style, widget->window, state, &event->area, widget, 0, widget->style->xthickness, widget->style->ythickness, 150, 150); }*/ cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); cairo_translate(cr, widget->style->xthickness + 0.5, widget->style->ythickness + 0.5); draw_wheel(ns, cr, ns->radius, ns->circle_width, ns->color_wheel_type); if (ns->selected){ double block_size = 2 * (ns->radius - ns->circle_width) * sin(M_PI / 4) - 6; Color hsl; ns->color_wheel_type->hue_to_hsl(ns->selected->hue, &hsl); draw_sat_val_block(cr, ns->radius, ns->radius, block_size, hsl.hsl.hue); draw_dot(cr, ns->radius - block_size / 2 + block_size * ns->selected->saturation, ns->radius - block_size / 2 + block_size * ns->selected->lightness, 4); } for (uint32_t i = 0; i != ns->n_cpoint; i++){ draw_dot(cr, ns->radius + (ns->radius - ns->circle_width / 2) * sin(ns->cpoint[i].hue * M_PI * 2), ns->radius - (ns->radius - ns->circle_width / 2) * cos(ns->cpoint[i].hue * M_PI * 2), (&ns->cpoint[i] == ns->selected) ? 7 : 4); } cairo_destroy(cr); return FALSE; } static gboolean gtk_color_wheel_button_press(GtkWidget *widget, GdkEventButton *event) { GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(widget); gint x = event->x - widget->style->xthickness; gint y = event->y - widget->style->ythickness; gtk_widget_grab_focus(widget); ColorPoint *p; if (is_inside_block(ns, x, y)){ if ((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){ if (ns->block_editable && ns->selected){ ns->grab_block = true; GdkCursor *cursor = gdk_cursor_new(GDK_CROSS); gdk_pointer_grab(gtk_widget_get_window(widget), false, GdkEventMask(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, cursor, GDK_CURRENT_TIME); gdk_cursor_destroy(cursor); return true; } } }else if ((p = get_cpoint_at(ns, x, y))){ if ((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){ ns->grab_active = p; ns->selected = p; GdkCursor *cursor = gdk_cursor_new(GDK_CROSS); gdk_pointer_grab(gtk_widget_get_window(widget), false, GdkEventMask(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, cursor, GDK_CURRENT_TIME); gdk_cursor_destroy(cursor); return true; } } return false; } static gboolean gtk_color_wheel_button_release(GtkWidget *widget, GdkEventButton *event) { GtkColorWheelPrivate *ns = GTK_COLOR_WHEEL_GET_PRIVATE(widget); gdk_pointer_ungrab(GDK_CURRENT_TIME); ns->grab_active = 0; ns->grab_block = false; return false; } gpick_0.2.5/source/gtk/LayoutPreview.h0000644000175000017500000000766012070605214016470 0ustar zbygzbyg/* * 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 GTK_LAYOUTPREVIEW_H_ #define GTK_LAYOUTPREVIEW_H_ #include #include "../ColorObject.h" #include "../layout/System.h" #include "../transformation/Chain.h" G_BEGIN_DECLS #define GTK_TYPE_LAYOUT_PREVIEW (gtk_layout_preview_get_type ()) #define GTK_LAYOUT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LAYOUT_PREVIEW, GtkLayoutPreview)) #define GTK_LAYOUT_PREVIEW_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_LAYOUT_PREVIEW, GtkLayoutPreviewClass)) #define GTK_IS_LAYOUT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_LAYOUT_PREVIEW)) #define GTK_IS_LAYOUT_PREVIEW_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_LAYOUT_PREVIEW)) #define GTK_LAYOUT_PREVIEW_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_LAYOUT_PREVIEW, GtkLayoutPreviewClass)) typedef struct GtkLayoutPreview GtkLayoutPreview; typedef struct GtkLayoutPreviewClass GtkLayoutPreviewClass; typedef gpointer GtkLayoutPreviewObject; typedef struct GtkLayoutPreview { GtkDrawingArea parent; /* < private > */ }GtkLayoutPreview; typedef struct GtkLayoutPreviewClass { GtkDrawingAreaClass parent_class; void (* active_color_changed)(GtkWidget* widget, gint32 active_color, gpointer userdata); void (* color_changed)(GtkWidget* widget, gpointer userdata); void (* color_activated)(GtkWidget* widget, gpointer userdata); }GtkLayoutPreviewClass; GtkWidget* gtk_layout_preview_new(void); GType gtk_layout_preview_get_type(void); int gtk_layout_preview_set_system(GtkLayoutPreview* widget, layout::System* system); int gtk_layout_preview_set_color_at(GtkLayoutPreview* widget, Color* color, gdouble x, gdouble y); int gtk_layout_preview_set_focus_at(GtkLayoutPreview* widget, gdouble x, gdouble y); int gtk_layout_preview_set_focus_named(GtkLayoutPreview* widget, const char *name); int gtk_layout_preview_set_color_named(GtkLayoutPreview* widget, Color* color, const char *name); int gtk_layout_preview_get_current_color(GtkLayoutPreview* widget, Color* color); int gtk_layout_preview_set_current_color(GtkLayoutPreview* widget, Color* color); bool gtk_layout_preview_is_selected(GtkLayoutPreview* widget); bool gtk_layout_preview_is_editable(GtkLayoutPreview* widget); int gtk_layout_preview_get_current_style(GtkLayoutPreview* widget, layout::Style** style); void gtk_layout_preview_set_transformation_chain(GtkLayoutPreview* widget, transformation::Chain *chain); G_END_DECLS #endif /* GTK_LAYOUTPREVIEW_H_ */ gpick_0.2.5/source/gtk/Range2D.h0000644000175000017500000000553112070605214015066 0ustar zbygzbyg/* * 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 RANGE_2D_H_ #define RANGE_2D_H_ #include #include "../Color.h" G_BEGIN_DECLS #define GTK_TYPE_RANGE_2D (gtk_range_2d_get_type ()) #define GTK_RANGE_2D(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RANGE_2D, GtkRange2D)) #define GTK_RANGE_2D_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_RANGE_2D, GtkRange2DClass)) #define GTK_IS_RANGE_2D(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RANGE_2D)) #define GTK_IS_RANGE_2D_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_RANGE_2D)) #define GTK_RANGE_2D_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RANGE_2D, GtkRange2DClass)) typedef struct GtkRange2D GtkRange2D; typedef struct GtkRange2DClass GtkRange2DClass; typedef gpointer GtkRange2DObject; typedef struct GtkRange2D { GtkDrawingArea parent; /* < private > */ }GtkRange2D; typedef struct GtkRange2DClass{ GtkDrawingAreaClass parent_class; void (*values_changed)(GtkWidget *widget, gpointer userdata); }GtkRange2DClass; GtkWidget* gtk_range_2d_new(void); void gtk_range_2d_set_values(GtkRange2D *range_2d, double x, double y); void gtk_range_2d_set_axis(GtkRange2D *range_2d, const char *x, const char *y); double gtk_range_2d_get_x(GtkRange2D *range_2d); double gtk_range_2d_get_y(GtkRange2D *range_2d); GType gtk_range_2d_get_type(void); G_END_DECLS #endif /* RANGE_2D_H_ */ gpick_0.2.5/source/gtk/Zoomed.h0000644000175000017500000000655212070605214015105 0ustar zbygzbyg/* * 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 ZOOMED_H_ #define ZOOMED_H_ #include #include #include "../Color.h" #include "../Rect2.h" #include "../Vector2.h" G_BEGIN_DECLS #define GTK_TYPE_ZOOMED (gtk_zoomed_get_type ()) #define GTK_ZOOMED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ZOOMED, GtkZoomed)) #define GTK_ZOOMED_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_ZOOMED, GtkZoomedClass)) #define GTK_IS_ZOOMED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ZOOMED)) #define GTK_IS_ZOOMED_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_ZOOMED)) #define GTK_ZOOMED_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ZOOMED, GtkZoomedClass)) typedef struct GtkZoomed GtkZoomed; typedef struct GtkZoomedClass GtkZoomedClass; typedef gpointer GtkZoomedObject; typedef struct GtkZoomed { GtkDrawingArea parent; /* < private > */ }GtkZoomed; typedef struct GtkZoomedClass { GtkDrawingAreaClass parent_class; void (* color_changed)(GtkWidget* widget, Color* c, gpointer userdata); void (*activated)(GtkWidget* widget, gpointer userdata); }GtkZoomedClass; GtkWidget* gtk_zoomed_new (); void gtk_zoomed_set_zoom(GtkZoomed* zoomed, gfloat zoom); gfloat gtk_zoomed_get_zoom(GtkZoomed* zoomed); void gtk_zoomed_set_fade(GtkZoomed* zoomed, bool fade); int32_t gtk_zoomed_get_size(GtkZoomed *zoomed); void gtk_zoomed_set_size(GtkZoomed *zoomed, int32_t width_height); void gtk_zoomed_set_mark(GtkZoomed *zoomed, int index, math::Vec2& position); void gtk_zoomed_clear_mark(GtkZoomed *zoomed, int index); void gtk_zoomed_update(GtkZoomed* zoomed, math::Vec2& pointer, math::Vec2& screen_size, math::Vec2& offset, GdkPixbuf* pixbuf); void gtk_zoomed_get_screen_rect(GtkZoomed* zoomed, math::Vec2& pointer, math::Vec2& screen_size, math::Rect2 *rect); GType gtk_zoomed_get_type(void); G_END_DECLS #endif /* ZOOMED_H_ */ gpick_0.2.5/source/gtk/ColorCell.cpp0000644000175000017500000001757612070605214016071 0ustar zbygzbyg/* * 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 "ColorCell.h" #include "../ColorObject.h" #include static void custom_cell_renderer_color_init(CustomCellRendererColor *cellcolor); static void custom_cell_renderer_color_class_init(CustomCellRendererColorClass *klass); static void custom_cell_renderer_color_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *pspec); static void custom_cell_renderer_color_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec); static void custom_cell_renderer_color_finalize(GObject *gobject); static void custom_cell_renderer_color_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height); static void custom_cell_renderer_color_render (GtkCellRenderer *cell, GdkDrawable *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags); enum { PROP_COLOR = 1, }; static gpointer parent_class; GType custom_cell_renderer_color_get_type(void) { static GType cell_color_type = 0; if (cell_color_type == 0){ static const GTypeInfo cell_color_info = { sizeof(CustomCellRendererColorClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) custom_cell_renderer_color_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof(CustomCellRendererColor), 0, /* n_preallocs */ (GInstanceInitFunc) custom_cell_renderer_color_init, }; cell_color_type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "CustomCellRendererColor", &cell_color_info, (GTypeFlags) 0); } return cell_color_type; } static void custom_cell_renderer_color_init(CustomCellRendererColor *cellrenderercolor) { GTK_CELL_RENDERER(cellrenderercolor)->mode = GTK_CELL_RENDERER_MODE_INERT; GTK_CELL_RENDERER(cellrenderercolor)->xpad = 2; GTK_CELL_RENDERER(cellrenderercolor)->ypad = 2; cellrenderercolor->width=32; cellrenderercolor->height=16; cellrenderercolor->color=0; } static void custom_cell_renderer_color_class_init(CustomCellRendererColorClass *klass) { GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass); GObjectClass *object_class = G_OBJECT_CLASS(klass); parent_class = g_type_class_peek_parent(klass); object_class->finalize = custom_cell_renderer_color_finalize; object_class->get_property = custom_cell_renderer_color_get_property; object_class->set_property = custom_cell_renderer_color_set_property; cell_class->get_size = custom_cell_renderer_color_get_size; cell_class->render = custom_cell_renderer_color_render; g_object_class_install_property(object_class, PROP_COLOR, g_param_spec_pointer("color", "Color", "ColorObject pointer", (GParamFlags) G_PARAM_READWRITE)); } static void custom_cell_renderer_color_finalize(GObject *object) { (*G_OBJECT_CLASS(parent_class)->finalize)(object); } static void custom_cell_renderer_color_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *psec) { CustomCellRendererColor *cellcolor = CUSTOM_CELL_RENDERER_COLOR(object); switch (param_id) { case PROP_COLOR: g_value_set_pointer(value, cellcolor->color); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); break; } } static void custom_cell_renderer_color_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { CustomCellRendererColor *cellcolor = CUSTOM_CELL_RENDERER_COLOR (object); switch (param_id) { case PROP_COLOR: cellcolor->color = (struct ColorObject*) g_value_get_pointer(value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); break; } } GtkCellRenderer * custom_cell_renderer_color_new() { return (GtkCellRenderer *) g_object_new(CUSTOM_TYPE_CELL_RENDERER_COLOR, NULL); } void custom_cell_renderer_color_set_size(GtkCellRenderer *cell, gint width, gint height){ CustomCellRendererColor *cellcolor=CUSTOM_CELL_RENDERER_COLOR(cell); cellcolor->width=width; cellcolor->height=height; } static void custom_cell_renderer_color_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height) { CustomCellRendererColor *cellcolor=CUSTOM_CELL_RENDERER_COLOR(cell); gint calc_width; gint calc_height; calc_width = (gint) cell->xpad * 2 + cellcolor->width; calc_height = (gint) cell->ypad * 2 + cellcolor->height; if (width) *width = calc_width; if (height) *height = calc_height; if (cell_area){ if (x_offset){ *x_offset = gint(cell->xalign * (cell_area->width - calc_width)); *x_offset = MAX(*x_offset, 0); } if (y_offset){ *y_offset = gint(cell->yalign * (cell_area->height - calc_height)); *y_offset = MAX(*y_offset, 0); } } } static void custom_cell_renderer_color_render(GtkCellRenderer *cell, GdkDrawable *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { CustomCellRendererColor *cellcolor = CUSTOM_CELL_RENDERER_COLOR (cell); /*GtkStateType state; gint width, height; gint x_offset, y_offset; custom_cell_renderer_color_get_size(cell, widget, cell_area, &x_offset, &y_offset, &width, &height); if (GTK_WIDGET_HAS_FOCUS(widget)) state = GTK_STATE_ACTIVE; else state = GTK_STATE_NORMAL; width -= cell->xpad * 2; height -= cell->ypad * 2;*/ cairo_t *cr; cr = gdk_cairo_create(window); cairo_rectangle(cr, expose_area->x, expose_area->y, expose_area->width, expose_area->height); cairo_clip(cr); cairo_rectangle(cr, expose_area->x, expose_area->y, expose_area->width, expose_area->height); Color c; color_object_get_color(cellcolor->color, &c); cairo_set_source_rgb(cr, boost::math::round(c.rgb.red * 255.0) / 255.0, boost::math::round(c.rgb.green * 255.0) / 255.0, boost::math::round(c.rgb.blue * 255.0) / 255.0); cairo_fill(cr); cairo_destroy(cr); /* gtk_paint_box(widget->style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, "trough", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width - 1, height - 1); gtk_paint_box (widget->style, window, state, GTK_SHADOW_OUT, NULL, widget, "bar", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width * 0.5, height - 1); */ } gpick_0.2.5/source/gtk/ColorWidget.cpp0000644000175000017500000002716212070605214016425 0ustar zbygzbyg/* * 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 "ColorWidget.h" #include "../Color.h" #include "../MathUtil.h" #include #include #include using namespace std; #define GTK_COLOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR, GtkColorPrivate)) G_DEFINE_TYPE (GtkColor, gtk_color, GTK_TYPE_DRAWING_AREA); static gboolean gtk_color_expose(GtkWidget *widget, GdkEventExpose *event); static gboolean gtk_color_button_release(GtkWidget *widget, GdkEventButton *event); static gboolean gtk_color_button_press(GtkWidget *widget, GdkEventButton *event); static void gtk_color_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_color_finalize(GObject *color_obj); static GtkWindowClass *parent_class = NULL; enum { ACTIVATED, LAST_SIGNAL, }; static guint gtk_color_signals[LAST_SIGNAL] = { }; typedef struct GtkColorPrivate GtkColorPrivate; typedef struct GtkColorPrivate { Color color; Color text_color; gchar* text; bool rounded_rectangle; bool h_center; bool secondary_color; double roundness; transformation::Chain *transformation_chain; } GtkColorPrivate; static void gtk_color_class_init(GtkColorClass *color_class) { GObjectClass *obj_class; GtkWidgetClass *widget_class; parent_class = (GtkWindowClass*)g_type_class_peek_parent(G_OBJECT_CLASS(color_class)); obj_class = G_OBJECT_CLASS(color_class); widget_class = GTK_WIDGET_CLASS(color_class); widget_class->expose_event = gtk_color_expose; widget_class->button_release_event = gtk_color_button_release; widget_class->button_press_event = gtk_color_button_press; widget_class->size_request = gtk_color_size_request; obj_class->finalize = gtk_color_finalize; g_type_class_add_private(obj_class, sizeof(GtkColorPrivate)); gtk_color_signals[ACTIVATED] = g_signal_new("activated", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkColorClass, activated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void gtk_color_init(GtkColor *color) { gtk_widget_add_events (GTK_WIDGET (color), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_2BUTTON_PRESS | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); } GtkWidget* gtk_color_new(void) { GtkWidget* widget = (GtkWidget*) g_object_new(GTK_TYPE_COLOR, NULL); GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); //gtk_widget_set_size_request(GTK_WIDGET(widget), 16+widget->style->xthickness*2, 16+widget->style->ythickness*2); color_set(&ns->color, 0); ns->text = 0; ns->rounded_rectangle = false; ns->h_center = false; ns->secondary_color = false; ns->roundness = 20; ns->transformation_chain = 0; GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS); return widget; } static void gtk_color_size_request (GtkWidget *widget, GtkRequisition *requisition){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); gint width = 32 + widget->style->xthickness * 2; gint height = 16 + widget->style->ythickness * 2; if (ns->rounded_rectangle){ width += ns->roundness; height += ns->roundness; } requisition->width = width; requisition->height = height; } static void gtk_color_finalize(GObject *color_obj){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(color_obj); if (ns->text){ g_free(ns->text); ns->text = 0; } G_OBJECT_CLASS(parent_class)->finalize (color_obj); } void gtk_color_get_color(GtkColor* widget, Color* color){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); color_copy(&ns->color, color); } void gtk_color_set_text_color(GtkColor* widget, Color* color) { GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); color_copy(color, &ns->text_color); gtk_widget_queue_draw(GTK_WIDGET(widget)); } void gtk_color_set_roundness(GtkColor* widget, double roundness){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); ns->roundness = roundness; gint width = 32 + GTK_WIDGET(widget)->style->xthickness * 2; gint height = 16 + GTK_WIDGET(widget)->style->ythickness * 2; if (ns->rounded_rectangle){ width += ns->roundness; height += ns->roundness; } gtk_widget_set_size_request(GTK_WIDGET(widget), width, height); gtk_widget_queue_draw(GTK_WIDGET(widget)); } void gtk_color_set_color(GtkColor* widget, Color* color, const char* text) { GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); color_copy(color, &ns->color); if (ns->secondary_color){ }else{ if (ns->transformation_chain){ Color c; ns->transformation_chain->apply(&ns->color, &c); color_get_contrasting(&c, &ns->text_color); }else{ color_get_contrasting(&ns->color, &ns->text_color); } } if (ns->text) g_free(ns->text); ns->text = 0; if (text) ns->text = g_strdup(text); gtk_widget_queue_draw(GTK_WIDGET(widget)); } void gtk_color_set_rounded(GtkColor* widget, bool rounded_rectangle){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); ns->rounded_rectangle = rounded_rectangle; //if (ns->rounded_rectangle) // gtk_widget_set_size_request(GTK_WIDGET(widget), 32+GTK_WIDGET(widget)->style->xthickness*2, 48+GTK_WIDGET(widget)->style->ythickness*2); gtk_widget_queue_draw(GTK_WIDGET(widget)); } void gtk_color_set_hcenter(GtkColor* widget, bool hcenter){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); ns->h_center = hcenter; gtk_widget_queue_draw(GTK_WIDGET(widget)); } static void cairo_rounded_rectangle(cairo_t *cr, double x, double y, double width, double height, double roundness){ double strength = 0.3; cairo_move_to(cr, x+roundness, y); cairo_line_to(cr, x+width-roundness, y); cairo_curve_to(cr, x+width-roundness*strength, y, x+width, y+roundness*strength, x+width, y+roundness); cairo_line_to(cr, x+width, y+height-roundness); cairo_curve_to(cr, x+width, y+height-roundness*strength, x+width-roundness*strength, y+height, x+width-roundness, y+height); cairo_line_to(cr, x+roundness, y+height); cairo_curve_to(cr, x+roundness*strength, y+height, x, y+height-roundness*strength, x, y+height-roundness); cairo_line_to(cr, x, y+roundness); cairo_curve_to(cr, x, y+roundness*strength, x+roundness*strength, y, x+roundness, y); cairo_close_path (cr); } static gboolean gtk_color_expose(GtkWidget *widget, GdkEventExpose *event) { GtkStateType state; if (GTK_WIDGET_HAS_FOCUS (widget)) state = GTK_STATE_SELECTED; else state = GTK_STATE_ACTIVE; cairo_t *cr; GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); Color color; if (ns->rounded_rectangle){ cairo_rounded_rectangle(cr, widget->style->xthickness, widget->style->ythickness, widget->allocation.width-widget->style->xthickness*2, widget->allocation.height-widget->style->ythickness*2, ns->roundness); if (ns->transformation_chain){ ns->transformation_chain->apply(&ns->color, &color); }else{ color_copy(&ns->color, &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); cairo_fill_preserve(cr); if (GTK_WIDGET_HAS_FOCUS(widget)){ cairo_set_source_rgb(cr, widget->style->fg[GTK_STATE_NORMAL].red/65536.0, widget->style->fg[GTK_STATE_NORMAL].green/65536.0, widget->style->fg[GTK_STATE_NORMAL].blue/65536.0); cairo_set_line_width(cr, 3); }else{ cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 1); } cairo_stroke(cr); }else{ cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); if (ns->transformation_chain){ ns->transformation_chain->apply(&ns->color, &color); }else{ color_copy(&ns->color, &color); } cairo_set_source_rgb(cr, color.rgb.red, color.rgb.green, color.rgb.blue); cairo_fill(cr); } if (ns->text){ PangoLayout *layout; PangoFontDescription *font_description; font_description = pango_font_description_new(); layout = pango_cairo_create_layout(cr); pango_font_description_set_family(font_description, "monospace"); pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_absolute_size(font_description, 14 * PANGO_SCALE); pango_layout_set_font_description(layout, font_description); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); if (ns->transformation_chain){ if (ns->secondary_color){ ns->transformation_chain->apply(&ns->text_color, &color); }else{ color_copy(&ns->text_color, &color); } }else{ color_copy(&ns->text_color, &color); } cairo_set_source_rgb(cr, color.rgb.red, color.rgb.green, color.rgb.blue); pango_layout_set_markup(layout, ns->text, -1); pango_layout_set_width(layout, (widget->allocation.width - widget->style->xthickness * 2) * PANGO_SCALE); pango_layout_set_height(layout, (widget->allocation.height - widget->style->ythickness * 2) * PANGO_SCALE); int width, height; pango_layout_get_pixel_size(layout, &width, &height); cairo_move_to(cr, widget->style->xthickness, widget->style->ythickness + (widget->allocation.height - height) / 2); if (ns->h_center) pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); else pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); g_object_unref (layout); pango_font_description_free (font_description); } cairo_destroy(cr); return FALSE; } static gboolean gtk_color_button_release(GtkWidget *widget, GdkEventButton *event){ gtk_widget_grab_focus(widget); return FALSE; } static gboolean gtk_color_button_press(GtkWidget *widget, GdkEventButton *event){ gtk_widget_grab_focus(widget); if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { g_signal_emit(widget, gtk_color_signals[ACTIVATED], 0); } return FALSE; } void gtk_color_set_transformation_chain(GtkColor* widget, transformation::Chain *chain){ GtkColorPrivate *ns = GTK_COLOR_GET_PRIVATE(widget); ns->transformation_chain = chain; if (!ns->secondary_color){ if (ns->transformation_chain){ Color c; ns->transformation_chain->apply(&ns->color, &c); color_get_contrasting(&c, &ns->text_color); }else{ color_get_contrasting(&ns->color, &ns->text_color); } } gtk_widget_queue_draw(GTK_WIDGET(widget)); } gpick_0.2.5/source/gtk/LayoutPreview.cpp0000644000175000017500000002370412070605214017020 0ustar zbygzbyg/* * 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 "LayoutPreview.h" #include "../layout/System.h" #include "../transformation/Chain.h" #include "../Rect2.h" #include #include using namespace std; using namespace math; using namespace layout; #define GTK_LAYOUT_PREVEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_LAYOUT_PREVIEW, GtkLayoutPreviewPrivate)) G_DEFINE_TYPE (GtkLayoutPreview, gtk_layout_preview, GTK_TYPE_DRAWING_AREA); static gboolean gtk_layout_preview_expose(GtkWidget *layout_preview, GdkEventExpose *event); static gboolean gtk_layout_preview_button_release(GtkWidget *layout_preview, GdkEventButton *event); static gboolean gtk_layout_preview_button_press(GtkWidget *layout_preview, GdkEventButton *event); enum { COLOR_CHANGED, EMPTY, LAST_SIGNAL }; static guint gtk_layout_preview_signals[LAST_SIGNAL] = { 0 }; typedef struct GtkLayoutPreviewPrivate GtkLayoutPreviewPrivate; typedef struct GtkLayoutPreviewPrivate{ System* system; Rect2 area; Style* selected_style; Box* selected_box; transformation::Chain *transformation_chain; }GtkLayoutPreviewPrivate; static void gtk_layout_preview_class_init(GtkLayoutPreviewClass *klass){ GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS(klass); widget_class = GTK_WIDGET_CLASS(klass); /* GtkWidget signals */ widget_class->expose_event = gtk_layout_preview_expose; widget_class->button_release_event = gtk_layout_preview_button_release; widget_class->button_press_event = gtk_layout_preview_button_press; g_type_class_add_private(obj_class, sizeof(GtkLayoutPreviewPrivate)); gtk_layout_preview_signals[COLOR_CHANGED] = g_signal_new("color_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkLayoutPreviewClass, color_changed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); } static void gtk_layout_preview_init(GtkLayoutPreview *layout_preview){ gtk_widget_add_events(GTK_WIDGET(layout_preview), GDK_2BUTTON_PRESS | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); } static void gtk_layout_preview_destroy(GtkLayoutPreview *widget){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system) System::unref(ns->system); } GtkWidget* gtk_layout_preview_new(void){ GtkWidget* widget = (GtkWidget*) g_object_new(GTK_TYPE_LAYOUT_PREVIEW, NULL); GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); ns->area = Rect2(0, 0, 1, 1); ns->selected_style = 0; ns->selected_box = 0; ns->system = 0; ns->transformation_chain = 0; g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK (gtk_layout_preview_destroy), NULL); GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS); return widget; } static bool set_selected_box(GtkLayoutPreviewPrivate *ns, Box* box){ bool changed = false; if (box && box->style){ if (ns->selected_style) ns->selected_style->SetState(false, 0); ns->selected_style = box->style; ns->selected_style->SetState(true, box); if (ns->selected_box != box) changed=true; ns->selected_box = box; }else{ if (ns->selected_style){ ns->selected_style->SetState(false, 0); changed = true; } ns->selected_style = 0; ns->selected_box = 0; } return changed; } static gboolean gtk_layout_preview_expose(GtkWidget *widget, GdkEventExpose *event){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); cairo_t *cr; cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); if (ns->system && ns->system->box){ ns->area = Rect2(0, 0, 1, 1); layout::Context context(cr, ns->transformation_chain); ns->system->box->Draw(&context, ns->area); } cairo_destroy(cr); return true; } static gboolean gtk_layout_preview_button_release(GtkWidget *layout_preview, GdkEventButton *event){ return true; } static gboolean gtk_layout_preview_button_press(GtkWidget *widget, GdkEventButton *event){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system){ Vec2 point = Vec2((event->x-ns->area.getX()) / ns->area.getWidth(), (event->y-ns->area.getY()) / ns->area.getHeight()); if (set_selected_box(ns, ns->system->GetBoxAt(point))){ gtk_widget_queue_draw(GTK_WIDGET(widget)); } } return false; } int gtk_layout_preview_set_system(GtkLayoutPreview* widget, System* system){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system){ System::unref(ns->system); } if (system){ ns->system = static_cast(system->ref()); if (ns->system->box) gtk_widget_set_size_request(GTK_WIDGET(widget), ns->system->box->rect.getWidth(), ns->system->box->rect.getHeight()); }else ns->system = 0; return 0; } int gtk_layout_preview_set_color_at(GtkLayoutPreview* widget, Color* color, gdouble x, gdouble y){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (!ns->system) return -1; Vec2 point = Vec2((x-ns->area.getX()) / ns->area.getWidth(), (y-ns->area.getY()) / ns->area.getHeight()); Box* box = ns->system->GetBoxAt(point); if (box && box->style && !box->locked){ color_copy(color, &box->style->color); /*if (typeid(*box)==typeid(Fill)){ color_copy(color, &box->style->background_color); }else if (typeid(*box)==typeid(Text)){ color_copy(color, &box->style->text_color); }*/ gtk_widget_queue_draw(GTK_WIDGET(widget)); return 0; } return -1; } int gtk_layout_preview_set_color_named(GtkLayoutPreview* widget, Color* color, const char *name){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (!ns->system) return -1; Box* box = ns->system->GetNamedBox(name); if (box && box->style && !box->locked){ color_copy(color, &box->style->color); gtk_widget_queue_draw(GTK_WIDGET(widget)); return 0; } return -1; } int gtk_layout_preview_set_focus_named(GtkLayoutPreview* widget, const char *name){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (!ns->system) return -1; Box* box; if (set_selected_box(ns, box = ns->system->GetNamedBox(name))){ gtk_widget_queue_draw(GTK_WIDGET(widget)); return (box)?(0):(-1); } return -1; } int gtk_layout_preview_set_focus_at(GtkLayoutPreview* widget, gdouble x, gdouble y){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (!ns->system) return -1; Vec2 point = Vec2((x-ns->area.getX()) / ns->area.getWidth(), (y-ns->area.getY()) / ns->area.getHeight()); Box* box; if (set_selected_box(ns, box = ns->system->GetBoxAt(point))){ gtk_widget_queue_draw(GTK_WIDGET(widget)); return (box)?(0):(-1); } return -1; } int gtk_layout_preview_get_current_style(GtkLayoutPreview* widget, Style** style){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system && ns->selected_style){ *style = ns->selected_style; return 0; } return -1; } int gtk_layout_preview_get_current_color(GtkLayoutPreview* widget, Color* color){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system && ns->selected_style){ Box* box = ns->selected_box; color_copy(&box->style->color, color); return 0; } return -1; } int gtk_layout_preview_set_current_color(GtkLayoutPreview* widget, Color* color){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system && ns->selected_style && !ns->selected_box->locked){ Box* box = ns->selected_box; color_copy(color, &box->style->color); /*if (typeid(*box)==typeid(Fill)){ color_copy(color, &box->style->background_color); }else if (typeid(*box)==typeid(Text)){ color_copy(color, &box->style->text_color); }*/ gtk_widget_queue_draw(GTK_WIDGET(widget)); return 0; } return -1; } bool gtk_layout_preview_is_selected(GtkLayoutPreview* widget){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system && ns->selected_style && ns->selected_box){ return true; } return false; } bool gtk_layout_preview_is_editable(GtkLayoutPreview* widget){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); if (ns->system && ns->selected_style && ns->selected_box){ return !ns->selected_box->locked; } return false; } void gtk_layout_preview_set_transformation_chain(GtkLayoutPreview* widget, transformation::Chain *chain){ GtkLayoutPreviewPrivate *ns = GTK_LAYOUT_PREVEW_GET_PRIVATE(widget); ns->transformation_chain = chain; gtk_widget_queue_draw(GTK_WIDGET(widget)); } gpick_0.2.5/source/gtk/ColorComponent.h0000644000175000017500000001057412070605214016610 0ustar zbygzbyg/* * 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 COLORCOMPONENT_H_ #define COLORCOMPONENT_H_ #include #include "../Color.h" G_BEGIN_DECLS #define GTK_TYPE_COLOR_COMPONENT (gtk_color_component_get_type ()) #define GTK_COLOR_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_COMPONENT, GtkColorComponent)) #define GTK_COLOR_COMPONENT_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_COLOR_COMPONENT, GtkColorComponentClass)) #define GTK_IS_COLOR_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_COMPONENT)) #define GTK_IS_COLOR_COMPONENT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_COLOR_COMPONENT)) #define GTK_COLOR_COMPONENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_COMPONENT, GtkColorComponentClass)) typedef struct GtkColorComponent GtkColorComponent; typedef struct GtkColorComponentClass GtkColorComponentClass; typedef gpointer GtkColorComponentObject; typedef struct GtkColorComponent{ GtkDrawingArea parent; /* < private > */ }GtkColorComponent; typedef struct GtkColorComponentClass{ GtkDrawingAreaClass parent_class; void (*color_changed)(GtkWidget* widget, Color* c, gpointer userdata); void (*input_clicked)(GtkWidget* widget, int component_id, gpointer userdata); }GtkColorComponentClass; enum GtkColorComponentComp{ rgb, hsv, hsl, cmyk, xyz, lab, lch, }; GtkWidget* gtk_color_component_new (GtkColorComponentComp component); void gtk_color_component_set_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_set_text(GtkColorComponent* color_component, const char **text); const char* gtk_color_component_get_text(GtkColorComponent* color_component, gint component_id); void gtk_color_component_set_label(GtkColorComponent* color_component, const char **label); void gtk_color_component_get_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_get_raw_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_set_raw_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_get_transformed_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_set_transformed_color(GtkColorComponent* color_component, Color* color); void gtk_color_component_set_out_of_gamut_mask(GtkColorComponent* color_component, bool mask_enabled); bool gtk_color_component_get_out_of_gamut_mask(GtkColorComponent* color_component); void gtk_color_component_set_lab_illuminant(GtkColorComponent* color_component, ReferenceIlluminant illuminant); void gtk_color_component_set_lab_observer(GtkColorComponent* color_component, ReferenceObserver observer); GtkColorComponentComp gtk_color_component_get_component(GtkColorComponent* color_component); int gtk_color_component_get_component_id_at(GtkColorComponent* color_component, gint x, gint y); GType gtk_color_component_get_type(void); G_END_DECLS #endif /* UICOLORCOMPONENT_H_ */ gpick_0.2.5/source/gtk/ColorWidget.h0000644000175000017500000000604612070605214016070 0ustar zbygzbyg/* * 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 COLORWIDGET_H_ #define COLORWIDGET_H_ #include #include "../Color.h" #include "../transformation/Chain.h" G_BEGIN_DECLS #define GTK_TYPE_COLOR (gtk_color_get_type ()) #define GTK_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR, GtkColor)) #define GTK_COLOR_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_COLOR, GtkColorClass)) #define GTK_IS_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR)) #define GTK_IS_COLOR_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_COLOR)) #define GTK_COLOR_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR, GtkColorClass)) typedef struct GtkColor GtkColor; typedef struct GtkColorClass GtkColorClass; typedef gpointer GtkColorObject; typedef struct GtkColor { GtkDrawingArea parent; /* < private > */ }GtkColor; typedef struct GtkColorClass { GtkDrawingAreaClass parent_class; void (*activated)(GtkWidget* widget, gpointer userdata); }GtkColorClass; GtkWidget* gtk_color_new (void); void gtk_color_set_color(GtkColor* widget, Color* color, const char* text); void gtk_color_set_text_color(GtkColor* widget, Color* color); void gtk_color_get_color(GtkColor* widget, Color* color); void gtk_color_set_rounded(GtkColor* widget, bool rounded_rectangle); void gtk_color_set_roundness(GtkColor* widget, double roundness); void gtk_color_set_hcenter(GtkColor* widget, bool hcenter); void gtk_color_set_transformation_chain(GtkColor* widget, transformation::Chain *chain); GType gtk_color_get_type(void); G_END_DECLS #endif /* COLORWIDGET_H_ */ gpick_0.2.5/source/gtk/ColorCell.h0000644000175000017500000000561012070605214015520 0ustar zbygzbyg/* * 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 COLORCELL_H_ #define COLORCELL_H_ #include #include "../ColorObject.h" #define CUSTOM_TYPE_CELL_RENDERER_COLOR (custom_cell_renderer_color_get_type()) #define CUSTOM_CELL_RENDERER_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CUSTOM_TYPE_CELL_RENDERER_COLOR, CustomCellRendererColor)) #define CUSTOM_CELL_RENDERER_COLOR_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), CUSTOM_TYPE_CELL_RENDERER_COLOR, CustomCellRendererColorClass)) #define CUSTOM_IS_CELL_COLOR_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_CELL_RENDERER_COLOR)) #define CUSTOM_IS_CELL_COLOR_COLOR_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), CUSTOM_TYPE_CELL_RENDERER_COLOR)) #define CUSTOM_CELL_RENDERER_COLOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CUSTOM_TYPE_CELL_RENDERER_COLOR, CustomCellRendererColorClass)) typedef struct _CustomCellRendererColor CustomCellRendererColor; typedef struct _CustomCellRendererColorClass CustomCellRendererColorClass; struct _CustomCellRendererColor { GtkCellRenderer parent; struct ColorObject* color; int width; int height; }; struct _CustomCellRendererColorClass { GtkCellRendererClass parent_class; }; GType custom_cell_renderer_color_get_type (void); GtkCellRenderer *custom_cell_renderer_color_new (void); void custom_cell_renderer_color_set_size(GtkCellRenderer *cell, gint width, gint height); #endif /* COLORCELL_H_ */ gpick_0.2.5/source/gtk/Swatch.cpp0000644000175000017500000003267212070605214015436 0ustar zbygzbyg/* * 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 "Swatch.h" #include "../Color.h" #include "../MathUtil.h" #include #include #define GTK_SWATCH_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SWATCH, GtkSwatchPrivate)) G_DEFINE_TYPE (GtkSwatch, gtk_swatch, GTK_TYPE_DRAWING_AREA); static gboolean gtk_swatch_expose(GtkWidget *swatch, GdkEventExpose *event); static gboolean gtk_swatch_button_release(GtkWidget *swatch, GdkEventButton *event); static gboolean gtk_swatch_button_press(GtkWidget *swatch, GdkEventButton *event); static int swatch_get_color_by_position(gint x, gint y); enum { ACTIVE_COLOR_CHANGED, COLOR_CHANGED, COLOR_ACTIVATED, CENTER_ACTIVATED, LAST_SIGNAL }; static guint gtk_swatch_signals[LAST_SIGNAL] = { 0 }; typedef struct GtkSwatchPrivate GtkSwatchPrivate; typedef struct GtkSwatchPrivate { Color color[7]; gint32 current_color; transformation::Chain *transformation_chain; } GtkSwatchPrivate; static void gtk_swatch_class_init(GtkSwatchClass *swatch_class) { GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS(swatch_class); widget_class = GTK_WIDGET_CLASS(swatch_class); /* GtkWidget signals */ widget_class->expose_event = gtk_swatch_expose; widget_class->button_release_event = gtk_swatch_button_release; widget_class->button_press_event = gtk_swatch_button_press; /*widget_class->button_press_event = gtk_node_view_button_press; widget_class->button_release_event = gtk_node_view_button_release; widget_class->motion_notify_event = gtk_node_view_motion_notify;*/ g_type_class_add_private(obj_class, sizeof(GtkSwatchPrivate)); gtk_swatch_signals[ACTIVE_COLOR_CHANGED] = g_signal_new("active_color_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkSwatchClass, active_color_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); gtk_swatch_signals[COLOR_CHANGED] = g_signal_new("color_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkSwatchClass, color_changed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gtk_swatch_signals[COLOR_ACTIVATED] = g_signal_new("color_activated", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkSwatchClass, color_activated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gtk_swatch_signals[CENTER_ACTIVATED] = g_signal_new("center_activated", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkSwatchClass, center_activated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void gtk_swatch_init(GtkSwatch *swatch) { gtk_widget_add_events(GTK_WIDGET(swatch), GDK_2BUTTON_PRESS | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); } GtkWidget * gtk_swatch_new(void) { GtkWidget* widget = (GtkWidget*) g_object_new(GTK_TYPE_SWATCH, NULL); GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(widget); gtk_widget_set_size_request(GTK_WIDGET(widget),150+widget->style->xthickness*2,150+widget->style->ythickness*2); for (gint32 i = 0; i < 7; ++i) color_set(&ns->color[i], i/7.0); ns->current_color = 1; ns->transformation_chain = 0; GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS); return widget; } void gtk_swatch_set_color_to_main(GtkSwatch* swatch) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(&ns->color[0], &ns->color[ns->current_color]); gtk_widget_queue_draw(GTK_WIDGET(swatch)); } void gtk_swatch_move_active(GtkSwatch* swatch, gint32 direction) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); if (direction < 0) { if (ns->current_color == 1) { ns->current_color = 7 - 1; } else { ns->current_color--; } } else { ns->current_color++; if (ns->current_color >= 7) ns->current_color = 1; } } void gtk_swatch_get_color(GtkSwatch* swatch, guint32 index, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(&ns->color[index], color); } void gtk_swatch_get_main_color(GtkSwatch* swatch, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(&ns->color[0], color); } gint32 gtk_swatch_get_active_index(GtkSwatch* swatch) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); return ns->current_color; } void gtk_swatch_get_active_color(GtkSwatch* swatch, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(&ns->color[ns->current_color], color); } void gtk_swatch_set_color(GtkSwatch* swatch, guint32 index, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(color, &ns->color[index]); gtk_widget_queue_draw(GTK_WIDGET(swatch)); } void gtk_swatch_set_main_color(GtkSwatch* swatch, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(color, &ns->color[0]); gtk_widget_queue_draw(GTK_WIDGET(swatch)); } void gtk_swatch_set_active_index(GtkSwatch* swatch, guint32 index) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); ns->current_color = index; //if (ns->current_color<=0) ns->current_color=1; gtk_widget_queue_draw(GTK_WIDGET(swatch)); } void gtk_swatch_set_active_color(GtkSwatch* swatch, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(color, &ns->color[ns->current_color]); gtk_widget_queue_draw(GTK_WIDGET(swatch)); //g_signal_emit(GTK_WIDGET(swatch), gtk_swatch_signals[COLOR_CHANGED], 0); } void gtk_swatch_set_main_color(GtkSwatch* swatch, guint index, Color* color) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(swatch); color_copy(color, &ns->color[0]); gtk_widget_queue_draw(GTK_WIDGET(swatch)); } gint gtk_swatch_get_color_at(GtkSwatch* swatch, gint x, gint y) { return swatch_get_color_by_position(x-GTK_WIDGET(swatch)->style->xthickness, y-GTK_WIDGET(swatch)->style->ythickness); } static void gtk_swatch_draw_hexagon(cairo_t *cr, float x, float y, float radius) { cairo_new_sub_path(cr); for (int i = 0; i < 6; ++i) { cairo_line_to(cr, x + sin(i * PI / 3) * radius, y + cos(i * PI / 3) * radius); } cairo_close_path(cr); } static gboolean gtk_swatch_expose(GtkWidget *widget, GdkEventExpose *event) { GtkStateType state; if (GTK_WIDGET_HAS_FOCUS (widget)) state = GTK_STATE_SELECTED; else state = GTK_STATE_ACTIVE; cairo_t *cr; GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(widget); //gtk_paint_shadow(widget->style, widget->window, state, GTK_SHADOW_IN, &event->area, widget, 0, widget->style->xthickness, widget->style->ythickness, 150, 150); if (GTK_WIDGET_HAS_FOCUS(widget)){ gtk_paint_focus(widget->style, widget->window, state, &event->area, widget, 0, widget->style->xthickness, widget->style->ythickness, 150, 150); } cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, 12); cairo_matrix_t matrix; cairo_get_matrix(cr, &matrix); cairo_translate(cr, 75+widget->style->xthickness, 75+widget->style->ythickness); int edges = 6; cairo_set_source_rgb(cr, 0, 0, 0); float radius_multi = 50 * cos((180 / edges) / (180 / PI)); float rotation = -(PI/6 * 4); //Draw stroke cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 3); for (int i = 1; i < 7; ++i) { if (i == ns->current_color) continue; gtk_swatch_draw_hexagon(cr, radius_multi * cos(rotation + i * (2 * PI) / edges), radius_multi * sin(rotation + i * (2 * PI) / edges), 27); } cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); cairo_stroke(cr); cairo_set_source_rgb(cr, 1, 1, 1); gtk_swatch_draw_hexagon(cr, radius_multi * cos(rotation + (ns->current_color) * (2 * PI) / edges), radius_multi * sin(rotation + (ns->current_color) * (2 * PI) / edges), 27); cairo_stroke(cr); Color color; //Draw fill for (int i = 1; i < 7; ++i) { if (i == ns->current_color) continue; if (ns->transformation_chain){ ns->transformation_chain->apply(&ns->color[i], &color); }else{ color_copy(&ns->color[i], &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); gtk_swatch_draw_hexagon(cr, radius_multi * cos(rotation + i * (2 * PI) / edges), radius_multi * sin(rotation + i * (2 * PI) / edges), 25.5); cairo_fill(cr); } if (ns->transformation_chain){ ns->transformation_chain->apply(&ns->color[ns->current_color], &color); }else{ color_copy(&ns->color[ns->current_color], &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); gtk_swatch_draw_hexagon(cr, radius_multi * cos(rotation + (ns->current_color) * (2 * PI) / edges), radius_multi * sin(rotation + (ns->current_color) * (2 * PI) / edges), 25.5); cairo_fill(cr); //Draw center if (ns->transformation_chain){ ns->transformation_chain->apply(&ns->color[0], &color); }else{ color_copy(&ns->color[0], &color); } cairo_set_source_rgb(cr, boost::math::round(color.rgb.red * 255.0) / 255.0, boost::math::round(color.rgb.green * 255.0) / 255.0, boost::math::round(color.rgb.blue * 255.0) / 255.0); gtk_swatch_draw_hexagon(cr, 0, 0, 25.5); cairo_fill(cr); //Draw numbers char numb[2] = " "; for (int i = 1; i < 7; ++i) { Color c; if (ns->transformation_chain){ Color t; ns->transformation_chain->apply(&ns->color[i], &t); color_get_contrasting(&t, &c); }else{ color_get_contrasting(&ns->color[i], &c); } cairo_text_extents_t extends; numb[0] = '0' + i; cairo_text_extents(cr, numb, &extends); cairo_set_source_rgb(cr, boost::math::round(c.rgb.red * 255.0) / 255.0, boost::math::round(c.rgb.green * 255.0) / 255.0, boost::math::round(c.rgb.blue * 255.0) / 255.0); cairo_move_to(cr, radius_multi * cos(rotation + i * (2 * PI) / edges) - extends.width / 2, radius_multi * sin(rotation + i * (2 * PI) / edges) + extends.height / 2); cairo_show_text(cr, numb); } cairo_set_matrix(cr, &matrix); cairo_destroy(cr); return FALSE; } static int swatch_get_color_by_position(gint x, gint y){ vector2 a, b; vector2_set(&a, 1, 0); vector2_set(&b, x - 75, y - 75); float distance = vector2_length(&b); if (distance<20){ //center color return 0; }else if (distance>70){ //outside return -1; }else{ vector2_normalize(&b, &b); float angle = acos(vector2_dot(&a, &b)); if (b.y < 0) angle = 2 * PI - angle; angle += (PI/6) * 3; if (angle < 0) angle += PI * 2; if (angle > 2 * PI) angle -= PI * 2; return 1 + (int) floor(angle / ((PI*2) / 6)); } } static gboolean gtk_swatch_button_press(GtkWidget *widget, GdkEventButton *event) { GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(widget); int new_color = swatch_get_color_by_position(event->x - widget->style->xthickness, event->y - widget->style->ythickness); gtk_widget_grab_focus(widget); if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { if (new_color>0){ g_signal_emit(widget, gtk_swatch_signals[COLOR_ACTIVATED], 0); } }else if ((event->type == GDK_BUTTON_PRESS) && ((event->button == 1) || (event->button == 3))) { if (new_color==0){ g_signal_emit(widget, gtk_swatch_signals[CENTER_ACTIVATED], 0); }else if (new_color<0){ g_signal_emit(widget, gtk_swatch_signals[ACTIVE_COLOR_CHANGED], 0, ns->current_color); }else{ if (new_color != ns->current_color){ ns->current_color = new_color; g_signal_emit(widget, gtk_swatch_signals[ACTIVE_COLOR_CHANGED], 0, ns->current_color); gtk_widget_queue_draw(GTK_WIDGET(widget)); } } } return FALSE; } static gboolean gtk_swatch_button_release(GtkWidget *widget, GdkEventButton *event) { return FALSE; } void gtk_swatch_set_transformation_chain(GtkSwatch* widget, transformation::Chain *chain){ GtkSwatchPrivate *ns = GTK_SWATCH_GET_PRIVATE(widget); ns->transformation_chain = chain; gtk_widget_queue_draw(GTK_WIDGET(widget)); } gpick_0.2.5/source/gtk/ColorWheel.h0000644000175000017500000000745512070605214015716 0ustar zbygzbyg/* * 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_H_ #define COLOR_WHEEL_H_ #include #include "../Color.h" #include "../ColorWheelType.h" G_BEGIN_DECLS #define GTK_TYPE_COLOR_WHEEL (gtk_color_wheel_get_type ()) #define GTK_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_WHEEL, GtkColorWheel)) #define GTK_COLOR_WHEEL_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_COLOR_WHEEL, GtkColorWheelClass)) #define GTK_IS_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_WHEEL)) #define GTK_IS_COLOR_WHEEL_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_COLOR_WHEEL)) #define GTK_COLOR_WHEEL_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_WHEEL, GtkColorWheelClass)) typedef struct GtkColorWheel GtkColorWheel; typedef struct GtkColorWheelClass GtkColorWheelClass; typedef gpointer GtkColorWheelObject; typedef struct GtkColorWheel { GtkDrawingArea parent; /* < private > */ }GtkColorWheel; typedef struct GtkColorWheelClass{ GtkDrawingAreaClass parent_class; void (*hue_changed)(GtkWidget *widget, gint color_id, gpointer userdata); void (*saturation_value_changed)(GtkWidget *widget, gint color_id, gpointer userdata); }GtkColorWheelClass; GtkWidget* gtk_color_wheel_new(void); void gtk_color_wheel_set_value(GtkColorWheel *color_wheel, guint32 index, double value); void gtk_color_wheel_set_hue(GtkColorWheel *color_wheel, guint32 index, double hue); void gtk_color_wheel_set_saturation(GtkColorWheel *color_wheel, guint32 index, double saturation); void gtk_color_wheel_set_selected(GtkColorWheel *color_wheel, guint32 index); double gtk_color_wheel_get_hue(GtkColorWheel *color_wheel, guint32 index); double gtk_color_wheel_get_saturation(GtkColorWheel *color_wheel, guint32 index); double gtk_color_wheel_get_value(GtkColorWheel *color_wheel, guint32 index); void gtk_color_wheel_set_block_editable(GtkColorWheel *color_wheel, bool editable); bool gtk_color_wheel_get_block_editable(GtkColorWheel *color_wheel); int gtk_color_wheel_get_at(GtkColorWheel *color_wheel, int x, int y); void gtk_color_wheel_set_n_colors(GtkColorWheel *color_wheel, guint32 number_of_colors); void gtk_color_wheel_set_color_wheel_type(GtkColorWheel *color_wheel, const ColorWheelType *color_wheel_type); GType gtk_color_wheel_get_type(void); G_END_DECLS #endif /* COLOR_WHEEL_H_ */ gpick_0.2.5/source/gtk/Zoomed.cpp0000644000175000017500000004040412070605214015432 0ustar zbygzbyg/* * 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 "Zoomed.h" #include "../Color.h" #include "../MathUtil.h" #include #include #include #include #include using namespace std; #define GTK_ZOOMED_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ZOOMED, GtkZoomedPrivate)) G_DEFINE_TYPE (GtkZoomed, gtk_zoomed, GTK_TYPE_DRAWING_AREA); static gboolean gtk_zoomed_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_zoomed_finalize(GObject *zoomed_obj); static GtkWindowClass *parent_class = NULL; static gboolean gtk_zoomed_button_press (GtkWidget *node_system, GdkEventButton *event); /* static gboolean gtk_zoomed_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean gtk_zoomed_motion_notify (GtkWidget *node_system, GdkEventMotion *event); */ enum { COLOR_CHANGED, ACTIVATED, LAST_SIGNAL }; static guint gtk_zoomed_signals[LAST_SIGNAL] = { 0 }; typedef struct GtkZoomedPrivate GtkZoomedPrivate; typedef struct GtkZoomedPrivate { Color color; gfloat zoom; GdkPixbuf *pixbuf; vector2 point; vector2 point_size; int32_t width_height; struct{ bool valid; math::Vec2 position; }marks[2]; math::Vec2 pointer; math::Vec2 screen_size; bool fade; }GtkZoomedPrivate; static void gtk_zoomed_class_init (GtkZoomedClass *zoomed_class) { GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS (zoomed_class); widget_class = GTK_WIDGET_CLASS (zoomed_class); parent_class = (GtkWindowClass*)g_type_class_peek_parent(G_OBJECT_CLASS(zoomed_class)); /* GtkWidget signals */ widget_class->expose_event = gtk_zoomed_expose; widget_class->button_press_event = gtk_zoomed_button_press; /*widget_class->button_release_event = gtk_zoomed_button_release; widget_class->motion_notify_event = gtk_zoomed_motion_notify;*/ obj_class->finalize = gtk_zoomed_finalize; g_type_class_add_private (obj_class, sizeof (GtkZoomedPrivate)); gtk_zoomed_signals[ACTIVATED] = g_signal_new( "activated", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkZoomedClass, activated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gtk_zoomed_signals[COLOR_CHANGED] = g_signal_new ( "color-changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkZoomedClass, color_changed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); } static void gtk_zoomed_init (GtkZoomed *zoomed) { gtk_widget_add_events (GTK_WIDGET (zoomed), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | GDK_2BUTTON_PRESS); } GtkWidget * gtk_zoomed_new () { GtkWidget* widget=(GtkWidget*)g_object_new (GTK_TYPE_ZOOMED, NULL); GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(widget); ns->fade = false; ns->zoom = 20; ns->point.x = 0; ns->point.y = 0; ns->width_height = 150; ns->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, ns->width_height, ns->width_height); int rowstride; rowstride = gdk_pixbuf_get_rowstride(ns->pixbuf); guchar *pixels = gdk_pixbuf_get_pixels(ns->pixbuf); for (int y = 0; y < ns->width_height; y++){ guchar *p = pixels + y * rowstride; for (int x = 0; x < ns->width_height * 3; x++){ p[x] = 0x80; } } gtk_widget_set_size_request(GTK_WIDGET(widget), ns->width_height + widget->style->xthickness*2, ns->width_height + widget->style->ythickness*2); return widget; } int32_t gtk_zoomed_get_size(GtkZoomed *zoomed){ GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); return ns->width_height; } void gtk_zoomed_set_size(GtkZoomed *zoomed, int32_t width_height){ GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); if (ns->width_height != width_height){ if (ns->pixbuf){ g_object_unref (ns->pixbuf); ns->pixbuf = 0; } ns->width_height = width_height; ns->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, ns->width_height, ns->width_height); int rowstride; rowstride = gdk_pixbuf_get_rowstride(ns->pixbuf); guchar *pixels = gdk_pixbuf_get_pixels(ns->pixbuf); for (int y = 0; y < ns->width_height; y++){ guchar *p = pixels + y * rowstride; for (int x = 0; x < ns->width_height * 3; x++){ p[x] = 0x80; } } gtk_widget_set_size_request(GTK_WIDGET(zoomed), ns->width_height + GTK_WIDGET(zoomed)->style->xthickness*2, ns->width_height + GTK_WIDGET(zoomed)->style->ythickness*2); } } void gtk_zoomed_set_fade(GtkZoomed* zoomed, bool fade){ GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed); ns->fade = fade; gtk_widget_queue_draw(GTK_WIDGET(zoomed)); } static void gtk_zoomed_finalize(GObject *zoomed_obj){ GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed_obj); if (ns->pixbuf){ g_object_unref (ns->pixbuf); ns->pixbuf = 0; } G_OBJECT_CLASS(parent_class)->finalize (zoomed_obj); } static double zoom_transformation(double value) { return (1 - log(1 + value * 0.01 * 3) / log((double)(1 + 3))) / 2; } void gtk_zoomed_get_current_screen_rect(GtkZoomed* zoomed, math::Rect2 *rect) { GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed); gtk_zoomed_get_screen_rect(zoomed, ns->pointer, ns->screen_size, rect); } void gtk_zoomed_get_screen_rect(GtkZoomed* zoomed, math::Vec2& pointer, math::Vec2& screen_size, math::Rect2 *rect){ GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed); gint32 x = pointer.x, y = pointer.y; gint32 width = screen_size.x, height = screen_size.y; gint32 left, right, top, bottom; gint32 area_width = uint32_t(ns->width_height * zoom_transformation(ns->zoom)); if (!area_width) area_width = 1; left = x - area_width / 2; top = y - area_width / 2; right = x + (area_width - area_width / 2); bottom = y + (area_width - area_width / 2); if (left < 0){ right += -left; left = 0; } if (right > width){ left -= right - width; right = width; } if (top < 0){ bottom += -top; top = 0; } if (bottom > height){ top -= bottom - height; bottom = height; } width = right - left; height = bottom - top; *rect = math::Rect2(left, top, right, bottom); } math::Vec2 gtk_zoomed_get_screen_position(GtkZoomed* zoomed, const math::Vec2& position){ GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); gint32 x = ns->pointer.x, y = ns->pointer.y; gint32 width = ns->screen_size.x, height = ns->screen_size.y; gint32 left, right, top, bottom; gint32 area_width = uint32_t(ns->width_height * zoom_transformation(ns->zoom)); if (!area_width) area_width = 1; left = x - area_width / 2; top = y - area_width / 2; right = x + (area_width - area_width / 2); bottom = y + (area_width - area_width / 2); if (left < 0){ right += -left; left=0; } if (right > width){ left -= right - width; right = width; } if (top < 0){ bottom += -top; top = 0; } if (bottom > height){ top -= bottom - height; bottom = height; } gint32 xl = ((position.x - left) * ns->width_height) / area_width; gint32 xh = (((position.x + 1) - left) * ns->width_height) / area_width; gint32 yl = ((position.y - top) * ns->width_height) / area_width; gint32 yh = (((position.y + 1) - top) * ns->width_height) / area_width; math::Vec2 result((xl + xh) / 2.0, (yl + yh) / 2.0); return result; } void gtk_zoomed_update(GtkZoomed* zoomed, math::Vec2& pointer, math::Vec2& screen_size, math::Vec2& offset, GdkPixbuf* pixbuf){ GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); ns->pointer = pointer; ns->screen_size = screen_size; gint32 x=pointer.x, y=pointer.y; gint32 width=screen_size.x, height=screen_size.y; gint32 left, right, top, bottom; gint32 area_width = uint32_t(ns->width_height * zoom_transformation(ns->zoom)); if (!area_width) area_width = 1; left = x - area_width / 2; top = y - area_width / 2; right = x + (area_width - area_width / 2); bottom = y + (area_width - area_width / 2); if (left < 0){ right += -left; left=0; } if (right > width){ left -= right - width; right = width; } if (top < 0){ bottom += -top; top = 0; } if (bottom > height){ top -= bottom - height; bottom = height; } gint32 xl = ((x - left) * ns->width_height) / area_width; gint32 xh = (((x + 1) - left) * ns->width_height) / area_width; gint32 yl = ((y - top) * ns->width_height) / area_width; gint32 yh = (((y + 1) - top) * ns->width_height) / area_width; ns->point.x = (xl + xh) / 2.0; ns->point.y = (yl + yh) / 2.0; ns->point_size.x = xh - xl; ns->point_size.y = yh - yl; width = right - left; height = bottom - top; gdk_pixbuf_scale(pixbuf, ns->pixbuf, 0, 0, ns->width_height, ns->width_height, -offset.x * ns->width_height / (double)width, -offset.y * ns->width_height / (double)height, ns->width_height / (double)width, ns->width_height / (double)height, GDK_INTERP_NEAREST); gtk_widget_queue_draw(GTK_WIDGET(zoomed)); } void gtk_zoomed_set_zoom (GtkZoomed* zoomed, gfloat zoom) { GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); if (zoom < 0){ ns->zoom = 0; }else if (zoom > 100){ ns->zoom = 100; }else{ ns->zoom = zoom; } gtk_widget_queue_draw(GTK_WIDGET(zoomed)); } gfloat gtk_zoomed_get_zoom (GtkZoomed* zoomed){ GtkZoomedPrivate *ns=GTK_ZOOMED_GET_PRIVATE(zoomed); return ns->zoom; } static gboolean gtk_zoomed_expose (GtkWidget *widget, GdkEventExpose *event){ GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(widget); cairo_t *cr; cr = gdk_cairo_create(widget->window); cairo_translate(cr, widget->style->xthickness, widget->style->ythickness); if (ns->pixbuf){ gdk_cairo_set_source_pixbuf(cr, ns->pixbuf, 0, 0); if (ns->fade){ cairo_paint_with_alpha(cr, 0.2); }else{ cairo_paint(cr); } } if (!ns->fade){ float radius; float size = vector2_length(&ns->point_size); if (size < 5){ radius = 5; }else if (size < 25){ radius = 7; }else if (size < 50){ radius = 10; }else{ radius = 15; } cairo_set_source_rgba(cr, 0,0,0,0.75); cairo_arc(cr, ns->point.x, ns->point.y, radius + 0.5, -PI, PI); cairo_stroke(cr); cairo_set_source_rgba(cr, 1,1,1,0.75); cairo_arc(cr, ns->point.x, ns->point.y, radius, -PI, PI); cairo_stroke(cr); } PangoLayout *layout; PangoFontDescription *font_description; font_description = pango_font_description_new(); layout = pango_cairo_create_layout(cr); pango_font_description_set_family(font_description, "sans"); pango_font_description_set_absolute_size(font_description, 12 * PANGO_SCALE); pango_layout_set_font_description(layout, font_description); math::Rect2 area_rect; math::Rect2 widget_rect = math::Rect2(5, 5, ns->width_height - 5, ns->width_height - 5); gtk_zoomed_get_current_screen_rect(GTK_ZOOMED(widget), &area_rect); cairo_rectangle(cr, widget->style->xthickness, widget->style->ythickness, ns->width_height - widget->style->xthickness * 2, ns->width_height - widget->style->ythickness * 2); cairo_clip(cr); vector > relative_positions(2); bool draw_distance = true; for (int i = 0; i < 2; i++){ if (ns->marks[i].valid){ relative_positions[i] = gtk_zoomed_get_screen_position(GTK_ZOOMED(widget), ns->marks[i].position); }else{ draw_distance = false; } } for (int layer = 0; layer != 2; layer++){ if (draw_distance){ cairo_move_to(cr, relative_positions[0].x, relative_positions[0].y); for (int i = 1; i < 2; i++){ cairo_line_to(cr, relative_positions[i].x, relative_positions[i].y); } if (layer == 0){ cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_set_line_width(cr, 3); }else{ cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_set_line_width(cr, 1); } cairo_stroke(cr); } for (int i = 0; i < 2; i++){ if (ns->marks[i].valid){ cairo_arc(cr, relative_positions[i].x, relative_positions[i].y, 2, -PI, PI); if (layer == 0){ cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_set_line_width(cr, 2); cairo_stroke(cr); }else{ cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_fill(cr); } stringstream ss; ss << ns->marks[i].position.x << "x" << ns->marks[i].position.y; pango_layout_set_text(layout, ss.str().c_str(), -1); pango_cairo_update_layout(cr, layout); cairo_move_to(cr, relative_positions[i].x + 5, relative_positions[i].y); if (layer == 0){ cairo_set_source_rgba(cr, 0, 0, 0, 1); pango_cairo_layout_path(cr, layout); cairo_set_line_width(cr, 1.5); cairo_stroke(cr); }else{ cairo_set_source_rgba(cr, 1, 1, 1, 1); pango_cairo_show_layout(cr, layout); } } } } for (int layer = 0; layer != 2; layer++){ if (draw_distance){ double distance = math::Vec2::distance( math::Vec2(ns->marks[0].position.x, ns->marks[0].position.y), math::Vec2(ns->marks[1].position.x, ns->marks[1].position.y) ); math::Vec2 center = (ns->marks[0].position + ns->marks[1].position) * 0.5; stringstream ss; ss << fixed << setprecision(1) << distance << endl << 1 + abs(ns->marks[0].position.x - ns->marks[1].position.x) << "x" << 1 + abs(ns->marks[0].position.y - ns->marks[1].position.y); pango_layout_set_text(layout, ss.str().c_str(), -1); pango_cairo_update_layout(cr, layout); math::Vec2 relative_position = gtk_zoomed_get_screen_position(GTK_ZOOMED(widget), center); PangoRectangle rect; pango_layout_get_pixel_extents(layout, NULL, &rect); int text_width = rect.width; int text_height = rect.height; math::Rect2 text_rect(relative_position.x + 10, relative_position.y, relative_position.x + 10 + text_width, relative_position.y + text_height); if (!text_rect.isInside(widget_rect)) text_rect = widget_rect.positionInside(text_rect); cairo_move_to(cr, text_rect.getX(), text_rect.getY()); if (layer == 0){ cairo_set_source_rgba(cr, 0, 0, 0, 1); pango_cairo_layout_path(cr, layout); cairo_set_line_width(cr, 1.5); cairo_stroke(cr); }else{ cairo_set_source_rgba(cr, 1, 1, 1, 1); pango_cairo_show_layout(cr, layout); } } } g_object_unref(layout); pango_font_description_free(font_description); cairo_destroy (cr); gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, &event->area, widget, 0, widget->style->xthickness, widget->style->ythickness, ns->width_height, ns->width_height); return true; } static gboolean gtk_zoomed_button_press(GtkWidget *widget, GdkEventButton *event){ gtk_widget_grab_focus(widget); if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { g_signal_emit(widget, gtk_zoomed_signals[ACTIVATED], 0); } return FALSE; } void gtk_zoomed_set_mark(GtkZoomed *zoomed, int index, math::Vec2& position) { GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed); ns->marks[index].position = position; ns->marks[index].valid = true; gtk_widget_queue_draw(GTK_WIDGET(zoomed)); } void gtk_zoomed_clear_mark(GtkZoomed *zoomed, int index) { GtkZoomedPrivate *ns = GTK_ZOOMED_GET_PRIVATE(zoomed); ns->marks[index].valid = false; gtk_widget_queue_draw(GTK_WIDGET(zoomed)); } gpick_0.2.5/source/gtk/Range2D.cpp0000644000175000017500000002567712070605214015436 0ustar zbygzbyg/* * 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 "Range2D.h" #include "../Color.h" #include "../MathUtil.h" #include #ifdef _MSC_VER #define M_PI 3.14159265359 #endif #include #include #include using namespace std; #define GTK_RANGE_2D_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RANGE_2D, GtkRange2DPrivate)) G_DEFINE_TYPE (GtkRange2D, gtk_range_2d, GTK_TYPE_DRAWING_AREA); static GtkWindowClass *parent_class = NULL; static gboolean gtk_range_2d_expose(GtkWidget *range_2d, GdkEventExpose *event); static gboolean gtk_range_2d_button_release(GtkWidget *range_2d, GdkEventButton *event); static gboolean gtk_range_2d_button_press(GtkWidget *range_2d, GdkEventButton *event); static gboolean gtk_range_2d_motion_notify(GtkWidget *widget, GdkEventMotion *event); enum { VALUES_CHANGED, LAST_SIGNAL }; static guint gtk_range_2d_signals[LAST_SIGNAL] = { 0 }; typedef struct GtkRange2DPrivate{ double x; double y; char *xname; char *yname; double block_size; bool grab_block; cairo_surface_t *cache_range_2d; }GtkRange2DPrivate; static void gtk_range_2d_finalize(GObject *range_2d_obj){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(range_2d_obj); if (ns->xname) g_free(ns->xname); if (ns->yname) g_free(ns->yname); if (ns->cache_range_2d){ cairo_surface_destroy(ns->cache_range_2d); ns->cache_range_2d = 0; } G_OBJECT_CLASS(parent_class)->finalize(range_2d_obj); } static void gtk_range_2d_class_init(GtkRange2DClass *range_2d_class) { GObjectClass *obj_class; GtkWidgetClass *widget_class; obj_class = G_OBJECT_CLASS(range_2d_class); widget_class = GTK_WIDGET_CLASS(range_2d_class); /* GtkWidget signals */ widget_class->expose_event = gtk_range_2d_expose; widget_class->button_release_event = gtk_range_2d_button_release; widget_class->button_press_event = gtk_range_2d_button_press; widget_class->motion_notify_event = gtk_range_2d_motion_notify; parent_class = (GtkWindowClass*)g_type_class_peek_parent(G_OBJECT_CLASS(range_2d_class)); obj_class->finalize = gtk_range_2d_finalize; g_type_class_add_private(obj_class, sizeof(GtkRange2DPrivate)); gtk_range_2d_signals[VALUES_CHANGED] = g_signal_new("values_changed", G_OBJECT_CLASS_TYPE(obj_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkRange2DClass, values_changed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void gtk_range_2d_init(GtkRange2D *range_2d){ gtk_widget_add_events(GTK_WIDGET(range_2d), GDK_2BUTTON_PRESS | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); } GtkWidget* gtk_range_2d_new(){ GtkWidget* widget = (GtkWidget*) g_object_new(GTK_TYPE_RANGE_2D, NULL); GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(widget); ns->block_size = 128; ns->grab_block = false; ns->xname = 0; ns->yname = 0; gtk_widget_set_size_request(GTK_WIDGET(widget), ns->block_size + widget->style->xthickness * 2, ns->block_size + widget->style->ythickness * 2); ns->cache_range_2d = 0; GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS); return widget; } void gtk_range_2d_set_values(GtkRange2D* range_2d, double x, double y){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(range_2d); ns->x = x; ns->y = 1 - y; gtk_widget_queue_draw(GTK_WIDGET(range_2d)); } double gtk_range_2d_get_x(GtkRange2D* range_2d){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(range_2d); return ns->x; } double gtk_range_2d_get_y(GtkRange2D* range_2d){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(range_2d); return 1 - ns->y; } static void draw_dot(cairo_t *cr, double x, double y, double size){ cairo_arc(cr, x, y, size - 1, 0, 2 * M_PI); cairo_set_source_rgba(cr, 1, 1, 1, 0.5); cairo_set_line_width(cr, 2); cairo_stroke(cr); cairo_arc(cr, x, y, size, 0, 2 * M_PI); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_set_line_width(cr, 1); cairo_stroke(cr); } static void draw_sat_val_block(GtkRange2DPrivate *ns, cairo_t *cr, double pos_x, double pos_y, double size){ cairo_surface_t *surface; if (ns->cache_range_2d){ surface = ns->cache_range_2d; }else{ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(size), ceil(size)); unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_image_surface_get_stride(surface); int surface_width = cairo_image_surface_get_width(surface); int surface_height = cairo_image_surface_get_height(surface); Color c; double hue = 0; float v; unsigned char *line_data; for (int y = 0; y < surface_height; ++y){ line_data = data + stride * y; for (int x = 0; x < surface_width; ++x){ if ((x % 16 < 8) ^ (y % 16 < 8) ){ v = mix_float(0.5, 1.0, pow(x / size, 2)); }else{ v = mix_float(0.5, 0.0, pow(1 - (y / size), 2)); } line_data[2] = v * 255; line_data[1] = v / 2 * 255; line_data[0] = v / 4 * 255; line_data[3] = 0xFF; line_data += 4; } } ns->cache_range_2d = surface; } cairo_surface_mark_dirty(surface); cairo_save(cr); cairo_set_source_surface(cr, surface, pos_x, pos_y); //cairo_surface_destroy(surface); cairo_rectangle(cr, pos_x, pos_y, size, size); cairo_fill(cr); cairo_restore(cr); } static gboolean gtk_range_2d_motion_notify(GtkWidget *widget, GdkEventMotion *event){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(widget); if (ns->grab_block){ double dx = (event->x - widget->style->xthickness); double dy = (event->y - widget->style->ythickness); ns->x = clamp_float(dx / ns->block_size, 0, 1); ns->y = clamp_float(dy / ns->block_size, 0, 1); g_signal_emit(widget, gtk_range_2d_signals[VALUES_CHANGED], 0); gtk_widget_queue_draw(widget); return true; } return false; } static gboolean gtk_range_2d_expose(GtkWidget *widget, GdkEventExpose *event){ GtkStateType state; if (GTK_WIDGET_HAS_FOCUS (widget)) state = GTK_STATE_SELECTED; else state = GTK_STATE_ACTIVE; cairo_t *cr; GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(widget); /* if (GTK_WIDGET_HAS_FOCUS(widget)){ gtk_paint_focus(widget->style, widget->window, state, &event->area, widget, 0, widget->style->xthickness, widget->style->ythickness, 150, 150); }*/ cr = gdk_cairo_create(widget->window); cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cr); cairo_translate(cr, widget->style->xthickness, widget->style->ythickness); draw_sat_val_block(ns, cr, 0, 0, ns->block_size); draw_dot(cr, ns->block_size * ns->x, ns->block_size * ns->y, 6); if (ns->xname){ PangoLayout *layout; PangoFontDescription *font_description; font_description = pango_font_description_new(); layout = pango_cairo_create_layout(cr); pango_font_description_set_family(font_description, "monospace"); pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_absolute_size(font_description, 12 * PANGO_SCALE); pango_layout_set_font_description(layout, font_description); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); cairo_set_source_rgb(cr, 1, 1, 1); pango_layout_set_text(layout, ns->xname, -1); pango_layout_set_width(layout, (widget->allocation.width - widget->style->xthickness * 2) * PANGO_SCALE); pango_layout_set_height(layout, (widget->allocation.height - widget->style->ythickness * 2) * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_cairo_update_layout(cr, layout); int width, height; pango_layout_get_pixel_size(layout, &width, &height); cairo_move_to(cr, 0, ns->block_size - height - 1); pango_cairo_show_layout(cr, layout); PangoContext *context = pango_layout_get_context(layout); pango_context_set_gravity_hint(context, PANGO_GRAVITY_HINT_STRONG); pango_context_set_base_gravity(context, PANGO_GRAVITY_NORTH); pango_layout_context_changed(layout); pango_layout_set_text(layout, ns->yname, -1); pango_layout_get_pixel_size(layout, &width, &height); cairo_move_to(cr, height + 1, 0); cairo_rotate(cr, 90 / (180.0 / M_PI)); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); g_object_unref (layout); pango_font_description_free (font_description); } cairo_destroy(cr); return FALSE; } static gboolean gtk_range_2d_button_press(GtkWidget *widget, GdkEventButton *event) { GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(widget); gtk_widget_grab_focus(widget); if ((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){ ns->grab_block = true; GdkCursor *cursor = gdk_cursor_new(GDK_CROSS); gdk_pointer_grab(gtk_widget_get_window(widget), false, GdkEventMask(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, cursor, GDK_CURRENT_TIME); gdk_cursor_destroy(cursor); double dx = (event->x - widget->style->xthickness); double dy = (event->y - widget->style->ythickness); ns->x = clamp_float(dx / ns->block_size, 0, 1); ns->y = clamp_float(dy / ns->block_size, 0, 1); g_signal_emit(widget, gtk_range_2d_signals[VALUES_CHANGED], 0); gtk_widget_queue_draw(widget); return true; } return false; } static gboolean gtk_range_2d_button_release(GtkWidget *widget, GdkEventButton *event) { GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(widget); gdk_pointer_ungrab(GDK_CURRENT_TIME); ns->grab_block = false; return false; } void gtk_range_2d_set_axis(GtkRange2D *range_2d, const char *x, const char *y){ GtkRange2DPrivate *ns = GTK_RANGE_2D_GET_PRIVATE(range_2d); if (ns->xname) g_free(ns->xname); ns->xname = g_strdup(x); if (ns->yname) g_free(ns->yname); ns->yname = g_strdup(y); gtk_widget_queue_draw(GTK_WIDGET(range_2d)); } gpick_0.2.5/source/ToolColorNaming.h0000644000175000017500000000471112070605214016124 0ustar zbygzbyg/* * 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 TOOL_COLOR_NAMING_H_ #define TOOL_COLOR_NAMING_H_ #include "GlobalStateStruct.h" #include "DynvHelpers.h" enum ToolColorNamingType { TOOL_COLOR_NAMING_UNKNOWN = 0, TOOL_COLOR_NAMING_EMPTY, TOOL_COLOR_NAMING_AUTOMATIC_NAME, TOOL_COLOR_NAMING_TOOL_SPECIFIC, }; typedef struct ToolColorNamingOption{ ToolColorNamingType type; const char *name; const char *label; }ToolColorNamingOption; const ToolColorNamingOption* tool_color_naming_get_options(); ToolColorNamingType tool_color_naming_name_to_type(const char *name); class ToolColorNameAssigner{ protected: ToolColorNamingType m_color_naming_type; GlobalState* m_gs; bool m_imprecision_postfix; public: ToolColorNameAssigner(GlobalState *gs); virtual ~ToolColorNameAssigner(); void assign(struct ColorObject *color_object, Color *color); virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color); }; #endif /* TOOL_COLOR_NAMING_H_ */ gpick_0.2.5/source/uiDialogMix.cpp0000644000175000017500000002507412070605214015631 0ustar zbygzbyg/* * 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 "uiDialogMix.h" #include "uiListPalette.h" #include "uiUtilities.h" #include "MathUtil.h" #include "DynvHelpers.h" #include "GlobalStateStruct.h" #include "ToolColorNaming.h" #include "Internationalisation.h" #ifndef _MSC_VER #include #endif #include using namespace std; typedef struct DialogMixArgs{ GtkWidget *mix_type; GtkWidget *mix_steps; GtkWidget *toggle_endpoints; struct ColorList *selected_color_list; struct ColorList *preview_color_list; struct dynvSystem *params; GlobalState* gs; }DialogMixArgs; class MixColorNameAssigner: public ToolColorNameAssigner { protected: stringstream m_stream; const char *m_color_start; const char *m_color_end; int m_start_percent; int m_end_percent; int m_is_node; public: MixColorNameAssigner(GlobalState *gs):ToolColorNameAssigner(gs){ } void assign(struct ColorObject *color_object, Color *color, const char *start_color_name, const char *end_color_name, int start_percent, int end_percent, bool is_node){ m_color_start = start_color_name; m_color_end = end_color_name; m_start_percent = start_percent; m_end_percent = end_percent; m_is_node = is_node; ToolColorNameAssigner::assign(color_object, color); } void assign(struct ColorObject *color_object, Color *color, const char *item_name){ m_color_start = item_name; ToolColorNameAssigner::assign(color_object, color); } virtual std::string getToolSpecificName(struct ColorObject *color_object, Color *color){ m_stream.str(""); if (m_is_node){ if (m_end_percent == 100){ m_stream << m_color_end << " " << _("mix node"); }else{ m_stream << m_color_start << " " << _("mix node"); } }else{ m_stream << m_color_start << " " << m_start_percent << " " << _("mix") << " " << m_end_percent << " " << m_color_end; } return m_stream.str(); } }; #define STORE_COLOR() struct ColorObject *color_object=color_list_new_color_object(color_list, &r); \ float mixfactor = step_i/(float)(steps-1); \ name_assigner.assign(color_object, &r, name_a, name_b, (int)((1.0 - mixfactor)*100), (int)(mixfactor*100), with_endpoints && (step_i == 0 || step_i == (max_step - 1))); \ color_list_add_color_object(color_list, color_object, 1); \ color_object_release(color_object) #define STORE_LINEARCOLOR() color_linear_get_rgb(&r, &r); \ STORE_COLOR() static void calc( DialogMixArgs *args, bool preview, int limit){ gint steps=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(args->mix_steps)); gint type=gtk_combo_box_get_active(GTK_COMBO_BOX(args->mix_type)); bool with_endpoints=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(args->toggle_endpoints)); gint start_step = 0; gint max_step = steps; MixColorNameAssigner name_assigner(args->gs); if (!preview){ dynv_set_int32(args->params, "type", type); dynv_set_int32(args->params, "steps", steps); dynv_set_bool(args->params, "includeendpoints", with_endpoints); } if (with_endpoints == false){ start_step = 1; max_step = steps - 1; } Color r; gint step_i; stringstream s; s.precision(0); s.setf(ios::fixed,ios::floatfield); Color a,b; struct ColorList *color_list; if (preview) color_list = args->preview_color_list; else color_list = args->gs->colors; ColorList::iter j; for (ColorList::iter i=args->selected_color_list->colors.begin(); i!=args->selected_color_list->colors.end(); ++i){ color_object_get_color(*i, &a); if (type == 0) color_rgb_get_linear(&a, &a); const char* name_a = dynv_get_string_wd((*i)->params, "name", 0); j=i; ++j; for (; j!=args->selected_color_list->colors.end(); ++j){ if (preview){ if (limit<=0) return; limit--; } color_object_get_color(*j, &b); if (type == 0) color_rgb_get_linear(&b, &b); const char* name_b = dynv_get_string_wd((*j)->params, "name", 0); switch (type) { case 0: for (step_i = start_step; step_i < max_step; ++step_i) { MIX_COMPONENTS(r.rgb, a.rgb, b.rgb, red, green, blue); STORE_LINEARCOLOR(); } break; case 1: { Color a_hsv, b_hsv, r_hsv; color_rgb_to_hsv(&a, &a_hsv); color_rgb_to_hsv(&b, &b_hsv); for (step_i = start_step; step_i < max_step; ++step_i) { MIX_COMPONENTS(r_hsv.hsv, a_hsv.hsv, b_hsv.hsv, hue, saturation, value); color_hsv_to_rgb(&r_hsv, &r); STORE_COLOR(); } } break; case 2: { Color a_hsv, b_hsv, r_hsv; color_rgb_to_hsv(&a, &a_hsv); color_rgb_to_hsv(&b, &b_hsv); if (a_hsv.hsv.hue>b_hsv.hsv.hue){ if (a_hsv.hsv.hue-b_hsv.hsv.hue>0.5) a_hsv.hsv.hue-=1; }else{ if (b_hsv.hsv.hue-a_hsv.hsv.hue>0.5) b_hsv.hsv.hue-=1; } for (step_i = start_step; step_i < max_step; ++step_i) { MIX_COMPONENTS(r_hsv.hsv, a_hsv.hsv, b_hsv.hsv, hue, saturation, value); if (r_hsv.hsv.hue<0) r_hsv.hsv.hue+=1; color_hsv_to_rgb(&r_hsv, &r); STORE_COLOR(); } } break; case 3: { Color a_lab, b_lab, r_lab; color_rgb_to_lab_d50(&a, &a_lab); color_rgb_to_lab_d50(&b, &b_lab); for (step_i = start_step; step_i < max_step; ++step_i) { MIX_COMPONENTS(r_lab.lab, a_lab.lab, b_lab.lab, L, a, b); color_lab_to_rgb_d50(&r_lab, &r); color_rgb_normalize(&r); STORE_COLOR(); } } break; } } } } static void update(GtkWidget *widget, DialogMixArgs *args ){ color_list_remove_all(args->preview_color_list); calc(args, true, 100); } void dialog_mix_show(GtkWindow* parent, struct ColorList *selected_color_list, GlobalState* gs) { DialogMixArgs *args = new DialogMixArgs; args->gs = gs; args->params = dynv_get_dynv(args->gs->params, "gpick.mix"); GtkWidget *table; GtkWidget *mix_type, *mix_steps; GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Mix colors"), 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(3, 2, FALSE); table_y=0; gtk_table_attach(GTK_TABLE(table), gtk_label_aligned_new(_("Type:"),0,0,0,0),0,1,table_y,table_y+1,GtkAttachOptions(GTK_FILL),GTK_FILL,5,5); mix_type = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("RGB")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("HSV")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("HSV shortest hue distance")); gtk_combo_box_append_text(GTK_COMBO_BOX(mix_type), _("LAB")); gtk_combo_box_set_active(GTK_COMBO_BOX(mix_type), dynv_get_int32_wd(args->params, "type", 0)); gtk_table_attach(GTK_TABLE(table), mix_type,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; args->mix_type = mix_type; g_signal_connect (G_OBJECT (mix_type), "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); mix_steps = gtk_spin_button_new_with_range (3,255,1); gtk_spin_button_set_value(GTK_SPIN_BUTTON(mix_steps), dynv_get_int32_wd(args->params, "steps", 3)); gtk_table_attach(GTK_TABLE(table), mix_steps,1,2,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); table_y++; args->mix_steps = mix_steps; g_signal_connect (G_OBJECT (mix_steps), "value-changed", G_CALLBACK (update), args); args->toggle_endpoints = gtk_check_button_new_with_mnemonic (_("_Include Endpoints")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(args->toggle_endpoints), dynv_get_bool_wd(args->params, "includeendpoints", true)); gtk_table_attach(GTK_TABLE(table), args->toggle_endpoints,1,4,table_y,table_y+1,GtkAttachOptions(GTK_FILL | GTK_EXPAND),GTK_FILL,5,0); g_signal_connect (G_OBJECT(args->toggle_endpoints), "toggled", G_CALLBACK (update), args); table_y++; 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, 2, 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/doc/Doxyfile0000644000175000017500000017762012070605213013671 0ustar zbygzbyg# Doxyfile 1.6.2-20100208 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project # # All text after a hash (#) is considered a comment and will be ignored # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = Gpick # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = build/ # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output # format and will distribute the generated files over these directories. # Enabling this option can be useful when feeding doxygen a huge amount of # source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = NO # This tag implements a quasi-intelligent brief description abbreviator # that is used to form the text in various listings. Each string # in this list, if found as the leading text of the brief description, will be # stripped from the text and the result after processing the whole list, is # used as the annotated text. Otherwise, the brief description is used as-is. # If left blank, the following values are used ("$name" is automatically # replaced with the name of the entity): "The $name class" "The $name widget" # "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = YES # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the # path to strip. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells # the reader which header file to include in order to use a class. # If left blank only the name of the header file containing the class # definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful is your file systems # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = NO # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style # comment as the brief description. If set to NO, the comments # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. # The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 4 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java # sources only. Doxygen will then generate output that is more tailored for # Java. For instance, namespaces will be presented as packages, qualified # scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources only. Doxygen will then generate output that is more tailored for # Fortran. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for # VHDL. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it parses. # With this tag you can assign which parser to use for a given extension. # Doxygen has a built-in mapping, but you can override or extend it using this tag. # The format is ext=language, where ext is a file extension, and language is one of # the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, # Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat # .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), # use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. EXTENSION_MAPPING = # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. # Doxygen will parse them like normal C++ but will assume all classes use public # instead of private inheritance when no explicit protection keyword is present. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate getter # and setter methods for a property. Setting this option to YES (the default) # will make doxygen to replace the get and set methods by a property in the # documentation. This will only work if the methods are indeed getting or # setting a simple type. If this is not the case, or you want to show the # methods anyway, you should set this option to NO. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically # be useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. TYPEDEF_HIDES_STRUCT = NO # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to # determine which symbols to keep in memory and which to flush to disk. # When the cache is full, less often used symbols will be written to disk. # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time # causing a significant performance penality. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on # a logarithmic scale so increasing the size by one will rougly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in # the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default # anonymous namespace are hidden. EXTRACT_ANON_NSPACES = YES # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all # friend (class|struct|union) declarations. # If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any # documentation blocks found inside the body of a function. # If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen # will list include files with double quotes in the documentation # rather than with sharp brackets. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the # brief documentation of file, namespace and class members alphabetically # by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, # not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or # disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or define consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and defines in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES # If the sources in your project are distributed over multiple directories # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy # in the documentation. The default is NO. SHOW_DIRECTORIES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the # Namespaces page. # This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by # doxygen. The layout file controls the global structure of the generated output files # in an output format independent way. The create the layout file that represents # doxygen's defaults, run doxygen with the -l option. You can optionally specify a # file name after the option, if omitted DoxygenLayout.xml will be used as the name # of the layout file. LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some # parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be abled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = NO # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. Optionally the format may contain # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = source/ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # also the default input encoding. Doxygen uses libiconv (or the iconv built # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for # the list of possible encodings. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 FILE_PATTERNS = # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. Note that the wildcards are matched # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. # If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. # Doxygen will compare the file name with each pattern and apply the # filter if there is a match. # The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER # is applied to all files. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will # link to the source code. # Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source # tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = NO # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for # each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet. Note that doxygen will try to copy # the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! HTML_STYLESHEET = # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting # this to NO can help when comparing the output of multiple runs. HTML_TIMESTAMP = NO # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. For this to work a browser that supports # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). HTML_DYNAMIC_SECTIONS = YES # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). # To create a documentation set, doxygen will generate a Makefile in the # HTML output directory. Running make will produce the docset in that # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. GENERATE_DOCSET = NO # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the # feed. A documentation feed provides an umbrella under which multiple # documentation sets from a single provider (such as a company or product suite) # can be grouped. DOCSET_FEEDNAME = "Doxygen generated docs" # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that # should uniquely identify the documentation set bundle. This should be a # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen # will append .docset to the name. DOCSET_BUNDLE_ID = org.doxygen.Project # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be # written to the html output directory. CHM_FILE = # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can # be used to specify the location (absolute path including file name) of # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. HHC_LOCATION = # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING # is used to encode HtmlHelp index (hhk), content (hhc) and project file # content. CHM_INDEX_ENCODING = # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER # are set, an additional index file will be generated that can be used as input for # Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated # HTML documentation. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can # be used to specify the file name of the resulting .qch file. # The path specified is relative to the HTML output folder. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#virtual-folders QHP_VIRTUAL_FOLDER = doc # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. # For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see # Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's # filter section matches. # Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can # be used to specify the location of Qt's qhelpgenerator. # If non-empty doxygen will try to run qhelpgenerator on the generated # .qhp file. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files # will be generated, which together with the HTML files, form an Eclipse help # plugin. To install this plugin and make it available under the help contents # menu in Eclipse, the contents of the directory containing the HTML and XML # files needs to be copied into the plugins directory of eclipse. The name of # the directory within the plugins directory should be the same as # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before the help appears. GENERATE_ECLIPSEHELP = NO # A unique identifier for the eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have # this name. ECLIPSE_DOC_ID = org.doxygen.Project # The DISABLE_INDEX tag can be used to turn on/off the condensed index at # top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO # This tag can be used to set the number of enum values (range [1..20]) # that doxygen will group on one line in the generated HTML documentation. ENUM_VALUES_PER_LINE = 4 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. # If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). # Windows users are probably better off using the HTML help feature. GENERATE_TREEVIEW = NO # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, # and Class Hierarchy pages using a tree view instead of an ordered list. USE_INLINE_TREES = NO # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. FORMULA_FONTSIZE = 10 # When the SEARCHENGINE tag is enabled doxygen will generate a search box for the HTML output. The underlying search engine uses javascript # and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) there is already a search function so this one should # typically be disabled. For large projects the javascript based search engine # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be implemented using a PHP enabled web server instead of at the web client using Javascript. Doxygen will generate the search PHP script and index # file to put on the web server. The advantage of the server based approach is that it scales better to large projects and allows full text search. The disadvances is that it is more difficult to setup # and does not have live searching capabilities. SERVER_BASED_SEARCH = NO #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. # Note that when enabling USE_PDFLATEX this option is only used for # generating bitmaps for formulas in the HTML output, but not in the # Makefile that is written to the output directory. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to # generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, a4wide, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not # include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO # If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER. LATEX_SOURCE_CODE = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = NO # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml # The XML_SCHEMA tag can be used to specify an XML schema, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_SCHEMA = # The XML_DTD tag can be used to specify an XML DTD, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_DTD = # If the XML_PROGRAMLISTING tag is set to YES Doxygen will # dump the program listings (including syntax highlighting # and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will # generate an AutoGen Definitions (see autogen.sf.net) file # that captures the structure of the code including all # documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES Doxygen will # generate a Perl module file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES Doxygen will generate # the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be # nicely formatted so it can be parsed by a human reader. # This is useful # if you want to understand what is going on. # On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. # This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. To prevent a macro definition from being # undefined via #undef or recursively expanded use the := operator # instead of the = operator. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all function-like macros that are alone # on a line, have an all uppercase name, and do not end with a semicolon. Such # function macros are typically used for boiler-plate code, and will confuse # the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- # The TAGFILES option can be used to specify one or more tagfiles. # Optionally an initial location of the external documentation # can be added for each tagfile. The format of a tag file without # this location is as follows: # # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # # TAGFILES = file1=loc1 "file2 = loc2" ... # where "loc1" and "loc2" can be relative or absolute paths or # URLs. If a location is present for each tag, the installdox tool # does not have to be run to correct the links. # Note that each tag file must have a unique name # (where the name does NOT include the path) # If a tag file is not located in the directory in which doxygen # is run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed # in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that # this option is superseded by the HAVE_DOT option below. This is only a # fallback. It is recommended to install and use dot, since it yields more # powerful graphs. CLASS_DIAGRAMS = NO # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. MSCGEN_PATH = # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = NO # By default doxygen will write a font called FreeSans.ttf to the output # directory and reference it in all dot files that doxygen generates. This # font does not include all possible unicode characters however, so when you need # these (or just want a differently looking font) you can specify the font name # using DOT_FONTNAME. You need need to make sure dot is able to find the font, # which can be done by putting it in a standard location or by setting the # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory # containing the font. DOT_FONTNAME = FreeSans # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. # The default size is 10pt. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the output directory to look for the # FreeSans.ttf font (which doxygen will put there itself). If you specify a # different font using DOT_FONTNAME you can set the path where dot # can find it using this tag. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = NO # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = NO # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH and HAVE_DOT options are set to YES then # doxygen will generate a call dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable call graphs # for selected functions only using the \callgraph command. CALL_GRAPH = NO # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then # doxygen will generate a caller dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable caller # graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are png, jpg, or gif # If left blank png will be used. DOT_IMAGE_FORMAT = png # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is # visualized by representing a node as a red box. Note that doxygen if the # number of direct children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large # code bases. Also note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not # seem to support this out of the box. Warning: Depending on the platform used, # enabling this option may lead to badly anti-aliased labels on the edges of # a graph (i.e. they become hard to read). DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = YES # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES gpick_0.2.5/deb/SConscript0000644000175000017500000000412012070605213014142 0ustar zbygzbyg#!/usr/bin/env python # coding: utf-8 import os import sys import shutil import glob import math import tools.gpick Import('*') DEBNAME = "gpick" DEBVERSION = str(env['GPICK_BUILD_VERSION'])+"-1" DEBMAINT = "Albertas Vyšniauskas " DEBARCH = env['DEBARCH'] DEBDEPENDS = "libgtk2.0-0 (>= 2.24), libc6 (>= 2.13), liblua5.2-0 (>= 5.2), libcairo2 (>=1.8), libglib2.0-0 (>=2.24)" DEBPRIORITY = "optional" DEBSECTION = "graphics" DEBDESC = "Advanced color picker" DEBDESCLONG = """ gpick is a program used to pick colors from anythere on the screen, mix them to get new colors, generate shades and tints and export palettes to common file formats or simply copy them to the clipboard """ DEBPACKAGEFILE = '%s_%s_%s.deb' % (DEBNAME, DEBVERSION, DEBARCH) CONTROL_TEMPLATE = """Package: %s Version: %s Section: %s Priority: %s Architecture: %s Depends: %s Installed-Size: %s Maintainer: %s Description: %s %s """ DEBCONTROLDIR = os.path.join(DEBNAME, "DEBIAN") DEBCONTROLFILE = os.path.join(DEBCONTROLDIR, "control") DEBINSTALLDIR = os.path.join('deb' , DEBNAME, 'usr') env['DESTDIR'] = DEBINSTALLDIR #redirect install location def debian_write_control(target=None, source=None, env=None): installed_size = 0 files = tools.gpick.Glob(os.path.join('build', 'deb', DEBNAME, 'usr')) for i in files: installed_size += os.stat(str(i))[6] installed_size = int(math.ceil(installed_size/1024)) control_info = CONTROL_TEMPLATE % ( DEBNAME, DEBVERSION, DEBSECTION, DEBPRIORITY, DEBARCH, DEBDEPENDS, str(installed_size), DEBMAINT, DEBDESC, DEBDESCLONG) f = open(str(target[0]), 'w') f.write(control_info) f.close() return None env.Append(BUILDERS = {'DebianPackage' : Builder(action = "fakeroot dpkg-deb -b %s %s" % ("$SOURCE", "$TARGET") )}) env.Append(BUILDERS = {'DebianControl' : Builder(action = debian_write_control)}) env.Alias(target="debian", source=[ env.Install(dir=DEBCONTROLDIR, source=[env.Glob("DEBIAN/*")]), env.DebianControl(source = env.Alias('install'), target = DEBCONTROLFILE), env.DebianPackage(source = env.Dir(DEBNAME), target = os.path.join('.', DEBPACKAGEFILE)) ]) gpick_0.2.5/deb/DEBIAN/postrm0000755000175000017500000000017712070605213014334 0ustar zbygzbyg#!/bin/sh set -e if [ "$1" = "remove" ] && which update-desktop-database >/dev/null 2>&1 ; then update-desktop-database -q fi gpick_0.2.5/deb/DEBIAN/postinst0000755000175000017500000000020212070605213014660 0ustar zbygzbyg#!/bin/sh set -e if [ "$1" = "configure" ] && which update-desktop-database >/dev/null 2>&1 ; then update-desktop-database -q fi gpick_0.2.5/share/doc/gpick/copyright0000644000175000017500000000071212070605213016300 0ustar zbygzbyggpick This package was debianized by Albertas Vyšniauskas The home page of gpick is at: http://code.google.com/p/gpick Upstream Author: Albertas Vyšniauskas This software is copyright (c) 2009 by Albertas Vyšniauskas. You are free to distribute this software under the terms of the BSD License. On Debian systems, the complete text of the BSD license can be found in the file `/usr/share/common-licenses/BSD'. gpick_0.2.5/share/applications/gpick.desktop0000644000175000017500000000041212070605213017656 0ustar zbygzbyg[Desktop Entry] Version=1.0 Name=Gpick Comment=Color picker Comment[ru]=Пипетка для снятия цвета GenericName=Color picker Exec=gpick Icon=gpick StartupNotify=true MimeType=text/x-utility; Terminal=false Type=Application Categories=Graphics;GTK; gpick_0.2.5/share/gpick/gpick-falloff-quadratic.png0000644000175000017500000000270412070605214020771 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<AIDATX[lUƿs;eiݶ-lmZ.+4F/Q1@44iRE#Ei6U!hA#-KCXae;{߇hI̙ߞgfr}]TUp$6s qh4*OقOp78"HLc*++iӦM:4844}w4@CCR8p8L^@#G#;HYJS\),ʉMIKhC/S.xz|>Z[[F"+V q;pn{GI€ bI< { }†h"~5&vPHܹDEE pv?`OP܇30X" (|آ |^m_7kjj^pe%88sOOMʹ-%HǏ7k oift-gIJ=ņ[|۲}%%% I)4ÄS0<μݹ, ~א1>=J6@RE:,XB%5XREG=O+Ǯm݌{/X,k.@:.9@sb 2X&'9R:{Ț41L|13?p“o߰5?0Va zf;J6k3ϵ(Dw>nݺՆaLki'Ya /Jp ΅i0lgM\4>|x.?4tlfSX T7X›XRʁԝϩj-(?Of<@^D,5dr9HrkXF-'A-[lG\0[|4"@<HJ9!%dc l_*\^Ej} B1 L!ysH!` %!6 0R!eg'^{܏ŋp)£?9s !aHP0)RT7hHPwNdvVu$32u~~GmKJtW`I,I²=b^Xa OVa&99:LuJZmڞsrr!L[\P%jCH BC6!8)KTHfC RavKdE`ɄzYҁi}X477݌d_p`~DgIENDB`gpick_0.2.5/share/gpick/gpick-falloff-none.png0000644000175000017500000000047112070605214017752 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATX1 0"JG+x)/E:9T `!H^HB9jizc388$H@if$i$sg Mp &a!L)S kGN2~Ā٩w] w}^y P;Z-Ǥ @ ZIENDB`gpick_0.2.5/share/gpick/colors.txt0000644000175000017500000013724312070605214015655 0ustar zbygzbyg! Resene RGB Values List ! For further information refer to http://www.resene.co.nz ! Copyright Resene Paints Ltd 2001 ! ! Permission to copy this dictionary, to modify it, to redistribute it, ! to distribute modified versions, and to use it for any purpose is ! granted, subject to the following restrictions and understandings. ! ! 1. Any text copy made of this dictionary must include this copyright ! notice in full. ! ! 2. Any redistribution in binary form must reproduce this copyright ! notice in the documentation or other materials provided with the ! distribution. ! ! 3. Resene Paints Ltd makes no warranty or representation that this ! dictionary is error-free, and is under no obligation to provide any ! services, by way of maintenance, update, or otherwise. ! ! 4. There shall be no use of the name of Resene or Resene Paints Ltd ! in any advertising, promotional, or sales literature without prior ! written consent in each case. ! ! 5. These RGB colour formulations may not be used to the detriment of ! Resene Paints Ltd. ! !"R" "G" "B" "Colour Name" 36 83 54 kaitoke green 36 83 54 KaitokeGreen 27 75 53 county green 27 75 53 CountyGreen 23 70 46 zuccini 29 57 60 nordic 0 73 78 sherpa blue 0 73 78 SherpaBlue 37 72 85 teal blue 37 72 85 TealBlue 53 81 79 blue dianne 53 81 79 BlueDianne 49 70 67 firefly 44 70 65 gable green 44 70 65 GableGreen 39 63 65 daintree 24 67 67 tiber 15 70 69 cyprus 25 68 60 deep teal 25 68 60 DeepTeal 32 72 63 zydeco 27 70 54 sherwood green 27 70 54 SherwoodGreen 39 66 52 english holly 39 66 52 EnglishHolly 38 67 52 everglade 37 70 54 bush 37 70 54 bottle green 37 70 54 BottleGreen 35 69 55 burnham 43 63 54 celtic 50 67 54 timber green 50 67 54 TimberGreen 51 66 49 forest green 51 66 49 ForestGreen 43 75 64 te papa green 43 75 64 TePapaGreen 52 83 61 goblin 58 69 49 mallard 54 72 47 palm leaf 54 72 47 PalmLeaf 55 65 42 seaweed 53 63 42 olive green 53 63 42 OliveGreen 25 57 37 deep fir 25 57 37 DeepFir 27 52 39 cardin green 27 52 39 CardinGreen 32 57 44 palm green 32 57 44 PalmGreen 37 52 43 holly 35 46 38 black bean 35 46 38 BlackBean 41 51 43 gordons green 41 51 43 GordonsGreen 44 50 39 black forest 44 50 39 BlackForest 42 47 35 pine tree 42 47 35 PineTree 47 49 37 hunter green 47 49 37 HunterGreen 45 47 40 eternity 43 46 37 rangoon green 43 46 37 RangoonGreen 43 46 38 marshland 44 45 36 green waterloo 44 45 36 GreenWaterloo 45 45 36 karaka 52 50 45 banjul 53 49 44 acadia 55 49 43 dark ebony 55 49 43 DarkEbony 57 50 39 creole 56 52 40 graphite 51 44 34 cannon black 51 44 34 CannonBlack 51 44 34 black magic 51 44 34 BlackMagic 53 40 30 cocoa brown 53 40 30 CocoaBrown 60 47 35 cola 59 46 37 sambuca 60 52 46 treehouse 61 50 44 deep oak 61 50 44 DeepOak 58 47 45 sepia 54 45 38 marlin 54 45 38 cuban tan 54 45 38 CubanTan 54 45 38 coffee bean 54 45 38 CoffeeBean 48 38 33 wood bark 48 38 33 WoodBark 42 41 34 maire 42 41 34 asphalt 41 41 36 jungle green 41 41 36 JungleGreen 70 54 35 clinker 70 54 41 woodburn 65 54 40 jacko bean 65 54 40 JackoBean 63 55 38 birch 63 54 35 mikado 73 63 47 ash brown 73 63 47 AshBrown 72 65 43 onion 71 62 35 madras 57 61 42 green kelp 57 61 42 GreenKelp 69 64 43 woodrush 76 78 49 waiouru 79 77 50 camouflage 84 78 49 thatch green 84 78 49 ThatchGreen 83 73 49 punga 81 65 45 deep bronze 81 65 45 DeepBronze 75 65 42 tumbleweed 85 74 60 metallic bronze 85 74 60 MetallicBronze 79 64 55 paco 75 67 59 space shuttle 75 67 59 SpaceShuttle 74 75 70 gravel 70 71 62 heavy metal 70 71 62 HeavyMetal 57 62 46 log cabin 57 62 46 LogCabin 61 64 49 scrub 58 65 51 rangitoto 57 57 44 el paso 57 57 44 ElPaso 58 55 46 touch wood 58 55 46 TouchWood 60 55 49 black pepper 60 55 49 BlackPepper 63 55 46 blackwood 68 54 45 tobago 66 52 43 slugger 69 54 43 dark rum 69 54 43 DarkRum 73 59 47 bronze 71 59 47 english walnut 71 59 47 EnglishWalnut 63 57 57 eclipse 70 61 62 jon 52 54 58 shark 54 56 60 vulcan 60 61 62 baltic sea 60 61 62 BalticSea 57 59 60 montana 60 59 60 fuscous grey 60 59 60 FuscousGrey 58 53 50 kilamanjaro 55 63 67 mirage 55 62 65 mine shaft 55 62 65 MineShaft 57 64 67 charade 59 60 56 zeus 69 70 66 tuatara 64 77 73 corduroy 72 74 70 armadillo 77 77 75 thunder 82 75 75 matterhorn 80 73 74 emperor 69 70 71 bleached cedar 69 70 71 BleachedCedar 67 70 75 steel grey 67 70 75 SteelGrey 70 73 78 tuna 72 71 83 gun powder 72 71 83 GunPowder 61 70 83 rhino 60 67 84 blue zodiac 60 67 84 BlueZodiac 58 78 95 cello 61 75 82 atomic 58 78 88 deep cove 58 78 88 DeepCove 51 64 70 big stone 51 64 70 BigStone 37 63 78 nile blue 37 63 78 NileBlue 35 65 78 green vogue 35 65 78 GreenVogue 37 60 72 tarawera 46 55 73 licorice 53 62 79 cloud burst 53 62 79 CloudBurst 56 55 64 black marlin 56 55 64 BlackMarlin 55 54 63 revolver 65 61 75 grape 44 45 60 black rock 44 45 60 BlackRock 44 42 53 haiti 49 42 41 livid brown 49 42 41 LividBrown 50 44 43 diesel 51 46 46 night rider 51 46 46 NightRider 55 51 50 gondola 50 49 46 crowshead 45 48 50 cod grey 45 48 50 CodGrey 41 44 47 bunker 38 43 47 blue charcoal 38 43 47 BlueCharcoal 44 44 50 bastille 51 52 58 woody bay 51 52 58 WoodyBay 50 52 56 ebony clay 50 52 56 EbonyClay 49 51 55 ebony 44 53 57 gunmetal 40 53 58 oxford blue 40 53 58 OxfordBlue 37 47 47 swamp 49 51 48 oil 43 50 48 woodsmoke 41 52 50 aztec 36 46 40 midnight moss 36 46 40 MidnightMoss 35 47 44 racing green 35 47 44 RacingGreen 30 52 66 blue whale 30 52 66 BlueWhale 41 55 65 mosaic 36 54 64 elephant 33 48 62 midnight 30 47 60 tangaroa 36 42 46 cinder 30 39 44 blue bark 30 39 44 BlueBark 30 39 44 black pearl 30 39 44 BlackPearl 36 37 43 black russian 36 37 43 BlackRussian 41 41 47 jaguar 37 37 37 nero 42 39 37 bokara grey 42 39 37 BokaraGrey 31 38 59 outer space 31 38 59 OuterSpace 33 38 58 stratos 33 38 58 midnight express 33 38 58 MidnightExpress 25 47 65 prussian blue 25 47 65 PrussianBlue 42 52 74 downriver 43 52 73 bunting 48 67 106 capri 38 65 107 bondi blue 38 65 107 BondiBlue 39 60 90 cobalt 39 60 90 catalina blue 39 60 90 CatalinaBlue 52 63 92 gulf blue 52 63 92 GulfBlue 52 63 92 cove grey 52 63 92 CoveGrey 47 60 83 biscay 45 60 84 madison 33 69 89 astronaut blue 33 69 89 AstronautBlue 32 63 88 regal blue 32 63 88 RegalBlue 39 74 93 arapawa 71 88 119 chambray 68 81 114 astronaut 71 82 110 east bay 71 82 110 EastBay 37 89 127 bahama blue 37 89 127 BahamaBlue 54 92 125 matisse 44 87 120 venice blue 44 87 120 VeniceBlue 50 84 130 st tropaz 50 84 130 StTropaz 41 89 139 endeavour 0 98 111 blue lagoon 0 98 111 BlueLagoon 48 92 113 blumine 44 89 113 chathams blue 44 89 113 ChathamsBlue 37 91 119 orient 31 106 125 allports 61 113 136 calypso 68 121 142 jelly bean 68 121 142 JellyBean 55 111 137 astral 73 136 154 hippie blue 73 136 154 HippieBlue 61 133 184 curious blue 61 133 184 CuriousBlue 49 110 160 lochmara 78 108 157 san marino 78 108 157 SanMarino 78 105 154 azure 87 132 193 havelock blue 87 132 193 HavelockBlue 91 110 145 waikawa grey 91 110 145 WaikawaGrey 87 109 142 kashmir blue 87 109 142 KashmirBlue 76 107 136 wedgewood 129 124 135 topaz 122 118 121 monsoon 119 118 114 dove grey 119 118 114 DoveGrey 116 120 128 storm grey 116 120 128 StormGrey 121 132 136 regent grey 121 132 136 RegentGrey 124 129 124 boulder 109 120 118 rolling stone 109 120 118 RollingStone 119 132 142 pigeon post 119 132 142 PigeonPost 105 125 137 lynch 100 125 134 hoki 98 119 126 blue bayoux 98 119 126 BlueBayoux 104 118 110 sirocco 102 111 111 nevada 99 109 112 pale sky 99 109 112 PaleSky 102 106 109 mid grey 102 106 109 MidGrey 111 116 123 raven 107 106 108 scarpa flow 107 106 108 ScarpaFlow 124 113 115 empress 106 104 115 dolphin 114 114 130 waterloo 96 93 107 smoky 99 99 115 comet 75 90 98 fiord 68 87 97 san juan 68 87 97 SanJuan 63 84 90 casal 87 89 93 bright grey 87 89 93 BrightGrey 88 84 82 tundora 86 80 81 mortar 90 79 81 don juan 90 79 81 DonJuan 78 78 76 ship grey 78 78 76 ShipGrey 78 85 82 cape cod 78 85 82 CapeCod 80 85 85 mako 76 83 86 trout 70 83 82 dark slate 70 83 82 DarkSlate 79 90 95 pickled bluewood 79 90 95 PickledBluewood 85 96 97 river bed 85 96 97 RiverBed 78 96 94 limed spruce 78 96 94 LimedSpruce 97 102 107 shuttle grey 97 102 107 ShuttleGrey 105 98 104 salt box 105 98 104 SaltBox 106 100 102 scorpion 108 94 83 kabul 110 95 86 dorado 105 95 80 makara 101 100 95 storm dust 101 100 95 StormDust 91 100 82 pickled aspen 91 100 82 PickledAspen 91 93 86 chicago 81 87 79 battleship grey 81 87 79 BattleshipGrey 89 86 72 millbrook 76 85 68 cabbage pont 76 85 68 CabbagePont 79 78 72 merlin 81 79 74 dune 87 83 75 masala 93 89 82 smokey ash 93 89 82 SmokeyAsh 93 83 70 judge grey 93 83 70 JudgeGrey 93 78 70 saddle 90 76 66 mash 90 76 66 cork 90 77 65 rock 91 82 68 iroko 85 77 66 mondo 84 79 58 panda 84 79 58 lisbon brown 84 79 58 LisbonBrown 77 80 60 kelp 78 85 65 lunar green 78 85 65 LunarGreen 105 104 75 hemlock 111 99 75 soya bean 111 99 75 SoyaBean 108 91 76 domino 117 101 86 pine cone 117 101 86 PineCone 114 103 81 coffee 118 109 82 peat 122 113 92 pablo 129 110 92 donkey brown 129 110 92 DonkeyBrown 133 113 88 cement 143 125 107 squirrel 130 122 103 arrowtown 128 118 97 stonewall 134 118 101 sand dune 134 118 101 SandDune 138 125 114 americano 139 126 119 hurricane 130 127 121 concord 120 109 95 sandstone 112 110 102 ironside grey 112 110 102 IronsideGrey 113 110 97 flint 103 109 99 limed ash 103 109 99 LimedAsh 122 124 118 gunsmoke 124 124 114 tapa 120 133 122 blue smoke 120 133 122 BlueSmoke 136 128 100 olive haze 136 128 100 OliveHaze 139 130 101 granite green 139 130 101 GraniteGreen 123 120 90 kokoda 117 120 90 finch 112 105 80 crocodile 104 107 80 siam 91 111 85 cactus 99 119 90 axolotl 97 117 91 finlandia 105 117 92 willow grove 105 117 92 WillowGrove 117 135 110 xanadu 92 129 115 cutty sark 92 129 115 CuttySark 98 103 70 woodland 79 99 72 tom thumb 79 99 72 TomThumb 82 86 54 grey green 82 86 54 GreyGreen 55 93 79 spectra 62 89 76 plantation 78 93 78 nandor 80 99 85 mineral green 80 99 85 MineralGreen 64 99 86 stromboli 75 95 86 viridian green 75 95 86 ViridianGreen 57 85 85 oracle 73 101 105 tax break 73 101 105 TaxBreak 73 98 103 smalt blue 73 98 103 SmaltBlue 72 108 122 bismark 64 117 119 ming 64 114 109 jade 81 123 120 breaker bay 81 123 120 BreakerBay 83 115 111 william 72 128 132 paradiso 0 123 119 surfie green 0 123 119 SurfieGreen 41 123 118 elm 49 121 109 genoa 43 121 122 atoll 31 99 97 sea green 31 99 97 SeaGreen 22 100 97 blue stone 22 100 97 BlueStone 0 95 91 mosque 38 98 85 eden 32 89 72 aquamarine 38 96 79 evening sea 38 96 79 EveningSea 48 93 53 parsley 22 91 49 crusoe 38 98 66 green pea 38 98 66 GreenPea 36 108 70 greenstone 73 118 79 killarney 76 120 92 como 92 138 100 spring green 92 138 100 SpringGreen 56 123 84 amazon 27 138 107 elf green 27 138 107 ElfGreen 22 126 101 deep sea 22 126 101 DeepSea 0 143 112 observatory 23 123 77 salem 19 104 67 jewel 21 99 61 fun green 21 99 61 FunGreen 0 110 78 watercourse 0 135 159 eastern blue 0 135 159 EasternBlue 37 153 178 pelorous 48 142 160 scooter 77 177 200 viking 91 160 208 picton blue 91 160 208 PictonBlue 67 142 172 boston blue 67 142 172 BostonBlue 96 154 184 shakespeare 111 140 159 bermuda grey 111 140 159 BermudaGrey 121 136 171 ship cove 121 136 171 ShipCove 91 137 192 danube 122 170 224 jordy blue 122 170 224 JordyBlue 147 162 186 rock blue 147 162 186 RockBlue 164 175 205 echo blue 164 175 205 EchoBlue 138 167 204 polo blue 138 167 204 PoloBlue 102 183 225 malibu 119 183 208 seagull 120 177 191 glacier 140 206 234 anakiwa 165 206 236 sail 174 201 235 tropical blue 174 201 235 TropicalBlue 126 205 221 spray 182 236 222 water leaf 182 236 222 WaterLeaf 111 210 190 downy 137 217 200 riptide 146 211 202 aqua 134 210 193 bermuda 151 213 179 vista blue 151 213 179 VistaBlue 180 225 187 fringy flower 180 225 187 FringyFlower 157 211 168 chinook 214 240 205 snowy mint 214 240 205 SnowyMint 239 245 209 rice flower 239 245 209 RiceFlower 223 241 214 hint of green 223 241 214 HintOfGreen 216 240 210 blue romance 216 240 210 BlueRomance 197 231 205 granny apple 197 231 205 GrannyApple 192 232 213 aero blue 192 232 213 AeroBlue 215 231 208 peppermint 222 241 221 tara 223 240 226 off green 223 240 226 OffGreen 226 242 228 frosted mint 226 242 228 FrostedMint 198 234 221 mint tulip 198 234 221 MintTulip 194 230 236 onahau 209 234 234 oyster bay 209 234 234 OysterBay 208 234 232 foam 203 232 232 mabel 202 225 217 iceberg 202 231 226 jagged ice 202 231 226 JaggedIce 206 239 228 humming bird 206 239 228 HummingBird 215 238 228 white ice 215 238 228 WhiteIce 233 238 235 lily white 233 238 235 LilyWhite 221 237 233 tranquil 223 239 234 clear day 223 239 234 ClearDay 230 242 234 bubbles 222 227 227 zircon 216 221 218 mystic 211 229 239 pattens blue 211 229 239 PattensBlue 210 218 237 hawkes blue 210 218 237 HawkesBlue 230 223 231 selago 231 229 232 white lilac 231 229 232 WhiteLilac 221 220 219 porcelain 220 221 221 athens grey 220 221 221 AthensGrey 227 225 224 seashell 239 230 230 whisper 238 223 222 soft peach 238 223 222 SoftPeach 238 232 235 magnolia 233 236 241 solitude 245 239 235 hint of red 245 239 235 HintOfRed 251 238 232 rose white 251 238 232 RoseWhite 242 240 230 alabaster 244 240 230 romance 244 234 228 sauvignon 249 232 226 wisp pink 249 232 226 WispPink 242 230 221 fantasy 248 234 223 chardon 248 235 221 bridal heath 248 235 221 BridalHeath 241 234 215 half pearl lusta 241 234 215 HalfPearlLusta 241 235 217 orchid white 241 235 217 OrchidWhite 241 235 218 buttery white 241 235 218 ButteryWhite 244 239 224 bianca 242 237 221 quarter pearl lusta 242 237 221 QuarterPearlLusta 248 237 219 island spice 248 237 219 IslandSpice 252 233 215 serenade 253 239 211 varden 248 234 202 gin fizz 248 234 202 GinFizz 247 240 219 apricot white 247 240 219 ApricotWhite 251 242 219 early dawn 251 242 219 EarlyDawn 251 240 214 half dutch white 251 240 214 HalfDutchWhite 253 239 219 forget me not 253 239 219 ForgetMeNot 249 247 222 chilean heath 249 247 222 ChileanHeath 248 246 223 promenade 250 243 220 off yellow 250 243 220 OffYellow 241 237 212 rum swizzle 241 237 212 RumSwizzle 251 243 211 china ivory 251 243 211 ChinaIvory 245 243 206 moon glow 245 243 206 MoonGlow 248 246 216 white nectar 248 246 216 WhiteNectar 246 245 215 hint of yellow 246 245 215 HintOfYellow 235 247 228 panache 232 243 232 aqua spring 232 243 232 AquaSpring 238 243 229 saltpan 244 246 236 twilight blue 244 246 236 TwilightBlue 238 239 223 sugar cane 238 239 223 SugarCane 239 236 222 rice cake 239 236 222 RiceCake 231 242 233 dew 229 242 231 polar 223 230 207 willow brook 223 230 207 WillowBrook 219 229 210 frostee 222 234 220 apple green 222 234 220 AppleGreen 218 230 221 swans down 218 230 221 SwansDown 219 228 220 aqua squeeze 219 228 220 AquaSqueeze 224 228 220 catskill white 224 228 220 CatskillWhite 229 230 223 black squeeze 229 230 223 BlackSqueeze 227 227 220 snow drift 227 227 220 SnowDrift 229 228 219 black white 229 228 219 BlackWhite 222 221 203 green white 222 221 203 GreenWhite 217 221 213 aqua haze 217 221 213 AquaHaze 217 223 205 gin 219 224 208 feta 225 228 197 frost 225 218 187 coconut cream 225 218 187 CoconutCream 238 231 200 scotch mist 238 231 200 ScotchMist 237 231 200 half and half 237 231 200 HalfAndHalf 234 227 205 orange white 234 227 205 OrangeWhite 226 221 199 travertine 234 218 194 solitaire 230 219 199 half spanish white 230 219 199 HalfSpanishWhite 234 224 200 pearl lusta 234 224 200 PearlLusta 245 230 196 pipi 233 220 190 double pearl lusta 233 220 190 DoublePearlLusta 249 228 197 egg sour 249 228 197 EggSour 249 228 198 derby 245 222 196 sazerac 225 218 203 albescent white 225 218 203 AlbescentWhite 235 226 210 quarter spanish white 235 226 210 QuarterSpanishWhite 235 225 206 bleach white 235 225 206 BleachWhite 235 229 213 cararra 243 229 220 fair pink 243 229 220 FairPink 234 228 220 pampas 237 231 224 desert storm 237 231 224 DesertStorm 238 231 220 white linen 238 231 220 WhiteLinen 236 229 218 soapstone 233 230 220 narvik 231 228 222 wild sand 231 228 222 WildSand 228 226 220 wan white 228 226 220 WanWhite 233 225 217 spring wood 233 225 217 SpringWood 227 223 217 vista white 227 223 217 VistaWhite 223 221 214 sea fog 223 221 214 SeaFog 223 221 214 hint of grey 223 221 214 HintOfGrey 223 221 214 ceramic 224 222 215 black haze 224 222 215 BlackHaze 220 217 205 milk white 220 217 205 MilkWhite 225 219 208 merino 230 214 205 dawn pink 230 214 205 DawnPink 230 216 212 ebb 219 208 202 swiss coffee 219 208 202 SwissCoffee 223 215 210 bon jour 223 215 210 BonJour 220 215 209 gallery 218 214 204 white pointer 218 214 204 WhitePointer 215 206 197 swirl 212 207 197 westar 217 208 193 blanc 222 209 198 pearl bush 222 209 198 PearlBush 230 214 184 rock salt 230 214 184 RockSalt 213 203 178 aths special 213 203 178 AthsSpecial 222 209 183 spanish white 222 209 183 SpanishWhite 222 209 183 janna 223 215 189 wheatfield 219 217 194 loafer 212 207 180 white rock 212 207 180 WhiteRock 210 211 179 orinoco 211 219 203 ottoman 209 211 204 grey nurse 209 211 204 GreyNurse 214 209 192 joanna 214 209 192 ecru white 214 209 192 EcruWhite 210 210 192 celeste 206 205 184 moon mist 206 205 184 MoonMist 203 206 192 harp 191 205 192 paris white 191 205 192 ParisWhite 202 199 183 chrome white 202 199 183 ChromeWhite 197 195 176 kangaroo 191 192 171 kidnapper 186 192 180 pumice 186 192 179 tasman 188 191 168 beryl green 188 191 168 BerylGreen 208 200 176 parchment 210 195 163 double spanish white 210 195 163 DoubleSpanishWhite 207 190 165 soft amber 207 190 165 SoftAmber 210 198 182 stark white 210 198 182 StarkWhite 203 201 192 quill grey 203 201 192 QuillGrey 190 189 182 silver sand 190 189 182 SilverSand 194 188 177 cloud 191 189 193 french grey 191 189 193 FrenchGrey 192 191 199 ghost 195 190 187 pale slate 195 190 187 PaleSlate 205 198 197 alto 203 205 205 iron 210 209 205 concrete 213 210 209 mercury 221 214 225 titan white 221 214 225 TitanWhite 199 205 216 link water 199 205 216 LinkWater 189 186 206 blue haze 189 186 206 BlueHaze 179 196 216 spindle 205 213 213 zumthor 203 208 207 geyser 184 198 190 nebula 176 196 196 jungle mist 176 196 196 JungleMist 185 195 190 tiara 168 195 188 opal 187 208 201 jet stream 187 208 201 JetStream 164 210 224 french pass 164 210 224 FrenchPass 160 205 217 regent st blue 160 205 217 RegentStBlue 158 209 211 morning glory 158 209 211 MorningGlory 164 220 230 charlotte 166 213 208 sinbad 175 227 214 ice cold 175 227 214 IceCold 180 226 213 cruise 173 217 209 scandal 172 201 178 gum leaf 172 201 178 GumLeaf 178 198 177 zanah 179 193 177 rainee 195 214 189 surf crest 195 214 189 SurfCrest 194 213 196 sea mist 194 213 196 SeaMist 193 216 197 edgewater 184 212 187 surf 187 205 165 pixie green 187 205 165 PixieGreen 189 202 168 pale leaf 189 202 168 PaleLeaf 163 189 156 spring rain 163 189 156 SpringRain 139 165 143 envy 150 167 147 mantle 143 182 156 summer green 143 182 156 SummerGreen 154 192 182 shadow green 154 192 182 ShadowGreen 138 174 164 sea nymph 138 174 164 SeaNymph 119 168 171 neptune 129 166 170 ziggurat 140 168 160 cascade 157 180 170 skeptic 174 187 193 heather 179 187 183 loblolly 172 182 178 periglacial blue 172 182 178 PeriglacialBlue 172 174 169 silver chalice 172 174 169 SilverChalice 170 181 184 casper 160 177 174 conch 156 172 165 tower grey 156 172 165 TowerGrey 161 169 168 hit grey 161 169 168 HitGrey 164 173 176 gull grey 164 173 176 GullGrey 146 172 180 botticelli 147 170 185 nepal 162 161 172 spun pearl 162 161 172 SpunPearl 165 169 178 mischka 159 163 167 grey chateau 159 163 167 GreyChateau 169 157 157 nobel 160 159 156 mountain mist 160 159 156 MountainMist 179 171 182 chatelle 174 174 173 bombay 191 179 178 pink swan 191 179 178 PinkSwan 190 180 171 tide 191 186 175 cotton seed 191 186 175 CottonSeed 189 186 174 grey nickel 189 186 174 GreyNickel 187 173 161 silk 202 184 162 grain brown 202 184 162 GrainBrown 204 182 155 vanilla 201 181 154 sour dough 201 181 154 SourDough 197 186 160 sisal 192 176 147 coral 190 178 154 akaroa 191 181 162 tea 186 183 162 linen 186 185 169 mist grey 186 185 169 MistGrey 190 186 167 ash 184 181 161 tana 169 175 153 green spring 169 175 153 GreenSpring 158 170 158 robins egg blue 158 170 158 RobinsEggBlue 167 166 157 foggy grey 167 166 157 FoggyGrey 160 161 151 star dust 160 161 151 StarDust 151 164 154 edward 165 168 143 bud 170 165 131 neutral green 170 165 131 NeutralGreen 176 172 148 eagle 181 172 148 bison hide 181 172 148 BisonHide 183 168 163 martini 176 169 159 cloudy 162 149 137 zorba 165 151 132 malta 167 151 129 bronco 161 153 134 nomad 163 152 129 raincloud 163 154 135 napa 152 145 113 gurkha 161 154 127 grey olive 161 154 127 GreyOlive 153 155 149 delta 159 157 145 dawn 153 154 134 lemon grass 153 154 134 LemonGrass 135 135 111 schist 136 137 108 bitter 135 132 102 bandicoot 156 141 114 pale oyster 156 141 114 PaleOyster 141 132 120 schooner 137 132 120 taupe grey 137 132 120 TaupeGrey 148 140 126 heathered grey 148 140 126 HeatheredGrey 134 131 122 friar grey 134 131 122 FriarGrey 132 135 137 aluminium 139 134 133 suva grey 139 134 133 SuvaGrey 135 135 133 jumbo 159 155 157 shady lady 159 155 157 ShadyLady 147 145 160 grey suit 147 145 160 GreySuit 153 152 167 santas grey 153 152 167 SantasGrey 132 156 169 bali hai 132 156 169 BaliHai 146 159 162 powder blue 146 159 162 PowderBlue 140 156 156 submarine 133 136 133 stack 129 137 136 oslo grey 129 137 136 OsloGrey 113 143 138 gumbo 123 148 140 granny smith 123 148 140 GrannySmith 116 145 142 juniper 100 136 148 horizon 105 136 144 gothic 85 143 147 half baked 85 143 147 HalfBaked 99 146 131 patina 123 137 118 spanish green 123 137 118 SpanishGreen 145 160 146 pewter 110 141 113 laurel 109 154 120 oxley 123 177 141 bay leaf 123 177 141 BayLeaf 126 179 148 padua 117 170 148 acapulco 116 178 168 gulf stream 116 178 168 GulfStream 109 175 167 tradewind 122 197 180 monte carlo 122 197 180 MonteCarlo 101 173 178 fountain blue 101 173 178 FountainBlue 64 143 144 blue chill 64 143 144 BlueChill 72 144 132 lochinvar 37 151 151 java 95 182 156 keppel 89 186 163 puerto rico 89 186 163 PuertoRico 103 190 144 silver tree 103 190 144 SilverTree 41 169 139 niagara 57 159 134 gossamer 50 151 96 eucalyptus 65 159 89 chateau green 65 159 89 ChateauGreen 76 169 115 ocean green 76 169 115 OceanGreen 133 202 135 de york 133 202 135 DeYork 127 193 92 mantis 102 179 72 apple 75 163 81 fruit salad 75 163 81 FruitSalad 95 146 40 vida loca 95 146 40 VidaLoca 136 169 91 chelsea cucumber 136 169 91 ChelseaCucumber 122 148 97 highland 149 152 107 avocado 152 159 122 sage 125 157 114 amulet 132 145 55 wasabi 146 140 60 sycamore 146 140 60 highball 150 132 40 lemon ginger 150 132 40 LemonGinger 169 141 54 reef gold 169 141 54 ReefGold 173 138 59 alpine 182 150 66 roti 178 153 75 husk 174 144 65 turmeric 171 141 63 luxor gold 171 141 63 LuxorGold 151 151 111 malachite green 151 151 111 MalachiteGreen 163 153 119 tallow 163 153 119 canvas 186 171 135 pavlova 167 160 126 hillary 199 184 130 yuma 187 181 141 coriander 184 173 138 chino 205 174 112 putty 198 169 94 laser 210 185 96 tacha 185 173 97 gimblet 175 193 130 caper 185 184 128 pea soup 185 184 128 PeaSoup 156 166 100 green smoke 156 166 100 GreenSmoke 162 165 128 locust 164 184 143 norway 184 202 157 sprout 191 194 152 green mist 191 194 152 GreenMist 189 192 126 pine glade 189 192 126 PineGlade 227 212 116 wild rice 227 212 116 WildRice 204 207 130 deco 222 203 129 sandwisp 222 195 113 chenin 245 205 130 cherokee 235 200 129 marzipan 228 195 133 new orleans 228 195 133 NewOrleans 223 194 129 chalky 221 194 131 zombie 218 190 130 straw 220 198 160 raffia 199 189 149 thistle 208 195 131 winter hazel 208 195 131 WinterHazel 224 216 167 mint julep 224 216 167 MintJulep 216 204 155 tahuna sands 216 204 155 TahunaSands 225 213 166 sapling 233 215 171 colonial white 233 215 171 ColonialWhite 233 215 171 beeswax 237 213 166 astra 235 212 174 givry 237 210 164 dairy cream 237 210 164 DairyCream 232 212 162 hampton 228 207 153 double colonial white 228 207 153 DoubleColonialWhite 232 205 154 chamois 224 200 141 egg white 224 200 141 EggWhite 241 215 158 splash 246 224 164 buttermilk 254 224 165 cape honey 254 224 165 CapeHoney 251 229 194 peach 243 215 182 pink lady 243 215 182 PinkLady 238 217 182 champagne 240 223 187 dutch white 240 223 187 DutchWhite 240 223 187 baja white 240 223 187 BajaWhite 243 229 192 milk punch 243 229 192 MilkPunch 247 229 183 barley white 247 229 183 BarleyWhite 233 217 169 sidecar 242 229 191 half colonial white 242 229 191 HalfColonialWhite 248 243 196 corn field 248 243 196 CornField 241 241 198 spring sun 241 241 198 SpringSun 245 245 204 mimosa 252 237 197 oasis 255 227 155 cream brulee 255 227 155 CreamBrulee 255 214 123 salomie 249 215 126 golden glow 249 215 126 GoldenGlow 249 228 150 vis vis 249 228 150 VisVis 248 234 151 picasso 251 235 155 drover 249 245 159 pale prim 249 245 159 PalePrim 248 246 168 shalimar 244 240 155 portafino 228 222 142 primrose 246 244 147 milan 240 245 144 tidal 238 242 147 jonquil 239 248 170 australian mint 239 248 170 AustralianMint 240 245 187 chiffon 227 229 177 tusk 245 249 203 carla 245 244 193 cumulus 234 247 201 snow flurry 234 247 201 SnowFlurry 183 227 168 madang 159 211 133 gossip 165 215 133 feijoa 198 234 128 sulu 209 239 159 reef 218 234 111 mindaro 177 221 82 conifer 156 208 59 atlantis 183 197 44 lime 183 198 26 rio grande 183 198 26 RioGrande 198 218 54 las palmas 198 218 54 LasPalmas 194 214 46 fuego 210 219 50 bitter lemon 210 219 50 BitterLemon 253 227 54 gorse 235 222 49 golden fizz 235 222 49 GoldenFizz 226 230 77 canary 251 235 80 paris daisy 251 235 80 ParisDaisy 245 241 113 dolly 232 237 105 honeysuckle 236 230 126 texas 251 240 115 witch haze 251 240 115 WitchHaze 249 225 118 sweet corn 249 225 118 SweetCorn 245 204 35 turbo 241 204 43 golden dream 241 204 43 GoldenDream 238 204 36 broom 245 215 82 energy yellow 245 215 82 EnergyYellow 234 204 74 festival 218 192 26 sunflower 240 196 32 moon yellow 240 196 32 MoonYellow 236 189 44 bright sun 236 189 44 BrightSun 238 192 81 cream can 238 192 81 CreamCan 249 208 84 kournikova 224 193 97 creme de banane 224 193 97 CremeDeBanane 234 206 106 golden sand 234 206 106 GoldenSand 240 213 85 portica 221 203 70 confetti 228 219 85 manz 190 202 96 wild willow 190 202 96 WildWillow 214 202 61 wattle 227 221 57 starship 208 193 23 bird flower 208 193 23 BirdFlower 210 198 31 barberry 184 167 34 earls green 184 167 34 EarlsGreen 196 170 77 sundance 217 178 32 lemon 188 155 27 buddha gold 188 155 27 BuddhaGold 183 152 38 sahara 158 128 34 hacienda 171 154 28 lucky 142 154 33 citron 186 192 14 la rioja 186 192 14 LaRioja 169 192 28 bahia 159 183 10 citrus 137 172 39 limerick 180 192 76 celery 124 159 47 sushi 95 151 39 limeade 122 172 33 lima 113 169 29 christi 32 105 55 camarone 44 110 49 san felix 44 110 49 SanFelix 47 117 50 japanese laurel 47 117 50 JapaneseLaurel 62 128 39 bilbao 66 137 41 la palma 66 137 41 LaPalma 95 129 81 glade green 95 129 81 GladeGreen 96 138 90 hippie green 96 138 90 HippieGreen 96 124 71 dingley 72 101 49 dell 82 107 45 green leaf 82 107 45 GreenLeaf 62 99 52 green house 62 99 52 GreenHouse 54 92 52 fern 72 83 26 verdun green 72 83 26 VerdunGreen 87 94 46 fern frond 87 94 46 FernFrond 71 86 47 clover 85 91 44 saratoga 90 110 65 chalet green 90 110 65 ChaletGreen 99 111 34 fiji green 99 111 34 FijiGreen 102 112 40 rain forest 102 112 40 RainForest 102 112 40 pacifika 116 112 40 olivetone 126 132 36 trendy green 126 132 36 TrendyGreen 103 105 39 pistachio 130 106 33 yukon gold 130 106 33 YukonGold 122 114 41 pesto 122 114 41 grass hopper 122 114 41 GrassHopper 119 113 43 crete 124 103 32 mustard 141 112 42 stinger 141 112 42 corn harvest 141 112 42 CornHarvest 137 126 89 clay creek 137 126 89 ClayCreek 130 133 98 flax 120 110 76 go ben 120 110 76 GoBen 107 91 61 limed gum 107 91 61 LimedGum 115 99 62 yellow metal 115 99 62 YellowMetal 117 91 39 kumera 115 99 48 himalaya 115 99 48 acorn 98 93 42 planter 98 93 42 costa del sol 98 93 42 CostaDelSol 98 96 62 verdigris 109 86 44 horses neck 109 86 44 HorsesNeck 92 81 47 west coast 92 81 47 WestCoast 88 76 37 bronze olive 88 76 37 BronzeOlive 67 76 40 bronzetone 54 62 29 turtle green 54 62 29 TurtleGreen 110 51 38 pueblo 115 61 31 peru tan 115 61 31 PeruTan 112 65 40 dark rimu 112 65 40 DarkRimu 109 59 36 new amber 109 59 36 NewAmber 91 58 36 carnaby tan 91 58 36 CarnabyTan 83 51 30 brown bramble 83 51 30 BrownBramble 80 56 30 saddle brown 80 56 30 SaddleBrown 91 61 39 bracken 98 66 43 irish coffee 98 66 43 IrishCoffee 102 74 45 dallas 109 77 44 ironbark 106 73 40 cafe royale 106 73 40 CafeRoyale 108 70 31 antique brass 108 70 31 AntiqueBrass 117 72 47 cape palliser 117 72 47 CapePalliser 125 78 56 cigar 121 77 46 walnut 132 92 64 potters clay 132 92 64 PottersClay 136 89 49 natural 116 89 55 shingle fawn 116 89 55 ShingleFawn 140 114 84 limed oak 140 114 84 LimedOak 140 99 56 mckenzie 143 111 72 driftwood 141 95 44 rusty nail 141 95 44 RustyNail 144 94 38 afghan tan 144 94 38 AfghanTan 157 112 46 buttered rum 157 112 46 ButteredRum 167 117 44 hot toddy 167 117 44 HotToddy 129 91 40 hot curry 129 91 40 HotCurry 129 91 40 brazil 153 82 43 hawaiian tan 153 82 43 HawaiianTan 178 110 51 reno sand 178 110 51 RenoSand 186 111 63 bamboo 175 108 62 bourbon 177 108 57 oregon 171 107 53 pumpkin 165 101 49 mai tai 165 101 49 MaiTai 161 82 38 rich gold 161 82 38 RichGold 157 84 50 piper 156 91 52 indochine 161 95 59 desert 161 98 59 red beech 161 98 59 RedBeech 173 98 66 tuscany 169 106 80 sante fe 169 106 80 SanteFe 149 78 44 alert tan 149 78 44 AlertTan 149 83 47 chelsea gem 149 83 47 ChelseaGem 142 89 60 rope 134 75 54 paarl 136 79 64 mule fawn 136 79 64 MuleFawn 134 80 64 ironstone 119 66 44 copper canyon 119 66 44 CopperCanyon 122 68 52 peanut 120 68 48 cumin 117 68 43 bull shot 117 68 43 BullShot 123 72 43 cinnamon 128 78 44 korma 136 60 50 prairie sand 136 60 50 PrairieSand 135 56 47 crab apple 135 56 47 CrabApple 136 53 49 totem pole 136 53 49 TotemPole 142 58 54 tabasco 140 63 48 embers 143 63 42 fire 142 53 55 well read 142 53 55 WellRead 146 56 48 thunderbird 155 61 61 mexican red 155 61 61 MexicanRed 161 71 67 roof terracotta 161 71 67 RoofTerracotta 151 66 45 tia maria 151 66 45 TiaMaria 157 68 45 rock spray 157 68 45 RockSpray 154 70 61 cognac 151 70 60 mojo 166 86 72 crail 169 82 73 apple blossom 169 82 73 AppleBlossom 199 97 85 sunglo 190 92 72 flame pea 190 92 72 FlamePea 168 83 53 orange roughy 168 83 53 OrangeRoughy 168 85 51 vesuvius 177 89 47 fiery orange 177 89 47 FieryOrange 172 81 45 rose of sharon 172 81 45 RoseOfSharon 173 82 46 red stage 173 82 46 RedStage 201 97 56 ecstasy 187 95 52 smoke tree 187 95 52 SmokeTree 191 101 46 christine 205 93 52 tangerine 208 94 52 chilean fire 208 94 52 ChileanFire 193 77 54 grenadier 197 79 51 trinidad 193 79 59 clementine 192 81 74 sunset 212 87 78 valencia 205 82 91 mandy 168 50 57 punch 158 51 50 milano red 158 51 50 MilanoRed 146 42 49 bright red 146 42 49 BrightRed 149 46 49 guardsman red 149 46 49 GuardsmanRed 134 40 46 monza 134 40 46 flame red 134 40 46 FlameRed 213 108 48 gold drop 213 108 48 GoldDrop 220 114 42 tahiti gold 220 114 42 TahitiGold 212 111 49 tango 229 127 61 pizazz 229 130 58 west side 229 130 58 WestSide 226 129 59 tree poppy 226 129 59 TreePoppy 234 134 69 flamenco 239 142 56 sun 186 120 42 pirate gold 186 120 42 PirateGold 197 131 46 geebung 202 129 54 golden bell 202 129 54 GoldenBell 205 132 49 dixie 209 144 51 fuel yellow 209 144 51 FuelYellow 187 142 52 hokey pokey 187 142 52 HokeyPokey 188 146 41 nugget 226 178 39 gold tips 226 178 39 GoldTips 216 167 35 galliano 223 170 40 corn 227 172 61 tulip tree 227 172 61 TulipTree 221 173 86 rob roy 221 173 86 RobRoy 220 159 69 saffron 224 157 55 candlelight 244 159 53 yellow sea 244 159 53 YellowSea 218 148 41 buttercup 224 152 66 fire bush 224 152 66 FireBush 250 157 73 sunshade 239 149 72 sea buckthorn 239 149 72 SeaBuckthorn 233 140 58 california 247 162 51 lightning yellow 247 162 51 LightningYellow 252 174 96 rajah 252 176 87 texas rose 252 176 87 TexasRose 253 174 69 my sin 253 174 69 MySin 254 181 82 koromiko 255 193 82 golden tainoi 255 193 82 GoldenTainoi 240 178 83 casablanca 234 184 82 ronchi 255 205 115 grandis 255 180 55 supernova 255 213 154 caramel 254 219 183 sandy beach 254 219 183 SandyBeach 255 215 160 frangipani 244 208 164 tequila 238 199 162 negroni 255 198 158 romantic 223 185 146 pancho 220 182 138 brandy 227 185 130 maize 233 186 129 corvette 255 200 120 chardonnay 234 183 106 harvest gold 234 183 106 HarvestGold 246 174 120 tacao 245 183 153 mandys pink 245 183 153 MandysPink 238 179 158 wax flower 238 179 158 WaxFlower 254 171 154 rose bud 254 171 154 RoseBud 231 158 136 tonys pink 231 158 136 TonysPink 253 164 112 hit pink 253 164 112 HitPink 228 143 103 apricot 223 157 91 porsche 212 145 93 whiskey sour 212 145 93 WhiskeySour 212 145 93 di serria 212 145 93 DiSerria 210 144 98 whiskey 211 169 92 apache 218 177 96 equator 213 177 133 calico 226 175 128 manhattan 204 164 131 cameo 199 163 132 rodeo dust 199 163 132 RodeoDust 182 147 92 barley corn 182 147 92 BarleyCorn 157 127 97 sorrell brown 157 127 97 SorrellBrown 163 135 106 sandal 165 139 111 mongoose 158 126 83 muesli 169 132 79 muddy waters 169 132 79 MuddyWaters 171 137 83 teak 191 145 75 tussock 191 141 60 pizza 184 138 61 marigold 181 123 46 mandalay 198 142 63 anzac 193 145 86 twine 192 124 64 brandy punch 192 124 64 BrandyPunch 187 116 49 meteor 198 114 59 zest 198 128 89 peach schnapps 198 128 89 PeachSchnapps 208 131 99 burning sand 208 131 99 BurningSand 206 114 89 japonica 231 123 117 geraldine 221 131 116 new york pink 221 131 116 NewYorkPink 255 152 137 mona lisa 255 152 137 MonaLisa 243 134 83 crusta 203 111 74 red damask 203 111 74 RedDamask 221 107 56 sorbus 226 121 69 jaffa 225 99 79 flamingo 239 115 94 persimmon 216 98 91 roman 229 109 117 froly 227 111 138 deep blush 227 111 138 DeepBlush 205 109 147 hopbush 232 153 190 shocking 239 149 174 illusion 224 147 171 kobi 230 128 149 carissma 241 145 154 wewak 238 145 141 sweet pink 238 145 141 SweetPink 219 129 126 sea pink 219 129 126 SeaPink 208 116 139 charm 193 111 104 contessa 194 142 136 oriental pink 194 142 136 OrientalPink 179 112 132 tapestry 208 138 155 can can 208 138 155 CanCan 167 129 153 bouquet 197 143 157 viola 164 135 139 wisteria 174 148 171 london hue 174 148 171 LondonHue 149 135 156 amethyst smoke 149 135 156 AmethystSmoke 157 156 180 logan 152 126 126 opium 154 134 120 almond frost 154 134 120 AlmondFrost 152 125 115 hemp 182 133 122 brandy rose 182 133 122 BrandyRose 175 147 125 sandrift 177 148 143 thatch 181 153 142 del rio 181 153 142 DelRio 195 152 139 quicksand 211 161 148 rose 205 165 156 eunry 209 179 153 cashmere 210 179 169 clam shell 210 179 169 ClamShell 202 181 178 cold turkey 202 181 178 ColdTurkey 200 177 192 maverick 172 155 155 dusty grey 172 155 155 DustyGrey 185 172 187 lola 193 159 179 lily 201 154 160 careys pink 201 154 160 CareysPink 218 151 144 petite orchid 218 151 144 PetiteOrchid 214 139 128 my pink 214 139 128 MyPink 255 171 160 cornflower 248 175 169 sundown 255 197 187 your pink 255 197 187 YourPink 249 192 196 azalea 223 177 182 blossom 245 178 197 cupid 222 183 217 french lilac 222 183 217 FrenchLilac 244 200 219 classic rose 244 200 219 ClassicRose 237 184 199 chantilly 224 183 194 melanie 218 192 205 twilight 246 204 215 pink lace 246 204 215 PinkLace 226 205 213 prim 212 181 176 oyster pink 212 181 176 OysterPink 212 187 177 wafer 220 191 172 just right 220 191 172 JustRight 219 194 171 bone 230 178 166 shilo 216 180 182 pink flare 216 180 182 PinkFlare 224 184 177 cavern pink 224 184 177 CavernPink 235 185 179 beauty bush 235 185 179 BeautyBush 245 208 201 coral candy 245 208 201 CoralCandy 242 205 187 watusi 231 210 200 bizarre 229 202 192 dust storm 229 202 192 DustStorm 235 210 209 vanilla ice 235 210 209 VanillaIce 239 220 212 pot pourri 239 220 212 PotPourri 246 222 218 remy 246 227 218 provincial pink 246 227 218 ProvincialPink 252 219 210 pippin 251 215 204 cinderella 254 220 193 karry 249 211 190 tuft bush 249 211 190 TuftBush 253 215 216 we peep 253 215 216 WePeep 252 213 207 cosmos 253 233 224 chablis 250 230 223 bridesmaid 248 228 227 tutu 245 230 234 amour 248 219 224 carousel pink 248 219 224 CarouselPink 239 214 218 pale rose 239 214 218 PaleRose 228 215 229 snuff 227 214 233 blue chalk 227 214 233 BlueChalk 245 215 220 cherub 213 199 232 fog 195 185 221 melrose 202 180 212 prelude 174 153 210 biloba flower 174 153 210 BilobaFlower 194 169 219 perfume 162 158 205 wistful 192 178 215 moon raker 192 178 215 MoonRaker 172 185 232 perano 139 152 216 portage 157 138 191 cold purple 157 138 191 ColdPurple 170 140 188 east side 170 140 188 EastSide 159 144 208 lavender 148 112 196 lilac bush 148 112 196 LilacBush 123 92 183 fuchsia 114 74 161 studio 91 62 144 daisy bush 91 62 144 DaisyBush 181 75 115 royal heath 181 75 115 RoyalHeath 138 45 82 rose bud cherry 138 45 82 RoseBudCherry 137 45 79 disco 150 44 84 lipstick 169 64 100 rouge 180 56 100 cranberry 162 61 84 night shadz 162 61 84 NightShadz 179 54 84 hibiscus 205 82 108 cabaret 181 80 103 blush 171 73 92 hippie pink 171 73 92 HippiePink 138 51 53 old brick 138 51 53 OldBrick 133 53 52 tall poppy 133 53 52 TallPoppy 143 62 63 rosewood 131 61 62 stiletto 128 58 75 camelot 149 82 100 vin rouge 149 82 100 VinRouge 152 73 97 cadillac 148 106 129 strikemaster 105 69 84 finn 121 77 96 cosmic 142 81 100 cannon pink 142 81 100 CannonPink 116 64 66 tosca 133 73 76 solid pink 133 73 76 SolidPink 125 65 56 red robin 125 65 56 RedRobin 126 74 59 nutmeg 143 78 69 el salva 143 78 69 ElSalva 142 77 69 matrix 139 80 75 lotus 149 82 76 copper rust 149 82 76 CopperRust 165 110 117 turkish rose 165 110 117 TurkishRose 171 110 103 coral tree 171 110 103 CoralTree 158 103 89 au chico 158 103 89 AuChico 139 95 77 spicy mix 139 95 77 SpicyMix 144 106 84 leather 159 113 95 toast 135 106 104 ferra 130 102 99 pharlap 125 101 92 russett 143 119 119 bazaar 125 103 87 roman coffee 125 103 87 RomanCoffee 109 88 67 tobacco brown 109 88 67 TobaccoBrown 115 85 62 pickled bean 115 85 62 PickledBean 115 80 59 old copper 115 80 59 OldCopper 103 72 52 jambalaya 108 79 63 spice 106 84 69 quincy 101 77 73 congo brown 101 77 73 CongoBrown 110 81 80 buccaneer 107 90 90 zambezi 110 90 91 falcon 82 77 91 mulled wine 82 77 91 MulledWine 98 86 101 fedora 96 90 103 mobster 118 109 124 mamba 113 102 117 rum 137 117 120 spicy pink 137 117 120 SpicyPink 139 125 130 venus 130 114 164 deluge 102 111 180 chetwode blue 102 111 180 ChetwodeBlue 111 99 160 scampi 131 120 199 moody blue 131 120 199 MoodyBlue 142 114 199 true v 142 114 199 TrueV 106 91 177 blue marguerite 106 91 177 BlueMarguerite 146 113 167 ce soir 146 113 167 CeSoir 128 93 128 trendy pink 128 93 128 TrendyPink 116 80 133 affair 104 87 140 butterfly bush 104 87 140 ButterflyBush 81 85 155 governor bay 81 85 155 GovernorBay 86 71 134 gigas 86 73 133 victoria 66 99 159 mariner 55 78 136 tory blue 55 78 136 ToryBlue 51 80 131 fun blue 51 80 131 FunBlue 63 82 129 sapphire 105 93 135 kimberly 53 62 100 bay of many 53 62 100 BayOfMany 61 50 93 jacarta 59 67 108 port gore 59 67 108 PortGore 52 52 103 deep koamaru 52 52 103 DeepKoamaru 53 61 117 torea bay 53 61 117 ToreaBay 50 63 117 resolution blue 50 63 117 ResolutionBlue 61 63 125 jacksons purple 61 63 125 JacksonsPurple 62 50 103 minsk 75 60 142 blue gem 75 60 142 BlueGem 57 45 115 blue bell 57 45 115 BlueBell 75 45 114 blue diamond 75 45 114 BlueDiamond 92 60 109 honey flower 92 60 109 HoneyFlower 74 59 106 meteorite 78 46 83 hot purple 78 46 83 HotPurple 74 45 87 scarlet gum 74 45 87 ScarletGum 46 24 59 blackcurrant 56 26 56 plum 56 33 97 christalle 49 39 96 paris m 49 39 96 ParisM 46 34 73 violent violet 46 34 73 ViolentViolet 42 37 81 paua 55 45 82 cherry pie 55 45 82 CherryPie 41 45 79 lucky point 41 45 79 LuckyPoint 42 43 65 valhalla 63 46 76 jagger 45 37 65 tolopea 55 37 40 aubergine 60 33 38 temptress 53 34 53 mardi gras 53 34 53 MardiGras 61 35 39 chocolate 62 38 49 toledo 69 46 57 barossa 59 43 44 jarrah 59 43 44 havana 52 41 49 melanzane 54 45 56 jacaranda 56 44 56 valentino 47 38 60 violet 60 55 72 martinique 68 50 64 voodoo 76 51 71 loulou 76 61 78 bossanova 85 69 69 woody brown 85 69 69 WoodyBrown 69 52 48 rebel 70 52 48 cedar 68 55 54 cowboy 77 62 60 crater brown 77 62 60 CraterBrown 79 56 53 cocoa bean 79 56 53 CocoaBean 82 57 54 van cleef 82 57 54 VanCleef 74 53 49 bean 74 46 50 cab sav 74 46 50 CabSav 78 49 45 espresso 78 49 46 cherrywood 89 69 55 brown derby 89 69 55 BrownDerby 93 59 46 cioccolato 85 52 43 dark oak 85 52 43 DarkOak 91 52 46 redwood 79 48 31 indian tan 79 48 31 IndianTan 68 45 33 morocco brown 68 45 33 MoroccoBrown 60 36 27 brown pod 60 36 27 BrownPod 62 47 46 tamarind 73 38 37 mahogany 64 35 39 maroon 58 24 26 rustic red 58 24 26 RusticRed 72 36 39 bulgarian rose 72 36 39 BulgarianRose 79 42 44 heath 78 39 40 volcano 82 36 38 lonestar 79 33 42 persian red 79 33 42 PersianRed 76 28 36 bordeaux 88 33 36 burnt crimson 88 33 36 BurntCrimson 91 31 34 venetian red 91 31 34 VenetianRed 93 31 30 red oxide 93 31 30 RedOxide 101 37 37 burgundy 102 42 44 red devil 102 42 44 RedDevil 97 45 45 dark tan 97 45 45 DarkTan 103 47 48 japanese maple 103 47 48 JapaneseMaple 88 47 43 moccaccino 99 53 40 hairy heath 99 53 40 HairyHeath 107 52 42 meranti 108 55 54 sanguine brown 108 55 54 SanguineBrown 102 54 45 oiled cedar 102 54 45 OiledCedar 110 61 52 metallic copper 110 61 52 MetallicCopper 118 60 51 crown of thorns 118 60 51 CrownOfThorns 111 55 45 mocha 108 50 46 kenyan copper 108 50 46 KenyanCopper 104 51 50 persian plum 104 51 50 PersianPlum 115 52 58 merlot 113 51 60 ribbon 95 44 47 jazz 94 42 64 mulberry 83 41 52 black rose 83 41 52 BlackRose 82 44 53 wine berry 82 44 53 WineBerry 100 58 72 tawny port 100 58 72 TawnyPort 68 35 47 castro 67 24 47 blackberry 122 46 77 flirt 106 31 68 pompadour 106 31 68 nightclub 105 41 59 siren 110 34 51 claret 124 45 55 paprika 117 43 47 tamarillo 120 46 44 lusty 130 42 50 sangria 132 40 51 shiraz 126 37 48 scarlett 112 31 40 red berry 112 31 40 RedBerry 101 28 38 pohutukawa 107 37 44 western red 107 37 44 WesternRed 107 37 44 monarch 107 37 44 hot chile 107 37 44 HotChile 138 36 78 cardinal 105 50 110 seance 110 57 116 eminence 104 59 125 clairvoyant 88 53 128 kingfisher daisy 88 53 128 KingfisherDaisy 70 44 119 windsor gpick_0.2.5/share/gpick/gpick-gray-pattern.png0000644000175000017500000000035512070605214020022 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYsvv}ՂtEXtSoftwarewww.inkscape.org<jIDATXԱ 0 DяG+K+@tVzZ~<#IU(UPBePgf/2ʸ;`v;`~C|+IENDB`gpick_0.2.5/share/gpick/helpers.lua0000644000175000017500000000047512070605214015754 0ustar zbygzbyg function suggest(filename) local function p_require() require(filename); end; local function supress_error(err) print(err); end; return xpcall(p_require, supress_error); end; function round(number) if number-math.floor(number)>=0.5 then return math.ceil(number); else return math.floor(number); end; end; gpick_0.2.5/share/gpick/layouts.lua0000644000175000017500000002015612113713537016016 0ustar zbygzbyg gpick.layouts = {}; layouts = {}; layouts.add_buttons = function (container, buttons, percentage, button_style, text_style, spacing) local root = layout:new_box('', spacing , spacing, 1-spacing*2, percentage-spacing*2); container:add(root); local size = 1/buttons; local padding = size/8; local styles_n = # button_style; local styles_text_n = # text_style; local texts = {_("Homepage"), _("About us"), _("Links to us"), _("Privacy"), _("Terms"), _("Contact us"), _("RSS")}; for i=0,buttons-1 do local button = layout:new_fill("button", padding, i*size+padding, 1-padding*2, size-padding, button_style[i % styles_n + 1] ); button:add(layouts.make_helper(layout:new_text("button_text", 0.25, 0.65, 0.5, 0.3, text_style[i % styles_text_n + 1], button_style[i % styles_n + 1]:humanname()))); button:add(layout:new_text("button_text", 0.25, 0.25, 0.5, 0.5, text_style[i % styles_text_n + 1], texts[i % (# texts) + 1])); root:add(button); end; return container; end; layouts.add_text = function (container, lines, style) local text = color:new(); for i=0,lines-1 do container:add(layout:new_text("content_text", 0.02, i*0.06+0.01, 0.96, 0.06, style, _("The quick brown fox jumps over the lazy dog"))); end; return container; end; layouts.make_helper = function (container) container:helper_only(true); return container; end; layouts.make_locked = function (container) container:locked(true); return container; end; gpick.layouts['std_layout_webpage_1'] = { human_readable = _("Webpage"), mask = 0, build = function (layout_system) local styles = { header = layout_style:new("header_b:" .. _("Header"), color:new(0.2, 0.2, 0.2)), header_text = layout_style:new("header_t:" .. _("Header text"), color:new(1.0, 1.0, 1.0), 1.0), content = layout_style:new("content_b:" .. _("Content"), color:new(0.6, 0.6, 0.6)), content_text = layout_style:new("content_t:" .. _("Content text"), color:new(0.1, 0.1, 0.1), 0.6), sidebar = layout_style:new("sidebar_b:" .. _("Sidebar"), color:new(0.7, 0.7, 0.7)), button = layout_style:new("navitem_b:" .. _("Button"), color:new(0.3, 0.3, 0.3)), button_hover = layout_style:new("navitem_bh:" .. _("Button (hover)"), color:new(0.35, 0.35, 0.35)), button_text = layout_style:new("navitem_t:" .. _("Button text"), color:new(0.8, 0.8, 0.8), 0.95), button_text_hover = layout_style:new("navitem_th:" .. _("Button text (hover)"), color:new(0.9, 0.9, 0.9), 0.95), footer = layout_style:new("footer_b:" .. _("Footer"), color:new(0.1, 0.1, 0.1)), }; for i,v in pairs(styles) do layout_system:addstyle(v); end; local root = layout:new_box("root", 0, 0, 640, 480); layout_system:setbox(root); root:add(layout:new_fill("header", 0, 0, 1, 0.15, styles['header']):add(layout:new_text("header_text", 0.25, 0.25, 0.5, 0.5, styles['header_text'], _("Header")))); root:add(layouts.add_buttons(layout:new_fill("sidebar", 0, 0.15, 0.25, 0.8, styles['sidebar']), 6, 0.7, { styles['button'], styles['button'], styles['button_hover'] }, { styles['button_text'], styles['button_text'], styles['button_text_hover'] }, 0, 0)); root:add(layouts.add_text(layout:new_fill("content", 0.25, 0.15, 0.75, 0.8, styles['content']), 10, styles['content_text'])); root:add(layout:new_fill("footer", 0, 0.95, 1, 0.05, styles['footer']):add(layouts.make_helper(layout:new_text("footer_text", 0.25, 0.5, 0.5, 0.45, nil, styles['footer']:humanname())))); return 1; end; }; gpick.layouts['std_layout_menu_1'] = { human_readable = _("Menu"), mask = 0, build = function (layout_system) local styles = { menu = layout_style:new("menu_b:" .. _("Menu"), color:new(0.7, 0.7, 0.7)), button = layout_style:new("navitem_b:" .. _("Button"), color:new(0.3, 0.3, 0.3)), button_hover = layout_style:new("navitem_bh:" .. _("Button (hover)"), color:new(0.3, 0.3, 0.3)), button_text = layout_style:new("navitem_t:" .. _("Button text"), color:new(0.8, 0.8, 0.8), 1.0), button_text_hover = layout_style:new("navitem_th:" .. _("Button text (hover)"), color:new(0.8, 0.8, 0.8), 1.0), }; for i,v in pairs(styles) do layout_system:addstyle(v); end; local root = layout:new_box("root", 0, 0, 300, 400); layout_system:setbox(root); root:add(layouts.add_buttons(layout:new_fill("menu", 0, 0, 1, 1, styles['menu']), 7, 1, { styles['button'], styles['button'], styles['button_hover'] }, { styles['button_text'], styles['button_text'], styles['button_text_hover'] }, 0.1)); return 1; end; }; gpick.layouts['std_layout_brightness_darkness'] = { human_readable = _("Brightness-Darkness"), mask = 1, build = function (layout_system) local styles = { main = layout_style:new("main:" .. _("main"), color:new(0.7, 0.7, 0.7)), bvar1 = layout_style:new("b1:b1", color:new(0.3, 0.3, 0.3)), bvar2 = layout_style:new("b2:b2", color:new(0.3, 0.3, 0.3)), bvar3 = layout_style:new("b3:b3", color:new(0.3, 0.3, 0.3)), bvar4 = layout_style:new("b4:b4", color:new(0.3, 0.3, 0.3)), cvar1 = layout_style:new("c1:c1", color:new(0.3, 0.3, 0.3)), cvar2 = layout_style:new("c2:c2", color:new(0.3, 0.3, 0.3)), cvar3 = layout_style:new("c3:c3", color:new(0.3, 0.3, 0.3)), cvar4 = layout_style:new("c4:c4", color:new(0.3, 0.3, 0.3)), }; local styles_order = {'cvar4', 'cvar3', 'cvar2','cvar1', 'main', 'bvar1', 'bvar2', 'bvar3', 'bvar4'}; for i,v in ipairs(styles_order) do layout_system:addstyle(styles[v]); end; local root = layout:new_box("root", 0, 0, 320, 128); layout_system:setbox(root); root:add(layouts.make_locked(layout:new_fill("b1", 0.00, 0.00, 0.30, 0.25, styles['bvar1']))); root:add(layouts.make_locked(layout:new_fill("b2", 0.00, 0.25, 0.30, 0.25, styles['bvar2']))); root:add(layouts.make_locked(layout:new_fill("b3", 0.00, 0.50, 0.30, 0.25, styles['bvar3']))); root:add(layouts.make_locked(layout:new_fill("b4", 0.00, 0.75, 0.30, 0.25, styles['bvar4']))); root:add(layouts.make_locked(layout:new_fill("c1", 0.70, 0.00, 0.30, 0.25, styles['cvar1']))); root:add(layouts.make_locked(layout:new_fill("c2", 0.70, 0.25, 0.30, 0.25, styles['cvar2']))); root:add(layouts.make_locked(layout:new_fill("c3", 0.70, 0.50, 0.30, 0.25, styles['cvar3']))); root:add(layouts.make_locked(layout:new_fill("c4", 0.70, 0.75, 0.30, 0.25, styles['cvar4']))); root:add(layout:new_fill("main", 0.30, 0.00, 0.40, 1.00, styles['main'])); return 1; end; }; gpick.layouts['std_layout_grid_1'] = { human_readable = _("Grid (4x3)"), mask = 0, build = function (layout_system) local root = layout:new_box("root", 0, 0, 400, 300); layout_system:setbox(root); for j=0,2 do for i=0,3 do local item_i = 1 + (i + j * 4); local style = layout_style:new("item" .. item_i .. ":" .. _("Item") .. item_i, color:new(0.8, 0.8, 0.8), 1.0); local style_text = layout_style:new("item" .. item_i .. "_text:" .. _("Item text") .. item_i, color:new(0.2, 0.2, 0.2), 0.5); layout_system:addstyle(style); layout_system:addstyle(style_text); local fill = layout:new_fill("b" .. item_i, (1 / 4) * i, (1 / 3) * j, (1 / 4) * 0.95, (1 / 3) * 0.95, style); fill:add(layout:new_text("item_text".. item_i, 0, 0.25, 1, 0.5, style_text, _("Item") .. item_i)); root:add(fill); end; end; return 1; end; }; gpick.layouts['std_layout_grid_2'] = { human_readable = _("Grid (5x4)"), mask = 0, build = function (layout_system) local root = layout:new_box("root", 0, 0, 500, 400); layout_system:setbox(root); for j=0,3 do for i=0,4 do local item_i = 1 + (i + j * 5); local style = layout_style:new("item" .. item_i .. ":" .. _("Item") .. item_i, color:new(0.8, 0.8, 0.8), 1.0); local style_text = layout_style:new("item" .. item_i .. "_text:" .. _("Item text") .. item_i, color:new(0.2, 0.2, 0.2), 0.5); layout_system:addstyle(style); layout_system:addstyle(style_text); local fill = layout:new_fill("b" .. item_i, (1 / 5) * i, (1 / 4) * j, (1 / 5) * 0.95, (1 / 4) * 0.95, style); fill:add(layout:new_text("item_text".. item_i, 0, 0.25, 1, 0.5, style_text, _("Item") .. item_i)); root:add(fill); end; end; return 1; end; }; gpick.layouts_get = function() local layouts = {}; for k,v in pairs(gpick.layouts) do table.insert(layouts, k) end; table.sort(layouts); return layouts; end; gpick_0.2.5/share/gpick/gpick-falloff-cubic.png0000644000175000017500000000274212070605214020103 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<_IDATX[lE3{vn/ҋjH9MD wB 6Ӡ@@P^%/@DC`Z6-֞r Җn0SZdrforsFT*Z<O>``+Xy涾>̛7ovQQDII_ZZ)**-..[SSӞ?)A9shH&ڵk/-\pd2y&RBJ|Æ 277Wr%Y:{_?}#eX4\afOC^= `F֭[7e˖uuuGg+@XGylWDC#]Zt:=Uno۶)q CpNdc!Xݷ7e=NmƁ~Ylf09i9FjlPPBFKnz:ojj|lҥ/ سgƕ q H0=gj >&$Hڣ?Pvq ٩o:]]]d2.4B2}]Es ɘp-)n7NHR뺋jkk`Z|'DJp)1k!TU2_U7[/\##I$K^ Lx‚'mx2,eqx ܕz6i“֤-dlb5W>00P  i%S O5*0&]hUUU⾾? /4kvdÓVŚTF҂'bUwH8ڜޭrLB ^#+05C&1U)6G,p u8:t~xxxM6Krǂ  A D ĢN9 ;Wky^bJ+zkV (4@F"Z\+!j. Q5q˖N ޜLmspNo#jIENDB`gpick_0.2.5/share/gpick/init.lua0000644000175000017500000001742612113713537015267 0ustar zbygzbyg gpick = {} gpick.converters = {} gpick.user = {} require('helpers') require('layouts') suggest('user_init') gpick.serialize_web_hex = function (color_object) local c = color_object:get_color() return '#' .. string.format('%02X%02X%02X', round(c:red()*255), round(c:green()*255), round(c:blue()*255)) end gpick.deserialize_web_hex = function (text, color_object) local c = color:new() local find_start, find_end, red, green, blue = string.find(text, '#([%x][%x])([%x][%x])([%x][%x])[^%x]?') if find_start~=nil then red = tonumber(red, 16) green = tonumber(green, 16) blue = tonumber(blue, 16) c:red(red/255) c:green(green/255) c:blue(blue/255) color_object:set_color(c) return 1-(math.atan(find_start-1)/math.pi)-(math.atan(string.len(text)-find_end)/math.pi) else return -1 end end gpick.serialize_web_hex_no_hash = function (color_object) local c = color_object:get_color() return string.format('%02X%02X%02X', round(c:red()*255), round(c:green()*255), round(c:blue()*255)) end gpick.deserialize_web_hex_no_hash = function (text, color_object) local c = color:new() local find_start, find_end, red, green, blue = string.find(text, '([%x][%x])([%x][%x])([%x][%x])[^%x]?') if find_start~=nil then red = tonumber(red, 16) green = tonumber(green, 16) blue = tonumber(blue, 16) c:red(red/255) c:green(green/255) c:blue(blue/255) color_object:set_color(c) return 1-(math.atan(find_start-1)/math.pi)-(math.atan(string.len(text)-find_end)/math.pi) else return -1 end end gpick.serialize_web_hex_3_digit = function (color_object) local c = color_object:get_color() return '#' .. string.format('%01X%01X%01X', round(c:red()*15), round(c:green()*15), round(c:blue()*15)) end gpick.deserialize_web_hex_3_digit = function (text, color_object) local c = color:new() local find_start, find_end, red, green, blue = string.find(text, '#([%x])([%x])([%x])[^%x]?') if find_start~=nil then red = tonumber(red, 16) green = tonumber(green, 16) blue = tonumber(blue, 16) c:red(red/15) c:green(green/15) c:blue(blue/15) color_object:set_color(c) return 1-(math.atan(find_start-1)/math.pi)-(math.atan(string.len(text)-find_end)/math.pi) else return -1 end end gpick.serialize_css_hsl = function (color_object) local c = color_object:get_color() c = c:rgb_to_hsl() return 'hsl(' .. string.format('%d, %d%%, %d%%', round(c:hue()*360), round(c:saturation()*100), round(c:lightness()*100)) .. ')' end gpick.serialize_css_rgb = function (color_object) local c = color_object:get_color() return 'rgb(' .. string.format('%d, %d, %d', round(c:red()*255), round(c:green()*255), round(c:blue()*255)) .. ')' end gpick.deserialize_css_rgb = function (text, color_object) local c = color:new() local find_start, find_end, red, green, blue = string.find(text, 'rgb%(([%d]*)[%s]*,[%s]*([%d]*)[%s]*,[%s]*([%d]*)%)') if find_start~=nil then c:rgb(math.min(1, red/255), math.min(1, green/255), math.min(1, blue/255)) color_object:set_color(c) return 1-(math.atan(find_start-1)/math.pi)-(math.atan(string.len(text)-find_end)/math.pi) else return -1 end end gpick.serialize_css_color_hex = function (color_object) return 'color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_background_color_hex = function (color_object) return 'background-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_border_color_hex = function (color_object) return 'border-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_border_top_color_hex = function (color_object) return 'border-top-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_border_right_color_hex = function (color_object) return 'border-right-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_border_bottom_color_hex = function (color_object) return 'border-bottom-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_css_border_left_hex = function (color_object) return 'border-left-color: ' .. gpick.serialize_web_hex(color_object) end gpick.serialize_color_csv = function (color_object) local c = color_object:get_color(); os.setlocale("C", "numeric"); local r = string.format('%f\t%f\t%f', c:red(), c:green(), c:blue()); os.setlocale("", "numeric"); return r; end; gpick.serialize_color_csv = function (color_object) local c = color_object:get_color(); os.setlocale("C", "numeric"); local r = string.format('%f\t%f\t%f', c:red(), c:green(), c:blue()); os.setlocale("", "numeric"); return r; end; gpick.converters['color_web_hex'] = { human_readable = _("Web: hex code"), serialize = gpick.serialize_web_hex, deserialize = gpick.deserialize_web_hex } gpick.converters['color_web_hex_3_digit'] = { human_readable = _("Web: hex code (3 digits)"), serialize = gpick.serialize_web_hex_3_digit, deserialize = gpick.deserialize_web_hex_3_digit } gpick.converters['color_web_hex_no_hash'] = { human_readable = _("Web: hex code (no hash symbol)"), serialize = gpick.serialize_web_hex_no_hash, deserialize = gpick.deserialize_web_hex_no_hash } gpick.converters['color_css_hsl'] = { human_readable = _("CSS: hue saturation lightness"), serialize = gpick.serialize_css_hsl, deserialize = nil } gpick.converters['color_css_rgb'] = { human_readable = _("CSS: red green blue"), serialize = gpick.serialize_css_rgb, deserialize = gpick.deserialize_css_rgb } gpick.converters['css_color_hex'] = { human_readable = 'CSS(color)', serialize = gpick.serialize_css_color_hex, deserialize = nil } gpick.converters['css_background_color_hex'] = { human_readable = 'CSS(background-color)', serialize = gpick.serialize_css_background_color_hex, deserialize = nil } gpick.converters['css_border_color_hex'] = { human_readable = 'CSS(border-color)', serialize = gpick.serialize_css_border_color_hex, deserialize = nil } gpick.converters['css_border_top_color_hex'] = { human_readable = 'CSS(border-top-color)', serialize = gpick.serialize_css_border_top_color_hex, deserialize = nil } gpick.converters['css_border_right_color_hex'] = { human_readable = 'CSS(border-right-color)', serialize = gpick.serialize_css_border_right_color_hex, deserialize = nil } gpick.converters['css_border_bottom_color_hex'] = { human_readable = 'CSS(border-bottom-color)', serialize = gpick.serialize_css_border_bottom_color_hex, deserialize = nil } gpick.converters['css_border_left_hex'] = { human_readable = 'CSS(border-left-color)', serialize = gpick.serialize_css_border_left_hex, deserialize = nil } gpick.converters['color_csv'] = { human_readable = 'CSV', serialize = gpick.serialize_color_csv, deserialize = nil }; gpick.color_serialize = function(converter, color_object) return gpick.converters[converter].serialize(color_object) end gpick.color_deserialize = function(converter, text, color_object) return gpick.converters[converter].deserialize(text, color_object) end gpick.component_to_text = function(component_type, color) if component_type == 'rgb' then return {round(color:red()*255) .. '', round(color:green()*255) .. '', round(color:blue()*255) .. ''} end if component_type == 'hsl' then return {round(color:hue()*360) .. '', round(color:saturation()*100) .. '', round(color:lightness()*100) .. ''} end if component_type == 'hsv' then return {round(color:hue()*360) .. '', round(color:saturation()*100) .. '', round(color:value()*100) .. ''} end if component_type == 'cmyk' then return {round(color:cyan()*255) .. '', round(color:magenta()*255) .. '', round(color:yellow()*255) .. '', round(color:key_black()*255) .. ''} end if component_type == 'lab' then return {round(color:lab_lightness()) .. '', round(color:lab_a()) .. '', round(color:lab_b()) .. ''} end if component_type == 'lch' then return {round(color:lch_lightness()) .. '', round(color:lch_chroma()) .. '', round(color:lch_hue()) .. ''} end return {} end gpick_0.2.5/share/gpick/gpick-falloff-linear.png0000644000175000017500000000245012070605214020264 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATX[lUݙ-e{׶)6RDDPp@(bDbb ">(,Z@@ Z 5$B&\ZD -p邰`R]97fXDdr;NfhћA{n&x<ߛT {C ZBN=px;ݷ hzʓn۶m:F& U777/Z' EBaMH pr ZNU2m񹯕*Jid F֙{ ?PXTi|Uk؏?XnQWPW'V"`Q ppb4m ROA4,ԆID,aJfu-՜9bcF -**|pQB* E 6R"R(PHMN0讖}$r8ͣP)W\C,b;B23+?%aq}&OHJv5 =liAAAn'/aRv;90+$ekjÆo qoΝ3 l  $N3(M { nN&RCmr9?m=ơÿuuuwX>} @\GwJO윐ΛhZAF"|z`"ݭJ;5\ ]?η6L 5TY?L%Cbێ?_3gd2 ]GH!` ٰr P*) J ulwP[ly7#&j 1E{\z&ʋ!*|i1iQqΗ^Ĕ8ss@ˌuz" @ !aoM_p o iIENDB`gpick_0.2.5/share/gpick/gpick-falloff-exponential.png0000644000175000017500000000235712070605214021346 0ustar zbygzbygPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<lIDATXoLuݵwɠt5flA[ƀDقD1107آ25j4dpJ1bBVdnSF(c -ݸ{|qmqD ŞIr}>ߟ#"d+&F p%WAYCC7KKK<%%%o[r M%4< HeKKca W25c( !V D0Dh{gXDPWW9@8@ ,ؚ_v^$D"n|d@4]F4fXi} O={voF|[ IЌ ]Y~^ƌ,ѓt Ds^ L|oо;n'hjj =3+Kf` ,oڏ컒"BMMMOB @4ݒ\ 60# ,!B#+d&UU.nkk_hj  88 nQIqZ9y?2uww]v#̭_#:ƙI.1bI@(B Ab(!nքsbb,lۺ%g~]^7r/,,< .\PвD!4FqV(wtuO䣟u +77n.-}U˲|4o[-P($_EfB EL}5bዮ]{4-ٲX&cʱ `@" 2lHdNX%$uhx>{SUֳ<0nUv\K yD$"\w#n7+%T}fS>IENDB`gpick_0.2.5/share/gpick/colors0.txt0000644000175000017500000000641112070605214015725 0ustar zbygzbyg240 248 255 Alice Blue 250 235 215 Antique White 0 255 255 Aqua 127 255 212 Aquamarine 0 127 255 Azure 245 245 220 Beige 255 228 196 Bisque 0 0 0 Black 255 235 205 Blanched Almond 0 0 255 Blue 138 43 226 Blue Violet 165 42 42 Brown 222 184 135 BurlyWood 95 158 160 Cadet Blue 127 255 0 Chartreuse 210 105 30 Chocolate 255 127 80 Coral 100 149 237 Cornflower 255 248 220 Cornsilk 220 20 60 Crimson 0 255 255 Cyan 0 0 139 Dark Blue 0 139 139 Dark Cyan 184 134 11 Dark Goldenrod 169 169 169 Dark Gray 0 100 0 Dark Green 189 183 107 Dark Khaki 139 0 139 Dark Magenta 85 107 47 Dark Olive Green 255 140 0 Dark Orange 153 50 204 Dark Orchid 139 0 0 Dark Red 233 150 122 Dark Salmon 143 188 143 Dark Sea Green 72 61 139 Dark Slate Blue 47 79 79 Dark Slate Gray 0 206 209 Dark Turquoise 148 0 211 Dark Violet 255 20 147 Deep Pink 0 191 255 Deep Sky Blue 105 105 105 Dim Gray 30 144 255 Dodger Blue 0 73 83 Eagle Green 178 34 34 Firebrick 255 250 240 Floral White 34 139 34 Forest Green 255 0 255 Fuchsia 220 220 220 Gainsboro 248 248 255 Ghost White 255 215 0 Gold 218 165 32 Goldenrod 190 190 190 Gray 0 255 0 Green 173 255 47 Green Yellow 240 255 240 Honeydew 255 105 180 Hot Pink 205 92 92 Indian Red 75 0 130 Indigo 255 255 240 Ivory 240 230 140 Khaki 230 230 250 Lavender 255 240 245 Lavender Blush 124 252 0 Lawn Green 255 250 205 Lemon Chiffon 173 216 230 Light Blue 240 128 128 Light Coral 224 255 255 Light Cyan 250 250 210 Light Goldenrod 144 238 144 Light Green 211 211 211 Light Grey 255 182 193 Light Pink 255 160 122 Light Salmon 32 178 170 Light Sea Green 135 206 250 Light Sky Blue 119 136 153 Light Slate Gray 176 196 222 Light Steel Blue 255 255 224 Light Yellow 0 255 0 Lime 50 205 50 Lime Green 250 240 230 Linen 255 0 255 Magenta 176 48 96 Maroon 102 205 170 Medium Aquamarine 0 0 205 Medium Blue 186 85 211 Medium Orchid 147 112 219 Medium Purple 60 179 113 Medium Sea Green 123 104 238 Medium Slate Blue 0 250 154 Medium Spring Green 72 209 204 Medium Turquoise 199 21 133 Medium Violet Red 25 25 112 Midnight Blue 245 255 250 Mint Cream 255 228 225 Misty Rose 255 228 181 Moccasin 255 222 173 Navajo White 0 0 128 Navy 253 245 230 Old Lace 128 128 0 Olive 107 142 35 Olive Drab 255 165 0 Orange 255 69 0 Orange Red 218 112 214 Orchid 238 232 170 Pale Goldenrod 152 251 152 Pale Green 175 238 238 Pale Turquoise 219 112 147 Pale Violet Red 255 239 213 Papaya Whip 255 218 185 Peach Puff 205 133 63 Peru 255 192 203 Pink 221 160 221 Plum 176 224 230 Powder Blue 160 32 240 Purple 155 225 255 Purwa Blue 255 0 0 Red 188 143 143 Rosy Brown 65 105 225 Royal Blue 139 69 19 Saddle Brown 250 128 114 Salmon 244 164 96 Sandy Brown 46 139 87 Sea Green 255 245 238 Seashell 160 82 45 Sienna 192 192 192 Silver 135 206 235 Sky Blue 106 90 205 Slate Blue 112 128 144 Slate Gray 255 250 250 Snow 0 255 127 Spring Green 70 130 180 Steel Blue 210 180 140 Tan 0 128 128 Teal 216 191 216 Thistle 255 99 71 Tomato 64 224 208 Turquoise 238 130 238 Violet 245 222 179 Wheat 255 255 255 White 245 245 245 White Smoke 255 255 0 Yellow 154 205 50 Yellow Green gpick_0.2.5/share/icons/hicolor/scalable/apps/gpick.svg0000644000175000017500000002262512070605214021614 0ustar zbygzbyg image/svg+xml gpick_0.2.5/share/icons/hicolor/48x48/apps/gpick.png0000644000175000017500000000334112070605214020624 0ustar zbygzbygPNG  IHDR00WsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<^IDAThmlTerܙig,3mm ZaqaĪՍDLQ]Q1 Uf YdhRiE` ڈFАmS;eZw;N&_~1)k蹉"++Kz(~1Ƣyyy2 IRyJ#TU= KsޣiӡPHI0le)?pP(j"ȉp8ᅯX(& %Q{" -眳.Wh4"] p8䄁x<MC0Dccc oDhyy>M$) Vv Ϸ,\cUV=ֶMQMAMӒ&A0b6Lj^^|w p8xҥ Ec4 $Fqˬx|u |[ @@(2^\\-ÌNvoڴt9sfDxxl6`۽<'''.I҆|g۶m<OשS~? |1&V5eyq \wΝ)yɚIab,/~ $:wFEQ>z#Ź^|""!Ojw쮺tx H7O=|QwkTlb{Z^0ZA |ﱀWUr_a" +?K,` )}=G v1 "qG4T--QT/ =2g_v/PnE`R>kU 9~m{\)Q4-_Xe7#2I5gp4 ~?b̶8R{WSiV9V?79Nx[To= BDT7;9%c}.cao<9w95L ̳_Α  >Vڧ**7+fox`&ʿ~w>FD7w  [[YRJ%/`*v<McFMWȴвj'IENDB`gpick_0.2.5/share/locale/es/LC_MESSAGES/gpick.po0000644000175000017500000006712312113713537017613 0ustar zbygzbygmsgid "" msgstr "" "Project-Id-Version: gpick 0.2.5rc1\n" "POT-Creation-Date: 2013-01-05 16:16+0200\n" "PO-Revision-Date: 2013-01-06 17:59-0300\n" "Last-Translator: Guillermo Espertino \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: source/BlendColors.cpp:114 source/BlendColors.cpp:116 msgid "blend node" msgstr "nodo de mezcla" #: source/BlendColors.cpp:119 msgid "blend" msgstr "mezcla" #: source/BlendColors.cpp:308 source/BrightnessDarkness.cpp:260 #: source/ColorMixer.cpp:321 source/ColorPicker.cpp:367 #: source/GenerateScheme.cpp:444 source/LayoutPreview.cpp:405 #: source/Variations.cpp:331 source/uiDialogOptions.cpp:215 #: source/uiDialogOptions.cpp:234 msgid "_Add to palette" msgstr "_Agregar a la paleta" #: source/BlendColors.cpp:314 source/BrightnessDarkness.cpp:265 #: source/ColorMixer.cpp:326 source/ColorPicker.cpp:371 #: source/GenerateScheme.cpp:449 source/LayoutPreview.cpp:410 #: source/Variations.cpp:336 msgid "A_dd all to palette" msgstr "Agregar to_do a la paleta" #: source/BlendColors.cpp:320 source/BrightnessDarkness.cpp:271 #: source/ColorMixer.cpp:333 source/ColorPicker.cpp:377 #: source/GenerateScheme.cpp:456 source/LayoutPreview.cpp:416 #: source/Variations.cpp:343 source/uiDialogOptions.cpp:220 #: source/uiDialogOptions.cpp:239 msgid "_Copy to clipboard" msgstr "_Copiar al portapapeles" #: source/BlendColors.cpp:374 source/GenerateScheme.cpp:485 msgid "_Reset" msgstr "_Reestablecer" #: source/BlendColors.cpp:517 msgid "Start:" msgstr "Inicio:" #: source/BlendColors.cpp:533 msgid "Middle:" msgstr "Medio:" #: source/BlendColors.cpp:551 msgid "End:" msgstr "Final:" #: source/BlendColors.cpp:568 source/GenerateScheme.cpp:875 #: source/uiDialogGenerate.cpp:237 source/uiDialogMix.cpp:249 #: source/transformation/ColorVisionDeficiency.cpp:363 msgid "Type:" msgstr "Tipo:" #: source/BlendColors.cpp:570 source/ColorWheelType.cpp:56 #: source/uiDialogMix.cpp:251 msgid "RGB" msgstr "RGB" #: source/BlendColors.cpp:571 source/uiDialogMix.cpp:252 msgid "HSV" msgstr "HSV" #: source/BlendColors.cpp:572 source/uiDialogMix.cpp:253 msgid "HSV shortest hue distance" msgstr "HSV distancia de matiz más corta" #: source/BlendColors.cpp:573 source/uiDialogMix.cpp:254 msgid "LAB" msgstr "LAB" #: source/BlendColors.cpp:582 msgid "Start steps:" msgstr "Pasos al inicio:" #: source/BlendColors.cpp:590 msgid "End steps:" msgstr "Pasos al final:" #: source/BlendColors.cpp:627 msgid "Blend colors" msgstr "Mezclar colores" #: source/BrightnessDarkness.cpp:86 msgid "brightness darkness" msgstr "brillo oscuridad" #: source/BrightnessDarkness.cpp:287 source/ColorMixer.cpp:373 #: source/ColorPicker.cpp:387 source/GenerateScheme.cpp:469 #: source/LayoutPreview.cpp:430 source/Variations.cpp:383 msgid "_Edit..." msgstr "_Editar..." #: source/BrightnessDarkness.cpp:292 source/ColorMixer.cpp:378 #: source/ColorPicker.cpp:391 source/GenerateScheme.cpp:474 #: source/LayoutPreview.cpp:435 source/Variations.cpp:388 msgid "_Paste" msgstr "_Pegar" #: source/BrightnessDarkness.cpp:385 msgid "Brightness" msgstr "Brillo" #: source/BrightnessDarkness.cpp:385 msgid "Darkness" msgstr "Oscuridad" #: source/BrightnessDarkness.cpp:431 msgid "Brightness Darkness" msgstr "Brillo - Oscuridad" #: source/ColorMixer.cpp:66 msgid "Normal" msgstr "Normal" #: source/ColorMixer.cpp:67 msgid "Multiply" msgstr "Multiplicar" #: source/ColorMixer.cpp:68 msgid "Add" msgstr "Suma" #: source/ColorMixer.cpp:69 msgid "Difference" msgstr "Diferencia" #: source/ColorMixer.cpp:70 source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 source/ColorSpaceType.cpp:30 #: source/ColorSpaceType.cpp:37 source/Variations.cpp:66 msgid "Hue" msgstr "Matiz" #: source/ColorMixer.cpp:71 source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 source/ColorSpaceType.cpp:31 #: source/ColorSpaceType.cpp:38 source/Variations.cpp:67 msgid "Saturation" msgstr "Saturación" #: source/ColorMixer.cpp:72 source/ColorPicker.cpp:1194 #: source/ColorPicker.cpp:1236 source/ColorPicker.cpp:1250 #: source/ColorSpaceType.cpp:39 source/ColorSpaceType.cpp:59 #: source/ColorSpaceType.cpp:66 source/Variations.cpp:68 msgid "Lightness" msgstr "Luminosidad" #: source/ColorMixer.cpp:114 msgid "color mixer" msgstr "mezclador de colores" #: source/ColorMixer.cpp:234 #, fuzzy msgid "secondary" msgstr "Vista _Secundaria" #: source/ColorMixer.cpp:238 source/Variations.cpp:229 #, c-format msgid "primary %d" msgstr "" #: source/ColorMixer.cpp:244 #, c-format msgid "result %d" msgstr "" #: source/ColorMixer.cpp:704 msgid "Opacity:" msgstr "Opacidad:" #: source/ColorMixer.cpp:732 msgid "Color mixer" msgstr "Mezclador de colores" #: source/ColorPicker.cpp:424 msgid "Press Spacebar to sample color under mouse pointer" msgstr "Presione Espacio para capturar el color debajo del puntero" #: source/ColorPicker.cpp:699 source/uiConverter.cpp:163 msgid "Copy" msgstr "Copiar" #: source/ColorPicker.cpp:703 source/uiConverter.cpp:172 msgid "Paste" msgstr "Pegar" #: source/ColorPicker.cpp:709 source/uiColorInput.cpp:119 msgid "Edit" msgstr "Editar" #: source/ColorPicker.cpp:771 source/uiApp.cpp:1012 #: source/uiDialogSort.cpp:222 msgid "None" msgstr "Ninguna" #: source/ColorPicker.cpp:772 msgid "Linear" msgstr "Lineal" #: source/ColorPicker.cpp:773 msgid "Quadratic" msgstr "Cuadrática" #: source/ColorPicker.cpp:774 msgid "Cubic" msgstr "Cúbica" #: source/ColorPicker.cpp:775 msgid "Exponential" msgstr "Exponencial" #: source/ColorPicker.cpp:951 msgid "Click on swatch area to begin adding colors to palette" msgstr "" "Haga click sobre el área de muestras para empezar a agregar colores a la " "paleta" #: source/ColorPicker.cpp:1143 msgid "Settings" msgstr "Ajustes" #: source/ColorPicker.cpp:1153 msgid "Oversample:" msgstr "Sobremuestreo:" #: source/ColorPicker.cpp:1160 msgid "Falloff:" msgstr "Atenuación:" #: source/ColorPicker.cpp:1167 msgid "Zoom:" msgstr "Ampliación:" #: source/ColorPicker.cpp:1180 source/ColorSpaceType.cpp:32 msgid "Value" msgstr "Valor" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:44 msgid "Red" msgstr "Rojo" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:45 msgid "Green" msgstr "Verde" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:46 msgid "Blue" msgstr "Azul" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:51 msgid "Cyan" msgstr "Cián" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:52 msgid "Magenta" msgstr "Magenta" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:53 msgid "Yellow" msgstr "Amarillo" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:54 msgid "Key" msgstr "Negro (key)" #: source/ColorPicker.cpp:1258 msgid "Info" msgstr "Información" #: source/ColorPicker.cpp:1267 msgid "Color name:" msgstr "Nombre del color:" #: source/ColorPicker.cpp:1280 msgid "Contrast:" msgstr "Contraste:" #: source/ColorPicker.cpp:1285 source/ColorPicker.cpp:1291 msgid "Sample" msgstr "Muestra" #: source/ColorPicker.cpp:1324 msgid "Color picker" msgstr "Selector de color" #: source/ColorWheelType.cpp:57 msgid "RYB v1" msgstr "RYB v1" #: source/ColorWheelType.cpp:58 msgid "RYB v2" msgstr "RYB v2" #: source/GenerateScheme.cpp:90 msgid "Complementary" msgstr "Complementarios" #: source/GenerateScheme.cpp:91 msgid "Analogous" msgstr "Análogos" #: source/GenerateScheme.cpp:92 msgid "Triadic" msgstr "Tríada" #: source/GenerateScheme.cpp:93 msgid "Split-Complementary" msgstr "Complementarios divididos" #: source/GenerateScheme.cpp:94 msgid "Rectangle (tetradic)" msgstr "Rectangular (Tétrada)" #: source/GenerateScheme.cpp:95 msgid "Square" msgstr "Cuadrado" #: source/GenerateScheme.cpp:96 msgid "Neutral" msgstr "Neutros" #: source/GenerateScheme.cpp:97 msgid "Clash" msgstr "Complementarios en tensión" #: source/GenerateScheme.cpp:98 msgid "Five-Tone" msgstr "Cinco Tonos" #: source/GenerateScheme.cpp:99 msgid "Six-Tone" msgstr "Seis Tonos" #: source/GenerateScheme.cpp:119 source/uiDialogGenerate.cpp:76 msgid "scheme" msgstr "armonía" #: source/GenerateScheme.cpp:292 msgid "_Locked" msgstr "_Bloqueado" #: source/GenerateScheme.cpp:299 msgid "_Reset scheme" msgstr "_Reestablecer armonía" #: source/GenerateScheme.cpp:851 msgid "Hue:" msgstr "Matiz:" #: source/GenerateScheme.cpp:858 source/uiDialogVariations.cpp:171 msgid "Saturation:" msgstr "Saturación:" #: source/GenerateScheme.cpp:866 source/uiDialogVariations.cpp:156 msgid "Lightness:" msgstr "Luminosidad:" #: source/GenerateScheme.cpp:885 source/uiDialogGenerate.cpp:246 msgid "Color wheel:" msgstr "Rueda de color:" #: source/GenerateScheme.cpp:919 msgid "Scheme generation" msgstr "Generación de armonías" #: source/LayoutPreview.cpp:78 msgid "layout preview" msgstr "vista previa de diseño" #: source/LayoutPreview.cpp:153 msgid "Style item" msgstr "Ítem de estilo" #: source/LayoutPreview.cpp:162 msgid "CSS selector" msgstr "Selector CSS" #: source/LayoutPreview.cpp:184 msgid "Assign CSS selectors" msgstr "Asignar selectores CSS" #: source/LayoutPreview.cpp:547 source/LayoutPreview.cpp:595 #: source/uiApp.cpp:690 source/uiApp.cpp:711 msgid "File could not be saved" msgstr "El archivo no pudo ser guardado" #: source/LayoutPreview.cpp:558 source/uiExport.cpp:457 #: source/uiExport.cpp:523 msgid "Export" msgstr "Exportar" #: source/LayoutPreview.cpp:572 msgid "Cascading Style Sheets *.css" msgstr "Hojas de Estilos en Cascada *.css" #: source/LayoutPreview.cpp:666 msgid "Layout:" msgstr "Diseño:" #: source/LayoutPreview.cpp:672 msgid "Export CSS File" msgstr "Exportar Archivo CSS" #: source/LayoutPreview.cpp:673 msgid "Export CSS file" msgstr "Exportar archivo CSS" #: source/LayoutPreview.cpp:682 msgid "_Export CSS File As..." msgstr "_Exportar archivo CSS como..." #: source/LayoutPreview.cpp:686 msgid "_Assign CSS Selectors..." msgstr "_Asignar selectores CSS..." #: source/LayoutPreview.cpp:759 msgid "Layout preview" msgstr "Vista previa de diseño" #: source/ToolColorNaming.cpp:25 msgid "_Empty" msgstr "Ninguno" #: source/ToolColorNaming.cpp:26 msgid "_Automatic name" msgstr "Nombre _automático" #: source/ToolColorNaming.cpp:27 msgid "_Tool specific" msgstr "Específico de la herramien_ta" #: source/Variations.cpp:69 msgid "Lightness (Lab)" msgstr "Luminosidad (Lab)" #: source/Variations.cpp:110 msgid "variations" msgstr "variaciones" #: source/Variations.cpp:225 #, fuzzy msgid "all colors" msgstr "Mezclar colores" #: source/Variations.cpp:239 #, c-format msgid "result %d line %d" msgstr "" #: source/Variations.cpp:717 #: source/transformation/ColorVisionDeficiency.cpp:386 msgid "Strength:" msgstr "Intensidad:" #: source/Variations.cpp:745 source/uiDialogVariations.cpp:142 msgid "Variations" msgstr "Variaciones" #: source/uiAbout.cpp:88 msgid "About Gpick" msgstr "Acerca de Gpick" #: source/uiAbout.cpp:121 msgid "Advanced color picker" msgstr "Selector de color avanzado" #: source/uiAbout.cpp:126 msgid "Copyrights © 2009-2013, Albertas Vyšniauskas and Gpick development team" msgstr "" "Copyrights © 2009-2013, Albertas Vyšniauskas y el equipo de desarrollo de " "Gpick" #: source/uiAbout.cpp:141 msgid "License" msgstr "Licencia" #: source/uiAbout.cpp:142 msgid "Credits" msgstr "Créditos" #: source/uiAbout.cpp:143 msgid "Expat License" msgstr "Licencia Expat" #: source/uiAbout.cpp:144 msgid "Lua License" msgstr "Licencia Lua" #: source/uiApp.cpp:354 msgid "New palette" msgstr "Nueva paleta" #: source/uiApp.cpp:360 msgid "(Imported)" msgstr "(Importado)" #: source/uiApp.cpp:530 source/uiApp.cpp:545 source/uiApp.cpp:563 #: source/uiApp.cpp:641 msgid "File could not be opened" msgstr "El archivo no pudo ser abierto" #: source/uiApp.cpp:531 source/uiApp.cpp:546 source/uiApp.cpp:564 #: source/uiApp.cpp:642 msgid "Open" msgstr "Abrir" #: source/uiApp.cpp:576 source/uiExport.cpp:473 source/uiExport.cpp:587 msgid "Gpick Palette (*.gpa)" msgstr "Paleta de Gpick (*.gpa)" #: source/uiApp.cpp:577 source/uiExport.cpp:474 source/uiExport.cpp:588 msgid "GIMP/Inkscape Palette (*.gpl)" msgstr "Paleta de GIMP/Inkscape (*.gpl)" #: source/uiApp.cpp:578 source/uiExport.cpp:476 source/uiExport.cpp:589 msgid "Adobe Swatch Exchange (*.ase)" msgstr "Adobe Swatch Exchange (*.ase)" #: source/uiApp.cpp:584 source/uiExport.cpp:598 #: source/tools/PaletteFromImage.cpp:548 msgid "All files" msgstr "Todos los archivos" #: source/uiApp.cpp:589 source/uiExport.cpp:607 msgid "All supported formats" msgstr "Todos los formatos soportados" #: source/uiApp.cpp:610 msgid "Open File" msgstr "Abrir archivo" #: source/uiApp.cpp:659 source/uiApp.cpp:691 msgid "Save As" msgstr "Guardar como" #: source/uiApp.cpp:712 msgid "Save" msgstr "Guardar" #: source/uiApp.cpp:771 msgid "Open Last File" msgstr "Abrir el último archivo" #: source/uiApp.cpp:916 msgid "Recent _files" msgstr "Archivos _Recientes" #: source/uiApp.cpp:946 msgid "Ex_port..." msgstr "E_xportar..." #: source/uiApp.cpp:954 msgid "Expo_rt Selected..." msgstr "Ex_portar Seleccionados..." #: source/uiApp.cpp:962 msgid "_Import..." msgstr "_Importar..." #: source/uiApp.cpp:977 msgid "_File" msgstr "_Archivo" #: source/uiApp.cpp:985 msgid "Edit _Converters..." msgstr "Editar _Convertidores..." #: source/uiApp.cpp:989 msgid "Display _Filters..." msgstr "Mostrar _Filtros" #: source/uiApp.cpp:1001 msgid "_Edit" msgstr "_Editar" #: source/uiApp.cpp:1037 msgid "_Secondary View" msgstr "Vista _Secundaria" #: source/uiApp.cpp:1043 msgid "Palette" msgstr "Paleta" #: source/uiApp.cpp:1049 msgid "_View" msgstr "_Vista" #: source/uiApp.cpp:1055 msgid "Palette From _Image..." msgstr "Paleta desde _Imagen..." #: source/uiApp.cpp:1063 msgid "_Tools" msgstr "_Herramientas" #: source/uiApp.cpp:1078 msgid "_Help" msgstr "A_yuda" #: source/uiApp.cpp:1386 msgid "_Copy to Clipboard" msgstr "_Copiar al Portapapeles" #: source/uiApp.cpp:1402 msgid "_Mix Colors..." msgstr "_Mezclar Colores..." #: source/uiApp.cpp:1407 msgid "_Variations..." msgstr "_Variaciones..." #: source/uiApp.cpp:1412 msgid "_Generate..." msgstr "_Generar..." #: source/uiApp.cpp:1421 msgid "C_lear names" msgstr "_Limpiar nombres" #: source/uiApp.cpp:1427 msgid "Autona_me" msgstr "No_mbre automático" #: source/uiApp.cpp:1433 msgid "Auto_number..." msgstr "_Numerado automático" #: source/uiApp.cpp:1441 msgid "R_everse" msgstr "_Reverso" #: source/uiApp.cpp:1447 msgid "Group and _sort..." msgstr "Agrupar y ordenar" #: source/uiApp.cpp:1455 msgid "_Remove" msgstr "_Quitar" #: source/uiApp.cpp:1461 msgid "Remove _All" msgstr "Quitar _Todo" #: source/uiApp.cpp:1869 msgid "Color pic_ker" msgstr "Selector de _Color" #: source/uiApp.cpp:1878 msgid "Scheme _generation" msgstr "_Generación de armonías" #: source/uiApp.cpp:1897 msgid "Lay_out preview" msgstr "Vista previa de diseñ_o" #: source/uiApp.cpp:1947 msgid "Pick colors (Ctrl+P)" msgstr "Elegir color (CTRL+P)" #: source/uiApp.cpp:1956 msgid "" "File is currently in a non-native format, possible loss of precision and/or " "metadata." msgstr "" "El archivo está actualmente en un formato no-nativo, posible pérdida de " "precisión y/o metadatos." #: source/uiColorInput.cpp:45 msgid "Edit color" msgstr "Editar color" #: source/uiColorInput.cpp:69 msgid "Color:" msgstr "Color:" #: source/uiConverter.cpp:56 msgid "Test color" msgstr "Probar color" #: source/uiConverter.cpp:74 msgid "error" msgstr "error" #: source/uiConverter.cpp:145 msgid "Function name" msgstr "Nombre de la función" #: source/uiConverter.cpp:154 msgid "Example" msgstr "Ejemplo" #: source/uiConverter.cpp:196 msgid "Converters" msgstr "Convertidores" #: source/uiConverter.cpp:224 msgid "Displays:" msgstr "Visualizaciones:" #: source/uiConverter.cpp:230 msgid "Color list:" msgstr "Lista de colores:" #: source/uiDialogAutonumber.cpp:108 msgid "Autonumber colors" msgstr "Autonumerar colores" #: source/uiDialogAutonumber.cpp:122 msgid "Name:" msgstr "Nombre:" #: source/uiDialogAutonumber.cpp:132 msgid "Decimal places:" msgstr "Lugares decimales:" #: source/uiDialogAutonumber.cpp:139 msgid "Starting number:" msgstr "Número inicial:" #: source/uiDialogAutonumber.cpp:146 msgid "_Decreasing" msgstr "_Decreciente" #: source/uiDialogAutonumber.cpp:152 msgid "_Append" msgstr "_Agregar" #: source/uiDialogAutonumber.cpp:158 msgid "Sample:" msgstr "Muestra:" #: source/uiDialogGenerate.cpp:216 msgid "Generate colors" msgstr "Generar colores" #: source/uiDialogGenerate.cpp:230 source/tools/PaletteFromImage.cpp:599 msgid "Colors:" msgstr "Colores:" #: source/uiDialogGenerate.cpp:257 msgid "Chaos:" msgstr "Caos:" #: source/uiDialogGenerate.cpp:263 msgid "Seed:" msgstr "Semilla:" #: source/uiDialogGenerate.cpp:271 msgid "_Reverse" msgstr "_Reverso" #: source/uiDialogMix.cpp:76 source/uiDialogMix.cpp:78 msgid "mix node" msgstr "nodo de mezcla" #: source/uiDialogMix.cpp:81 msgid "mix" msgstr "mezcla" #: source/uiDialogMix.cpp:235 msgid "Mix colors" msgstr "Mezclar colores" #: source/uiDialogMix.cpp:262 source/uiDialogVariations.cpp:186 msgid "Steps:" msgstr "Pasos:" #: source/uiDialogMix.cpp:270 msgid "_Include Endpoints" msgstr "_incluir extremos" #: source/uiDialogOptions.cpp:117 source/tools/PaletteFromImage.cpp:589 msgid "Options" msgstr "Opciones" #: source/uiDialogOptions.cpp:134 msgid "System" msgstr "Sistema" #: source/uiDialogOptions.cpp:143 msgid "_Single instance" msgstr "In_stancia única" #: source/uiDialogOptions.cpp:148 msgid "Save/_Restore palette" msgstr "Guardar/_Reestablecer paleta" #: source/uiDialogOptions.cpp:154 msgid "System tray" msgstr "Bandeja de sistema" #: source/uiDialogOptions.cpp:162 msgid "_Minimize to system tray" msgstr "_Minimizar a la bandeja de sistema" #: source/uiDialogOptions.cpp:167 msgid "_Close to system tray" msgstr "_Cerrar a la bandeja de sistema" #: source/uiDialogOptions.cpp:172 msgid "_Start in system tray" msgstr "Iniciar en la bandeja de _sistema" #: source/uiDialogOptions.cpp:178 msgid "_Main" msgstr "_Principal" #: source/uiDialogOptions.cpp:184 msgid "Display" msgstr "Visualización" #: source/uiDialogOptions.cpp:193 msgid "_Refresh rate:" msgstr "Tasa de _refresco:" #: source/uiDialogOptions.cpp:201 msgid "_Magnified area size:" msgstr "Tamaño del área _magnificada:" #: source/uiDialogOptions.cpp:207 msgid "Floating picker click behaviour" msgstr "Comportamiento del selector flotante" #: source/uiDialogOptions.cpp:226 msgid "'Spacebar' button behaviour" msgstr "Comportamiento de la barra espaciadora" #: source/uiDialogOptions.cpp:244 msgid "_Rotate swatch" msgstr "_Rotar muestras" #: source/uiDialogOptions.cpp:251 msgid "Enabled color spaces" msgstr "Espacios de color habilitados" #: source/uiDialogOptions.cpp:266 msgid "Lab settings" msgstr "Ajustes Lab" #: source/uiDialogOptions.cpp:278 msgid "_Illuminant:" msgstr "_Iluminante" #: source/uiDialogOptions.cpp:302 msgid "_Observer:" msgstr "_Observador" #: source/uiDialogOptions.cpp:321 msgid "Other settings" msgstr "Otros ajustes" #: source/uiDialogOptions.cpp:330 msgid "_Mask out of gamut colors" msgstr "En_mascarar colores fuera de gamut" #: source/uiDialogOptions.cpp:336 msgid "_Picker" msgstr "_Selector" #: source/uiDialogOptions.cpp:341 msgid "Color name generation" msgstr "Generación de nombres de color" #: source/uiDialogOptions.cpp:350 msgid "_Imprecision postfix" msgstr "Sufijo de _impresición" #: source/uiDialogOptions.cpp:356 msgid "Tool color naming" msgstr "Asignación de nombres de color" #: source/uiDialogOptions.cpp:381 msgid "_Color names" msgstr "Nombre del _color" #: source/uiDialogSort.cpp:135 source/uiDialogSort.cpp:223 msgid "RGB Red" msgstr "Rojo RGB" #: source/uiDialogSort.cpp:136 source/uiDialogSort.cpp:224 msgid "RGB Green" msgstr "Verde RGB" #: source/uiDialogSort.cpp:137 source/uiDialogSort.cpp:225 msgid "RGB Blue" msgstr "Azul RGB" #: source/uiDialogSort.cpp:138 source/uiDialogSort.cpp:226 msgid "RGB Grayscale" msgstr "Escala de grises RGB" #: source/uiDialogSort.cpp:139 source/uiDialogSort.cpp:227 msgid "HSL Hue" msgstr "Matiz HSL" #: source/uiDialogSort.cpp:140 source/uiDialogSort.cpp:228 msgid "HSL Saturation" msgstr "Saturación HSL" #: source/uiDialogSort.cpp:141 source/uiDialogSort.cpp:229 msgid "HSL Lightness" msgstr "Luminosidad HSL" #: source/uiDialogSort.cpp:142 source/uiDialogSort.cpp:230 msgid "Lab Lightness" msgstr "Luminosidad Lab" #: source/uiDialogSort.cpp:143 source/uiDialogSort.cpp:231 msgid "Lab A" msgstr "Lab A" #: source/uiDialogSort.cpp:144 source/uiDialogSort.cpp:232 msgid "Lab B" msgstr "Lab B" #: source/uiDialogSort.cpp:145 source/uiDialogSort.cpp:233 msgid "LCh Lightness" msgstr "Luminosidad LCh" #: source/uiDialogSort.cpp:146 source/uiDialogSort.cpp:234 msgid "LCh Chroma" msgstr "Crominancia LCh" #: source/uiDialogSort.cpp:147 source/uiDialogSort.cpp:235 msgid "LCh Hue" msgstr "Matiz LCh" #: source/uiDialogSort.cpp:556 msgid "Group and sort" msgstr "Agrupar y ordenar" #: source/uiDialogSort.cpp:564 msgid "Group type:" msgstr "Tipo de grupo:" #: source/uiDialogSort.cpp:574 msgid "Grouping sensitivity:" msgstr "Sensibilidad de agrupamiento:" #: source/uiDialogSort.cpp:581 msgid "Maximum number of groups:" msgstr "Número máximo de grupos:" #: source/uiDialogSort.cpp:588 msgid "Sort type:" msgstr "Tipo de ordenamiento:" #: source/uiDialogSort.cpp:598 msgid "_Reverse group order" msgstr "Orden de grupo inve_rso" #: source/uiDialogSort.cpp:604 msgid "_Reverse order inside groups" msgstr "Orden de grupo inve_rso dentro de grupos" #: source/uiDialogVariations.cpp:60 msgid "variation" msgstr "variación" #: source/uiDialogVariations.cpp:194 msgid "_Use multiplication" msgstr "_Usar multiplicación" #: source/uiExport.cpp:475 msgid "Alias/WaveFront Material (*.mtl)" msgstr "Material de Alias/WaveFront (*.mtl)" #: source/uiExport.cpp:477 msgid "Text file (*.txt)" msgstr "Archivo de texto (*.txt)" #: source/uiExport.cpp:522 msgid "File could not be exported" msgstr "El archivo no pudo ser exportado" #: source/uiExport.cpp:573 source/uiExport.cpp:654 source/uiExport.cpp:666 msgid "Import" msgstr "Importar" #: source/uiExport.cpp:653 msgid "File format is not supported" msgstr "El formato de archivo no está soportado" #: source/uiExport.cpp:665 msgid "File could not be imported" msgstr "El archivo no pudo ser importado" #: source/uiListPalette.cpp:158 source/uiListPalette.cpp:160 #, c-format msgid "%d color" msgid_plural "%d colors" msgstr[0] "%d color" msgstr[1] "%d colores" #: source/uiListPalette.cpp:166 msgid "selected" msgstr "seleccionado" #: source/uiListPalette.cpp:172 source/uiListPalette.cpp:174 #, c-format msgid "Total %d color" msgid_plural "Total %d colors" msgstr[0] "Total %d color" msgstr[1] "Total %d colores" #: source/uiListPalette.cpp:353 msgid "Preview" msgstr "Vista previa" #: source/uiListPalette.cpp:708 source/uiListPalette.cpp:717 msgid "Color" msgstr "Color" #: source/uiListPalette.cpp:726 source/uiTransformations.cpp:183 msgid "Name" msgstr "Nombre" #: source/uiStatusIcon.cpp:67 msgid "_Show Main Window" msgstr "Mo_strar Ventana Principal" #: source/uiStatusIcon.cpp:74 msgid "_Quit" msgstr "Salir" #: source/uiTransformations.cpp:245 msgid "Display filters" msgstr "Filtros de visualización" #: source/uiTransformations.cpp:259 msgid "_Enabled" msgstr "_Activado" #: source/tools/PaletteFromImage.cpp:514 msgid "Palette from image" msgstr "Paleta desde imagen" #: source/tools/PaletteFromImage.cpp:527 msgid "Image" msgstr "Imagen" #: source/tools/PaletteFromImage.cpp:536 msgid "Image file" msgstr "Archivo de imagen" #: source/tools/PaletteFromImage.cpp:556 msgid "All images" msgstr "Todas las imágenes" #: source/transformation/ColorVisionDeficiency.cpp:41 msgid "Color vision deficiency" msgstr "Visión de color deficiente" #: source/transformation/ColorVisionDeficiency.cpp:330 msgid "Protanomaly" msgstr "Protanomalía" #: source/transformation/ColorVisionDeficiency.cpp:331 msgid "Deuteranomaly" msgstr "Deuteranomalía" #: source/transformation/ColorVisionDeficiency.cpp:332 msgid "Tritanomaly" msgstr "Tritanomalía" #: source/transformation/ColorVisionDeficiency.cpp:333 msgid "Protanopia" msgstr "Protanopía" #: source/transformation/ColorVisionDeficiency.cpp:334 msgid "Deuteranopia" msgstr "Deuteranopía" #: source/transformation/ColorVisionDeficiency.cpp:335 msgid "Tritanopia" msgstr "Tritanopía" #: source/transformation/ColorVisionDeficiency.cpp:422 msgid "Altered spectral sensitivity of red receptors" msgstr "Sensibilidad espectral alterada en receptores de rojos" #: source/transformation/ColorVisionDeficiency.cpp:423 msgid "Altered spectral sensitivity of green receptors" msgstr "Sensibilidad espectral alterada en receptores de verdes" #: source/transformation/ColorVisionDeficiency.cpp:424 msgid "Altered spectral sensitivity of blue receptors" msgstr "Sensibilidad espectral alterada en receptores de azules" #: source/transformation/ColorVisionDeficiency.cpp:425 msgid "Absence of red receptors" msgstr "Ausencia de receptores de rojo" #: source/transformation/ColorVisionDeficiency.cpp:426 msgid "Absence of green receptors" msgstr "Ausencia de receptores de verde" #: source/transformation/ColorVisionDeficiency.cpp:427 msgid "Absence of blue receptors" msgstr "Ausencia de receptores de azul" #: source/transformation/GammaModification.cpp:38 msgid "Gamma modification" msgstr "Modificación de gamma" #: source/transformation/GammaModification.cpp:88 #: source/transformation/Quantization.cpp:96 msgid "Value:" msgstr "Valor:" #: source/transformation/Quantization.cpp:40 msgid "Quantization" msgstr "Cuantización" #: source/transformation/Quantization.cpp:101 msgid "Clip top-end" msgstr "Recortar límite superior" #: share/gpick/init.lua:173 msgid "Web: hex code" msgstr "" #: share/gpick/init.lua:178 msgid "Web: hex code (3 digits)" msgstr "" #: share/gpick/init.lua:183 msgid "Web: hex code (no hash symbol)" msgstr "" #: share/gpick/init.lua:188 msgid "CSS: hue saturation lightness" msgstr "" #: share/gpick/init.lua:193 msgid "CSS: red green blue" msgstr "" #: share/gpick/layouts.lua:15 msgid "Homepage" msgstr "" #: share/gpick/layouts.lua:15 #, fuzzy msgid "About us" msgstr "Acerca de Gpick" #: share/gpick/layouts.lua:15 msgid "Links to us" msgstr "" #: share/gpick/layouts.lua:15 msgid "Privacy" msgstr "" #: share/gpick/layouts.lua:15 msgid "Terms" msgstr "" #: share/gpick/layouts.lua:15 #, fuzzy msgid "Contact us" msgstr "Contraste:" #: share/gpick/layouts.lua:15 msgid "RSS" msgstr "" #: share/gpick/layouts.lua:30 msgid "The quick brown fox jumps over the lazy dog" msgstr "" #: share/gpick/layouts.lua:46 msgid "Webpage" msgstr "" #: share/gpick/layouts.lua:51 share/gpick/layouts.lua:73 msgid "Header" msgstr "" #: share/gpick/layouts.lua:52 msgid "Header text" msgstr "" #: share/gpick/layouts.lua:54 #, fuzzy msgid "Content" msgstr "Contraste:" #: share/gpick/layouts.lua:55 msgid "Content text" msgstr "" #: share/gpick/layouts.lua:57 msgid "Sidebar" msgstr "" #: share/gpick/layouts.lua:59 share/gpick/layouts.lua:87 msgid "Button" msgstr "" #: share/gpick/layouts.lua:60 share/gpick/layouts.lua:88 msgid "Button (hover)" msgstr "" #: share/gpick/layouts.lua:61 share/gpick/layouts.lua:89 msgid "Button text" msgstr "" #: share/gpick/layouts.lua:62 share/gpick/layouts.lua:90 msgid "Button text (hover)" msgstr "" #: share/gpick/layouts.lua:64 msgid "Footer" msgstr "" #: share/gpick/layouts.lua:82 share/gpick/layouts.lua:86 msgid "Menu" msgstr "" #: share/gpick/layouts.lua:106 #, fuzzy msgid "Brightness-Darkness" msgstr "Brillo - Oscuridad" #: share/gpick/layouts.lua:110 msgid "main" msgstr "" #: share/gpick/layouts.lua:144 msgid "Grid (4x3)" msgstr "" #: share/gpick/layouts.lua:153 share/gpick/layouts.lua:159 #: share/gpick/layouts.lua:180 share/gpick/layouts.lua:186 msgid "Item" msgstr "" #: share/gpick/layouts.lua:154 share/gpick/layouts.lua:181 msgid "Item text" msgstr "" #: share/gpick/layouts.lua:171 msgid "Grid (5x4)" msgstr "" #~ msgid "Edit _Transformations..." #~ msgstr "Editar _Transformaciones..." gpick_0.2.5/share/locale/lt/LC_MESSAGES/gpick.po0000644000175000017500000007030612113713537017620 0ustar zbygzbyg# msgid "" msgstr "" "Project-Id-Version: gpick 0.2.4\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-01-09 00:06+0200\n" "PO-Revision-Date: 2013-01-09 00:07+0300\n" "Last-Translator: Albertas Vyšniauskas \n" "Language-Team: \n" "Language: Lithuanian\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 1.5.4\n" "X-Poedit-SourceCharset: UTF-8\n" "Plural-Forms: nplurals=3; plural=((n%10==1) && (n%100!=11) ? 0 : ((n%10>=2) " "&& (n%100<10) || (n%100>=20)) ? 1 : 2);\n" #: source/BlendColors.cpp:114 source/BlendColors.cpp:116 msgid "blend node" msgstr "suliejimo mazgas" #: source/BlendColors.cpp:119 msgid "blend" msgstr "suliejimas" #: source/BlendColors.cpp:308 source/BrightnessDarkness.cpp:260 #: source/ColorMixer.cpp:321 source/ColorPicker.cpp:367 #: source/GenerateScheme.cpp:444 source/LayoutPreview.cpp:405 #: source/Variations.cpp:331 source/uiDialogOptions.cpp:215 #: source/uiDialogOptions.cpp:234 msgid "_Add to palette" msgstr "_Įkelti į paletę" #: source/BlendColors.cpp:314 source/BrightnessDarkness.cpp:265 #: source/ColorMixer.cpp:326 source/ColorPicker.cpp:371 #: source/GenerateScheme.cpp:449 source/LayoutPreview.cpp:410 #: source/Variations.cpp:336 msgid "A_dd all to palette" msgstr "Į_kelti visas į paletę" #: source/BlendColors.cpp:320 source/BrightnessDarkness.cpp:271 #: source/ColorMixer.cpp:333 source/ColorPicker.cpp:377 #: source/GenerateScheme.cpp:456 source/LayoutPreview.cpp:416 #: source/Variations.cpp:343 source/uiDialogOptions.cpp:220 #: source/uiDialogOptions.cpp:239 msgid "_Copy to clipboard" msgstr "_Kopijuoti" #: source/BlendColors.cpp:374 source/GenerateScheme.cpp:485 msgid "_Reset" msgstr "_Atstatyti" #: source/BlendColors.cpp:517 msgid "Start:" msgstr "Pradžia:" #: source/BlendColors.cpp:533 msgid "Middle:" msgstr "Vidurys:" #: source/BlendColors.cpp:551 msgid "End:" msgstr "Pabaiga:" #: source/BlendColors.cpp:568 source/GenerateScheme.cpp:875 #: source/uiDialogGenerate.cpp:237 source/uiDialogMix.cpp:249 #: source/transformation/ColorVisionDeficiency.cpp:363 msgid "Type:" msgstr "Tipas:" #: source/BlendColors.cpp:570 source/ColorWheelType.cpp:56 #: source/uiDialogMix.cpp:251 msgid "RGB" msgstr "RGB" #: source/BlendColors.cpp:571 source/uiDialogMix.cpp:252 msgid "HSV" msgstr "HSV" #: source/BlendColors.cpp:572 source/uiDialogMix.cpp:253 msgid "HSV shortest hue distance" msgstr "HSV su mažiausiu atspalvio skirumu" #: source/BlendColors.cpp:573 source/uiDialogMix.cpp:254 msgid "LAB" msgstr "LAB" #: source/BlendColors.cpp:582 msgid "Start steps:" msgstr "Pradiniai žingsniai:" #: source/BlendColors.cpp:590 msgid "End steps:" msgstr "Pabaigos žingsniai:" #: source/BlendColors.cpp:627 msgid "Blend colors" msgstr "Sulieti spalvas" #: source/BrightnessDarkness.cpp:86 msgid "brightness darkness" msgstr "šviesumas tamsumas" #: source/BrightnessDarkness.cpp:287 source/ColorMixer.cpp:373 #: source/ColorPicker.cpp:387 source/GenerateScheme.cpp:469 #: source/LayoutPreview.cpp:430 source/Variations.cpp:383 msgid "_Edit..." msgstr "_Keisti..." #: source/BrightnessDarkness.cpp:292 source/ColorMixer.cpp:378 #: source/ColorPicker.cpp:391 source/GenerateScheme.cpp:474 #: source/LayoutPreview.cpp:435 source/Variations.cpp:388 msgid "_Paste" msgstr "_Įdėti" #: source/BrightnessDarkness.cpp:385 msgid "Brightness" msgstr "Šviesumas" #: source/BrightnessDarkness.cpp:385 msgid "Darkness" msgstr "Tamsumas" #: source/BrightnessDarkness.cpp:431 msgid "Brightness Darkness" msgstr "Šviesumas, tamsumas" #: source/ColorMixer.cpp:66 msgid "Normal" msgstr "Paprastas" #: source/ColorMixer.cpp:67 msgid "Multiply" msgstr "Daugyba" #: source/ColorMixer.cpp:68 msgid "Add" msgstr "Sudėtis" #: source/ColorMixer.cpp:69 msgid "Difference" msgstr "Skirtumas" #: source/ColorMixer.cpp:70 source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 source/ColorSpaceType.cpp:30 #: source/ColorSpaceType.cpp:37 source/Variations.cpp:66 msgid "Hue" msgstr "Atspalvis" #: source/ColorMixer.cpp:71 source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 source/ColorSpaceType.cpp:31 #: source/ColorSpaceType.cpp:38 source/Variations.cpp:67 msgid "Saturation" msgstr "Įsotinimas" #: source/ColorMixer.cpp:72 source/ColorPicker.cpp:1194 #: source/ColorPicker.cpp:1236 source/ColorPicker.cpp:1250 #: source/ColorSpaceType.cpp:39 source/ColorSpaceType.cpp:59 #: source/ColorSpaceType.cpp:66 source/Variations.cpp:68 msgid "Lightness" msgstr "Šviesumas" #: source/ColorMixer.cpp:114 msgid "color mixer" msgstr "spalvų maišyklė" #: source/ColorMixer.cpp:234 msgid "secondary" msgstr "antrinė" #: source/ColorMixer.cpp:238 source/Variations.cpp:229 #, c-format msgid "primary %d" msgstr "pirminė %d" #: source/ColorMixer.cpp:244 #, c-format msgid "result %d" msgstr "rezultatas %d" #: source/ColorMixer.cpp:704 msgid "Opacity:" msgstr "Nepermatomumas:" #: source/ColorMixer.cpp:732 msgid "Color mixer" msgstr "Spalvų maišyklė" #: source/ColorPicker.cpp:424 msgid "Press Spacebar to sample color under mouse pointer" msgstr "Paspauskite Tarpą norėdami gauti spalvą esančią po pelės kursoriu" #: source/ColorPicker.cpp:699 source/uiConverter.cpp:163 msgid "Copy" msgstr "Kopijavimas" #: source/ColorPicker.cpp:703 source/uiConverter.cpp:172 msgid "Paste" msgstr "Įdėjimas" #: source/ColorPicker.cpp:709 source/uiColorInput.cpp:119 msgid "Edit" msgstr "Keisti" #: source/ColorPicker.cpp:771 source/uiApp.cpp:1012 #: source/uiDialogSort.cpp:222 msgid "None" msgstr "Joks" #: source/ColorPicker.cpp:772 msgid "Linear" msgstr "Tiesinis" #: source/ColorPicker.cpp:773 msgid "Quadratic" msgstr "Kvardatinis" #: source/ColorPicker.cpp:774 msgid "Cubic" msgstr "Kubinis" #: source/ColorPicker.cpp:775 msgid "Exponential" msgstr "Eksponentinis" #: source/ColorPicker.cpp:951 msgid "Click on swatch area to begin adding colors to palette" msgstr "Paspauskite mėginio plote norėdami pradėti spalvų rinkimą į paletę" #: source/ColorPicker.cpp:1143 msgid "Settings" msgstr "Nustatymai" #: source/ColorPicker.cpp:1153 msgid "Oversample:" msgstr "Mėginio vidurkis" #: source/ColorPicker.cpp:1160 msgid "Falloff:" msgstr "Nuožulnumas:" #: source/ColorPicker.cpp:1167 msgid "Zoom:" msgstr "Priartinimas:" #: source/ColorPicker.cpp:1180 source/ColorSpaceType.cpp:32 msgid "Value" msgstr "Reikšmė" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:44 msgid "Red" msgstr "Raudona" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:45 msgid "Green" msgstr "Žalia" #: source/ColorPicker.cpp:1208 source/ColorSpaceType.cpp:46 msgid "Blue" msgstr "Mėlyna" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:51 msgid "Cyan" msgstr "Žydra" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:52 msgid "Magenta" msgstr "Purpurinė" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:53 msgid "Yellow" msgstr "Geltona" #: source/ColorPicker.cpp:1222 source/ColorSpaceType.cpp:54 msgid "Key" msgstr "Juoda" #: source/ColorPicker.cpp:1258 msgid "Info" msgstr "Informacija" #: source/ColorPicker.cpp:1267 msgid "Color name:" msgstr "Spalvos pavadinimas:" #: source/ColorPicker.cpp:1280 msgid "Contrast:" msgstr "Kontrastas:" #: source/ColorPicker.cpp:1285 source/ColorPicker.cpp:1291 msgid "Sample" msgstr "Pavyzdys" #: source/ColorPicker.cpp:1324 msgid "Color picker" msgstr "Spalvų rinkyklė" #: source/ColorWheelType.cpp:57 msgid "RYB v1" msgstr "RYB v1" #: source/ColorWheelType.cpp:58 msgid "RYB v2" msgstr "RYB v2" #: source/GenerateScheme.cpp:90 msgid "Complementary" msgstr "Papildanti" #: source/GenerateScheme.cpp:91 msgid "Analogous" msgstr "Analogiška" #: source/GenerateScheme.cpp:92 msgid "Triadic" msgstr "Triada" #: source/GenerateScheme.cpp:93 msgid "Split-Complementary" msgstr "Perskirtas papildantis" #: source/GenerateScheme.cpp:94 msgid "Rectangle (tetradic)" msgstr "Keturkampis (tetrada)" #: source/GenerateScheme.cpp:95 msgid "Square" msgstr "Kvadratas" #: source/GenerateScheme.cpp:96 msgid "Neutral" msgstr "Neutralus" #: source/GenerateScheme.cpp:97 msgid "Clash" msgstr "Nedarna" #: source/GenerateScheme.cpp:98 msgid "Five-Tone" msgstr "Penki tonai" #: source/GenerateScheme.cpp:99 msgid "Six-Tone" msgstr "Šeši tonai" #: source/GenerateScheme.cpp:119 source/uiDialogGenerate.cpp:76 msgid "scheme" msgstr "schema" #: source/GenerateScheme.cpp:292 msgid "_Locked" msgstr "_Užrakinta" #: source/GenerateScheme.cpp:299 msgid "_Reset scheme" msgstr "_Atstatyti schemą" #: source/GenerateScheme.cpp:851 msgid "Hue:" msgstr "Atspalvis:" #: source/GenerateScheme.cpp:858 source/uiDialogVariations.cpp:171 msgid "Saturation:" msgstr "Įsotinimas:" #: source/GenerateScheme.cpp:866 source/uiDialogVariations.cpp:156 msgid "Lightness:" msgstr "Šviesumas:" #: source/GenerateScheme.cpp:885 source/uiDialogGenerate.cpp:246 msgid "Color wheel:" msgstr "Spalvų ratas:" #: source/GenerateScheme.cpp:919 msgid "Scheme generation" msgstr "Schemos generavimas" #: source/LayoutPreview.cpp:78 msgid "layout preview" msgstr "išdėstymo peržiūra" #: source/LayoutPreview.cpp:153 msgid "Style item" msgstr "Stiliaus objektas" #: source/LayoutPreview.cpp:162 msgid "CSS selector" msgstr "CSS selectorius" #: source/LayoutPreview.cpp:184 msgid "Assign CSS selectors" msgstr "Priskirti CSS selektorius" #: source/LayoutPreview.cpp:547 source/LayoutPreview.cpp:595 #: source/uiApp.cpp:690 source/uiApp.cpp:711 msgid "File could not be saved" msgstr "Nepavyko išsaugoti failą" #: source/LayoutPreview.cpp:558 source/uiExport.cpp:457 #: source/uiExport.cpp:523 msgid "Export" msgstr "Eksportuoti" #: source/LayoutPreview.cpp:572 msgid "Cascading Style Sheets *.css" msgstr "Cascading Style Sheets *.css" #: source/LayoutPreview.cpp:666 msgid "Layout:" msgstr "Išdėstymas:" #: source/LayoutPreview.cpp:672 msgid "Export CSS File" msgstr "Eksportuoti CSS failą" #: source/LayoutPreview.cpp:673 msgid "Export CSS file" msgstr "Eksportuoti CSS failą" #: source/LayoutPreview.cpp:682 msgid "_Export CSS File As..." msgstr "_Eksportuoti CSS failą kaip..." #: source/LayoutPreview.cpp:686 msgid "_Assign CSS Selectors..." msgstr "_Priskirti CSS selektorius..." #: source/LayoutPreview.cpp:759 msgid "Layout preview" msgstr "Išdėstymo peržiūra" #: source/ToolColorNaming.cpp:25 msgid "_Empty" msgstr "_Tuščia" #: source/ToolColorNaming.cpp:26 msgid "_Automatic name" msgstr "_Automatinis pavadinimas" #: source/ToolColorNaming.cpp:27 msgid "_Tool specific" msgstr "_Priklausomai nuo įrankio" #: source/Variations.cpp:69 msgid "Lightness (Lab)" msgstr "Šviesumas (Lab)" #: source/Variations.cpp:110 msgid "variations" msgstr "pokyčiai" #: source/Variations.cpp:225 msgid "all colors" msgstr "visos spalvos" #: source/Variations.cpp:239 #, c-format msgid "result %d line %d" msgstr "rezultatas %d eilutėje %d" #: source/Variations.cpp:717 #: source/transformation/ColorVisionDeficiency.cpp:386 msgid "Strength:" msgstr "Stiprumas:" #: source/Variations.cpp:745 source/uiDialogVariations.cpp:142 msgid "Variations" msgstr "Pokyčiai" #: source/uiAbout.cpp:88 msgid "About Gpick" msgstr "Apie Gpick" #: source/uiAbout.cpp:121 msgid "Advanced color picker" msgstr "Pažangi spalvų rinkyklė" #: source/uiAbout.cpp:126 msgid "Copyrights © 2009-2013, Albertas Vyšniauskas and Gpick development team" msgstr "" "Autorinės teisės priklauso © 2009-2013, Albertui Vyšniauskui ir Gpick kūrimo " "komandai" #: source/uiAbout.cpp:141 msgid "License" msgstr "Licencija" #: source/uiAbout.cpp:142 msgid "Credits" msgstr "Padėkos" #: source/uiAbout.cpp:143 msgid "Expat License" msgstr "Expat licencija" #: source/uiAbout.cpp:144 msgid "Lua License" msgstr "Lua licencija" #: source/uiApp.cpp:354 msgid "New palette" msgstr "Nauja paletė" #: source/uiApp.cpp:360 msgid "(Imported)" msgstr "(Importuotas)" #: source/uiApp.cpp:530 source/uiApp.cpp:545 source/uiApp.cpp:563 #: source/uiApp.cpp:641 msgid "File could not be opened" msgstr "Nepavyko atidaryti failo" #: source/uiApp.cpp:531 source/uiApp.cpp:546 source/uiApp.cpp:564 #: source/uiApp.cpp:642 msgid "Open" msgstr "Atidaryti" #: source/uiApp.cpp:576 source/uiExport.cpp:473 source/uiExport.cpp:587 msgid "Gpick Palette (*.gpa)" msgstr "Gpick paletė (*.gpa)" #: source/uiApp.cpp:577 source/uiExport.cpp:474 source/uiExport.cpp:588 msgid "GIMP/Inkscape Palette (*.gpl)" msgstr "GIMP/Inkscape paletė (*.gpl)" #: source/uiApp.cpp:578 source/uiExport.cpp:476 source/uiExport.cpp:589 msgid "Adobe Swatch Exchange (*.ase)" msgstr "Adobe Swatch Exchange (*.ase)" #: source/uiApp.cpp:584 source/uiExport.cpp:598 #: source/tools/PaletteFromImage.cpp:548 msgid "All files" msgstr "Visi failai" #: source/uiApp.cpp:589 source/uiExport.cpp:607 msgid "All supported formats" msgstr "Visi palaikomi formatai" #: source/uiApp.cpp:610 msgid "Open File" msgstr "Atidaryti failą" #: source/uiApp.cpp:659 source/uiApp.cpp:691 msgid "Save As" msgstr "Išsaugoti kaip" #: source/uiApp.cpp:712 msgid "Save" msgstr "Išsaugoti" #: source/uiApp.cpp:771 msgid "Open Last File" msgstr "Atidaryti vėliausią failą" #: source/uiApp.cpp:916 msgid "Recent _files" msgstr "Paskutiniai _failai" #: source/uiApp.cpp:946 msgid "Ex_port..." msgstr "Eksportuoti..." #: source/uiApp.cpp:954 msgid "Expo_rt Selected..." msgstr "Eksportuoti _pažymėtas..." #: source/uiApp.cpp:962 msgid "_Import..." msgstr "_Importuoti..." #: source/uiApp.cpp:977 msgid "_File" msgstr "_Failas" #: source/uiApp.cpp:985 msgid "Edit _Converters..." msgstr "Keisti _keitėjus..." #: source/uiApp.cpp:989 msgid "Display _Filters..." msgstr "Rodymo _Filtrai..." #: source/uiApp.cpp:1001 msgid "_Edit" msgstr "_Keisti" #: source/uiApp.cpp:1037 msgid "_Secondary View" msgstr "_Antrinis vaizdas" #: source/uiApp.cpp:1043 msgid "Palette" msgstr "Paletė" #: source/uiApp.cpp:1049 msgid "_View" msgstr "_Rodymas" #: source/uiApp.cpp:1055 msgid "Palette From _Image..." msgstr "Paletė iš paveikslėlio..." #: source/uiApp.cpp:1063 msgid "_Tools" msgstr "_Įrankiai" #: source/uiApp.cpp:1078 msgid "_Help" msgstr "_Pagalba" #: source/uiApp.cpp:1386 msgid "_Copy to Clipboard" msgstr "_Kopijuoti" #: source/uiApp.cpp:1402 msgid "_Mix Colors..." msgstr "_Maišyti spalvas..." #: source/uiApp.cpp:1407 msgid "_Variations..." msgstr "_Pokyčiai..." #: source/uiApp.cpp:1412 msgid "_Generate..." msgstr "_Generuoti..." #: source/uiApp.cpp:1421 msgid "C_lear names" msgstr "I_švalyti pavadinimus" #: source/uiApp.cpp:1427 msgid "Autona_me" msgstr "Auto. pavadinimai" #: source/uiApp.cpp:1433 msgid "Auto_number..." msgstr "Auto. _numeracija..." #: source/uiApp.cpp:1441 msgid "R_everse" msgstr "_Atvirkščiai" #: source/uiApp.cpp:1447 msgid "Group and _sort..." msgstr "_Grupavimas ir rūšiavimas..." #: source/uiApp.cpp:1455 msgid "_Remove" msgstr "_Pašalinti" #: source/uiApp.cpp:1461 msgid "Remove _All" msgstr "Pašalinti _visas" #: source/uiApp.cpp:1869 msgid "Color pic_ker" msgstr "Spalvų rin_kyklė" #: source/uiApp.cpp:1878 msgid "Scheme _generation" msgstr "Schemos _generavimas" #: source/uiApp.cpp:1897 msgid "Lay_out preview" msgstr "Maket_o peržiūra" #: source/uiApp.cpp:1947 msgid "Pick colors (Ctrl+P)" msgstr "Rinkti spalvas (Vald+P)" #: source/uiApp.cpp:1956 msgid "" "File is currently in a non-native format, possible loss of precision and/or " "metadata." msgstr "" "Šiuo metu failas išsaugotas ne pagrindiniu formatu, galimas tinkslumo ir/ar " "metaduomenų praradimas." #: source/uiColorInput.cpp:45 msgid "Edit color" msgstr "Keisti spalvą" #: source/uiColorInput.cpp:69 msgid "Color:" msgstr "Spalva:" #: source/uiConverter.cpp:56 msgid "Test color" msgstr "Testavimo spalva" #: source/uiConverter.cpp:74 msgid "error" msgstr "klaida" #: source/uiConverter.cpp:145 msgid "Function name" msgstr "Funkcijos pavadinimas" #: source/uiConverter.cpp:154 msgid "Example" msgstr "Pavyzdys" #: source/uiConverter.cpp:196 msgid "Converters" msgstr "Keitėjai" #: source/uiConverter.cpp:224 msgid "Displays:" msgstr "Rodymas:" #: source/uiConverter.cpp:230 msgid "Color list:" msgstr "Spalvų sąrašas::" #: source/uiDialogAutonumber.cpp:108 msgid "Autonumber colors" msgstr "Sunumeruoti spalvas" #: source/uiDialogAutonumber.cpp:122 msgid "Name:" msgstr "Pavadinimas:" #: source/uiDialogAutonumber.cpp:132 msgid "Decimal places:" msgstr "Skaitmenys:" #: source/uiDialogAutonumber.cpp:139 msgid "Starting number:" msgstr "Pradėti nuo:" #: source/uiDialogAutonumber.cpp:146 msgid "_Decreasing" msgstr "Mažėjantis" #: source/uiDialogAutonumber.cpp:152 msgid "_Append" msgstr "_Pridėti" #: source/uiDialogAutonumber.cpp:158 msgid "Sample:" msgstr "Pavyzdys:" #: source/uiDialogGenerate.cpp:216 msgid "Generate colors" msgstr "Generuoti spalvas" #: source/uiDialogGenerate.cpp:230 source/tools/PaletteFromImage.cpp:599 msgid "Colors:" msgstr "Spalvos:" #: source/uiDialogGenerate.cpp:257 msgid "Chaos:" msgstr "Chaosas:" #: source/uiDialogGenerate.cpp:263 msgid "Seed:" msgstr "Sėkla:" #: source/uiDialogGenerate.cpp:271 msgid "_Reverse" msgstr "_Atvirkščiai" #: source/uiDialogMix.cpp:76 source/uiDialogMix.cpp:78 msgid "mix node" msgstr "maišymo mazgas" #: source/uiDialogMix.cpp:81 msgid "mix" msgstr "maišymas" #: source/uiDialogMix.cpp:235 msgid "Mix colors" msgstr "Maišyti spalvas" #: source/uiDialogMix.cpp:262 source/uiDialogVariations.cpp:186 msgid "Steps:" msgstr "Žingsniai:" #: source/uiDialogMix.cpp:270 msgid "_Include Endpoints" msgstr "Įtraukti _galinius taškus" #: source/uiDialogOptions.cpp:117 source/tools/PaletteFromImage.cpp:589 msgid "Options" msgstr "Nustatymai" #: source/uiDialogOptions.cpp:134 msgid "System" msgstr "Sistema" #: source/uiDialogOptions.cpp:143 msgid "_Single instance" msgstr "_Vienas egzempliorius" #: source/uiDialogOptions.cpp:148 msgid "Save/_Restore palette" msgstr "I6saugoti/_Atstatyti paletę" #: source/uiDialogOptions.cpp:154 msgid "System tray" msgstr "Sisteminis dėklas" #: source/uiDialogOptions.cpp:162 msgid "_Minimize to system tray" msgstr "_Nuleisti į sisteminį dėklą" #: source/uiDialogOptions.cpp:167 msgid "_Close to system tray" msgstr "_Uždaryti į sisteminį dėklą" #: source/uiDialogOptions.cpp:172 msgid "_Start in system tray" msgstr "_Paleisti sisteminiame dėkle" #: source/uiDialogOptions.cpp:178 msgid "_Main" msgstr "_Pagrindiniai" #: source/uiDialogOptions.cpp:184 msgid "Display" msgstr "Rodymas" #: source/uiDialogOptions.cpp:193 msgid "_Refresh rate:" msgstr "_Atnaujinimo dažnis:" #: source/uiDialogOptions.cpp:201 msgid "_Magnified area size:" msgstr "_Padidinto ploto dydis:" #: source/uiDialogOptions.cpp:207 msgid "Floating picker click behaviour" msgstr "Slankaus rinkėjo elgsena" #: source/uiDialogOptions.cpp:226 msgid "'Spacebar' button behaviour" msgstr "'Tarpo' mygtuko elgsena" #: source/uiDialogOptions.cpp:244 msgid "_Rotate swatch" msgstr "_Pasukti mėginį" #: source/uiDialogOptions.cpp:251 msgid "Enabled color spaces" msgstr "Aktyvios spalvų erdvės" #: source/uiDialogOptions.cpp:266 msgid "Lab settings" msgstr "Lab nustatymai" #: source/uiDialogOptions.cpp:278 msgid "_Illuminant:" msgstr "_Apšvietimas:" #: source/uiDialogOptions.cpp:302 msgid "_Observer:" msgstr "_Stebėtojas:" #: source/uiDialogOptions.cpp:321 msgid "Other settings" msgstr "Kiti nustatymai" #: source/uiDialogOptions.cpp:330 msgid "_Mask out of gamut colors" msgstr "Maskuoti spalvas esančias už gamos ribų" #: source/uiDialogOptions.cpp:336 msgid "_Picker" msgstr "_Rinkėjas" #: source/uiDialogOptions.cpp:341 msgid "Color name generation" msgstr "Spalvų pavadinimų generavimas" #: source/uiDialogOptions.cpp:350 msgid "_Imprecision postfix" msgstr "_Netikslumo ženklas" #: source/uiDialogOptions.cpp:356 msgid "Tool color naming" msgstr "Įrankių spalvų pavadinimai" #: source/uiDialogOptions.cpp:381 msgid "_Color names" msgstr "_Spalvų pavadinimai" #: source/uiDialogSort.cpp:135 source/uiDialogSort.cpp:223 msgid "RGB Red" msgstr "RGB Raudona" #: source/uiDialogSort.cpp:136 source/uiDialogSort.cpp:224 msgid "RGB Green" msgstr "RGB Žalia" #: source/uiDialogSort.cpp:137 source/uiDialogSort.cpp:225 msgid "RGB Blue" msgstr "RGB Mėlyna" #: source/uiDialogSort.cpp:138 source/uiDialogSort.cpp:226 msgid "RGB Grayscale" msgstr "RGB Pustonis" #: source/uiDialogSort.cpp:139 source/uiDialogSort.cpp:227 msgid "HSL Hue" msgstr "HSL Atspalvis" #: source/uiDialogSort.cpp:140 source/uiDialogSort.cpp:228 msgid "HSL Saturation" msgstr "HSL Įsotinimas" #: source/uiDialogSort.cpp:141 source/uiDialogSort.cpp:229 msgid "HSL Lightness" msgstr "HSL Šviesumas" #: source/uiDialogSort.cpp:142 source/uiDialogSort.cpp:230 msgid "Lab Lightness" msgstr "Lab Šviesumas" #: source/uiDialogSort.cpp:143 source/uiDialogSort.cpp:231 msgid "Lab A" msgstr "Lab A" #: source/uiDialogSort.cpp:144 source/uiDialogSort.cpp:232 msgid "Lab B" msgstr "Lab B" #: source/uiDialogSort.cpp:145 source/uiDialogSort.cpp:233 msgid "LCh Lightness" msgstr "LCh Šviesumas" #: source/uiDialogSort.cpp:146 source/uiDialogSort.cpp:234 msgid "LCh Chroma" msgstr "LCh Chroma" #: source/uiDialogSort.cpp:147 source/uiDialogSort.cpp:235 msgid "LCh Hue" msgstr "LCh Atspalvis" #: source/uiDialogSort.cpp:556 msgid "Group and sort" msgstr "Grupuoti ir rūšiuoti" #: source/uiDialogSort.cpp:564 msgid "Group type:" msgstr "Grupavimo tipas:" #: source/uiDialogSort.cpp:574 msgid "Grouping sensitivity:" msgstr "Grupavimo jautrumas:" #: source/uiDialogSort.cpp:581 msgid "Maximum number of groups:" msgstr "Maksimalus grupių skaičius:" #: source/uiDialogSort.cpp:588 msgid "Sort type:" msgstr "Rūšiavimo tipas:" #: source/uiDialogSort.cpp:598 msgid "_Reverse group order" msgstr "_Atvirkščia grupių tvarka" #: source/uiDialogSort.cpp:604 msgid "_Reverse order inside groups" msgstr "_Atvirkščia tvarka grupėse" #: source/uiDialogVariations.cpp:60 msgid "variation" msgstr "pokyčiai" #: source/uiDialogVariations.cpp:194 msgid "_Use multiplication" msgstr "_Naudoti daugybą" #: source/uiExport.cpp:475 msgid "Alias/WaveFront Material (*.mtl)" msgstr "Alias/WaveFront Material (*.mtl)" #: source/uiExport.cpp:477 msgid "Text file (*.txt)" msgstr "Tekstinis failas (*.txt)" #: source/uiExport.cpp:522 msgid "File could not be exported" msgstr "Nepavyko eksportuoti failą" #: source/uiExport.cpp:573 source/uiExport.cpp:654 source/uiExport.cpp:666 msgid "Import" msgstr "Importuoti" #: source/uiExport.cpp:653 msgid "File format is not supported" msgstr "Failo formatas nėra palaikomas" #: source/uiExport.cpp:665 msgid "File could not be imported" msgstr "Nepavyko importuoti failą" #: source/uiListPalette.cpp:158 source/uiListPalette.cpp:160 #, c-format msgid "%d color" msgid_plural "%d colors" msgstr[0] "%d spalva" msgstr[1] "%d spalvos" msgstr[2] "%d spalvų" #: source/uiListPalette.cpp:166 msgid "selected" msgstr "pasirinkta" #: source/uiListPalette.cpp:172 source/uiListPalette.cpp:174 #, c-format msgid "Total %d color" msgid_plural "Total %d colors" msgstr[0] "Viso %d spalva" msgstr[1] "Viso %d spalvos" msgstr[2] "Viso %d spalvų" #: source/uiListPalette.cpp:353 msgid "Preview" msgstr "Peržiūra" #: source/uiListPalette.cpp:708 source/uiListPalette.cpp:717 msgid "Color" msgstr "Spalva" #: source/uiListPalette.cpp:726 source/uiTransformations.cpp:183 msgid "Name" msgstr "Pavadinimas" #: source/uiStatusIcon.cpp:67 msgid "_Show Main Window" msgstr "_Rodyti pagrindinį langą" #: source/uiStatusIcon.cpp:74 msgid "_Quit" msgstr "_Išeiti" #: source/uiTransformations.cpp:245 msgid "Display filters" msgstr "Rodymo filtrai" #: source/uiTransformations.cpp:259 msgid "_Enabled" msgstr "_Įjungta" #: source/tools/PaletteFromImage.cpp:514 msgid "Palette from image" msgstr "Paletė iš paveikslėlio" #: source/tools/PaletteFromImage.cpp:527 msgid "Image" msgstr "Paveikslėlis" #: source/tools/PaletteFromImage.cpp:536 msgid "Image file" msgstr "Paveikslėlio failas" #: source/tools/PaletteFromImage.cpp:556 msgid "All images" msgstr "Visi paveikslėliai" #: source/transformation/ColorVisionDeficiency.cpp:41 msgid "Color vision deficiency" msgstr "Spalvų matymo defektai" #: source/transformation/ColorVisionDeficiency.cpp:330 msgid "Protanomaly" msgstr "Protanomalija" #: source/transformation/ColorVisionDeficiency.cpp:331 msgid "Deuteranomaly" msgstr "Deuteranomalija" #: source/transformation/ColorVisionDeficiency.cpp:332 msgid "Tritanomaly" msgstr "Tritanomalija" #: source/transformation/ColorVisionDeficiency.cpp:333 msgid "Protanopia" msgstr "Protanopija" #: source/transformation/ColorVisionDeficiency.cpp:334 msgid "Deuteranopia" msgstr "Deuteranopija" #: source/transformation/ColorVisionDeficiency.cpp:335 msgid "Tritanopia" msgstr "Tritanopija" #: source/transformation/ColorVisionDeficiency.cpp:422 msgid "Altered spectral sensitivity of red receptors" msgstr "Pakitęs raudonų receptorių spektro jautrumas" #: source/transformation/ColorVisionDeficiency.cpp:423 msgid "Altered spectral sensitivity of green receptors" msgstr "Pakitęs žalių receptorių spektro jautrumas" #: source/transformation/ColorVisionDeficiency.cpp:424 msgid "Altered spectral sensitivity of blue receptors" msgstr "Pakitęs mėlynų receptorių spektro jautrumas" #: source/transformation/ColorVisionDeficiency.cpp:425 msgid "Absence of red receptors" msgstr "Raudonų receptorių nebūvimas" #: source/transformation/ColorVisionDeficiency.cpp:426 msgid "Absence of green receptors" msgstr "Žalių receptorių nebūvimas" #: source/transformation/ColorVisionDeficiency.cpp:427 msgid "Absence of blue receptors" msgstr "Mėlynų receptorių nebūvimas" #: source/transformation/GammaModification.cpp:38 msgid "Gamma modification" msgstr "Gamos pakeitimas" #: source/transformation/GammaModification.cpp:88 #: source/transformation/Quantization.cpp:96 msgid "Value:" msgstr "Reikšmė:" #: source/transformation/Quantization.cpp:40 msgid "Quantization" msgstr "Kvantavimas" #: source/transformation/Quantization.cpp:101 msgid "Clip top-end" msgstr "Apkirpti viršutinę dalį" #: share/gpick/init.lua:173 msgid "Web: hex code" msgstr "Tinklas: šešioliktainis kodas" #: share/gpick/init.lua:178 msgid "Web: hex code (3 digits)" msgstr "Tinklas: šešioliktainis kodas (3 skaitmenys)" #: share/gpick/init.lua:183 msgid "Web: hex code (no hash symbol)" msgstr "Tinklas: šešioliktainis kodas (be grotelių simbolio)" #: share/gpick/init.lua:188 msgid "CSS: hue saturation lightness" msgstr "CSS: atspalvis įsotinimas šviesumas" #: share/gpick/init.lua:193 msgid "CSS: red green blue" msgstr "CSS: raudona žalia mėlyna" #: share/gpick/layouts.lua:15 msgid "Homepage" msgstr "Namų puslapis" #: share/gpick/layouts.lua:15 msgid "About us" msgstr "Apie mus" #: share/gpick/layouts.lua:15 msgid "Links to us" msgstr "Nuorodos" #: share/gpick/layouts.lua:15 msgid "Privacy" msgstr "Privatumas" #: share/gpick/layouts.lua:15 msgid "Terms" msgstr "Sąlygos" #: share/gpick/layouts.lua:15 msgid "Contact us" msgstr "Kontaktai" #: share/gpick/layouts.lua:15 msgid "RSS" msgstr "RSS" #: share/gpick/layouts.lua:30 msgid "The quick brown fox jumps over the lazy dog" msgstr "Greita ruda lapė šoka per tingų šunį" #: share/gpick/layouts.lua:46 msgid "Webpage" msgstr "Puslapis" #: share/gpick/layouts.lua:51 share/gpick/layouts.lua:73 msgid "Header" msgstr "Antraštė" #: share/gpick/layouts.lua:52 msgid "Header text" msgstr "Antraštės tekstas" #: share/gpick/layouts.lua:54 msgid "Content" msgstr "Turinys" #: share/gpick/layouts.lua:55 msgid "Content text" msgstr "Turinio tekstas" #: share/gpick/layouts.lua:57 msgid "Sidebar" msgstr "Šonas" #: share/gpick/layouts.lua:59 share/gpick/layouts.lua:87 msgid "Button" msgstr "Mygtukas" #: share/gpick/layouts.lua:60 share/gpick/layouts.lua:88 msgid "Button (hover)" msgstr "Mygtukas (pažymėtas)" #: share/gpick/layouts.lua:61 share/gpick/layouts.lua:89 msgid "Button text" msgstr "Mygtuko tekstas" #: share/gpick/layouts.lua:62 share/gpick/layouts.lua:90 msgid "Button text (hover)" msgstr "Mytuko tekstas (pažymėtas)" #: share/gpick/layouts.lua:64 msgid "Footer" msgstr "Paraštė" #: share/gpick/layouts.lua:82 share/gpick/layouts.lua:86 msgid "Menu" msgstr "Meniu" #: share/gpick/layouts.lua:106 msgid "Brightness-Darkness" msgstr "Šviesumas-Tamsumas" #: share/gpick/layouts.lua:110 msgid "main" msgstr "pagrindinis" #: share/gpick/layouts.lua:144 msgid "Grid (4x3)" msgstr "Tinklas (4x3)" #: share/gpick/layouts.lua:153 share/gpick/layouts.lua:159 #: share/gpick/layouts.lua:180 share/gpick/layouts.lua:186 msgid "Item" msgstr "Lauk." #: share/gpick/layouts.lua:154 share/gpick/layouts.lua:181 msgid "Item text" msgstr "Laukelio tekstas" #: share/gpick/layouts.lua:171 msgid "Grid (5x4)" msgstr "Tinklas (5x4)" gpick_0.2.5/share/locale/ru/LC_MESSAGES/gpick.po0000644000175000017500000010006512113713537017623 0ustar zbygzbyg# Translation of Gpick into Russian # Александр Прокудин , 2011. # msgid "" msgstr "" "Project-Id-Version: gpick 0.2.5\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-01-10 04:26+0400\n" "PO-Revision-Date: 2013-01-10 14:18+0300\n" "Last-Translator: Александр Прокудин \n" "Language-Team: Russian \n" "Language: ru\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); 10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Poedit-Language: Russian\n" "X-Poedit-Country: RUSSIAN FEDERATION\n" #: source/BlendColors.cpp:114 #: source/BlendColors.cpp:116 msgid "blend node" msgstr "основной" #: source/BlendColors.cpp:119 msgid "blend" msgstr "переход" #: source/BlendColors.cpp:308 #: source/BrightnessDarkness.cpp:260 #: source/ColorMixer.cpp:321 #: source/ColorPicker.cpp:367 #: source/GenerateScheme.cpp:444 #: source/LayoutPreview.cpp:405 #: source/Variations.cpp:331 #: source/uiDialogOptions.cpp:215 #: source/uiDialogOptions.cpp:234 msgid "_Add to palette" msgstr "_Добавить в палитру" #: source/BlendColors.cpp:314 #: source/BrightnessDarkness.cpp:265 #: source/ColorMixer.cpp:326 #: source/ColorPicker.cpp:371 #: source/GenerateScheme.cpp:449 #: source/LayoutPreview.cpp:410 #: source/Variations.cpp:336 msgid "A_dd all to palette" msgstr "Доб_авить все в палитру" #: source/BlendColors.cpp:320 #: source/BrightnessDarkness.cpp:271 #: source/ColorMixer.cpp:333 #: source/ColorPicker.cpp:377 #: source/GenerateScheme.cpp:456 #: source/LayoutPreview.cpp:416 #: source/Variations.cpp:343 #: source/uiDialogOptions.cpp:220 #: source/uiDialogOptions.cpp:239 msgid "_Copy to clipboard" msgstr "С_копировать в буфер обмена" #: source/BlendColors.cpp:374 #: source/GenerateScheme.cpp:485 msgid "_Reset" msgstr "С_бросить" #: source/BlendColors.cpp:517 msgid "Start:" msgstr "Начало:" #: source/BlendColors.cpp:533 msgid "Middle:" msgstr "Середина:" #: source/BlendColors.cpp:551 msgid "End:" msgstr "Конец:" #: source/BlendColors.cpp:568 #: source/GenerateScheme.cpp:875 #: source/uiDialogGenerate.cpp:237 #: source/uiDialogMix.cpp:249 #: source/transformation/ColorVisionDeficiency.cpp:363 msgid "Type:" msgstr "Тип:" #: source/BlendColors.cpp:570 #: source/ColorWheelType.cpp:56 #: source/uiDialogMix.cpp:251 msgid "RGB" msgstr "RGB" #: source/BlendColors.cpp:571 #: source/uiDialogMix.cpp:252 msgid "HSV" msgstr "HSV" #: source/BlendColors.cpp:572 #: source/uiDialogMix.cpp:253 msgid "HSV shortest hue distance" msgstr "HSV, кратчайшее расстояние" #: source/BlendColors.cpp:573 #: source/uiDialogMix.cpp:254 msgid "LAB" msgstr "LAB" #: source/BlendColors.cpp:582 msgid "Start steps:" msgstr "Шагов в начале:" #: source/BlendColors.cpp:590 msgid "End steps:" msgstr "Шагов в конце:" #: source/BlendColors.cpp:627 msgid "Blend colors" msgstr "Переход между цветами" #: source/BrightnessDarkness.cpp:86 msgid "brightness darkness" msgstr "Яркость-Темнота" #: source/BrightnessDarkness.cpp:287 #: source/ColorMixer.cpp:373 #: source/ColorPicker.cpp:387 #: source/GenerateScheme.cpp:469 #: source/LayoutPreview.cpp:430 #: source/Variations.cpp:383 msgid "_Edit..." msgstr "_Изменить…" #: source/BrightnessDarkness.cpp:292 #: source/ColorMixer.cpp:378 #: source/ColorPicker.cpp:391 #: source/GenerateScheme.cpp:474 #: source/LayoutPreview.cpp:435 #: source/Variations.cpp:388 msgid "_Paste" msgstr "_Вставить" #: source/BrightnessDarkness.cpp:385 msgid "Brightness" msgstr "Яркость" #: source/BrightnessDarkness.cpp:385 msgid "Darkness" msgstr "Темнота" #: source/BrightnessDarkness.cpp:431 msgid "Brightness Darkness" msgstr "Яркость-Темнота" #: source/ColorMixer.cpp:66 msgid "Normal" msgstr "Нормальный" #: source/ColorMixer.cpp:67 msgid "Multiply" msgstr "Умножение" #: source/ColorMixer.cpp:68 msgid "Add" msgstr "Добавление" #: source/ColorMixer.cpp:69 msgid "Difference" msgstr "Разница" #: source/ColorMixer.cpp:70 #: source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 #: source/ColorSpaceType.cpp:30 #: source/ColorSpaceType.cpp:37 #: source/Variations.cpp:66 msgid "Hue" msgstr "Тон" #: source/ColorMixer.cpp:71 #: source/ColorPicker.cpp:1180 #: source/ColorPicker.cpp:1194 #: source/ColorSpaceType.cpp:31 #: source/ColorSpaceType.cpp:38 #: source/Variations.cpp:67 msgid "Saturation" msgstr "Насыщенность" #: source/ColorMixer.cpp:72 #: source/ColorPicker.cpp:1194 #: source/ColorPicker.cpp:1236 #: source/ColorPicker.cpp:1250 #: source/ColorSpaceType.cpp:39 #: source/ColorSpaceType.cpp:59 #: source/ColorSpaceType.cpp:66 #: source/Variations.cpp:68 msgid "Lightness" msgstr "Светлота" #: source/ColorMixer.cpp:114 msgid "color mixer" msgstr "Микшер цветов" #: source/ColorMixer.cpp:234 msgid "secondary" msgstr "первичный" #: source/ColorMixer.cpp:238 #: source/Variations.cpp:229 #, c-format msgid "primary %d" msgstr "вторичный %d" #: source/ColorMixer.cpp:244 #, c-format msgid "result %d" msgstr "результат %d" #: source/ColorMixer.cpp:704 msgid "Opacity:" msgstr "Непрозрачность:" #: source/ColorMixer.cpp:732 msgid "Color mixer" msgstr "Микшер цветов" #: source/ColorPicker.cpp:424 msgid "Press Spacebar to sample color under mouse pointer" msgstr "Нажмите пробел для добавления цвета под указателем" #: source/ColorPicker.cpp:699 #: source/uiConverter.cpp:163 msgid "Copy" msgstr "Копирование" #: source/ColorPicker.cpp:703 #: source/uiConverter.cpp:172 msgid "Paste" msgstr "Вставка" #: source/ColorPicker.cpp:709 #: source/uiColorInput.cpp:119 msgid "Edit" msgstr "Изменить" #: source/ColorPicker.cpp:771 #: source/uiApp.cpp:1012 #: source/uiDialogSort.cpp:222 msgid "None" msgstr "Нет" #: source/ColorPicker.cpp:772 msgid "Linear" msgstr "Линейное" #: source/ColorPicker.cpp:773 msgid "Quadratic" msgstr "Квадратичное" #: source/ColorPicker.cpp:774 msgid "Cubic" msgstr "Кубическое" #: source/ColorPicker.cpp:775 msgid "Exponential" msgstr "Экспоненциальное" #: source/ColorPicker.cpp:951 msgid "Click on swatch area to begin adding colors to palette" msgstr "" #: source/ColorPicker.cpp:1143 msgid "Settings" msgstr "Параметры" #: source/ColorPicker.cpp:1153 msgid "Oversample:" msgstr "Оверсэмплинг:" #: source/ColorPicker.cpp:1160 msgid "Falloff:" msgstr "Спадание:" #: source/ColorPicker.cpp:1167 msgid "Zoom:" msgstr "Масштаб:" #: source/ColorPicker.cpp:1180 #: source/ColorSpaceType.cpp:32 msgid "Value" msgstr "Значение" #: source/ColorPicker.cpp:1208 #: source/ColorSpaceType.cpp:44 msgid "Red" msgstr "Красный" #: source/ColorPicker.cpp:1208 #: source/ColorSpaceType.cpp:45 msgid "Green" msgstr "Зелёный" #: source/ColorPicker.cpp:1208 #: source/ColorSpaceType.cpp:46 msgid "Blue" msgstr "Синий" #: source/ColorPicker.cpp:1222 #: source/ColorSpaceType.cpp:51 msgid "Cyan" msgstr "Cyan" #: source/ColorPicker.cpp:1222 #: source/ColorSpaceType.cpp:52 msgid "Magenta" msgstr "Magenta" #: source/ColorPicker.cpp:1222 #: source/ColorSpaceType.cpp:53 msgid "Yellow" msgstr "Yellow" #: source/ColorPicker.cpp:1222 #: source/ColorSpaceType.cpp:54 msgid "Key" msgstr "Key" #: source/ColorPicker.cpp:1258 msgid "Info" msgstr "Информация" #: source/ColorPicker.cpp:1267 msgid "Color name:" msgstr "Название цвета:" #: source/ColorPicker.cpp:1280 msgid "Contrast:" msgstr "Контраст:" #: source/ColorPicker.cpp:1285 #: source/ColorPicker.cpp:1291 msgid "Sample" msgstr "Образец" #: source/ColorPicker.cpp:1324 msgid "Color picker" msgstr "Пипетка" #: source/ColorWheelType.cpp:57 msgid "RYB v1" msgstr "RYB v1" #: source/ColorWheelType.cpp:58 msgid "RYB v2" msgstr "RYB v2" #: source/GenerateScheme.cpp:90 msgid "Complementary" msgstr "Противоположные" #: source/GenerateScheme.cpp:91 msgid "Analogous" msgstr "Аналоговая" #: source/GenerateScheme.cpp:92 msgid "Triadic" msgstr "Триады" #: source/GenerateScheme.cpp:93 msgid "Split-Complementary" msgstr "Разделённые противоположные" #: source/GenerateScheme.cpp:94 msgid "Rectangle (tetradic)" msgstr "Прямоугольник (тетрады)" #: source/GenerateScheme.cpp:95 msgid "Square" msgstr "Квадрат" #: source/GenerateScheme.cpp:96 msgid "Neutral" msgstr "Нейтральная" #: source/GenerateScheme.cpp:97 msgid "Clash" msgstr "Конфликт" #: source/GenerateScheme.cpp:98 msgid "Five-Tone" msgstr "Пять тонов" #: source/GenerateScheme.cpp:99 msgid "Six-Tone" msgstr "Шесть тонов" #: source/GenerateScheme.cpp:119 #: source/uiDialogGenerate.cpp:76 msgid "scheme" msgstr "Схема" #: source/GenerateScheme.cpp:292 msgid "_Locked" msgstr "_Блокировать насыщенность и светлоту" #: source/GenerateScheme.cpp:299 msgid "_Reset scheme" msgstr "_Сбросить изменения" #: source/GenerateScheme.cpp:851 msgid "Hue:" msgstr "Тон:" #: source/GenerateScheme.cpp:858 #: source/uiDialogVariations.cpp:171 msgid "Saturation:" msgstr "Насыщенность:" #: source/GenerateScheme.cpp:866 #: source/uiDialogVariations.cpp:156 msgid "Lightness:" msgstr "Светлота:" #: source/GenerateScheme.cpp:885 #: source/uiDialogGenerate.cpp:246 msgid "Color wheel:" msgstr "Цветовой круг:" #: source/GenerateScheme.cpp:919 msgid "Scheme generation" msgstr "Создание цветовой схемы" #: source/LayoutPreview.cpp:78 msgid "layout preview" msgstr "Просмотр макета" #: source/LayoutPreview.cpp:153 msgid "Style item" msgstr "Объект стиля" #: source/LayoutPreview.cpp:162 msgid "CSS selector" msgstr "Селектор CSS" #: source/LayoutPreview.cpp:184 msgid "Assign CSS selectors" msgstr "Назначить селекторы CSS" #: source/LayoutPreview.cpp:547 #: source/LayoutPreview.cpp:595 #: source/uiApp.cpp:690 #: source/uiApp.cpp:711 msgid "File could not be saved" msgstr "Не удалось сохранить файл" #: source/LayoutPreview.cpp:558 #: source/uiExport.cpp:457 #: source/uiExport.cpp:523 msgid "Export" msgstr "Экспортировать" #: source/LayoutPreview.cpp:572 msgid "Cascading Style Sheets *.css" msgstr "Каскадные таблицы стилей (*.css)" #: source/LayoutPreview.cpp:666 msgid "Layout:" msgstr "Макет:" #: source/LayoutPreview.cpp:672 msgid "Export CSS File" msgstr "Экспортировать файл CSS" #: source/LayoutPreview.cpp:673 msgid "Export CSS file" msgstr "Экспортировать файл CSS" #: source/LayoutPreview.cpp:682 msgid "_Export CSS File As..." msgstr "_Экспортировать файл CSS как…" #: source/LayoutPreview.cpp:686 msgid "_Assign CSS Selectors..." msgstr "_Назначить селекторы CSS…" #: source/LayoutPreview.cpp:759 msgid "Layout preview" msgstr "Просмотр макета" #: source/ToolColorNaming.cpp:25 msgid "_Empty" msgstr "_Без названия" #: source/ToolColorNaming.cpp:26 msgid "_Automatic name" msgstr "_Автоматическое именование" #: source/ToolColorNaming.cpp:27 msgid "_Tool specific" msgstr "_В зависимости от инструмента" #: source/Variations.cpp:69 msgid "Lightness (Lab)" msgstr "Светлота (Lab)" #: source/Variations.cpp:110 msgid "variations" msgstr "Вариации" #: source/Variations.cpp:225 msgid "all colors" msgstr "все цвета" #: source/Variations.cpp:239 #, c-format msgid "result %d line %d" msgstr "результат %d строка %d" #: source/Variations.cpp:717 #: source/transformation/ColorVisionDeficiency.cpp:386 msgid "Strength:" msgstr "Сила:" #: source/Variations.cpp:745 #: source/uiDialogVariations.cpp:142 msgid "Variations" msgstr "Вариации светлоты и насыщенности" #: source/uiAbout.cpp:88 msgid "About Gpick" msgstr "О программе Gpick" #: source/uiAbout.cpp:121 msgid "Advanced color picker" msgstr "Продвинутая цветовая пипетка" #: source/uiAbout.cpp:126 msgid "Copyrights © 2009-2013, Albertas Vyšniauskas and Gpick development team" msgstr "Авторские права © 2009-2013, Albertas Vyšniauskas and Gpick development team" #: source/uiAbout.cpp:141 msgid "License" msgstr "Лицензия" #: source/uiAbout.cpp:142 msgid "Credits" msgstr "Авторы" #: source/uiAbout.cpp:143 msgid "Expat License" msgstr "Лицензия на Expat" #: source/uiAbout.cpp:144 msgid "Lua License" msgstr "Лицензия на Lua" #: source/uiApp.cpp:354 msgid "New palette" msgstr "Новая палитра" #: source/uiApp.cpp:360 msgid "(Imported)" msgstr "(импортировано)" #: source/uiApp.cpp:530 #: source/uiApp.cpp:545 #: source/uiApp.cpp:563 #: source/uiApp.cpp:641 msgid "File could not be opened" msgstr "Не удалось открыть файл" #: source/uiApp.cpp:531 #: source/uiApp.cpp:546 #: source/uiApp.cpp:564 #: source/uiApp.cpp:642 msgid "Open" msgstr "Открыть" #: source/uiApp.cpp:576 #: source/uiExport.cpp:473 #: source/uiExport.cpp:587 msgid "Gpick Palette (*.gpa)" msgstr "Палитры Gpick (*.gpa)" #: source/uiApp.cpp:577 #: source/uiExport.cpp:474 #: source/uiExport.cpp:588 msgid "GIMP/Inkscape Palette (*.gpl)" msgstr "Палитры GIMP/Inkscape (*.gpl)" #: source/uiApp.cpp:578 #: source/uiExport.cpp:476 #: source/uiExport.cpp:589 msgid "Adobe Swatch Exchange (*.ase)" msgstr "Палитры Adobe Swatch Exchange (*.ase)" #: source/uiApp.cpp:584 #: source/uiExport.cpp:598 #: source/tools/PaletteFromImage.cpp:548 msgid "All files" msgstr "Все файлы" #: source/uiApp.cpp:589 #: source/uiExport.cpp:607 msgid "All supported formats" msgstr "Все поддерживаемые форматы" #: source/uiApp.cpp:610 msgid "Open File" msgstr "Открыть файл" #: source/uiApp.cpp:659 #: source/uiApp.cpp:691 msgid "Save As" msgstr "Сохранить как" #: source/uiApp.cpp:712 msgid "Save" msgstr "Сохранить" #: source/uiApp.cpp:771 msgid "Open Last File" msgstr "Открыть последний файл" #: source/uiApp.cpp:916 msgid "Recent _files" msgstr "_Недавние файлы" #: source/uiApp.cpp:946 msgid "Ex_port..." msgstr "_Экспортировать…" #: source/uiApp.cpp:954 msgid "Expo_rt Selected..." msgstr "Экспортировать _выделенное…" #: source/uiApp.cpp:962 msgid "_Import..." msgstr "_Импортировать…" #: source/uiApp.cpp:977 msgid "_File" msgstr "_Файл" #: source/uiApp.cpp:985 msgid "Edit _Converters..." msgstr "_Конвертеры…" #: source/uiApp.cpp:989 msgid "Display _Filters..." msgstr "_Экранные фильтры..." #: source/uiApp.cpp:1001 msgid "_Edit" msgstr "_Правка" #: source/uiApp.cpp:1037 msgid "_Secondary View" msgstr "_Дополнительная панель" #: source/uiApp.cpp:1043 msgid "Palette" msgstr "Палитра цветов" #: source/uiApp.cpp:1049 msgid "_View" msgstr "_Вид" #: source/uiApp.cpp:1055 msgid "Palette From _Image..." msgstr "_Палитра из изображения…" #: source/uiApp.cpp:1063 msgid "_Tools" msgstr "_Инструменты" #: source/uiApp.cpp:1078 msgid "_Help" msgstr "_Справка" #: source/uiApp.cpp:1386 msgid "_Copy to Clipboard" msgstr "С_копировать в буфер обмена" #: source/uiApp.cpp:1402 msgid "_Mix Colors..." msgstr "С_мешать цвета…" #: source/uiApp.cpp:1407 msgid "_Variations..." msgstr "Вариации _светлоты и насыщенности…" #: source/uiApp.cpp:1412 msgid "_Generate..." msgstr "Вариации _тонов…" #: source/uiApp.cpp:1421 msgid "C_lear names" msgstr "Ст_ереть названия" #: source/uiApp.cpp:1427 msgid "Autona_me" msgstr "_Автоматически подобрать названия" #: source/uiApp.cpp:1433 msgid "Auto_number..." msgstr "Автоматически _пронумеровать..." #: source/uiApp.cpp:1441 msgid "R_everse" msgstr "_Развернуть" #: source/uiApp.cpp:1447 msgid "Group and _sort..." msgstr "С_группировать и отсортировать..." #: source/uiApp.cpp:1455 msgid "_Remove" msgstr "_Удалить" #: source/uiApp.cpp:1461 msgid "Remove _All" msgstr "Удалить _все" #: source/uiApp.cpp:1869 msgid "Color pic_ker" msgstr "П_ипетка" #: source/uiApp.cpp:1878 msgid "Scheme _generation" msgstr "Создание _цветовой схемы" #: source/uiApp.cpp:1897 msgid "Lay_out preview" msgstr "Просмотр _макета" #: source/uiApp.cpp:1947 msgid "Pick colors (Ctrl+P)" msgstr "Снять цвет пипеткой (Ctrl+P)" #: source/uiApp.cpp:1956 msgid "File is currently in a non-native format, possible loss of precision and/or metadata." msgstr "Файл сохранён не в собственном формате Gpick, возможны потери точности или метаданных." #: source/uiColorInput.cpp:45 msgid "Edit color" msgstr "Изменить цвет" #: source/uiColorInput.cpp:69 msgid "Color:" msgstr "Цвет:" #: source/uiConverter.cpp:56 msgid "Test color" msgstr "Пробный цвет" #: source/uiConverter.cpp:74 msgid "error" msgstr "Ошибка" #: source/uiConverter.cpp:145 msgid "Function name" msgstr "Название функции" #: source/uiConverter.cpp:154 msgid "Example" msgstr "Пример" #: source/uiConverter.cpp:196 msgid "Converters" msgstr "Конвертеры" #: source/uiConverter.cpp:224 msgid "Displays:" msgstr "Показывает:" #: source/uiConverter.cpp:230 msgid "Color list:" msgstr "Список цветов:" #: source/uiDialogAutonumber.cpp:108 msgid "Autonumber colors" msgstr "Автоматически пронумеровать цвета" #: source/uiDialogAutonumber.cpp:122 msgid "Name:" msgstr "Название:" #: source/uiDialogAutonumber.cpp:132 msgid "Decimal places:" msgstr "Число разрядов:" #: source/uiDialogAutonumber.cpp:139 msgid "Starting number:" msgstr "Начать с цифры:" #: source/uiDialogAutonumber.cpp:146 msgid "_Decreasing" msgstr "По _нисходящей" #: source/uiDialogAutonumber.cpp:152 msgid "_Append" msgstr "_Добавлять поверх" #: source/uiDialogAutonumber.cpp:158 msgid "Sample:" msgstr "Образец:" #: source/uiDialogGenerate.cpp:216 msgid "Generate colors" msgstr "Вариации тонов" #: source/uiDialogGenerate.cpp:230 #: source/tools/PaletteFromImage.cpp:599 msgid "Colors:" msgstr "Цветов:" #: source/uiDialogGenerate.cpp:257 msgid "Chaos:" msgstr "Хаос:" #: source/uiDialogGenerate.cpp:263 msgid "Seed:" msgstr "Зерно:" #: source/uiDialogGenerate.cpp:271 msgid "_Reverse" msgstr "_Развернуть" #: source/uiDialogMix.cpp:76 #: source/uiDialogMix.cpp:78 msgid "mix node" msgstr "" #: source/uiDialogMix.cpp:81 msgid "mix" msgstr "" #: source/uiDialogMix.cpp:235 msgid "Mix colors" msgstr "Смешать цвета" #: source/uiDialogMix.cpp:262 #: source/uiDialogVariations.cpp:186 msgid "Steps:" msgstr "Шагов:" #: source/uiDialogMix.cpp:270 msgid "_Include Endpoints" msgstr "_Включая оконечные цвета" #: source/uiDialogOptions.cpp:117 #: source/tools/PaletteFromImage.cpp:589 msgid "Options" msgstr "Параметры" #: source/uiDialogOptions.cpp:134 msgid "System" msgstr "Системные" #: source/uiDialogOptions.cpp:143 msgid "_Single instance" msgstr "_Запускать лишь одну копию приложения" #: source/uiDialogOptions.cpp:148 msgid "Save/_Restore palette" msgstr "Сохранить/_Восстановить палитру" #: source/uiDialogOptions.cpp:154 msgid "System tray" msgstr "Область уведомления" #: source/uiDialogOptions.cpp:162 msgid "_Minimize to system tray" msgstr "С_ворачивать в область уведомления" #: source/uiDialogOptions.cpp:167 msgid "_Close to system tray" msgstr "_Закрывать в область уведомления" #: source/uiDialogOptions.cpp:172 msgid "_Start in system tray" msgstr "З_апускать в области уведомления" #: source/uiDialogOptions.cpp:178 msgid "_Main" msgstr "О_сновные" #: source/uiDialogOptions.cpp:184 msgid "Display" msgstr "Внешний вид" #: source/uiDialogOptions.cpp:193 msgid "_Refresh rate:" msgstr "_Частота обновления:" #: source/uiDialogOptions.cpp:201 msgid "_Magnified area size:" msgstr "_Размер области увеличения:" #: source/uiDialogOptions.cpp:207 msgid "Floating picker click behaviour" msgstr "Действие по щелчку пипеткой" #: source/uiDialogOptions.cpp:226 msgid "'Spacebar' button behaviour" msgstr "Действие по нажатию пробела" #: source/uiDialogOptions.cpp:244 msgid "_Rotate swatch" msgstr "По_вернуть образец" #: source/uiDialogOptions.cpp:251 msgid "Enabled color spaces" msgstr "Используемые цветовые пространства" #: source/uiDialogOptions.cpp:266 msgid "Lab settings" msgstr "Параметры Lab" #: source/uiDialogOptions.cpp:278 msgid "_Illuminant:" msgstr "Ос_ветитель:" #: source/uiDialogOptions.cpp:302 msgid "_Observer:" msgstr "_Наблюдатель:" #: source/uiDialogOptions.cpp:321 msgid "Other settings" msgstr "Прочие параметры" #: source/uiDialogOptions.cpp:330 msgid "_Mask out of gamut colors" msgstr "_Маскировать цвета вне охвата" #: source/uiDialogOptions.cpp:336 msgid "_Picker" msgstr "_Пипетка" #: source/uiDialogOptions.cpp:341 msgid "Color name generation" msgstr "Подбор названий" #: source/uiDialogOptions.cpp:350 msgid "_Imprecision postfix" msgstr "Помечать _неточное совпадение тильдой" #: source/uiDialogOptions.cpp:356 msgid "Tool color naming" msgstr "Именование снятых цветов" #: source/uiDialogOptions.cpp:381 msgid "_Color names" msgstr "_Названия цветов" #: source/uiDialogSort.cpp:135 #: source/uiDialogSort.cpp:223 msgid "RGB Red" msgstr "Красный в RGB" #: source/uiDialogSort.cpp:136 #: source/uiDialogSort.cpp:224 msgid "RGB Green" msgstr "Зелёный в RGB" #: source/uiDialogSort.cpp:137 #: source/uiDialogSort.cpp:225 msgid "RGB Blue" msgstr "Синий в RGB" #: source/uiDialogSort.cpp:138 #: source/uiDialogSort.cpp:226 msgid "RGB Grayscale" msgstr "Градации серого в RGB" #: source/uiDialogSort.cpp:139 #: source/uiDialogSort.cpp:227 msgid "HSL Hue" msgstr "Тон HSL" #: source/uiDialogSort.cpp:140 #: source/uiDialogSort.cpp:228 msgid "HSL Saturation" msgstr "Насыщенность в HSL" #: source/uiDialogSort.cpp:141 #: source/uiDialogSort.cpp:229 msgid "HSL Lightness" msgstr "Светлота в HSL" #: source/uiDialogSort.cpp:142 #: source/uiDialogSort.cpp:230 msgid "Lab Lightness" msgstr "Светлота в Lab" #: source/uiDialogSort.cpp:143 #: source/uiDialogSort.cpp:231 msgid "Lab A" msgstr "Lab A" #: source/uiDialogSort.cpp:144 #: source/uiDialogSort.cpp:232 msgid "Lab B" msgstr "Lab B" #: source/uiDialogSort.cpp:145 #: source/uiDialogSort.cpp:233 msgid "LCh Lightness" msgstr "Светлота в LCh" #: source/uiDialogSort.cpp:146 #: source/uiDialogSort.cpp:234 msgid "LCh Chroma" msgstr "Цветность в LCh" #: source/uiDialogSort.cpp:147 #: source/uiDialogSort.cpp:235 msgid "LCh Hue" msgstr "Тон в LCh" #: source/uiDialogSort.cpp:556 msgid "Group and sort" msgstr "Сгруппировать и отсортировать" #: source/uiDialogSort.cpp:564 msgid "Group type:" msgstr "Критерий группировки:" #: source/uiDialogSort.cpp:574 msgid "Grouping sensitivity:" msgstr "Чувствительность группировки:" #: source/uiDialogSort.cpp:581 msgid "Maximum number of groups:" msgstr "Предельное количество групп:" #: source/uiDialogSort.cpp:588 msgid "Sort type:" msgstr "Критерий сортировки:" #: source/uiDialogSort.cpp:598 msgid "_Reverse group order" msgstr "О_братить порядок группировки" #: source/uiDialogSort.cpp:604 msgid "_Reverse order inside groups" msgstr "Обратить порядок _внутри группы" #: source/uiDialogVariations.cpp:60 msgid "variation" msgstr "Вариации светлоты и насыщенности" #: source/uiDialogVariations.cpp:194 msgid "_Use multiplication" msgstr "_Использовать умножение" #: source/uiExport.cpp:475 msgid "Alias/WaveFront Material (*.mtl)" msgstr "Материалы Alias/WaveFront (*.mtl)" #: source/uiExport.cpp:477 msgid "Text file (*.txt)" msgstr "Текстовые файлы (*.txt)" #: source/uiExport.cpp:522 msgid "File could not be exported" msgstr "Не удалось экспортировать файл" #: source/uiExport.cpp:573 #: source/uiExport.cpp:654 #: source/uiExport.cpp:666 msgid "Import" msgstr "Импортировать" #: source/uiExport.cpp:653 msgid "File format is not supported" msgstr "Этот формат файлов не поддерживается" #: source/uiExport.cpp:665 msgid "File could not be imported" msgstr "Не удалось импортировать файл" #: source/uiListPalette.cpp:158 #: source/uiListPalette.cpp:160 #, c-format msgid "%d color" msgid_plural "%d colors" msgstr[0] "%d цвет" msgstr[1] "%d цвета" msgstr[2] "%d цветов" #: source/uiListPalette.cpp:166 msgid "selected" msgstr "выбрано" #: source/uiListPalette.cpp:172 #: source/uiListPalette.cpp:174 #, c-format msgid "Total %d color" msgid_plural "Total %d colors" msgstr[0] "Всего %d цвет" msgstr[1] "Всего %d цвета" msgstr[2] "Всего %d цветов" #: source/uiListPalette.cpp:353 msgid "Preview" msgstr "Предпросмотр" #: source/uiListPalette.cpp:708 #: source/uiListPalette.cpp:717 msgid "Color" msgstr "Цвет" #: source/uiListPalette.cpp:726 #: source/uiTransformations.cpp:183 msgid "Name" msgstr "Название" #: source/uiStatusIcon.cpp:67 msgid "_Show Main Window" msgstr "_Показать основное окно" #: source/uiStatusIcon.cpp:74 msgid "_Quit" msgstr "В_ыход" #: source/uiTransformations.cpp:245 msgid "Display filters" msgstr "Экранные фильтры" #: source/uiTransformations.cpp:259 msgid "_Enabled" msgstr "_Применять экранные фильтры" #: source/tools/PaletteFromImage.cpp:514 msgid "Palette from image" msgstr "Палитра из изображения" #: source/tools/PaletteFromImage.cpp:527 msgid "Image" msgstr "Изображение" #: source/tools/PaletteFromImage.cpp:536 msgid "Image file" msgstr "Файл изображения" #: source/tools/PaletteFromImage.cpp:556 msgid "All images" msgstr "Все изображения" #: source/transformation/ColorVisionDeficiency.cpp:41 msgid "Color vision deficiency" msgstr "Цветонеразличение" #: source/transformation/ColorVisionDeficiency.cpp:330 msgid "Protanomaly" msgstr "Протаномалия" #: source/transformation/ColorVisionDeficiency.cpp:331 msgid "Deuteranomaly" msgstr "Дейтераномалия" #: source/transformation/ColorVisionDeficiency.cpp:332 msgid "Tritanomaly" msgstr "Тританомалия" #: source/transformation/ColorVisionDeficiency.cpp:333 msgid "Protanopia" msgstr "Протанопия" #: source/transformation/ColorVisionDeficiency.cpp:334 msgid "Deuteranopia" msgstr "Дейтеранопия" #: source/transformation/ColorVisionDeficiency.cpp:335 msgid "Tritanopia" msgstr "Тританопия" #: source/transformation/ColorVisionDeficiency.cpp:422 msgid "Altered spectral sensitivity of red receptors" msgstr "Слабое восприятие красного цвета" #: source/transformation/ColorVisionDeficiency.cpp:423 msgid "Altered spectral sensitivity of green receptors" msgstr "Слабое восприятие зелёного цвета" #: source/transformation/ColorVisionDeficiency.cpp:424 msgid "Altered spectral sensitivity of blue receptors" msgstr "Слабое восприятие синего цвета" #: source/transformation/ColorVisionDeficiency.cpp:425 msgid "Absence of red receptors" msgstr "Отсутствие рецепторов красного цвета" #: source/transformation/ColorVisionDeficiency.cpp:426 msgid "Absence of green receptors" msgstr "Отсутствие рецепторов зелёного цвета" #: source/transformation/ColorVisionDeficiency.cpp:427 msgid "Absence of blue receptors" msgstr "Отсутствие рецепторов синего цвета" #: source/transformation/GammaModification.cpp:38 msgid "Gamma modification" msgstr "Гамма-коррекция" #: source/transformation/GammaModification.cpp:88 #: source/transformation/Quantization.cpp:96 msgid "Value:" msgstr "Значение:" #: source/transformation/Quantization.cpp:40 msgid "Quantization" msgstr "Квантование" #: source/transformation/Quantization.cpp:101 msgid "Clip top-end" msgstr "" #: share/gpick/init.lua:173 msgid "Web: hex code" msgstr "Web: hex-код" #: share/gpick/init.lua:178 msgid "Web: hex code (3 digits)" msgstr "Web: hex-код (3 знака)" #: share/gpick/init.lua:183 msgid "Web: hex code (no hash symbol)" msgstr "Web: hex-код (без решётки)" #: share/gpick/init.lua:188 msgid "CSS: hue saturation lightness" msgstr "CSS: тон, насыщенность, светлота" #: share/gpick/init.lua:193 msgid "CSS: red green blue" msgstr "CSS: красный, зелёный, синий" #: share/gpick/layouts.lua:15 msgid "Homepage" msgstr "Homepage" #: share/gpick/layouts.lua:15 msgid "About us" msgstr "About us" #: share/gpick/layouts.lua:15 msgid "Links to us" msgstr "Links to us" #: share/gpick/layouts.lua:15 msgid "Privacy" msgstr "Privacy" #: share/gpick/layouts.lua:15 msgid "Terms" msgstr "Terms" #: share/gpick/layouts.lua:15 msgid "Contact us" msgstr "Contact us" #: share/gpick/layouts.lua:15 msgid "RSS" msgstr "RSS" #: share/gpick/layouts.lua:30 msgid "The quick brown fox jumps over the lazy dog" msgstr "" #: share/gpick/layouts.lua:46 msgid "Webpage" msgstr "Webpage" #: share/gpick/layouts.lua:51 #: share/gpick/layouts.lua:73 msgid "Header" msgstr "Header" #: share/gpick/layouts.lua:52 msgid "Header text" msgstr "Header text" #: share/gpick/layouts.lua:54 msgid "Content" msgstr "Content" #: share/gpick/layouts.lua:55 msgid "Content text" msgstr "Content text" #: share/gpick/layouts.lua:57 msgid "Sidebar" msgstr "Sidebar" #: share/gpick/layouts.lua:59 #: share/gpick/layouts.lua:87 msgid "Button" msgstr "Button" #: share/gpick/layouts.lua:60 #: share/gpick/layouts.lua:88 msgid "Button (hover)" msgstr "Button (hover)" #: share/gpick/layouts.lua:61 #: share/gpick/layouts.lua:89 msgid "Button text" msgstr "Button text" #: share/gpick/layouts.lua:62 #: share/gpick/layouts.lua:90 msgid "Button text (hover)" msgstr "Button text (hover)" #: share/gpick/layouts.lua:64 msgid "Footer" msgstr "Footer" #: share/gpick/layouts.lua:82 #: share/gpick/layouts.lua:86 msgid "Menu" msgstr "Menu" #: share/gpick/layouts.lua:106 msgid "Brightness-Darkness" msgstr "Brightness-Darkness" #: share/gpick/layouts.lua:110 msgid "main" msgstr "основной" #: share/gpick/layouts.lua:144 msgid "Grid (4x3)" msgstr "Сетка (4x3)" #: share/gpick/layouts.lua:153 #: share/gpick/layouts.lua:159 #: share/gpick/layouts.lua:180 #: share/gpick/layouts.lua:186 msgid "Item" msgstr "Item" #: share/gpick/layouts.lua:154 #: share/gpick/layouts.lua:181 msgid "Item text" msgstr "Item text" #: share/gpick/layouts.lua:171 msgid "Grid (5x4)" msgstr "Сетка (5x4)" #~ msgid "Edit _Transformations..." #~ msgstr "_Коррекция вывода цвета…" gpick_0.2.5/share/man/man1/gpick.10000644000175000017500000000032412070605214015271 0ustar zbygzbyg.TH gpick .SH NAME gpick \- advanced color picker .SH SYNOPSIS .B gpick [\fIFILE\fR] .SH DESCRIPTION \fBgpick\fR starts an application and opens FILE if it is specified .SH AUTHOR Written by Albertas Vyšniauskasgpick_0.2.5/version.py0000644000175000017500000000003412113713537013444 0ustar zbygzbygGPICK_BUILD_VERSION='0.2.5' gpick_0.2.5/tools/__init__.py0000644000175000017500000000000012070605214014641 0ustar zbygzbyggpick_0.2.5/tools/crossmingw.py0000644000175000017500000001131112070605214015304 0ustar zbygzbyg import os import os.path import string import SCons.Action import SCons.Builder import SCons.Defaults import SCons.Tool import SCons.Util # This is what we search for to find mingw: prefixes = SCons.Util.Split(""" mingw32- i386-mingw32msvc- i486-mingw32msvc- i586-mingw32msvc- i686-mingw32msvc- i686-w64-mingw32- """) def find(env): for prefix in prefixes: # First search in the SCons path and then the OS path: if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'): return prefix return '' def shlib_generator(target, source, env, for_signature): cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS']) dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') if dll: cmd.extend(['-o', dll]) cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS']) implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX') if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature)) def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature)) return [cmd] def shlib_emitter(target, source, env): dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') no_import_lib = env.get('no_import_lib', 0) if not dll: raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX") if not no_import_lib and \ not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'): # Append an import library to the list of targets. target.append(env.ReplaceIxes(dll, 'SHLIBPREFIX', 'SHLIBSUFFIX', 'LIBPREFIX', 'LIBSUFFIX')) # Append a def file target if there isn't already a def file target # or a def file source. There is no option to disable def file # target emitting, because I can't figure out why someone would ever # want to turn it off. def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX') if not def_source and not def_target: target.append(env.ReplaceIxes(dll, 'SHLIBPREFIX', 'SHLIBSUFFIX', 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')) return (target, source) shlib_action = SCons.Action.Action(shlib_generator, generator=1) res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') res_builder = SCons.Builder.Builder(action=res_action, suffix='.o', source_scanner=SCons.Tool.SourceFileScanner) SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan) def generate(env): mingw_prefix = find(env) if mingw_prefix: dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc')) # The mingw bin directory must be added to the path: path = env['ENV'].get('PATH', []) if not path: path = [] if SCons.Util.is_String(path): path = path.split(os.pathsep) env['ENV']['PATH'] = os.pathsep.join([dir] + path) # Most of mingw is the same as gcc and friends... gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas'] for tool in gnu_tools: SCons.Tool.Tool(tool)(env) #... but a few things differ: env['CC'] = mingw_prefix + 'gcc' env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') env['CXX'] = mingw_prefix + 'g++' env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared') env['SHLINKCOM'] = shlib_action env.Append(SHLIBEMITTER = [shlib_emitter]) # This line isn't required and breaks C++ linking #env['LINK'] = mingw_prefix + 'g++' env['AS'] = mingw_prefix + 'as' env['AR'] = mingw_prefix + 'ar' env['RANLIB'] = mingw_prefix + 'ranlib' env['WIN32DEFPREFIX'] = '' env['WIN32DEFSUFFIX'] = '.def' env['SHOBJSUFFIX'] = '.o' env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 env['RC'] = mingw_prefix + 'windres' env['RCFLAGS'] = SCons.Util.CLVar('') env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET)} $)' env['RCINCPREFIX'] = '--include-dir ' env['RCINCSUFFIX'] = '' env['RCCOM'] = '$RC $RCINCFLAGS $RCINCPREFIX $SOURCE.dir $RCFLAGS -i $SOURCE -o $TARGET' env['BUILDERS']['RES'] = res_builder # Some setting from the platform also have to be overridden: env['OBJPREFIX'] = '' env['OBJSUFFIX'] = '.o' env['LIBPREFIX'] = 'lib' env['LIBSUFFIX'] = '.a' env['SHOBJPREFIX'] = '$OBJPREFIX' env['SHOBJSUFFIX'] = '$OBJSUFFIX' env['PROGPREFIX'] = '' env['PROGSUFFIX'] = '.exe' env['LIBPREFIX'] = '' env['LIBSUFFIX'] = '.lib' env['SHLIBPREFIX'] = '' env['SHLIBSUFFIX'] = '.dll' env['LIBPREFIXES'] = [ '$LIBPREFIX' ] env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ] def exists(env): return find(env) gpick_0.2.5/tools/lemon.py0000644000175000017500000000166312070605214014234 0ustar zbygzbygfrom SCons.Script import * from SCons.Tool.install import copyFunc def addLemonBuilder(env): LemonAction = SCons.Action.Action("$LEMONCOM", "$LEMONCOMSTR") env["LEMON"] = env.Detect("lemon") env["LEMONCOM"] = "cd build/; $LEMON $SOURCE" def headerEmitter(target, source, env): bs = SCons.Util.splitext(str(source[0].name))[0] target.append(bs + '.h') bs = SCons.Util.splitext(str(target[0]))[0] + ".y" source.append(bs) return (target, source) def buildAction(target, source, env): source_dest = SCons.Util.splitext(str(target[0]))[0] + ".y" Execute(Copy('build/lempar.c', 'extern/lempar.c')) Execute(Copy(source_dest, File(source[0]).srcnode())) LemonAction.execute([target], ['../' + source_dest], env); Execute(Delete(source_dest)) return 0 builder = Builder( action = buildAction, suffix = '.c', src_suffix = '.y', emitter = headerEmitter) env.Append(BUILDERS = {'Lemon': builder}) gpick_0.2.5/tools/gpick.py0000644000175000017500000001140512072045012014206 0ustar zbygzbyg#!/usr/bin/env python import os import time import SCons import re import string import sys import glob import subprocess from lemon import * from flex import * from gettext import * from resource_template import * from SCons.Script import * from SCons.Util import * from SCons.Script.SConscript import SConsEnvironment import SCons.Script.SConscript import SCons.SConf import SCons.Conftest def MatchFiles (files, path, repath, dir_exclude_pattern, file_exclude_pattern): for filename in os.listdir(path): fullname = os.path.join (path, filename) repath_file = os.path.join (repath, filename); if os.path.isdir (fullname): if not dir_exclude_pattern.search(repath_file): MatchFiles (files, fullname, repath_file, dir_exclude_pattern, file_exclude_pattern) else: if not file_exclude_pattern.search(filename): files.append (fullname) def CheckPKG(context, name): context.Message('Checking for library %s... ' % name) ret = context.TryAction('pkg-config --exists "%s"' % name)[0] context.Result(ret) return ret def CheckProgram(context, env, name, member_name): context.Message('Checking for program %s... ' % name) if env[member_name]: context.Result(True) return True else: context.Result(False) return False class GpickLibrary(NodeList): include_dirs = [] class GpickEnvironment(SConsEnvironment): extern_libs = {} def AddCustomBuilders(self): addLemonBuilder(self) addFlexBuilder(self) addGettextBuilder(self) addResourceTemplateBuilder(self) def DefineLibrary(self, library_name, library): self.extern_libs[library_name] = library def UseLibrary(self, library_name): lib = self.extern_libs[library_name] for i in lib: lib_include_path = os.path.split(i.path)[0] self.PrependUnique(LIBS = [library_name], LIBPATH = ['#' + lib_include_path]) self.PrependUnique(CPPPATH = lib.include_dirs) return lib def ConfirmPrograms(self, conf, programs): conf.AddTests({'CheckProgram': CheckProgram}) for evar, args in programs.iteritems(): found = False for name, member_name in args['checks'].iteritems(): if conf.CheckProgram(self, name, member_name): found = True; break if not found: if 'required' in args: if not args['required']==False: self.Exit(1) else: self.Exit(1) def ConfirmLibs(self, conf, libs): conf.AddTests({'CheckPKG': CheckPKG}) for evar, args in libs.iteritems(): found = False for name, version in args['checks'].iteritems(): if conf.CheckPKG(name + ' ' + version): self[evar]=name found = True; break if not found: if 'required' in args: if not args['required']==False: self.Exit(1) else: self.Exit(1) def InstallPerm(self, dir, source, perm): obj = self.Install(dir, source) for i in obj: self.AddPostAction(i, Chmod(i, perm)) return dir def InstallPermAutoDir(self, dir, relative_dir, source, perm): for f in Flatten(source): path = dir if str(f.get_dir()).startswith(relative_dir): path = os.path.join(path, str(f.get_dir())[len(relative_dir):]) else: path = os.path.join(path, str(f.get_dir())) obj = self.Install(path, f) for i in obj: self.AddPostAction(i, Chmod(i, perm)) return dir InstallProgram = lambda self, dir, source: GpickEnvironment.InstallPerm(self, dir, source, 0755) InstallData = lambda self, dir, source: GpickEnvironment.InstallPerm(self, dir, source, 0644) InstallDataAutoDir = lambda self, dir, relative_dir, source: GpickEnvironment.InstallPermAutoDir(self, dir, relative_dir, source, 0644) def GetSourceFiles(self, dir_exclude_pattern, file_exclude_pattern): dir_exclude_prog = re.compile(dir_exclude_pattern) file_exclude_prog = re.compile(file_exclude_pattern) files = [] MatchFiles(files, self.GetLaunchDir(), os.sep, dir_exclude_prog, file_exclude_prog) return files def GetVersionInfo(self): try: revision = subprocess.Popen(['hg', 'log', '--template', '"{rev}:{node}\\n"', '-r', 'tip', self.GetLaunchDir()], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] match = re.search('([\d]+):([\d\w]+)', str(revision)) revision = match.group(2) except: revision = 'not under version control system' self.Replace(GPICK_BUILD_REVISION = revision, GPICK_BUILD_DATE = time.strftime ("%Y-%m-%d"), GPICK_BUILD_TIME = time.strftime ("%H:%M:%S")); def RegexEscape(str): return str.replace('\\', '\\\\') def WriteNsisVersion(target, source, env): for t in target: for s in source: file = open(str(t),"w") file.writelines('!define VERSION "' + str(env['GPICK_BUILD_VERSION']) + '"') file.close() return 0 def Glob(path): files = [] for f in glob.glob(os.path.join(path, '*')): if os.path.isdir(str(f)): files.extend(Glob(str(f))); else: files.append(str(f)); return files gpick_0.2.5/tools/flex.py0000644000175000017500000000102612070605214014051 0ustar zbygzbygfrom SCons.Script import * def addFlexBuilder(env): FlexAction = SCons.Action.Action("$FLEXCOM", "$FLEXCOMSTR") env["FLEX"] = env.Detect("flex") env["FLEXCOM"] = "flex --header-file=${TARGET.base}.h -o $TARGET $SOURCE" def headerEmitter(target, source, env): bs = SCons.Util.splitext(str(source[0].name))[0] target.append(bs + '.h') return (target, source) builder = Builder(action = FlexAction, suffix = '.cpp', src_suffix = '.l', emitter = headerEmitter) env.Append(BUILDERS = {'Flex': builder}) gpick_0.2.5/tools/gettext.py0000644000175000017500000000277612113713537014622 0ustar zbygzbygfrom SCons.Script import * def addGettextBuilder(env): GettextAction = SCons.Action.Action("$GETTEXTCOM", "$GETTEXTCOMSTR") env["GETTEXT"] = env.Detect("msgfmt") env["GETTEXTCOM"] = "$GETTEXT --check-format --check-domain -f -o $TARGET $SOURCE" builder = Builder( action = GettextAction, suffix = '.mo', src_suffix = '.po', single_source = True) env.Append(BUILDERS = {'Gettext': builder}) XgettextAction = SCons.Action.Action("$XGETTEXTCOM", "$XGETTEXTCOMSTR") env["XGETTEXT"] = env.Detect("xgettext") env["XGETTEXTCOM"] = "$XGETTEXT --keyword=_ --from-code utf8 --package-name=gpick $XGETTEXT_FLAGS --output=$TARGET $SOURCES" builder = Builder( action = XgettextAction, suffix = '.pot', src_suffix = '.cpp', single_source = False) env.Append(BUILDERS = {'Xgettext': builder}) MsgmergeAction = SCons.Action.Action("$MSGMERGECOM", "$MSGMERGECOMSTR") env["MSGMERGE"] = env.Detect("msgmerge") env["MSGMERGECOM"] = "$MSGMERGE $MSGMERGE_FLAGS --output-file=$TARGET $SOURCES" builder = Builder( action = MsgmergeAction, suffix = '.pot', src_suffix = '.pot', single_source = False) env.Append(BUILDERS = {'Msgmerge': builder}) MsgcatAction = SCons.Action.Action("$MSGCATCOM", "$MSGCATCOMSTR") env["MSGCAT"] = env.Detect("msgcat") env["MSGCATCOM"] = "$MSGCAT $MSGCAT_FLAGS --output-file=$TARGET $SOURCES" builder = Builder( action = MsgcatAction, suffix = '.pot', src_suffix = '.pot', single_source = False) env.Append(BUILDERS = {'Msgcat': builder}) gpick_0.2.5/tools/resource_template.py0000644000175000017500000000142512113713537016646 0ustar zbygzbygfrom SCons.Script import * from SCons.Tool.install import copyFunc import re def addResourceTemplateBuilder(env): def buildResourceFile(target, source, env): source_dest = SCons.Util.splitext(str(target[0]))[0] + ".rc" wfile = open(source_dest,"w") data = open(str(File(source[0]).srcnode())).read() for key, var in env['RESOURCE_TEMPLATE_VARS'].iteritems(): data = re.sub("%" + key + "%", var, data) wfile.write(data) wfile.close() return 0 def buildResourceFileString(target, source, env): return "Preparing resource file %s" % os.path.basename(str(target[0])) builder = Builder( action = SCons.Action.Action(buildResourceFile, buildResourceFileString), suffix = '.rc', src_suffix = '.rct', ) env.Append(BUILDERS = {'ResourceTemplate': builder}) gpick_0.2.5/installer/script.nsi0000644000175000017500000003110312113713537015422 0ustar zbygzbyg !include "MUI2.nsh" !include "FileFunc.nsh" ; GetOptions !include ..\build\version.nsi !define PRODUCT_VERSION "${VERSION}" !define PRODUCT_NAME "Gpick" !define PRODUCT_NAME_SMALL "gpick" !define PRODUCT_PUBLISHER "Albertas Vyniauskas" !define PRODUCT_WEB_SITE "http://code.google.com/p/gpick/" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_UNINST_ROOT_KEY "HKLM" !define REGISTRY_APP_PATHS "Software\Microsoft\Windows\CurrentVersion\App Paths" Name "Gpick" OutFile "Gpick_${VERSION}_win32-setup.exe" Caption "Gpick v${VERSION} Setup" SetCompressor /SOLID lzma SetCompressorDictSize 32 InstallDir $PROGRAMFILES\Gpick InstallDirRegKey HKLM "Software\Gpick" "" RequestExecutionLevel admin ; gtk installer name for embedding !define GTK_INSTALLER_EXE "gtk2-runtime-2.24.10-2012-10-10-ash.exe" Var MUI_TEMP Var STARTMENU_FOLDER var install_option_removeold ; uninstall the old version first (if present): yes (default), no. var gtk_mode ; "public", "private" or "none" var gtk_tmp ; temporary variable !define MUI_WELCOMEPAGE !define MUI_LICENSEPAGE !define MUI_DIRECTORYPAGE !define MUI_ABORTWARNING !define MUI_UNINSTALLER !define MUI_UNCONFIRMPAGE !define MUI_FINISHPAGE !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "License.txt" !define MUI_PAGE_CUSTOMFUNCTION_LEAVE on_components_page_leave !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER !insertmacro MUI_PAGE_INSTFILES !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_FINISHPAGE_NOREBOOTSUPPORT !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_LANGUAGE "English" AllowSkipFiles off var gtk_dll_abs_path Section "!Program Files" SecProgramFiles SectionIn RO SetOutPath "$INSTDIR" File ..\build\source\gpick.exe File lua5.2.dll SetOutPath "$INSTDIR\share\gpick" File ..\share\gpick\colors0.txt File ..\share\gpick\colors.txt File ..\share\gpick\gpick-falloff-none.png File ..\share\gpick\gpick-falloff-linear.png File ..\share\gpick\gpick-falloff-quadratic.png File ..\share\gpick\gpick-falloff-cubic.png File ..\share\gpick\gpick-falloff-exponential.png File ..\share\icons\hicolor\48x48\apps\gpick.png File ..\share\gpick\init.lua File ..\share\gpick\helpers.lua File ..\share\gpick\layouts.lua SetOutPath "$INSTDIR" WriteRegStr HKLM "Software\Gpick" "" $INSTDIR SetShellVarContext all ; use all user variables as opposed to current user ; Don't set any paths for this exe if it has a private GTK+ installation. !ifndef NO_GTK StrCmp $gtk_mode "private" skip_exe_PATH !endif ; set a special path for this exe, as GTK may not be in a global path. ReadRegStr $gtk_dll_abs_path HKLM "SOFTWARE\GTK\2.0" "DllPath" WriteRegStr HKLM "${REGISTRY_APP_PATHS}\gpick.exe" "Path" "$gtk_dll_abs_path" !ifndef NO_GTK skip_exe_PATH: !endif !ifndef NO_GTK WriteRegStr HKLM "SOFTWARE\${PRODUCT_NAME}" "GtkInstalledMode" "$gtk_mode" !endif WriteRegStr HKLM "SOFTWARE\${PRODUCT_NAME}" "InstallationDirectory" "$INSTDIR" WriteRegStr HKLM "SOFTWARE\${PRODUCT_NAME}" "Vendor" "${PRODUCT_PUBLISHER}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\Uninstall.exe" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\gpick.ico" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoModify" 1 WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoRepair" 1 WriteUninstaller "$INSTDIR\Uninstall.exe" SectionEnd Section "GTK+ (for this program only)" SecGtkPrivate SectionIn 1 SetShellVarContext all ; use all user variables as opposed to current user AddSize 12200 ; ~ size of unpacked gtk SetOutPath "$INSTDIR" File "${GTK_INSTALLER_EXE}" ; TODO: in the future, when we have translations for this program, ; make the GTK+ translations installation dependent on their installation status. ExecWait '"${GTK_INSTALLER_EXE}" /sideeffects=no /dllpath=root /translations=no /compatdlls=no /S /D=$INSTDIR' Delete "$INSTDIR\${GTK_INSTALLER_EXE}" SectionEnd ; disabled by default Section /o "GTK+ (shared installation)" SecGtkPublic SectionIn 1 SetShellVarContext all ; use all user variables as opposed to current user AddSize 12200 ; ~ size of unpacked gtk SetOutPath "$INSTDIR" File "${GTK_INSTALLER_EXE}" ExecWait '"${GTK_INSTALLER_EXE}"' Delete "$INSTDIR\${GTK_INSTALLER_EXE}" SectionEnd ; Executed on installation start Function .onInit SetShellVarContext all ; use all user variables as opposed to current user ${GetOptions} "$CMDLINE" "/removeold=" $install_option_removeold Call PreventMultipleInstances Call DetectPrevInstallation StrCpy $gtk_mode "private" ; default FunctionEnd function .onselchange !ifndef NO_GTK ; Remember which gtk section was selected. ; Deselect the other section. ; If it was private, we check if public is checked and uncheck private. StrCmp $gtk_mode "private" check_public ; old selection StrCmp $gtk_mode "public" check_private ; old selection goto check_exit check_public: SectionGetFlags ${SecGtkPublic} $gtk_tmp ; see if it's checked IntOp $gtk_tmp $gtk_tmp & ${SF_SELECTED} IntCmp $gtk_tmp ${SF_SELECTED} "" check_exit check_exit SectionGetFlags ${SecGtkPrivate} $gtk_tmp ; unselect the other one IntOp $gtk_tmp $gtk_tmp & ${SECTION_OFF} SectionSetFlags ${SecGtkPrivate} $gtk_tmp goto check_exit check_private: SectionGetFlags ${SecGtkPrivate} $gtk_tmp ; see if it's checked IntOp $gtk_tmp $gtk_tmp & ${SF_SELECTED} IntCmp $gtk_tmp ${SF_SELECTED} "" check_exit check_exit SectionGetFlags ${SecGtkPublic} $gtk_tmp ; unselect the other one IntOp $gtk_tmp $gtk_tmp & ${SECTION_OFF} SectionSetFlags ${SecGtkPublic} $gtk_tmp check_exit: ; store the current mode StrCpy $gtk_mode "none" SectionGetFlags ${SecGtkPrivate} $gtk_tmp IntOp $gtk_tmp $gtk_tmp & ${SF_SELECTED} IntCmp $gtk_tmp ${SF_SELECTED} "" mode_end_private mode_end_private StrCpy $gtk_mode "private" mode_end_private: SectionGetFlags ${SecGtkPublic} $gtk_tmp IntOp $gtk_tmp $gtk_tmp & ${SF_SELECTED} IntCmp $gtk_tmp ${SF_SELECTED} "" mode_end_public mode_end_public StrCpy $gtk_mode "public" mode_end_public: ; MessageBox MB_ICONINFORMATION|MB_OK "gtk_mode: $gtk_mode" /SD IDOK !endif ; !NO_GTK functionend Function on_components_page_leave StrCmp $gtk_mode "none" "" noabort Call AskForGtk noabort: FunctionEnd ; Section descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SecProgramFiles} "Gpick - Advanced color picker" !insertmacro MUI_DESCRIPTION_TEXT ${SecGtkPrivate} "GTK+ libraries, needed by Gpick. \ This will install a private version of GTK+, usable only by Gpick." !insertmacro MUI_DESCRIPTION_TEXT ${SecGtkPublic} "GTK+ libraries, needed by Gpick. \ This will install a system-wide version of GTK+, shareable with other programs." !insertmacro MUI_FUNCTION_DESCRIPTION_END Section "Desktop Shortcut" SecDesktopShortcut SetOutPath "$INSTDIR" CreateShortCut "$DESKTOP\Gpick.lnk" "$INSTDIR\Gpick.exe" "" SectionEnd Section "-Start Menu Shortcut" SecStartMenu SetOutPath "$INSTDIR" !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER" CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Gpick.lnk" "$INSTDIR\Gpick.exe" CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd ; ------------------ POST INSTALL ;Uninstaller Section Section "Uninstall" SetShellVarContext all ; use all user variables as opposed to current user SetAutoClose false ReadRegStr $gtk_mode HKLM "SOFTWARE\${PRODUCT_NAME}" "GtkInstalledMode" StrCmp $gtk_mode "private" "" skip_gtk_remove ; remove private GTK+, specify the same custom options are during installation ExecWait "$INSTDIR\gtk2_runtime_uninst.exe /remove_config=yes /sideeffects=no /dllpath=root /translations=no /compatdlls=no /S" ; _?=$INSTDIR ; Delete "$INSTDIR\gtk2_runtime_uninst.exe" ; If using _? flag, it won't get deleted automatically, do it manually. skip_gtk_remove: DeleteRegKey HKLM "SOFTWARE\${PRODUCT_NAME}" DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}" StrCmp $gtk_mode "private" skip_exe_PATH_remove DeleteRegKey HKLM "${REGISTRY_APP_PATHS}\gpick.exe" skip_exe_PATH_remove: Delete "$INSTDIR\Uninstall.exe" Delete "$INSTDIR\gpick.exe" Delete "$INSTDIR\lua5.2.dll" Delete "$INSTDIR\share\gpick\colors0.txt" Delete "$INSTDIR\share\gpick\colors.txt" Delete "$INSTDIR\share\gpick\gpick-falloff-none.png" Delete "$INSTDIR\share\gpick\gpick-falloff-linear.png" Delete "$INSTDIR\share\gpick\gpick-falloff-quadratic.png" Delete "$INSTDIR\share\gpick\gpick-falloff-cubic.png" Delete "$INSTDIR\share\gpick\gpick-falloff-exponential.png" Delete "$INSTDIR\share\gpick\gpick.png" Delete "$INSTDIR\share\gpick\init.lua" Delete "$INSTDIR\share\gpick\helpers.lua" Delete "$INSTDIR\share\gpick\layouts.lua" RMDir "$INSTDIR\share\gpick" RMDir "$INSTDIR\share\locale" RMDir "$INSTDIR\share" RMDir "$INSTDIR" !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP Delete "$SMPROGRAMS\$MUI_TEMP\Gpick.lnk" Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk" Delete "$DESKTOP\Gpick.lnk" ;Delete empty start menu parent diretories StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP" startMenuDeleteLoop: ClearErrors RMDir $MUI_TEMP GetFullPathName $MUI_TEMP "$MUI_TEMP\.." IfErrors startMenuDeleteLoopDone StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop startMenuDeleteLoopDone: DeleteRegKey /ifempty HKLM "Software\Gpick" SectionEnd ; Detect previous installation Function DetectPrevInstallation ; if /removeold=no option is given, don't check anything. StrCmp $install_option_removeold "no" old_detect_done SetShellVarContext all ; use all user variables as opposed to current user push $R0 ; detect previous installation ReadRegStr $R0 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" StrCmp $R0 "" old_detect_done MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ "${PRODUCT_NAME} is already installed. $\n$\nClick `OK` to remove the \ previous version or `Cancel` to continue anyway." \ /SD IDOK IDOK old_uninst ; Abort goto old_detect_done ; Run the old uninstaller old_uninst: ClearErrors IfSilent old_silent_uninst old_nosilent_uninst old_nosilent_uninst: ExecWait '$R0' goto old_uninst_continue old_silent_uninst: ExecWait '$R0 /S _?=$INSTDIR' old_uninst_continue: IfErrors old_no_remove_uninstaller ; You can either use Delete /REBOOTOK in the uninstaller or add some code ; here to remove to remove the uninstaller. Use a registry key to check ; whether the user has chosen to uninstall. If you are using an uninstaller ; components page, make sure all sections are uninstalled. old_no_remove_uninstaller: old_detect_done: ; old installation not found, all ok pop $R0 FunctionEnd ; detect GTK installation (any of available versions) Function AskForGtk SetShellVarContext all ; use all user variables as opposed to current user push $R0 ReadRegStr $R0 HKLM "SOFTWARE\GTK\2.0" "DllPath" StrCmp $R0 "" no_gtk have_gtk no_gtk: MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ "GTK2-Runtime is not installed. This product needs it to function properly.$\n\ Please install GTK2-Runtime from http://gtk-win.sf.net/ first.$\n$\n\ Click 'Cancel' to abort the installation \ or 'OK' to continue anyway." \ /SD IDOK IDOK have_gtk ;Abort ; Abort has different meaning from onpage callbacks, so use Quit Quit goto end_gtk_check have_gtk: ; do nothing end_gtk_check: pop $R0 FunctionEnd ; Prevent running multiple instances of the installer Function PreventMultipleInstances Push $R0 System::Call 'kernel32::CreateMutexA(i 0, i 0, t ${PRODUCT_NAME}) ?e' Pop $R0 StrCmp $R0 0 +3 MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running." /SD IDOK Abort Pop $R0 FunctionEnd gpick_0.2.5/installer/gpick.wxs0000644000175000017500000002246612113713537015257 0ustar zbygzbyg Privileged 1 NOT Installed Installed AND PATCH Installed NOT Installed 1 NOT Installed OR WixUI_InstallMode = "Change" Installed AND NOT PATCH Installed AND PATCH 1 1 1 1 1 gpick_0.2.5/installer/gpick_files.xstl0000644000175000017500000000132412113713537016600 0ustar zbygzbyg gpick_0.2.5/installer/License.txt0000644000175000017500000000277012113713537015536 0ustar zbygzbygCopyright (c) 2009-2013, Albertas Vyniauskas and Gpick developers 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. gpick_0.2.5/installer/getversion.py0000644000175000017500000000056312113713537016150 0ustar zbygzbygimport os,sys,re parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0,parentdir) import version def getversion(style): if style == "full": print version.GPICK_BUILD_VERSION else: result = re.match(r"^(\d+\.\d+\.\d+)(.*)$", version.GPICK_BUILD_VERSION) if result: print result.group(1) else: print "invalid_version" gpick_0.2.5/installer/Makefile0000644000175000017500000000206612113713537015051 0ustar zbygzbyg VERSION_FULL=$(shell python -c 'import getversion; getversion.getversion("full")') VERSION=$(shell python -c 'import getversion; getversion.getversion("ms")') MSI=gpick_$(VERSION_FULL) HEAT_SRCS=gpick_files.xstl gtk_files.xstl SRCS=gpick.wxs $(HEAT_SRCS:.xstl=.wxs) OBJS=$(SRCS:.wxs=.wixobj) CANDLE=candle.exe LIGHT=light.exe HEAT=heat.exe HEAT_FLAGS=-ag -dr INSTALLDIR -suid -srd -var var.FilePath FLAGS=-dFilePath=files -dVersionFull=$(VERSION_FULL) -dVersion=$(VERSION) LIGHT_FLAGS=-ext WixUtilExtension -ext WixUIExtension $(FLAGS) CANDLE_FLAGS=$(FLAGS) DEPFILES= files/Gpick.exe .SUFFIXES: .wxs .wixobj .xstl all: $(MSI).msi $(MSI).msi: $(OBJS) $(DEPFILES) $(HEAT_SRCS) $(LIGHT) -nologo $(LIGHT_FLAGS) -out $@ $(OBJS) .xstl.wxs: $(HEAT) dir "files" -nologo $(HEAT_FLAGS) -cg C.Files.$(<:.xstl=) -t $< -out $@ .wxs.wixobj: $(CANDLE) -nologo $(CANDLE_FLAGS) -out $@ $^ clean: $(RM) $(MSI).msi $(OBJS) install: $(MSI).msi $(RM) install.log msiexec -i $(MSI).msi -l*v install.log uninstall: msiexec -x $(MSI).msi gpick_0.2.5/installer/gtk_files.xstl0000644000175000017500000000136612113713537016276 0ustar zbygzbyg gpick_0.2.5/extern/SConscript0000644000175000017500000000010312070605213014712 0ustar zbygzbyg#!/usr/bin/env python Import('*') objects = [] Return('objects') gpick_0.2.5/extern/lempar.c0000644000175000017500000006617512070605213014351 0ustar zbygzbyg/* Driver template for the LEMON parser generator. ** The author disclaims copyright to this source code. */ /* First off, code is included that follows the "include" declaration ** in the input grammar file. */ #include %% /* Next is all token values, in a form suitable for use by makeheaders. ** This section will be null unless lemon is run with the -m switch. */ /* ** These constants (all generated automatically by the parser generator) ** specify the various kinds of tokens (terminals) that the parser ** understands. ** ** Each symbol here is a terminal symbol in the grammar. */ %% /* Make sure the INTERFACE macro is defined. */ #ifndef INTERFACE # define INTERFACE 1 #endif /* The next thing included is series of defines which control ** various aspects of the generated parser. ** YYCODETYPE is the data type used for storing terminal ** and nonterminal numbers. "unsigned char" is ** used if there are fewer than 250 terminals ** and nonterminals. "int" is used otherwise. ** YYNOCODE is a number of type YYCODETYPE which corresponds ** to no legal terminal or nonterminal number. This ** number is used to fill in empty slots of the hash ** table. ** YYFALLBACK If defined, this indicates that one or more tokens ** have fall-back values which should be used if the ** original value of the token will not parse. ** YYACTIONTYPE is the data type used for storing terminal ** and nonterminal numbers. "unsigned char" is ** used if there are fewer than 250 rules and ** states combined. "int" is used otherwise. ** ParseTOKENTYPE is the data type used for minor tokens given ** directly to the parser from the tokenizer. ** YYMINORTYPE is the data type used for all minor tokens. ** This is typically a union of many types, one of ** which is ParseTOKENTYPE. The entry in the union ** for base tokens is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. */ %% #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) /* The yyzerominor constant is used to initialize instances of ** YYMINORTYPE objects to zero. */ static const YYMINORTYPE yyzerominor = { 0 }; /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. ** ** Applications can choose to define yytestcase() in the %include section ** to a macro that can assist in verifying code coverage. For production ** code the yytestcase() macro should be turned off. But it is useful ** for testing. */ #ifndef yytestcase # define yytestcase(X) #endif /* Next are the tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement ** functions that take a state number and lookahead value and return an ** action integer. ** ** Suppose the action integer is N. Then the action is determined as ** follows ** ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead ** token onto the stack and goto state N. ** ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. ** ** N == YYNSTATE+YYNRULE A syntax error has occurred. ** ** N == YYNSTATE+YYNRULE+1 The parser accepts its input. ** ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused ** slots in the yy_action[] table. ** ** The action table is constructed as a single large table named yy_action[]. ** Given state S and lookahead X, the action is computed as ** ** yy_action[ yy_shift_ofst[S] + X ] ** ** If the index value yy_shift_ofst[S]+X is out of range or if the value ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table ** and that yy_default[S] should be used instead. ** ** The formula above is for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of ** YY_SHIFT_USE_DFLT. ** ** The following are the tables generated in this section: ** ** yy_action[] A single table containing all actions. ** yy_lookahead[] A table containing the lookahead for each entry in ** yy_action. Used to detect hash collisions. ** yy_shift_ofst[] For each state, the offset into yy_action for ** shifting terminals. ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. */ %% /* The next table maps tokens into fallback tokens. If a construct ** like the following: ** ** %fallback ID X Y Z. ** ** appears in the grammar, then ID becomes a fallback token for X, Y, ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. */ #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { %% }; #endif /* YYFALLBACK */ /* The following structure represents a single element of the ** parser's stack. Information stored includes: ** ** + The state number for the parser at this level of the stack. ** ** + The value of the token stored at this level of the stack. ** (In other words, the "major" token.) ** ** + The semantic value stored at this level of the stack. This is ** the information used by the action routines in the grammar. ** It is sometimes called the "minor" token. */ struct yyStackEntry { YYACTIONTYPE stateno; /* The state-number */ YYCODETYPE major; /* The major token value. This is the code ** number for the token at this stack level */ YYMINORTYPE minor; /* The user-supplied minor token value. This ** is the value of the token */ }; typedef struct yyStackEntry yyStackEntry; /* The state of the parser is completely contained in an instance of ** the following structure */ struct yyParser { int yyidx; /* Index of top element in stack */ #ifdef YYTRACKMAXSTACKDEPTH int yyidxMax; /* Maximum value of yyidx */ #endif int yyerrcnt; /* Shifts left before out of the error */ ParseARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ #else yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ #endif }; typedef struct yyParser yyParser; #ifndef NDEBUG #include static FILE *yyTraceFILE = 0; static char *yyTracePrompt = 0; #endif /* NDEBUG */ #ifndef NDEBUG /* ** Turn parser tracing on by giving a stream to which to write the trace ** and a prompt to preface each trace message. Tracing is turned off ** by making either argument NULL ** ** Inputs: **
      **
    • A FILE* to which trace output should be written. ** If NULL, then tracing is turned off. **
    • A prefix string written at the beginning of every ** line of trace output. If NULL, then tracing is ** turned off. **
    ** ** Outputs: ** None. */ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ yyTraceFILE = TraceFILE; yyTracePrompt = zTracePrompt; if( yyTraceFILE==0 ) yyTracePrompt = 0; else if( yyTracePrompt==0 ) yyTraceFILE = 0; } #endif /* NDEBUG */ #ifndef NDEBUG /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { %% }; #endif /* NDEBUG */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. */ static const char *const yyRuleName[] = { %% }; #endif /* NDEBUG */ #if YYSTACKDEPTH<=0 /* ** Try to increase the size of the parser stack. */ static void yyGrowStack(yyParser *p){ int newSize; yyStackEntry *pNew; newSize = p->yystksz*2 + 100; pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); if( pNew ){ p->yystack = pNew; p->yystksz = newSize; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", yyTracePrompt, p->yystksz); } #endif } } #endif /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like ** malloc. ** ** Inputs: ** A pointer to the function used to allocate memory. ** ** Outputs: ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ void *ParseAlloc(void *(*mallocProc)(size_t)){ yyParser *pParser; pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); if( pParser ){ pParser->yyidx = -1; #ifdef YYTRACKMAXSTACKDEPTH pParser->yyidxMax = 0; #endif #if YYSTACKDEPTH<=0 pParser->yystack = NULL; pParser->yystksz = 0; yyGrowStack(pParser); #endif } return pParser; } /* The following function deletes the value associated with a ** symbol. The symbol can be either a terminal or nonterminal. ** "yymajor" is the symbol code, and "yypminor" is a pointer to ** the value. */ static void yy_destructor( yyParser *yypParser, /* The parser */ YYCODETYPE yymajor, /* Type code for object to destroy */ YYMINORTYPE *yypminor /* The object to be destroyed */ ){ ParseARG_FETCH; switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen ** when the symbol is popped from the stack during a ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ %% default: break; /* If no destructor action specified: do nothing */ } } /* ** Pop the parser's stack once. ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. ** ** Return the major token number for the symbol popped. */ static int yy_pop_parser_stack(yyParser *pParser){ YYCODETYPE yymajor; yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; if( pParser->yyidx<0 ) return 0; #ifndef NDEBUG if( yyTraceFILE && pParser->yyidx>=0 ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif yymajor = yytos->major; yy_destructor(pParser, yymajor, &yytos->minor); pParser->yyidx--; return yymajor; } /* ** Deallocate and destroy a parser. Destructors are all called for ** all stack elements before shutting the parser down. ** ** Inputs: **
      **
    • A pointer to the parser. This should be a pointer ** obtained from ParseAlloc. **
    • A pointer to a function used to reclaim memory obtained ** from malloc. **
    */ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ yyParser *pParser = (yyParser*)p; if( pParser==0 ) return; while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 free(pParser->yystack); #endif (*freeProc)((void*)pParser); } /* ** Return the peak depth of the stack for a parser. */ #ifdef YYTRACKMAXSTACKDEPTH int ParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; return pParser->yyidxMax; } #endif /* ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. ** ** If the look-ahead token is YYNOCODE, then check to see if the action is ** independent of the look-ahead. If it is, return the action, otherwise ** return YY_NO_ACTION. */ static int yy_find_shift_action( yyParser *pParser, /* The parser */ YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; int stateno = pParser->yystack[pParser->yyidx].stateno; if( stateno>YY_SHIFT_COUNT || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ return yy_default[stateno]; } assert( iLookAhead!=YYNOCODE ); i += iLookAhead; if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ if( iLookAhead>0 ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ if( iLookAhead %s\n", yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); } #endif return yy_find_shift_action(pParser, iFallback); } #endif #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; if( #if YY_SHIFT_MIN+YYWILDCARD<0 j>=0 && #endif #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT j %s\n", yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); } #endif /* NDEBUG */ return yy_action[j]; } } #endif /* YYWILDCARD */ } return yy_default[stateno]; }else{ return yy_action[i]; } } /* ** Find the appropriate action for a parser given the non-terminal ** look-ahead token iLookAhead. ** ** If the look-ahead token is YYNOCODE, then check to see if the action is ** independent of the look-ahead. If it is, return the action, otherwise ** return YY_NO_ACTION. */ static int yy_find_reduce_action( int stateno, /* Current state number */ YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; #ifdef YYERRORSYMBOL if( stateno>YY_REDUCE_COUNT ){ return yy_default[stateno]; } #else assert( stateno<=YY_REDUCE_COUNT ); #endif i = yy_reduce_ofst[stateno]; assert( i!=YY_REDUCE_USE_DFLT ); assert( iLookAhead!=YYNOCODE ); i += iLookAhead; #ifdef YYERRORSYMBOL if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ return yy_default[stateno]; } #else assert( i>=0 && iyyidx--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); } #endif while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ %% ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ } /* ** Perform a shift action. */ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ ){ yyStackEntry *yytos; yypParser->yyidx++; #ifdef YYTRACKMAXSTACKDEPTH if( yypParser->yyidx>yypParser->yyidxMax ){ yypParser->yyidxMax = yypParser->yyidx; } #endif #if YYSTACKDEPTH>0 if( yypParser->yyidx>=YYSTACKDEPTH ){ yyStackOverflow(yypParser, yypMinor); return; } #else if( yypParser->yyidx>=yypParser->yystksz ){ yyGrowStack(yypParser); if( yypParser->yyidx>=yypParser->yystksz ){ yyStackOverflow(yypParser, yypMinor); return; } } #endif yytos = &yypParser->yystack[yypParser->yyidx]; yytos->stateno = (YYACTIONTYPE)yyNewState; yytos->major = (YYCODETYPE)yyMajor; yytos->minor = *yypMinor; #ifndef NDEBUG if( yyTraceFILE && yypParser->yyidx>0 ){ int i; fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); for(i=1; i<=yypParser->yyidx; i++) fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); fprintf(yyTraceFILE,"\n"); } #endif } /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { %% }; static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. */ static void yy_reduce( yyParser *yypParser, /* The parser */ int yyruleno /* Number of the rule by which to reduce */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ ParseARG_FETCH; yymsp = &yypParser->yystack[yypParser->yyidx]; #ifndef NDEBUG if( yyTraceFILE && yyruleno>=0 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, yyRuleName[yyruleno]); } #endif /* NDEBUG */ /* Silence complaints from purify about yygotominor being uninitialized ** in some cases when it is copied into the stack after the following ** switch. yygotominor is uninitialized when a rule reduces that does ** not set the value of its left-hand side nonterminal. Leaving the ** value of the nonterminal uninitialized is utterly harmless as long ** as the value is never used. So really the only thing this code ** accomplishes is to quieten purify. ** ** 2007-01-16: The wireshark project (www.wireshark.org) reports that ** without this code, their parser segfaults. I'm not sure what there ** parser is doing to make this happen. This is the second bug report ** from wireshark this week. Clearly they are stressing Lemon in ways ** that it has not been previously stressed... (SQLite ticket #2172) */ /*memset(&yygotominor, 0, sizeof(yygotominor));*/ yygotominor = yyzerominor; switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: ** case 0: ** #line ** { ... } // User supplied code ** #line ** break; */ %% }; yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); if( yyact < YYNSTATE ){ #ifdef NDEBUG /* If we are not debugging and the reduce action popped at least ** one element off the stack, then we can push the new element back ** onto the stack here, and skip the stack overflow test in yy_shift(). ** That gives a significant speed improvement. */ if( yysize ){ yypParser->yyidx++; yymsp -= yysize-1; yymsp->stateno = (YYACTIONTYPE)yyact; yymsp->major = (YYCODETYPE)yygoto; yymsp->minor = yygotominor; }else #endif { yy_shift(yypParser,yyact,yygoto,&yygotominor); } }else{ assert( yyact == YYNSTATE + YYNRULE + 1 ); yy_accept(yypParser); } } /* ** The following code executes when the parse fails */ #ifndef YYNOERRORRECOVERY static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ ParseARG_FETCH; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); } #endif while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ %% ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } #endif /* YYNOERRORRECOVERY */ /* ** The following code executes when a syntax error first occurs. */ static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ YYMINORTYPE yyminor /* The minor type of the error token */ ){ ParseARG_FETCH; #define TOKEN (yyminor.yy0) %% ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* ** The following is executed when the parser accepts */ static void yy_accept( yyParser *yypParser /* The parser */ ){ ParseARG_FETCH; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); } #endif while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser accepts */ %% ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* The main parser program. ** The first argument is a pointer to a structure obtained from ** "ParseAlloc" which describes the current state of the parser. ** The second argument is the major token number. The third is ** the minor token. The fourth optional argument is whatever the ** user wants (and specified in the grammar) and is available for ** use by the action routines. ** ** Inputs: **
      **
    • A pointer to the parser (an opaque structure.) **
    • The major token number. **
    • The minor token number. **
    • An option argument of a grammar-specified type. **
    ** ** Outputs: ** None. */ void Parse( void *yyp, /* The parser */ int yymajor, /* The major token code number */ ParseTOKENTYPE yyminor /* The value for the token */ ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; int yyact; /* The parser action. */ int yyendofinput; /* True if we are at the end of input */ #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif yyParser *yypParser; /* The parser */ /* (re)initialize the parser, if necessary */ yypParser = (yyParser*)yyp; if( yypParser->yyidx<0 ){ #if YYSTACKDEPTH<=0 if( yypParser->yystksz <=0 ){ /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ yyminorunion = yyzerominor; yyStackOverflow(yypParser, &yyminorunion); return; } #endif yypParser->yyidx = 0; yypParser->yyerrcnt = -1; yypParser->yystack[0].stateno = 0; yypParser->yystack[0].major = 0; } yyminorunion.yy0 = yyminor; yyendofinput = (yymajor==0); ParseARG_STORE; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); } #endif do{ yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); if( yyactyyerrcnt--; yymajor = YYNOCODE; }else if( yyact < YYNSTATE + YYNRULE ){ yy_reduce(yypParser,yyact-YYNSTATE); }else{ assert( yyact == YY_ERROR_ACTION ); #ifdef YYERRORSYMBOL int yymx; #endif #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); } #endif #ifdef YYERRORSYMBOL /* A syntax error has occurred. ** The response to an error depends upon whether or not the ** grammar defines an error token "ERROR". ** ** This is what we do if the grammar does define ERROR: ** ** * Call the %syntax_error function. ** ** * Begin popping the stack until we enter a state where ** it is legal to shift the error symbol, then shift ** the error symbol. ** ** * Set the error count to three. ** ** * Begin accepting and shifting new tokens. No new error ** processing will occur until three tokens have been ** shifted successfully. ** */ if( yypParser->yyerrcnt<0 ){ yy_syntax_error(yypParser,yymajor,yyminorunion); } yymx = yypParser->yystack[yypParser->yyidx].major; if( yymx==YYERRORSYMBOL || yyerrorhit ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sDiscard input token %s\n", yyTracePrompt,yyTokenName[yymajor]); } #endif yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; }else{ while( yypParser->yyidx >= 0 && yymx != YYERRORSYMBOL && (yyact = yy_find_reduce_action( yypParser->yystack[yypParser->yyidx].stateno, YYERRORSYMBOL)) >= YYNSTATE ){ yy_pop_parser_stack(yypParser); } if( yypParser->yyidx < 0 || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ YYMINORTYPE u2; u2.YYERRSYMDT = 0; yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); } } yypParser->yyerrcnt = 3; yyerrorhit = 1; #elif defined(YYNOERRORRECOVERY) /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to ** do any kind of error recovery. Instead, simply invoke the syntax ** error routine and continue going as if nothing had happened. ** ** Applications can set this macro (for example inside %include) if ** they intend to abandon the parse upon the first syntax error seen. */ yy_syntax_error(yypParser,yymajor,yyminorunion); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** ** * Report an error message, and throw away the input token. ** ** * If the input token is $, then fail the parse. ** ** As before, subsequent error messages are suppressed until ** three input tokens have been successfully shifted. */ if( yypParser->yyerrcnt<=0 ){ yy_syntax_error(yypParser,yymajor,yyminorunion); } yypParser->yyerrcnt = 3; yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); } yymajor = YYNOCODE; #endif } }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); return; } gpick_0.2.5/SConstruct0000644000175000017500000000012412070605213013430 0ustar zbygzbyg#!/usr/bin/env python SConscript(['SConscript'], variant_dir='build', duplicate=0)