GUI test and buf fixes

fixed a few bugs
found a few new bugs
made a GUI for testing
This commit is contained in:
SalnikovDE
2021-03-14 21:36:15 +03:00
parent d11c2e5b1b
commit d58bd76f8c
4 changed files with 819 additions and 41 deletions

View File

@ -50,16 +50,19 @@ public:
{
x -= cx;
y -= cy;
rotate(x, y);
x *= invXsize;
y *= invYsize;
rotate(x, y);
float t = sqrt(x * x + y * y) * factor;
if (t < ginfo.littleRadius || t < 0)
if (t < ginfo.littleRadius)
return 0.;
if (t > ginfo.largeRadius || t > 1)
{
if (t > ginfo.largeRadius)
return 1.;
}
if (ginfo.largeRadius - ginfo.littleRadius < FLT_EPSILON)
return t;
t = (t - ginfo.littleRadius) / (ginfo.largeRadius - ginfo.littleRadius);// TODO optimize
return t;
}
virtual ~calcRadial() {}
@ -86,9 +89,9 @@ public:
{
x -= cx;
y -= cy;
rotate(x, y);
x *= invXsize;
y *= invYsize;
rotate(x, y);
float t = fabs(atan2(x, y)) * m1pi;
if (ginfo.angle > FLT_EPSILON)
{
@ -97,10 +100,14 @@ public:
t -= floor(t);
}
}
if (t > ginfo.largeRadius || t > 1)
if (t > ginfo.largeRadius)
return 1;
if (t < ginfo.littleRadius || t < 0)
if (t < ginfo.littleRadius)
return 0;
if (ginfo.largeRadius - ginfo.littleRadius < FLT_EPSILON)
return t;
t = (t - ginfo.littleRadius) / (ginfo.largeRadius - ginfo.littleRadius);// TODO optimize
return t;
}
@ -127,17 +134,20 @@ public:
{
x -= cx;
y -= cy;
rotate(x, y);
x *= invXsize;
y *= invYsize;
rotate(x, y);
float t = std::max(fabs(x * factor), fabs(y * factor));
if (t > ginfo.largeRadius || t > 1)
if (t > ginfo.largeRadius)
return 1;
if (t < ginfo.littleRadius || t < 0)
if (t < ginfo.littleRadius)
return 0;
if (ginfo.largeRadius - ginfo.littleRadius < FLT_EPSILON)
return t;
t = (t - ginfo.littleRadius) / (ginfo.largeRadius - ginfo.littleRadius);// TODO optimize
return t;
}
@ -171,10 +181,14 @@ public:
rotate(x, y);
float t = (x + 0.5 * xlen) * invXlen * invStretch - ginfo.linoffset;
if (t > ginfo.largeRadius || t > 1)
if (t > ginfo.largeRadius)
return 1;
if (t < ginfo.littleRadius || t < 0)
if (t < ginfo.littleRadius)
return 0;
if (ginfo.largeRadius - ginfo.littleRadius < FLT_EPSILON)
return t;
t = (t - ginfo.littleRadius) / (ginfo.largeRadius - ginfo.littleRadius);// TODO optimize
return t;
}

View File

