Skip to content

Commit

Permalink
Working on #12
Browse files Browse the repository at this point in the history
  • Loading branch information
chriku committed Mar 17, 2017
1 parent 1fbd3e7 commit d30239e
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 138 deletions.
14 changes: 7 additions & 7 deletions block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ QPicture Block::drawBlock(QColor color, bool plain) {
if (pins[i].type == true) {
double rad = abs(dir.x()) / 4.0;
qpainter.drawEllipse(
(QPointF(pins[i].point * Settings::final()->gridSize())) +
(QPointF(pins[i].m_point * Settings::final()->gridSize())) +
((dir / 4.0) * 3.0),
rad, rad);
dir /= 2.0;
}
if(!plain)
{
qpainter.drawLine(pins[i].point * Settings::final()->gridSize(),
(pins[i].point * Settings::final()->gridSize()) + dir);
qpainter.drawLine(pins[i].m_point * Settings::final()->gridSize(),
(pins[i].m_point * Settings::final()->gridSize()) + dir);
pen.setColor(Qt::black);
pen.setStyle(Qt::DotLine);
pen.setWidth(Settings::final()->penWidth()*Settings::final()->gridSize());
Expand All @@ -97,8 +97,8 @@ QPicture Block::drawBlock(QColor color, bool plain) {
}
}
qpainter.setPen(pen);
qpainter.drawLine(pins[i].point * Settings::final()->gridSize(),
(pins[i].point * Settings::final()->gridSize()) + dir);
qpainter.drawLine(pins[i].m_point * Settings::final()->gridSize(),
(pins[i].m_point * Settings::final()->gridSize()) + dir);
// qDebug()<<(pins[i].point*10)<<pins[i].direction<<width;
}

Expand Down Expand Up @@ -288,15 +288,15 @@ void Block::init(Block *blk)
lua_pop(L, 1);
if (type == "INPUT") {
pin_t pin;
pin.point = QPoint(x, y);
pin.m_point = QPoint(x, y);
pin.direction = 0;
pin.state = false;
pin.type = false;
blk->pins.append(pin);
}
if (type == "OUTPUT") {
pin_t pin;
pin.point = QPoint(x, y);
pin.m_point = QPoint(x, y);
pin.direction = 2;
pin.type = false;
blk->pins.append(pin);
Expand Down
58 changes: 46 additions & 12 deletions block.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
#include <QPainter>
#include <QObject>
#include <QPicture>
#include <QDebug>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include <QMap>
#include <QPoint>
struct pin_t {
QPoint point;
int direction;
int state;
bool type;
QColor color;
pin_t()
{
state=false;
color=Qt::black;
}
};
class Block;
class block_t;
class pin_t;

class Block : public QObject
{
Expand Down Expand Up @@ -63,5 +55,47 @@ QFileSystemWatcher watcher;
public slots:
void fileChanged(const QString &path);
};
class block_t {
public:
Block* block;
QColor color;
block_t()
{
color=Qt::black;
}
QPoint m_pos;
QRectF rect()
{
QRectF rect(m_pos.x()+0.5,m_pos.y(),block->width,block->height+1.0);
return rect;
}
QRectF pinsRect()
{
QRectF rect(m_pos.x(),m_pos.y(),block->width+1,block->height+1.0);
return rect;
}

QPointF unmap(QPointF p)
{
return p-m_pos;
}
};
class pin_t {
public:
QPoint pos(){
return parent->m_pos+m_point;
}

int direction;
int state;
bool type;
QColor color;
block_t* parent;
pin_t()
{
state=false;
color=Qt::black;
}
QPoint m_point;
};
#endif // BLOCK_H
Loading

0 comments on commit d30239e

Please sign in to comment.