Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  • Loading branch information
meh2481 committed Nov 27, 2016
2 parents 8066a13 + 930a2a6 commit 969e028
Show file tree
Hide file tree
Showing 74 changed files with 4,442 additions and 1,769 deletions.
579 changes: 579 additions & 0 deletions Animation.cpp

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions Animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#ifndef ANIMATION_H
#define ANIMATION_H
#include <QObject>
#include <QVector>
#include <QImage>
#include <QGraphicsScene>
#include <QMap>
#include <QGraphicsPixmapItem>
#include <QGraphicsRectItem>
#include <QColor>
#include <QPainter>
#include <QGraphicsSimpleTextItem>
#include <QFont>
#include "BalancePos.h"
#include "Frame.h"

#define ANIM_DRAG_SPACINGY 0.2
#define ANIM_BEFORE -1
#define ANIM_AFTER -2
#define ANIM_NONE -3

class Animation : public QObject
{
Q_OBJECT

Animation(){}

QGraphicsScene* scene;
QVector<Frame*> frames;
int offsetX, offsetY; //Position on the screen
int spacingX, spacingY;
int width;
int curHeight; //Last-calculated height for the animation
QColor frameBgCol;
bool frameBgTransparent;
QImage transparentBg;
unsigned int minWidth; //Minimum width for this animation at the current width
QString name;
QGraphicsSimpleTextItem* label;
bool drawLabel;
bool frameBgVisible;

unsigned int heightRecalc(); //Recalculate where each image is on in the sheet
unsigned int widthOfImages();
public:
explicit Animation(QImage bg, QGraphicsScene* s, QObject *parent = 0);
~Animation();

//Insert an image at the end of the animation and hand over control of the memory
void insertImage(QImage img);

//Insert an image at the specified index and hand over control of the memory
void insertImage(QImage img, unsigned int index);

//Insert a list of images at the end of the animation and hand over control of the memory
void insertImages(QVector<QImage>& imgs);

//Insert a list of images at the specified index and hand over control of the memory
void insertImages(QVector<QImage>& imgs, unsigned int index);

//Remove the selected images from the given animation and add them to this one
void addImages(QVector<Frame*>& imgs, unsigned int index);

QVector<Frame*> pullSelected(int* pullLoc = NULL); //Remove selected frames from this anim

//Set the width of the animation. Return the new height
unsigned int setWidth(unsigned int width);

//Set the spacing between animations and frames
void setSpacing(unsigned int x, unsigned int y);
void setXSpacing(unsigned int x);
void setYSpacing(unsigned int y);

//Set the offset to draw this animation at
void setOffset(unsigned int x, unsigned int y);

//Set the background color for each frame
void setFrameBgCol(QColor c);

//Set the background transparency for each frame
void setFrameBgTransparent(bool b);

//Set the visibility of the frame bg (if both sheet and frame bgs are invisible, don't draw the latter)
void setFrameBgVisible(bool b);

//Get the last-calculated height for the animation
unsigned int getCurHeight() {return curHeight;}

//Reverse the animation
void reverse();

//Get the largest width/height out of all animation frames
QPoint getMaxFrameSize();

//Balance sheet to the given size
//TODO don't include BalanceSheetDialog just for this
void balance(QPoint sz, BalancePos::Pos vert, BalancePos::Pos horiz);

//Test if a point is inside the animation
bool isInside(int x, int y);

unsigned int getMinWidth() {return minWidth;} //Get the minimum width for the current width

unsigned int getSmallestImageWidth(); //Get the smallest possible width for this animation

bool toggleSelect(QGraphicsItem* it); //Select the given item as a frame (return selected)

bool toggleSelect(int pos);

bool hasSelected(); //Return true if any frames in this animation are selected

bool isSelected(QGraphicsItem* it); //Return true if this item is in this sheet and selected

QLine getDragPos(int x, int y);

//Get location in the animation this is dropped.
//ANIM_BEFORE if before this animation, ANIM_AFTER if after, ANIM_NONE if not on this animation
int getDropPos(int x, int y);

bool isEmpty() {return frames.isEmpty();}

void deselectAll();

QVector<Frame*>& getFrames() {return frames;}

QVector<Frame*>* getFramePtr() {return &frames;}

void render(QPainter& painter);

QString getName() {return name;}

void setName(QString s);

void setFont(QFont& f);

void setFontColor(QColor c);

void saveGIF(QString saveFilename, int animFPS);

int getPosX() {return offsetX;}

int getPosY() {return offsetY;}

void setNameVisible(bool b);

void clear();

Frame* getFrame(unsigned int index);

void removeFrame(int index);

void selectAll();

signals:

public slots:

private:
};

#endif // ANIMATION_H
14 changes: 14 additions & 0 deletions BalancePos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef BALANCEPOS_H
#define BALANCEPOS_H

namespace BalancePos
{
typedef int Pos;
static const Pos Up = 0;
static const Pos Mid = 1;
static const Pos Down = 2;
static const Pos Left = 0;
static const Pos Right = 2;
};

#endif // BALANCEPOS_H
38 changes: 19 additions & 19 deletions BalanceSheetDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BalanceSheetDialog::BalanceSheetDialog(QWidget *parent) : QDialog(parent),
ui(new Ui::balanceSheet)
{
ui->setupUi(this);
vertPos = horizPos = Mid;
vertPos = horizPos = BalancePos::Mid;
}

BalanceSheetDialog::~BalanceSheetDialog()
Expand Down Expand Up @@ -47,72 +47,72 @@ void BalanceSheetDialog::clearIcons()

