Tool structure- input bug

This commit is contained in:
Sonaion
2019-12-10 15:32:22 +01:00
parent 0aa3b17b8a
commit 30d6781e7f
10 changed files with 118 additions and 41 deletions

View File

@@ -133,22 +133,22 @@ void IntelliPhotoGui::slotSetActiveAlpha(){
}
void IntelliPhotoGui::slotPositionMoveUp(){
paintingArea->movePositionActive(0,-2);
paintingArea->movePositionActive(0,-20);
update();
}
void IntelliPhotoGui::slotPositionMoveDown(){
paintingArea->movePositionActive(0,2);
paintingArea->movePositionActive(0,20);
update();
}
void IntelliPhotoGui::slotPositionMoveLeft(){
paintingArea->movePositionActive(-2,0);
paintingArea->movePositionActive(-20,0);
update();
}
void IntelliPhotoGui::slotPositionMoveRight(){
paintingArea->movePositionActive(2,0);
paintingArea->movePositionActive(20,0);
update();
}
@@ -269,10 +269,6 @@ void IntelliPhotoGui::createActions()
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
// Delete Active Layer action and tie to paintingArea::deleteActiveLayerLayer()
actionDeleteActiveLayer = new QAction(tr("&Delete active Layer"), this);
connect(actionDeleteActiveLayer, SIGNAL(triggered()), paintingArea, SLOT(deleteActiveLayer()));
actionFloodFill = new QAction(tr("&clear Image"), this);
connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer()));
@@ -347,7 +343,6 @@ void IntelliPhotoGui::createMenus()
layerMenu = new QMenu(tr("&Layer"), this);
layerMenu->addAction(actionCreateNewLayer);
layerMenu->addAction(actionDeleteLayer);
layerMenu->addAction(actionDeleteActiveLayer);
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);

View File

@@ -75,7 +75,6 @@ private:
QAction *actionCreateNewLayer;
QAction *actionDeleteLayer;
QAction *actionDeleteActiveLayer;
QAction *actionAboutDialog;
QAction *actionAboutQtDialog;

View File

@@ -50,9 +50,6 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Draw a line from the last registered point to the current
painter.drawPoint(p1);
// Call to update the rectangular space where we drew
//update(QRect(p1, p2));
}
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
@@ -69,5 +66,4 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co
void IntelliImage::floodFill(const QColor& color){
imageData.fill(color);
}

View File

@@ -31,7 +31,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
for(int y = 0; y<copy.height(); y++){
for(int x = 0; x<copy.width(); x++){
QColor clr = copy.pixelColor(x,y);
clr.setAlpha(alpha);
clr.setAlpha(std::min(alpha, clr.alpha()));
copy.setPixelColor(x,y, clr);
}
}

View File

@@ -23,6 +23,7 @@ SOURCES += \
IntelliHelper/IntelliHelper.cpp \
Layer/PaintingArea.cpp \
Tool/IntelliTool.cpp \
Tool/IntelliToolPen.cpp \
main.cpp
HEADERS += \
@@ -32,7 +33,8 @@ HEADERS += \
Image/IntelliShapedImage.h \
IntelliHelper/IntelliHelper.h \
Layer/PaintingArea.h \
Tool/IntelliTool.h
Tool/IntelliTool.h \
Tool/IntelliToolPen.h
FORMS += \
widget.ui

View File