@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>
#include <iostream>
#include "../../../../DesktopEditor/graphics/pro/Graphics.h"
std::vector<Point> drawCircle1(int n, double cx, double cy, double r) {
@ -20,28 +21,19 @@ MainWindow::MainWindow(QWidget *parent)
, lable(new QLabel)
{
ui->setupUi(this);
QImage pm(1000, 1000,QImage::Format_RGB888);
// std::vector<Point> points {{40, 40}, {150, 40}, {140, 140}, {40, 140}};
// std::vector<Point> points {{150, 170}, {100, 160}, {150, 150}, {160, 100}, {170, 150}, {230, 160}, {170, 170}, {150, 170}};
std::vector<Point> points;
points = drawCircle1(100, 130.,100.,40);
GenerateImg(pm, c_BrushTypePathDiamondGradient, 0, points);
//setColor2(pm, 0x0000FF);
//pm.invertPixels();
ui->lable_test->setPixmap(QPixmap::fromImage(pm));
ui->lable_test->setScaledContents(true);
ui->lable_test->resize(pm.size());
this->resize(pm.size());
pm.save("test.bmp");
ui->lable_test->setStyleSheet("QLabel { background-color : white;}");
points = {{0, 0}, {105, 0}, {105, 105}, {0, 105}};
}
MainWindow::~MainWindow()
{
delete ui;
}
void GenerateImg(QImage &img, int grad, double angle, std::vector<Point> points) {
void GenerateImg(QImage &img, std::vector<Point> &points, const Info &info) {
NSGraphics::IGraphicsRenderer* pRasterRenderer = NSGraphics::Create();
pRasterRenderer->SetFontManager(NULL);
int nRasterW = img.size().width();
@ -70,18 +62,13 @@ void GenerateImg(QImage &img, int grad, double angle, std::vector<Point> points)
pRasterRenderer->put_Width(dW_MM);
pRasterRenderer->put_Height(dH_MM);
NSStructures::GradientInfo ginfo;
ginfo.periods = 0.5;
ginfo.discrete_step = 0.00;
ginfo.setAngleDegrees(-45);
ginfo.xsize = 1;
NSStructures::GradientInfo ginfo = info.ginfo;
//ginfo.reflected = true;
pRasterRenderer->put_BrushGradInfo(ginfo);
pRasterRenderer->put_PenColor(0xFF000000);
//pRasterRenderer->put_BrushColor1(0xFF00FF00);
LONG c[] = {0xFFff0000, 0xFFffa500, 0xFFffff00, 0xFF008000, 0xFF0000ff, 0xFFFF00FF};
double p[] = {0.0,0.2,0.4,0.6,0.8,1};
pRasterRenderer->put_BrushLinearAngle(angle);
pRasterRenderer->put_BrushType(grad);
pRasterRenderer->put_BrushType(info.gradient_type);
pRasterRenderer->put_BrushGradientColors(c, p, 6);
pRasterRenderer->PathCommandStart();
pRasterRenderer->BeginCommand(c_nPathType);
@ -102,3 +89,151 @@ void GenerateImg(QImage &img, int grad, double angle, std::vector<Point> points)
}
}
}
void MainWindow::on_RenderPic_clicked()
{
QImage pm(400, 400,QImage::Format_RGB888);
GenerateImg(pm, points, info);
//setColor2(pm, 0x0000FF);
//pm.invertPixels();
ui->lable_test->setPixmap(QPixmap::fromImage(pm));
ui->lable_test->setScaledContents(true);
ui->lable_test->resize(pm.size());
pm.save("test.bmp");
}
void MainWindow::on_AngleSlider_sliderMoved(int position)
{
double angleT = 360. / 100 * position;
ui->lable_angle->setText(std::to_string(angleT).c_str());
info.ginfo.setAngleDegrees(angleT);
this->on_RenderPic_clicked();
}
void MainWindow::on_OffsetSlider_sliderMoved(int position)
{
double offset = ((double)position - 50.0) / 25.0;
ui->lable_offset->setText(std::to_string(offset).c_str());
info.ginfo.linoffset = offset;
this->on_RenderPic_clicked();
}
void MainWindow::on_PeriodicCheckBox_clicked()
{
info.ginfo.periodic = false; //!info.ginfo.periodic; BUG!
this->on_RenderPic_clicked();
}
void MainWindow::on_StretchSlide_sliderMoved(int position)
{
double stretch = pow(2.0, (position - 50.) / 25.0);
ui->lable_stretch->setText(std::to_string(stretch).c_str());
info.ginfo.linstretch = stretch;
this->on_RenderPic_clicked();
}
void MainWindow::on_DiscreteStepSlider_sliderMoved(int position)
{
if (position == 0) {
info.ginfo.discrete_step = 0.0;
ui->label_discrete->setText("Continious");
this->on_RenderPic_clicked();
return;
}
info.ginfo.setStepByNum(position);
ui->label_discrete->setText(std::to_string(position).c_str());
this->on_RenderPic_clicked();
}
void MainWindow::on_PathType_itemDoubleClicked(QListWidgetItem *item)
{
on_PathType_itemClicked(item);
this->on_RenderPic_clicked();
}
void MainWindow::on_PathType_itemClicked(QListWidgetItem *item)
{
if (item->text() == "Circle") {
points = drawCircle1(100, 53, 53, 50);
}
else if (item->text() == "Square") {
points = {{0, 0}, {105, 0}, {105, 105}, {0, 105}};
}
else if (item->text() == "Triangle") {
points = {{5, 10}, {40, 100}, {100, 1}};
}
}
void MainWindow::on_GradientType_itemDoubleClicked(QListWidgetItem *item)
{
on_GradientType_itemClicked(item);
on_RenderPic_clicked();
}
void MainWindow::on_GradientType_itemClicked(QListWidgetItem *item)
{
if (item->text() == "Linear") {
info.gradient_type = c_BrushTypePathNewLinearGradient;
}
else if (item->text() == "Radial") {
info.gradient_type = c_BrushTypePathRadialGradient;
}
else if (item->text() == "Diamond") {
info.gradient_type = c_BrushTypePathDiamondGradient;
}
else if (item->text() == "Conical") {
info.gradient_type = c_BrushTypePathConicalGradient;
}
}
void MainWindow::on_LittleRadiusSlider_sliderMoved(int position)
{
double llr = (double)position / 100.0;
ui->lable_little_radius->setText(std::to_string(llr).c_str());
info.ginfo.littleRadius = llr;
this->on_RenderPic_clicked();
}
void MainWindow::on_LargeRadiusSlider_sliderMoved(int position)
{
double lgr = (double)position / 100.0;
ui->lable_large_radius->setText(std::to_string(lgr).c_str());
info.ginfo.largeRadius = lgr;
this->on_RenderPic_clicked();
}
void MainWindow::on_xcenterSlider_sliderMoved(int position)
{
double xc = ((double)position - 50.0) / 25.0;
ui->lable_xcenter->setText(std::to_string(xc).c_str());
info.ginfo.centerX = xc;
this->on_RenderPic_clicked();
}
void MainWindow::on_ycenterSlider_sliderMoved(int position)
{
double yc = ((double)position - 50.0) / 25.0;
ui->lable_ycenter->setText(std::to_string(yc).c_str());
info.ginfo.centerY = yc;
this->on_RenderPic_clicked();
}
void MainWindow::on_XSizeSlider_sliderMoved(int position)
{
double xsize = pow(2.0, (position - 50.) / 25.0);
ui->lable_xsize->setText(std::to_string(xsize).c_str());
info.ginfo.xsize = xsize;
this->on_RenderPic_clicked();
}
void MainWindow::on_YSizeSlider_sliderMoved(int position)
{
double ysize = pow(2.0, (position - 50.) / 25.0);
ui->lable_ysize->setText(std::to_string(ysize).c_str());
info.ginfo.ysize = ysize;
this->on_RenderPic_clicked();
}

