1 /* 2 Drawpile - a collaborative drawing program. 3 4 Copyright (C) 2015 Calle Laakkonen 5 6 Drawpile is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Drawpile is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef PAINTCORE_BLENDMODES_H 20 #define PAINTCORE_BLENDMODES_H 21 22 #include <QString> 23 #include <QList> 24 #include <QPair> 25 26 namespace paintcore { 27 28 /** 29 * Blend mode metadata 30 */ 31 struct BlendMode { 32 enum Flag { 33 PrivateMode = 0x00, // not available for selection 34 LayerMode = 0x01, // available for use as a layer mode 35 BrushMode = 0x02, // available for use as a brush mode 36 UniversalMode = 0x03, // can be used with brushes and layers 37 DecrOpacity = 0x04, // this mode can decrease pixel opacity 38 IncrOpacity = 0x08 // this mode can increase pixel opacity 39 }; 40 Q_DECLARE_FLAGS(Flags, Flag) 41 42 //! The blending mode IDs 43 // Note: these IDs are part of the protocol, so they cannot be 44 // reordered without breaking it. The app internal order is different. 45 enum Mode { 46 MODE_ERASE=0, 47 MODE_NORMAL, 48 MODE_MULTIPLY, 49 MODE_DIVIDE, 50 MODE_BURN, 51 MODE_DODGE, 52 MODE_DARKEN, 53 MODE_LIGHTEN, 54 MODE_SUBTRACT, 55 MODE_ADD, 56 MODE_RECOLOR, 57 MODE_BEHIND, 58 MODE_COLORERASE, 59 MODE_REPLACE=255 60 }; 61 62 const char *name; // translatable name 63 const QString svgname; // SVG style name of this blending mode 64 const Mode id; // ID as used in the protocol 65 const Flags flags; // Behaviour info 66 BlendModeBlendMode67 BlendMode() : name(nullptr), id(MODE_ERASE) { } BlendModeBlendMode68 BlendMode(const char *n, const QString &s, Mode i, Flags f) 69 : name(n), svgname(s), id(i), flags(f) { } 70 }; 71 72 Q_DECLARE_OPERATORS_FOR_FLAGS(BlendMode::Flags) 73 74 /** 75 * @brief Find the blending mode with the given protocol ID 76 * @param id blend mode ID 77 * @return blend mode or default if ID does not exist 78 */ 79 const BlendMode &findBlendMode(int id); 80 81 /** 82 * @brief Find the blending mode based on its SVG name 83 * @param svgname 84 * @param found set to false if the exact match wasn't found 85 * @return blend mode or default if none by such name was found 86 */ 87 const BlendMode &findBlendModeByName(const QString &svgname, bool *found); 88 89 /** 90 * @brief Get list of blend mode IDs and names that have the given flags. 91 * 92 * The returned list is sorted into somewhat logical groupings. 93 * 94 * @param flags filter by these flags 95 * @return list of blending mode (id, name) pairs. 96 */ 97 QList<QPair<int, QString>> getBlendModeNames(BlendMode::Flags flags); 98 99 } 100 101 #endif 102 103