File indexing completed on 2024-05-12 15:56:55
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_ACS_TYPES_H 0008 #define __KIS_ACS_TYPES_H 0009 0010 #include <QPoint> 0011 #include <KoColor.h> 0012 #include "kis_iterator_ng.h" 0013 0014 0015 namespace Acs { 0016 enum ColorRole {Foreground, Background}; 0017 0018 inline ColorRole buttonToRole(Qt::MouseButton button) { 0019 return button == Qt::LeftButton ? Acs::Foreground : Acs::Background; 0020 } 0021 0022 inline ColorRole buttonsToRole(Qt::MouseButton button, Qt::MouseButtons buttons) { 0023 return button == Qt::LeftButton || buttons & Qt::LeftButton ? Acs::Foreground : Acs::Background; 0024 } 0025 0026 template <class ResourceProvider> 0027 void setCurrentColor(ResourceProvider *provider, ColorRole role, const KoColor &color) { 0028 if (role == Acs::Foreground) { 0029 provider->setFGColor(color); 0030 } else { 0031 provider->setBGColor(color); 0032 } 0033 } 0034 0035 template <class ResourceProvider> 0036 KoColor currentColor(ResourceProvider *provider, ColorRole role) { 0037 return role == Acs::Foreground ? provider->fgColor() : provider->bgColor(); 0038 } 0039 0040 template <class PaintDeviceSP> 0041 KoColor sampleColor(PaintDeviceSP device, const QPoint &pt) { 0042 KoColor color; 0043 if (device) { 0044 (void) device->pixel(pt.x(), pt.y(), &color); 0045 } 0046 return color; 0047 } 0048 0049 template <class PaintDeviceSP> 0050 void setColor(PaintDeviceSP device, const QPoint &pt, const KoColor &color) { 0051 (void) device->setPixel(pt.x(), pt.y(), color); 0052 } 0053 0054 template<class Iterator> 0055 void setColorWithIterator(Iterator &it, const KoColor &color, const int pixelSize) { 0056 memcpy(it.rawData(), color.data(), pixelSize); 0057 } 0058 0059 } 0060 0061 0062 0063 #endif /* __KIS_ACS_TYPES_H */