View File

@ -4,6 +4,8 @@
#include <QMainWindow>
#include <QLabel>
#include <cmath>
#include <QListWidgetItem>
#include "../../../../DesktopEditor/graphics/pro/Graphics.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
@ -27,6 +29,12 @@ struct Color {
}
};
struct Info {
NSStructures::GradientInfo ginfo;
int gradient_type;
Info() : gradient_type(c_BrushTypePathNewLinearGradient) {};
};
void GenerateImg(QImage &img, int grad = 1,double angle = 0,std::vector<Point> points = {});
std::vector<Point> drawCircle1(int n, double cx, double cy, double r);
class MainWindow : public QMainWindow
@ -38,6 +46,41 @@ public:
~MainWindow();
QImage img;
QLabel *lable;
Info info;
std::vector<Point> points;
private slots:
void on_RenderPic_clicked();
void on_AngleSlider_sliderMoved(int position);
void on_OffsetSlider_sliderMoved(int position);
void on_PeriodicCheckBox_clicked();
void on_StretchSlide_sliderMoved(int position);
void on_DiscreteStepSlider_sliderMoved(int position);
void on_PathType_itemDoubleClicked(QListWidgetItem *item);
void on_PathType_itemClicked(QListWidgetItem *item);
void on_GradientType_itemDoubleClicked(QListWidgetItem *item);
void on_GradientType_itemClicked(QListWidgetItem *item);
void on_LittleRadiusSlider_sliderMoved(int position);
void on_LargeRadiusSlider_sliderMoved(int position);
void on_XSizeSlider_sliderMoved(int position);
void on_ycenterSlider_sliderMoved(int position);
void on_xcenterSlider_sliderMoved(int position);
void on_YSizeSlider_sliderMoved(int position);
private:
Ui::MainWindow *ui;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>1025</width>
<height>651</height>
</rect>
</property>
<property name="windowTitle">
@ -22,12 +22,595 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QPushButton" name="RenderPic">
<property name="geometry">
<rect>
<x>600</x>
<y>540</y>
<width>171</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>RenderPic</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="labelName">
<property name="geometry">
<rect>
<x>610</x>
<y>10</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Set Params</string>
</property>
</widget>
<widget class="QSlider" name="AngleSlider">
<property name="geometry">
<rect>
<x>470</x>
<y>460</y>
<width>211</width>
<height>21</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="TextLable2">
<property name="geometry">
<rect>
<x>470</x>
<y>440</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
<string>Angle</string>
</property>
</widget>
<widget class="QLabel" name="lable_angle">
<property name="geometry">
<rect>
<x>530</x>
<y>440</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QSlider" name="OffsetSlider">
<property name="geometry">
<rect>
<x>470</x>
<y>410</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="labelName2">
<property name="geometry">
<rect>
<x>470</x>
<y>380</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>LinOffset</string>
</property>
</widget>
<widget class="QLabel" name="lable_offset">
<property name="geometry">
<rect>
<x>550</x>
<y>380</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QSlider" name="StretchSlide">
<property name="geometry">
<rect>
<x>470</x>
<y>350</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="labelName3">
<property name="geometry">
<rect>
<x>470</x>
<y>320</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Stretch</string>
</property>
</widget>
<widget class="QLabel" name="lable_stretch">
<property name="geometry">
<rect>
<x>550</x>
<y>320</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QSlider" name="XSizeSlider">
<property name="geometry">
<rect>
<x>750</x>
<y>320</y>
<width>16</width>
<height>160</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="YSizeSlider">
<property name="geometry">
<rect>
<x>810</x>
<y>320</y>
<width>16</width>
<height>160</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="LittleRadiusSlider">
<property name="geometry">
<rect>
<x>470</x>
<y>290</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSlider" name="LargeRadiusSlider">
<property name="geometry">
<rect>
<x>470</x>
<y>230</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSlider" name="DiscreteStepSlider">
<property name="geometry">
<rect>
<x>470</x>
<y>170</y>
<width>211</width>
<height>16</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="labelName4">
<property name="geometry">
<rect>
<x>730</x>
<y>300</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>xsize</string>
</property>
</widget>
<widget class="QLabel" name="labelName5">
<property name="geometry">
<rect>
<x>800</x>
<y>300</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>ysize</string>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>697</x>
<y>280</y>
<width>161</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="labelName6">
<property name="geometry">
<rect>
<x>470</x>
<y>260</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>LittleRadius</string>
</property>
</widget>
<widget class="QLabel" name="lable_little_radius">
<property name="geometry">
<rect>
<x>570</x>
<y>260</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="labelName7">
<property name="geometry">
<rect>
<x>470</x>
<y>200</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>LargeRadius</string>
</property>
</widget>
<widget class="QLabel" name="lable_large_radius">
<property name="geometry">
<rect>
<x>580</x>
<y>200</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="labelName8">
<property name="geometry">
<rect>
<x>470</x>
<y>140</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>DiscreteStep</string>
</property>
</widget>
<widget class="QLabel" name="label_discrete">
<property name="geometry">
<rect>
<x>580</x>
<y>140</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QCheckBox" name="PeriodicCheckBox">
<property name="geometry">
<rect>
<x>470</x>
<y>80</y>
<width>81</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Periodic</string>
</property>
</widget>
<widget class="QSlider" name="xcenterSlider">
<property name="geometry">
<rect>
<x>750</x>
<y>110</y>
<width>16</width>
<height>160</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QSlider" name="ycenterSlider">
<property name="geometry">
<rect>
<x>810</x>
<y>110</y>
<width>16</width>
<height>160</height>
</rect>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QListWidget" name="GradientType">
<property name="geometry">
<rect>
<x>20</x>
<y>400</y>
<width>81</width>
<height>161</height>
</rect>
</property>
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
<item>
<property name="text">
<string>Diamond</string>
</property>
</item>
<item>
<property name="text">
<string>Radial</string>
</property>
</item>
<item>
<property name="text">
<string>Conical</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>570</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Gradient Type</string>
</property>
</widget>
<widget class="QListWidget" name="PathType">
<property name="geometry">
<rect>
<x>120</x>
<y>400</y>
<width>71</width>
<height>161</height>
</rect>
</property>
<item>
<property name="text">
<string>Square</string>
</property>
</item>
<item>
<property name="text">
<string>Circle</string>
</property>
</item>
<item>
<property name="text">
<string>Triangle</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>130</x>
<y>570</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Path</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>730</x>
<y>90</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>xcenter</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>790</x>
<y>90</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>ycenter</string>
</property>
</widget>
<widget class="QLabel" name="lable_xcenter">
<property name="geometry">
<rect>
<x>750</x>
<y>270</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QLabel" name="lable_ycenter">
<property name="geometry">
<rect>
<x>810</x>
<y>270</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QLabel" name="lable_xsize">
<property name="geometry">
<rect>
<x>750</x>
<y>480</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QLabel" name="lable_ysize">
<property name="geometry">
<rect>
<x>810</x>
<y>480</y>
<width>51</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
</widget>
@ -36,7 +619,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>1025</width>
<height>21</height>
</rect>
</property>
@ -56,4 +639,7 @@
</widget>
<resources/>
<connections/>
<slots>
<signal>on_button_Push()</signal>
</slots>
</ui>