IntelliPhoto  0.5
IntelliTool.cpp
Go to the documentation of this file.
1 #include "IntelliTool.h"
2 #include "Layer/PaintingArea.h"
3 
5  this->Area=Area;
6  this->colorPicker=colorPicker;
7  this->Toolsettings=Toolsettings;
8 }
9 
10 
12 
13 }
14 
16  if(isDrawing) {
17  isDrawing=false;
18  this->deleteToolLayer();
19  }
20 }
21 
23  //optional for tool
24 }
25 
27  this->isDrawing=true;
28  //create drawing layer
29  this->createToolLayer();
31 }
32 
34  if(isDrawing) {
35  isDrawing=false;
36  this->mergeToolLayer();
37  this->deleteToolLayer();
39  }
40 }
41 
42 void IntelliTool::onMouseMoved(int x, int y){
43  if(isDrawing)
45 }
46 
48  //if needed for future general tasks implement in here
49 }
50 
51 void IntelliTool::createToolLayer(){
52  Area->createTempTopLayer(Area->activeLayer);
53  this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
54  this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
55 }
56 
57 void IntelliTool::mergeToolLayer(){
58  QColor clr_0;
59  QColor clr_1;
60  for(int y=0; y<activeLayer->height; y++) {
61  for(int x=0; x<activeLayer->width; x++) {
62  clr_0=activeLayer->image->imageData.pixelColor(x,y);
63  clr_1=Canvas->image->imageData.pixelColor(x,y);
64  float t = static_cast<float>(clr_1.alpha())/255.f;
65  int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
66  int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
67  int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
68  int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
69  clr_0.setRed(r);
70  clr_0.setGreen(g);
71  clr_0.setBlue(b);
72  clr_0.setAlpha(a);
73 
74  activeLayer->image->imageData.setPixelColor(x, y, clr_0);
75  }
76  }
77  Area->DumpyGui->UpdateGui();
78 }
79 
80 void IntelliTool::deleteToolLayer(){
81  Area->deleteLayer(Area->activeLayer+1);
82  this->Canvas=nullptr;
83 }
84 
86  return ActiveType;
87 }
88 
90  return isDrawing;
91 }
IntelliTool::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y)
A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on....
Definition: IntelliTool.cpp:15
IntelliTool::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y)
A function managing the left click Released of a Mouse. Call this in child classes!
Definition: IntelliTool.cpp:33
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:51
IntelliTool.h
IntelliTool::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y)
A function managing the left click Pressed of a Mouse. Resetting the current draw....
Definition: IntelliTool.cpp:26
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:53
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:44
PaintingArea::deleteLayer
void deleteLayer(int idx)
The deleteLayer method removes a layer at a given idx.
Definition: PaintingArea.cpp:74
IntelliTool::Tooltype
Tooltype
Definition: IntelliTool.h:16
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:37
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:68
IntelliTool::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y)
A function managing the right click Released of a Mouse. Merging the Canvas to Active....
Definition: IntelliTool.cpp:22
IntelliTool::activeLayer
LayerObject * activeLayer
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:58
IntelliTool::getTooltype
Tooltype getTooltype()
Definition: IntelliTool.cpp:85
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:63
LayerObject::width
int width
Definition: PaintingArea.h:27
IntelliTool::getIsDrawing
bool getIsDrawing()
Definition: IntelliTool.cpp:89
PaintingArea.h
LayerObject::height
int height
Definition: PaintingArea.h:28
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:46
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliTool::IntelliTool
IntelliTool(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings)
A constructor setting the general Painting Area and colorPicker.
Definition: IntelliTool.cpp:4
IntelliPhotoGui::UpdateGui
void UpdateGui()
Definition: IntelliPhotoGui.cpp:694
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:37
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:42
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
IntelliTool::onWheelScrolled
virtual void onWheelScrolled(int value)
A function managing the scroll event. A positive value means scrolling outwards. Call this in child c...
Definition: IntelliTool.cpp:47
IntelliToolsettings
Definition: IntelliToolsettings.h:4
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
An abstract Destructor.
Definition: IntelliTool.cpp:11