void BalanceSheetDialog::on_pos_ul_clicked()
{
vertPos = Up;
horizPos = Left;
vertPos = BalancePos::Up;
horizPos = BalancePos::Left;
clearIcons();
ui->pos_ul->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_um_clicked()
{
vertPos = Up;
horizPos = Mid;
vertPos = BalancePos::Up;
horizPos = BalancePos::Mid;
clearIcons();
ui->pos_um->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_ur_clicked()
{
vertPos = Up;
horizPos = Right;
vertPos = BalancePos::Up;
horizPos = BalancePos::Right;
clearIcons();
ui->pos_ur->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_ml_clicked()
{
vertPos = Mid;
horizPos = Left;
vertPos = BalancePos::Mid;
horizPos = BalancePos::Left;
clearIcons();
ui->pos_ml->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_mm_clicked()
{
vertPos = Mid;
horizPos = Mid;
vertPos = BalancePos::Mid;
horizPos = BalancePos::Mid;
clearIcons();
ui->pos_mm->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_mr_clicked()
{
vertPos = Mid;
horizPos = Right;
vertPos = BalancePos::Mid;
horizPos = BalancePos::Right;
clearIcons();
ui->pos_mr->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_bl_clicked()
{
vertPos = Down;
horizPos = Left;
vertPos = BalancePos::Down;
horizPos = BalancePos::Left;
clearIcons();
ui->pos_bl->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_bm_clicked()
{
vertPos = Down;
horizPos = Mid;
vertPos = BalancePos::Down;
horizPos = BalancePos::Mid;
clearIcons();
ui->pos_bm->setIcon(QIcon("://stop"));
}

void BalanceSheetDialog::on_pos_br_clicked()
{
vertPos = Down;
horizPos = Right;
vertPos = BalancePos::Down;
horizPos = BalancePos::Right;
clearIcons();
ui->pos_br->setIcon(QIcon("://stop"));
}
Expand Down
16 changes: 5 additions & 11 deletions BalanceSheetDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include "BalancePos.h"

namespace Ui {
class balanceSheet;
class balanceSheet;
}

class BalanceSheetDialog : public QDialog
Expand All @@ -18,16 +19,9 @@ class BalanceSheetDialog : public QDialog
explicit BalanceSheetDialog(QWidget *parent = 0);
~BalanceSheetDialog();

typedef int Pos;
static const Pos Up = 0;
static const Pos Mid = 1;
static const Pos Down = 2;
static const Pos Left = 0;
static const Pos Right = 2;

signals:

void balance(int w, int h, BalanceSheetDialog::Pos vert, BalanceSheetDialog::Pos horiz);
void balance(int w, int h, BalancePos::Pos vert, BalancePos::Pos horiz);

public slots:
void defaultWH(int w, int h);
Expand All @@ -49,8 +43,8 @@ private slots:
private:
Ui::balanceSheet *ui;

Pos vertPos;
Pos horizPos;
BalancePos::Pos vertPos;
BalancePos::Pos horizPos;

void clearIcons();
};
Expand Down
21 changes: 8 additions & 13 deletions BatchRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,20 @@ void BatchRenderer::run()

//Periodically check if we should stop
QCoreApplication::processEvents();
if(bStop) return;
if(bStop)
return;

//Create sheet
mCurSheet = new QImage(iSizeX, iSizeY, QImage::Format_ARGB32);
mCurSheet = QImage(iSizeX, iSizeY, QImage::Format_ARGB32);

//Create image of the proper size and fill it with a good bg color
QPainter painter(mCurSheet);
QPainter painter(&mCurSheet);
painter.setFont(sheetFont);
painter.setCompositionMode(QPainter::CompositionMode_Source);
if(sheetBgTransparent)
{
mCurSheet->fill(QColor(0,0,0,0));
}
mCurSheet.fill(QColor(0,0,0,0));
else
mCurSheet->fill(sheetBgCol);
mCurSheet.fill(sheetBgCol);

//Second pass: Print each frame into the final image
int curX = offsetX;
Expand All @@ -117,7 +116,7 @@ void BatchRenderer::run()
//Draw label for animation
if(sName->length() && animNameEnabled)
{
painter.setPen(QColor(255,255,255,255));
painter.setPen(fontColor);
painter.drawText(QRectF(offsetX,curY,1000,textHeight), Qt::AlignLeft|Qt::AlignVCenter, *sName);
curY += textHeight;
}
Expand Down Expand Up @@ -151,7 +150,6 @@ void BatchRenderer::run()
if(bStop)
{
painter.end();
delete mCurSheet;
return;
}

Expand All @@ -163,10 +161,7 @@ void BatchRenderer::run()
painter.end();

//Save image as PNG
mCurSheet->save(folder + ".png", "PNG");

//Clean up
delete mCurSheet;
mCurSheet.save(folder + ".png", "PNG");

//Emit a signal saying we're done bro
renderingDone();
Expand Down
3 changes: 2 additions & 1 deletion BatchRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BatchRenderer : public QObject, public QRunnable

QList<QList<QImage> > mSheetFrames;
QStringList mAnimNames;
QImage* mCurSheet;
QImage mCurSheet;
bool bStop;

public:
Expand All @@ -33,6 +33,7 @@ class BatchRenderer : public QObject, public QRunnable
QColor animHighlightCol;
bool frameBgTransparent;
QColor frameBgCol;
QColor fontColor;

void run();

Expand Down
Loading

0 comments on commit 969e028

Please sign in to comment.