File indexing completed on 2024-06-23 04:19:01

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #ifndef KP_IMAGE_SELECTION_TRANSPARENCY_H
0030 #define KP_IMAGE_SELECTION_TRANSPARENCY_H
0031 
0032 
0033 #include "imagelib/kpColor.h"
0034 
0035 
0036 // This does not apply to the Text Tool.  Use kpTextStyle for that.
0037 class kpImageSelectionTransparency
0038 {
0039 public:
0040     // Opaque selection
0041     kpImageSelectionTransparency ();
0042     // Selection that's transparent at pixels with <color>
0043     kpImageSelectionTransparency (const kpColor &transparentColor, double colorSimilarity);
0044     // If <isOpaque>, <transparentColor> is allowed to be anything
0045     // (including invalid) as the color would have no effect.
0046     // However, you are encouraged to set it as you would if !<isOpaque>,
0047     // because setTransparent(true) might be called later, after which
0048     // the <transparentColor> would suddenly become important.
0049     //
0050     // It is a similar case with <colorSimilarity>, although <colorSimilarity>
0051     // must be in-range (see kpColorSimilarityHolder).
0052     kpImageSelectionTransparency (bool isOpaque, const kpColor &transparentColor, double colorSimilarity);
0053     // Returns whether they are visually equivalent.
0054     // This is the same as a memcmp() except that if they are both opaque,
0055     // this function will return true regardless of the transparentColor's.
0056     bool operator== (const kpImageSelectionTransparency &rhs) const;
0057     bool operator!= (const kpImageSelectionTransparency &rhs) const;
0058     ~kpImageSelectionTransparency ();
0059 
0060     bool isOpaque () const;
0061     bool isTransparent () const;
0062     void setOpaque (bool yes = true);
0063     void setTransparent (bool yes = true);
0064 
0065     // If isOpaque(), transparentColor() is generally not called because
0066     // the transparent color would have no effect.
0067     kpColor transparentColor () const;
0068     void setTransparentColor (const kpColor &transparentColor);
0069 
0070     double colorSimilarity () const;
0071     void setColorSimilarity (double colorSimilarity);
0072     int processedColorSimilarity () const;
0073 
0074 private:
0075     bool m_isOpaque;
0076     kpColor m_transparentColor;
0077     double m_colorSimilarity;
0078     int m_processedColorSimilarity;
0079 };
0080 
0081 
0082 #endif  // KP_IMAGE_SELECTION_TRANSPARENCY_H