Skip to content

Commit

Permalink
Add CustomDistributor to wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
psieg committed Jun 8, 2016
1 parent 00a3502 commit 3590932
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 56 deletions.
6 changes: 4 additions & 2 deletions Software/src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ SOURCES += \
wizard/MonitorIdForm.cpp \
wizard/MonitorConfigurationPage.cpp \
wizard/LightpackDiscoveryPage.cpp \
wizard/AndromedaDistributor.cpp \
wizard/ConfigureDevicePage.cpp \
wizard/SelectDevicePage.cpp \
wizard/AndromedaDistributor.cpp \
wizard/CassiopeiaDistributor.cpp \
wizard/PegasusDistributor.cpp \
wizard/CustomDistributor.cpp \
systrayicon/SysTrayIcon.cpp \
UpdatesProcessor.cpp

Expand Down Expand Up @@ -274,13 +275,14 @@ HEADERS += \
wizard/MonitorIdForm.hpp \
wizard/MonitorConfigurationPage.hpp \
wizard/LightpackDiscoveryPage.hpp \
wizard/AndromedaDistributor.hpp \
wizard/ConfigureDevicePage.hpp \
wizard/SelectDevicePage.hpp \
types.h \
wizard/AreaDistributor.hpp \
wizard/AndromedaDistributor.hpp \
wizard/CassiopeiaDistributor.hpp \
wizard/PegasusDistributor.hpp \
wizard/CustomDistributor.hpp \
systrayicon/SysTrayIcon.hpp \
systrayicon/SysTrayIcon_p.hpp \
UpdatesProcessor.hpp
Expand Down
116 changes: 116 additions & 0 deletions Software/src/wizard/CustomDistributor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* CustomDistributor.cpp
*
* Created on: 08.06.2016
* Project: Prismatik
*
* Copyright (c) 2015 Patrick Siegler
*
* Lightpack is an open-source, USB content-driving ambient lighting
* hardware.
*
* Prismatik is a free, open-source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Prismatik and Lightpack files is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "CustomDistributor.hpp"
#include "PrismatikMath.hpp"

#define STAND_WIDTH 0.3333 //33%

int roundDown(int n) {
return (n % 2 == 0) ? n : (n - 1);
}

CustomDistributor::~CustomDistributor() {
if (_currentArea)
cleanCurrentArea();
}

ScreenArea * CustomDistributor::next() {
const double thikness = 0.15;
double x, y;

if (_dx == 0 && _dy == 0) {
_dx = 1;
_width = 1.0 / areaCountOnBottomEdge();
_height = thikness;
x = 1.0 - roundDown(areaCountOnBottomEdge()) * _width / 2;
y = 1.0 - _height;
} else if (_dx > 0 && cmp(_currentArea->hScanEnd(), 1.0, 0.01) >= 0 ) {
cleanCurrentArea();
_dx = 0;
_dy = -1;
_width = thikness;
_height = 1.0f / areaCountOnSideEdge();
x = 1.0f - _width;
y = 1.0f - _height;
} else if (_dy < 0 && cmp(_currentArea->vScanStart(), 0.0, .01) <= 0) {
cleanCurrentArea();
_dx = -1;
_dy = 0;
_width = 1.0 / areaCountOnTopEdge();
_height = thikness;
x = 1.0 - _width;
y = 0.0;
} else if (_dx < 0 && cmp(_currentArea->hScanStart(), 0.0, .01) <= 0) {
cleanCurrentArea();
_dx = 0;
_dy = 1;
_width = thikness;
_height = 1.0 / areaCountOnSideEdge();
x = 0.0;
y = 0.0;
} else if (_dy > 0 && cmp(_currentArea->vScanEnd(), 1.0, .01) >= 0) {
cleanCurrentArea();
_dx = 1;
_dy = 0;
_width = 1.0 / areaCountOnBottomEdge();
_height = thikness;
x = 0.0;
y = 1.0 - _height;
}

ScreenArea *result = NULL;
if (!_currentArea) {
result = new ScreenArea( x, x + _width, y, y + _height);
} else {
ScreenArea *cf = _currentArea;
double dx = _width * (double)_dx;
double dy = _height * (double)_dy;

result = new ScreenArea(within1(cf->hScanStart() + dx), within1(cf->hScanEnd() + dx),
within1(cf->vScanStart() + dy), within1(cf->vScanEnd() + dy));
cleanCurrentArea();
}

_currentArea = result;
return new ScreenArea(*_currentArea);

}

size_t CustomDistributor::areaCountOnTopEdge() const
{
return _top;
}

size_t CustomDistributor::areaCountOnBottomEdge() const
{
return _bottom;
}

size_t CustomDistributor::areaCountOnSideEdge() const
{
return _side;
}
59 changes: 59 additions & 0 deletions Software/src/wizard/CustomDistributor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* CustomDistributor.hpp
*
* Created on: 08.06.2016
* Project: Prismatik
*
* Copyright (c) 2015 Patrick Siegler
*
* Lightpack is an open-source, USB content-driving ambient lighting
* hardware.
*
* Prismatik is a free, open-source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Prismatik and Lightpack files is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef CUSTOMDISTRIBUTOR_HPP
#define CUSTOMDISTRIBUTOR_HPP
#include "AreaDistributor.hpp"

class CustomDistributor : public AreaDistributor
{
public:
CustomDistributor(int screenId, size_t top, size_t side, size_t bottom):
AreaDistributor(screenId, top + 2*side + bottom),
_top(top), _side(side), _bottom(bottom),
_dx(0), _dy(0)
{}
virtual ~CustomDistributor();

virtual ScreenArea * next();

protected:
char _dx, _dy;
double _width, _height;
size_t _top, _side, _bottom;

virtual size_t areaCountOnSideEdge() const;
virtual size_t areaCountOnTopEdge() const;
virtual size_t areaCountOnBottomEdge() const;

private:
void cleanCurrentArea() {
delete _currentArea;
_currentArea = NULL;
}
};

#endif // CUSTOMDISTRIBUTOR_HPP
10 changes: 10 additions & 0 deletions Software/src/wizard/ZonePlacementPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "AndromedaDistributor.hpp"
#include "CassiopeiaDistributor.hpp"
#include "PegasusDistributor.hpp"
#include "CustomDistributor.hpp"
#include "GrabWidget.hpp"
#include "LedDeviceLightpack.hpp"

Expand Down Expand Up @@ -233,7 +234,16 @@ void ZonePlacementPage::on_pbPegasus_clicked()
distributeAreas(pegasus);

delete pegasus;
}


void ZonePlacementPage::on_pbCustom_clicked()
{
CustomDistributor *custom = new CustomDistributor(_screenId, _ui->sbTopLeds->value(), _ui->sbSideLeds->value(), _ui->sbBottomLeds->value());

distributeAreas(custom);

delete custom;
}


Expand Down
6 changes: 3 additions & 3 deletions Software/src/wizard/ZonePlacementPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public slots:

private slots:
void on_pbAndromeda_clicked();
void on_pbCassiopeia_clicked();
void on_pbCassiopeia_clicked();
void on_pbPegasus_clicked();
void on_pbCustom_clicked();

void on_numberOfLeds_valueChanged(int arg1);

void on_pbPegasus_clicked();

private:
void addGrabArea(int id, const QRect &rect);
void removeLastGrabArea();
Expand Down
Loading

0 comments on commit 3590932

Please sign in to comment.