mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 20:30:32 +02:00
basics of layer structure
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.10.2, 2019-12-04T18:01:33. -->
|
||||
<!-- Written by QtCreator 4.10.2, 2019-12-04T18:58:17. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -306,8 +306,8 @@
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">IntelliPhoto</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">IntelliPhoto2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jonas/Desktop/IntelliPhoto/Painting/IntelliPhoto.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
|
||||
@@ -15,7 +15,10 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||
|
||||
//tetsing
|
||||
this->addLayer(200,200,0,0);
|
||||
this->addLayer(200,200,201,201);
|
||||
layerStructure[0].image->floodFill(QColor(255,0,0,255));
|
||||
this->addLayer(200,200,150,150);
|
||||
layerStructure[1].image->floodFill(QColor(0,255,0,255));
|
||||
layerStructure[1].alpha=100;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +54,7 @@ void PaintingArea::addLayer(int width, int height, int widthOffset, int heightOf
|
||||
}
|
||||
newLayer.alpha = 255;
|
||||
this->layerStructure.push_back(newLayer);
|
||||
|
||||
}
|
||||
|
||||
void PaintingArea::deleteLayer(int index){
|
||||
@@ -89,22 +93,16 @@ bool PaintingArea::openImage(const QString &fileName)
|
||||
// Save the current image
|
||||
bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat)
|
||||
{
|
||||
if(this->activeLayer==-1){
|
||||
if(layerStructure.size()==0){
|
||||
return false;
|
||||
}
|
||||
// Created to hold the image
|
||||
this->assembleLayers();
|
||||
|
||||
for(size_t i=0; i<layerStructure.size(); i++){
|
||||
LayerObject layer;
|
||||
QImage cpy = layer.image->getDisplayable(layer.alpha);
|
||||
//TODO draw cpy to CANVAS
|
||||
if (Canvas->save(fileName, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (Canvas.save(fileName, fileFormat)) {
|
||||
// return true;
|
||||
//} else {
|
||||
// return false;
|
||||
//}
|
||||
}
|
||||
|
||||
// Used to change the pen color
|
||||
@@ -196,14 +194,11 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
||||
// update themselves
|
||||
void PaintingArea::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
if(this->activeLayer==-1){
|
||||
return;
|
||||
}
|
||||
LayerObject active = layerStructure[activeLayer];
|
||||
this->assembleLayers();
|
||||
|
||||
QPainter painter(this);
|
||||
QRect dirtyRec = event->rect();
|
||||
painter.drawImage(dirtyRec, active.image->getDisplayable(dirtyRec.size(), active.alpha), dirtyRec);
|
||||
painter.drawImage(dirtyRec, *Canvas, dirtyRec);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -239,3 +234,28 @@ void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){
|
||||
image_res->scaled(newSize,Qt::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
void PaintingArea::assembleLayers(){
|
||||
Canvas->fill(Qt::GlobalColor::black);
|
||||
for(size_t i=0; i<layerStructure.size(); i++){
|
||||
LayerObject layer = layerStructure[i];
|
||||
QImage cpy = layer.image->getDisplayable(layer.alpha);
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<layer.height; y++){
|
||||
for(int x=0; x<layer.width; x++){
|
||||
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
|
||||
clr_1=cpy.pixelColor(x,y);
|
||||
float t = (float)clr_1.alpha()/255.f;
|
||||
int r =(float)clr_1.red()*(t)+(float)clr_0.red()*(1.-t);
|
||||
int g =(float)clr_1.green()*(t)+(float)clr_0.green()*(1.-t);
|
||||
int b =(float)clr_1.blue()*(t)+(float)clr_0.blue()*(1.-t);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
|
||||
Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,8 @@ private:
|
||||
std::vector<LayerObject> layerStructure;
|
||||
int activeLayer=-1;
|
||||
|
||||
void assembleLayers();
|
||||
|
||||
void drawLineTo(const QPoint &endPoint);
|
||||
void resizeImage(QImage *image_res, const QSize &newSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user