@@ -1,18 +1,21 @@
// ---------- PaintingArea.cpp ----------
#include "string.h"
#include <vector>
#include <QtWidgets>
#include <QPoint>
#include <QRect>
#include "string.h"
#include "PaintingArea.h"
#include "Image/IntelliRasterImage.h"
#include "Image/IntelliShapedImage.h"
#include <vector>
#include <QPoint>
#include "Tool/IntelliToolPen.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
:QWidget(parent){
this->Tool = new IntelliToolPen(this);
this->setUp(maxWidth, maxHeight);
//tetsing
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
@@ -160,7 +163,13 @@ void PaintingArea::slotActivateLayer(int a){
// Set that we are currently drawing
void PaintingArea::mousePressEvent(QMouseEvent *event)
{
//TODO implement in tool
int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset;
int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset;
if(event->button() == Qt::LeftButton){
Tool->onMouseLeftPressed(x, y);
}else if(event->button() == Qt::RightButton){
Tool->onMouseRightPressed(x, y);
}
}
@@ -169,13 +178,21 @@ void PaintingArea::mousePressEvent(QMouseEvent *event)
// from the last position to the current
void PaintingArea::mouseMoveEvent(QMouseEvent *event)
{
//TODO implement in Tool
int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset;
int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset;
Tool->onMouseMoved(x, y);
}
// If the button is released we set variables to stop drawing
void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
{
//TODO implement in tool
int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset;
int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset;
if(event->button() == Qt::LeftButton){
Tool->onMouseLeftReleased(x, y);
}else if(event->button() == Qt::RightButton){
Tool->onMouseRightReleased(x, y);
}
}
// QPainter provides functions to draw on the widget
@@ -235,7 +252,7 @@ void PaintingArea::assembleLayers(bool forSaving){
if(layer.hightOffset+y>=maxHeight) break;
for(int x=0; x<layer.width; x++){
if(layer.widthOffset+x<0) continue;
if(layer.hightOffset+y>=maxWidth) break;
if(layer.widthOffset+x>=maxWidth) break;
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y);
clr_1=cpy.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f;
@@ -257,7 +274,7 @@ void PaintingArea::assembleLayers(bool forSaving){
void PaintingArea::createTempLayerAfter(int idx){
if(idx>=0){
LayerObject newLayer;
newLayer.alpha = layerBundle[idx].alpha;
newLayer.alpha = 255;
newLayer.hight = layerBundle[idx].hight;
newLayer.width = layerBundle[idx].width;
newLayer.hightOffset = layerBundle[idx].hightOffset;

View File

@@ -4,11 +4,11 @@
#include <QColor>
#include <QImage>
#include"Image/IntelliImage.h"
#include"Tool/IntelliTool.h"
#include <QPoint>
#include <QWidget>
#include <QList>
#include"Image/IntelliImage.h"
#include"Tool/IntelliTool.h"
struct LayerObject{
@@ -77,6 +77,8 @@ private:
int maxWidth;
int maxHeight;
IntelliTool* Tool;
std::vector<LayerObject> layerBundle;
int activeLayer=-1;

View File

@@ -12,12 +12,24 @@ IntelliTool::~IntelliTool(){
void IntelliTool::onMouseRightPressed(int x, int y){
this->drawing=true;
//create drawing layer
this->createToolLayer();
if(drawing){
drawing=false;
this->deleteToolLayer();
}
}
void IntelliTool::onMouseRightReleased(int x, int y){
//optional for tool
}
void IntelliTool::onMouseLeftPressed(int x, int y){
this->drawing=true;
//create drawing layer
this->createToolLayer();
}
void IntelliTool::onMouseLeftReleased(int x, int y){
if(drawing){
drawing=false;
this->mergeToolLayer();
@@ -25,17 +37,6 @@ void IntelliTool::onMouseRightReleased(int x, int y){
}
}
void IntelliTool::onMouseLeftPressed(int x, int y){
if(drawing){
drawing=false;
this->deleteToolLayer();
}
}
void IntelliTool::onMouseLeftReleased(int x, int y){
//optional for tool
}
void IntelliTool::onMouseMoved(int x, int y){
//optional for tool
}

View File

@@ -0,0 +1,42 @@
#include"IntelliToolPen.h"
#include"Layer/PaintingArea.h"
#include"QDebug"
IntelliToolPen::IntelliToolPen(PaintingArea* Area)
:IntelliTool(Area){
}
IntelliToolPen::~IntelliToolPen(){
}
void IntelliToolPen::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
//implement in here
this->point=QPoint(x,y);
this->Canvas->image->drawPixel(point, QColor(255,0,0,255));
}
void IntelliToolPen::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
//implemnt in here
}
void IntelliToolPen::onMouseLeftPressed(int x, int y){
//implement in here
IntelliTool::onMouseLeftPressed(x,y);
}
void IntelliToolPen::onMouseLeftReleased(int x, int y){
//implement in here
IntelliTool::onMouseLeftReleased(x,y);
}
void IntelliToolPen::onMouseMoved(int x, int y){
if(this->drawing){
QPoint newPoint(x,y);
this->Canvas->image->drawLine(this->point, newPoint, QColor(255,0,0,255), 2);
this->point=newPoint;
}
}

View File

@@ -0,0 +1,23 @@
#ifndef INTELLITOOLPEN_H
#define INTELLITOOLPEN_H
#include"IntelliTool.h"
#include"QColor"
#include"QPoint"
class IntelliToolPen : public IntelliTool{
QColor clr;
QPoint point;
public:
IntelliToolPen(PaintingArea* Area);
virtual ~IntelliToolPen() override;
virtual void onMouseRightPressed(int x, int y) override;
virtual void onMouseRightReleased(int x, int y) override;
virtual void onMouseLeftPressed(int x, int y) override;
virtual void onMouseLeftReleased(int x, int y) override;
virtual void onMouseMoved(int x, int y) override;
};
#endif // INTELLITOOLPEN_H