IntelliPhoto  0.4
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 }
8 
9 
11 
12 }
13 
15  if(drawing){
16  drawing=false;
17  this->deleteToolLayer();
18  }
19 }
20 
22  //optional for tool
23 }
24 
26  this->drawing=true;
27  //create drawing layer
28  this->createToolLayer();
30 }
31 
33  if(drawing){
34  drawing=false;
35  this->mergeToolLayer();
36  this->deleteToolLayer();
38  }
39 }
40 
41 void IntelliTool::onMouseMoved(int x, int y){
42  if(drawing)
44 }
45 
46 void IntelliTool::createToolLayer(){
47  Area->createTempLayerAfter(Area->activeLayer);
48  this->Active=&Area->layerBundle[Area->activeLayer];
49  this->Canvas=&Area->layerBundle[Area->activeLayer+1];
50 }
51 
52 void IntelliTool::mergeToolLayer(){
53  QColor clr_0;
54  QColor clr_1;
55  for(int y=0; y<Active->hight; y++){
56  for(int x=0; x<Active->width; x++){
57  clr_0=Active->image->imageData.pixelColor(x,y);
58  clr_1=Canvas->image->imageData.pixelColor(x,y);
59  float t = static_cast<float>(clr_1.alpha())/255.f;
60  int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
61  int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
62  int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
63  int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
64  clr_0.setRed(r);
65  clr_0.setGreen(g);
66  clr_0.setBlue(b);
67  clr_0.setAlpha(a);
68 
69  Active->image->imageData.setPixelColor(x, y, clr_0);
70  }
71  }
72 }
73 
74 void IntelliTool::deleteToolLayer(){
75  Area->deleteLayer(Area->activeLayer+1);
76  this->Canvas=nullptr;
77 }
IntelliTool::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y)
Definition: IntelliTool.cpp:14
IntelliTool::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y)
Definition: IntelliTool.cpp:32
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
Definition: IntelliTool.h:17
IntelliTool.h
IntelliTool::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y)
Definition: IntelliTool.cpp:25
IntelliTool::IntelliTool
IntelliTool(PaintingArea *Area, IntelliColorPicker *colorPicker)
Definition: IntelliTool.cpp:4
IntelliTool::Area
PaintingArea * Area
Definition: IntelliTool.h:16
PaintingArea
Definition: PaintingArea.h:28
PaintingArea::deleteLayer
void deleteLayer(int index)
Definition: PaintingArea.cpp:70
IntelliTool::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y)
Definition: IntelliTool.cpp:21
IntelliTool::Canvas
LayerObject * Canvas
Definition: IntelliTool.h:20
LayerObject::width
int width
Definition: PaintingArea.h:19
IntelliTool::drawing
bool drawing
Definition: IntelliTool.h:21
PaintingArea.h
LayerObject::hight
int hight
Definition: PaintingArea.h:20
IntelliColorPicker
Definition: IntelliColorPicker.h:8
IntelliImage::imageData
QImage imageData
Definition: IntelliImage.h:23
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:18
IntelliTool::Active
LayerObject * Active
Definition: IntelliTool.h:19
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
Definition: IntelliTool.cpp:41
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
Definition: IntelliTool.cpp:10