Added alpha-blending and 2d-transformations projects
This commit is contained in:
parent
8fd16f569c
commit
0f66ea28ca
20
QT/2d-transformations/2d-transformations.pro
Normal file
20
QT/2d-transformations/2d-transformations.pro
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2015-03-03T00:14:51
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = 2d-transformations
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
OUTPUT += Console
|
||||||
|
SOURCES += main.cpp\
|
||||||
|
mywindow.cpp
|
||||||
|
|
||||||
|
HEADERS += mywindow.h
|
||||||
|
|
||||||
|
FORMS += mywindow.ui
|
33
QT/2d-transformations/main.cpp
Normal file
33
QT/2d-transformations/main.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Glowny plik aplikacji, utworzony automatycznie przez QtCreator
|
||||||
|
// W wiekszosci przypadkow nie musimy tu nic zmieniac
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy QApplication
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy glownego widgetu (okna) aplikacji
|
||||||
|
#include "mywindow.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
|
||||||
|
// Tworzymy objekt QApplication. Zarzadza on zasobami calej aplikacji
|
||||||
|
// i jest niezbedny do stworzenia jakiejkolwiek aplikacji Qt posiadajacej GUI.
|
||||||
|
// Przekazujemy mu dwa argumenty argc i argv, poniewaz Qt moze rowniez
|
||||||
|
// przyjmowac argumenty z linii komend.
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
// Tworzymy obiekt klasy MyWindow - glownego okna naszej aplikacji.
|
||||||
|
// Jest to klasa zdefiniowana przez nas.
|
||||||
|
// Jej definicja znajduje sie w plikach mainwindow.h i mainwindow.cpp
|
||||||
|
MyWindow w;
|
||||||
|
|
||||||
|
// w.setMouseTracking(true);
|
||||||
|
// Pokazujemy glowne okno aplikacji na ekranie. Domyslnie jest ono niewidoczne.
|
||||||
|
// Wszystkie widgety (elementy GUI) zawarte w glownym oknie beda rowniez widoczne.
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
// Przekazujemy kontrole nad aplikacja do Qt. Program wchodzi w petle zdarzen
|
||||||
|
// tzn. zaczyna oczekiwac na akcje uzytkownika - klikniecia przycisku myszy,
|
||||||
|
// lub klawisza klawiatury itp.
|
||||||
|
return a.exec();
|
||||||
|
}
|
304
QT/2d-transformations/mywindow.cpp
Normal file
304
QT/2d-transformations/mywindow.cpp
Normal file
@ -0,0 +1,304 @@
|
|||||||
|
// Dolaczamy plik naglowkowy naszej klasy MyWindow
|
||||||
|
#include "mywindow.h"
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy zawierajacy definicje GUI
|
||||||
|
// Plik ten jest generowany automatycznie
|
||||||
|
// z pliku XML "mywindow.ui"
|
||||||
|
#include "ui_mywindow.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <iostream>
|
||||||
|
#include <float.h> // for float,double macros
|
||||||
|
#include <string.h>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define PI 3.1415
|
||||||
|
|
||||||
|
std::vector<float> matrixMul(std::vector<float> p, std::vector<float> m)
|
||||||
|
{
|
||||||
|
std::vector<float> res(3);
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
res.push_back(0);
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
res[i] += m[i * 3 + j] * p[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> matrixMul3x3(std::vector<float> m1, std::vector<float> m2)
|
||||||
|
{
|
||||||
|
std::vector<float> res(9, 0);
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < 3; k++)
|
||||||
|
{
|
||||||
|
res[i * 3 + j] += m1[i * 3 + k] * m2[k * 3 + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definicja konstruktora, wywolujemy najpierw
|
||||||
|
// konstruktor klasy nadrzednej, nastepnie tworzymy
|
||||||
|
// obiekt klasy Ui_MyWindow reprezentujacy GUI
|
||||||
|
MyWindow::MyWindow(QWidget *parent) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
ui(new Ui::MyWindow)
|
||||||
|
{
|
||||||
|
// Wywolujemy funkcje tworzaca elementy GUI
|
||||||
|
// Jej definicja znajduje sie w pliku "ui_mywindow.h"
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Pobieramy wymiary i wspolrzedne lewego gornego naroznika ramki
|
||||||
|
// i ustawiamy wartosci odpowiednich pol
|
||||||
|
// Uwaga: ramke "rysujFrame" wykorzystujemy tylko do
|
||||||
|
// wygodnego ustaiwenia tych wymiarow. Rysunek bedziemy wyswietlac
|
||||||
|
// bezposrednio w glownym oknie aplikacji.
|
||||||
|
szer = ui->rysujFrame->width();
|
||||||
|
wys = ui->rysujFrame->height();
|
||||||
|
poczX = ui->rysujFrame->x();
|
||||||
|
poczY = ui->rysujFrame->y();
|
||||||
|
|
||||||
|
// Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci
|
||||||
|
// i wysokosci. Ustawiamy format bitmapy na 32 bitowe RGB
|
||||||
|
// (0xffRRGGBB).
|
||||||
|
img = new QImage(szer,wys,QImage::Format_RGB32);
|
||||||
|
|
||||||
|
loaded_img = new QImage("/Users/dawidpietrykowski/Desktop/projects/umk/GK/QT/2d-transformations/p.png");
|
||||||
|
|
||||||
|
rotation_angle = 0;
|
||||||
|
|
||||||
|
translation_vec.push_back(0);
|
||||||
|
translation_vec.push_back(0);
|
||||||
|
|
||||||
|
scale_vec.push_back(1.0f);
|
||||||
|
scale_vec.push_back(1.0f);
|
||||||
|
|
||||||
|
sh_vec.push_back(0.0f);
|
||||||
|
sh_vec.push_back(0.0f);
|
||||||
|
|
||||||
|
UpdateImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definicja destruktora
|
||||||
|
MyWindow::~MyWindow()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funkcja (slot) wywolywana po nacisnieciu przycisku "Wyjscie" (exitButton)
|
||||||
|
// Uwaga: polaczenie tej funkcji z sygnalem "clicked"
|
||||||
|
// emitowanym przez przycisk jest realizowane
|
||||||
|
// za pomoca funkcji QMetaObject::connectSlotsByName(MyWindow)
|
||||||
|
// znajdujacej sie w automatycznie generowanym pliku "ui_mywindow.h"
|
||||||
|
// Nie musimy wiec sami wywolywac funkcji "connect"
|
||||||
|
void MyWindow::on_exitButton_clicked()
|
||||||
|
{
|
||||||
|
// qApp to globalny wskaznik do obiektu reprezentujacego aplikacje
|
||||||
|
// quit() to funkcja (slot) powodujaca zakonczenie aplikacji z kodem 0 (brak bledu)
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_tx_valueChanged(int val){
|
||||||
|
translation_vec[0] = val / 100.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_ty_valueChanged(int val){
|
||||||
|
translation_vec[1] = val / 100.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_a_valueChanged(int val){
|
||||||
|
rotation_angle = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_sx_valueChanged(int val){
|
||||||
|
scale_vec[0] = 1.0f / ( val / 100.0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_sy_valueChanged(int val){
|
||||||
|
scale_vec[1] = 1.0f / ( val / 100.0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_shx_valueChanged(int val){
|
||||||
|
sh_vec[0] = val / 100.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_shy_valueChanged(int val){
|
||||||
|
sh_vec[1] = val / 100.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::UpdateImage(){
|
||||||
|
float sina = sin(rotation_angle * 0.01745329252f);
|
||||||
|
float cosa = cos(rotation_angle * 0.01745329252f);
|
||||||
|
|
||||||
|
std::vector<float> translate_mat = {
|
||||||
|
1, 0, translation_vec[0],
|
||||||
|
0, 1, translation_vec[1],
|
||||||
|
0, 0, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<float> scale_mat = {
|
||||||
|
scale_vec[0], 0, 0,
|
||||||
|
0, scale_vec[1], 0,
|
||||||
|
0, 0, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<float> rotation_mat = {
|
||||||
|
cosa, -sina, 0,
|
||||||
|
sina, cosa, 0,
|
||||||
|
0, 0, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<float> shx_mat = {
|
||||||
|
1, sh_vec[0], 0,
|
||||||
|
0, 1, 0,
|
||||||
|
0, 0, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<float> shy_mat = {
|
||||||
|
1, 0, 0,
|
||||||
|
sh_vec[1], 1, 0,
|
||||||
|
0, 0, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<float> tansform_mat = matrixMul3x3(matrixMul3x3(matrixMul3x3(matrixMul3x3(
|
||||||
|
scale_mat,
|
||||||
|
rotation_mat),
|
||||||
|
shx_mat),
|
||||||
|
shy_mat),
|
||||||
|
translate_mat);
|
||||||
|
|
||||||
|
for(int x = 0; x < szer; x++)
|
||||||
|
for(int y = 0; y < wys; y++){
|
||||||
|
float xw = (float) x / (float)szer;
|
||||||
|
float yh = (float) y / (float) wys;
|
||||||
|
xw -= 0.5f;
|
||||||
|
yh -= 0.5f;
|
||||||
|
std::vector<float> P1 = {xw, yh, 1};
|
||||||
|
std::vector<float> P2 = matrixMul(P1, tansform_mat);
|
||||||
|
P2[0] += 0.5f;
|
||||||
|
P2[1] += 0.5f;
|
||||||
|
DrawPixel(img, x, y, GetInterpolatedColor(P2[0], P2[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor MyWindow::GetPixel(QImage* img, int x, int y){
|
||||||
|
QColor res;
|
||||||
|
int width = img->width();
|
||||||
|
int height = img->height();
|
||||||
|
if(x >= width || y >= height || x < 0 || y < 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
|
||||||
|
res.setBlue(ptr[width*4*y + 4*x]);
|
||||||
|
res.setGreen(ptr[width*4*y + 4*x + 1]);
|
||||||
|
res.setRed(ptr[width*4*y + 4*x + 2]);
|
||||||
|
res.setAlpha(ptr[width*4*y + 4*x + 3]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor mul(float v, QColor c){
|
||||||
|
int red = (int)(c.red() * v);
|
||||||
|
if(red > 255) red = 255;
|
||||||
|
int green = (int)(c.green() * v);
|
||||||
|
if(green > 255) green = 255;
|
||||||
|
int blue = (int)(c.blue() * v);
|
||||||
|
if(blue > 255) blue = 255;
|
||||||
|
return QColor(red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor add(QColor c1, QColor c2){
|
||||||
|
int red = (int)(c1.red() + c2.red());
|
||||||
|
if(red > 255) red = 255;
|
||||||
|
int green = (int)(c1.green() + c2.green());
|
||||||
|
if(green > 255) green = 255;
|
||||||
|
int blue = (int)(c1.blue() + c2.blue());
|
||||||
|
if(blue > 255) blue = 255;
|
||||||
|
return QColor(red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor MyWindow::GetInterpolatedColor(float x, float y){
|
||||||
|
float width = loaded_img->width();
|
||||||
|
float height = loaded_img->height();
|
||||||
|
float xw = (x * width);
|
||||||
|
float yw = (y * height);
|
||||||
|
int x_f = (int) (x * width);
|
||||||
|
int y_f = (int) (y * height);
|
||||||
|
int x_c = ceil(x * width);
|
||||||
|
int y_c = ceil(y * height);
|
||||||
|
float a = (xw - (float) x_f);
|
||||||
|
float b = ((yw) - (float) y_f);
|
||||||
|
|
||||||
|
QColor P1 = GetPixel(loaded_img, x_f, y_c);
|
||||||
|
QColor P2 = GetPixel(loaded_img, x_c, y_c);
|
||||||
|
QColor P3 = GetPixel(loaded_img, x_c, y_f);
|
||||||
|
QColor P4 = GetPixel(loaded_img, x_f, y_f);
|
||||||
|
|
||||||
|
QColor v1 = mul(1.0f - a, P1);
|
||||||
|
QColor v2 = mul(a, P2);
|
||||||
|
QColor v3 = mul(a, P3);
|
||||||
|
QColor v4 = mul(1.0f - a, P4);
|
||||||
|
QColor top = add(v1, v2);
|
||||||
|
QColor bottom = add(v3, v4);
|
||||||
|
QColor btop = mul(b, top);
|
||||||
|
QColor bbottom = mul(1.0f - b, bottom);
|
||||||
|
QColor res = add(btop, bbottom);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funkcja "odmalowujaca" komponent
|
||||||
|
void MyWindow::paintEvent(QPaintEvent*)
|
||||||
|
{
|
||||||
|
// Obiekt klasy QPainter pozwala nam rysowac na komponentach
|
||||||
|
QPainter p(this);
|
||||||
|
|
||||||
|
|
||||||
|
UpdateImage();
|
||||||
|
// Rysuje obrazek "img" w punkcie (poczX,poczY)
|
||||||
|
// (tu bedzie lewy gorny naroznik)
|
||||||
|
p.drawImage(poczX,poczY,*img);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyWindow::DrawPixel(QImage* img, int x, int y, QColor color){
|
||||||
|
if(x >= szer || y >= wys || x < 0 || y < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
|
||||||
|
ptr[szer*4*y + 4*x] = color.blue();
|
||||||
|
ptr[szer*4*y + 4*x + 1] = color.green();
|
||||||
|
ptr[szer*4*y + 4*x + 2] = color.red();
|
||||||
|
ptr[szer*4*y + 4*x + 3] = color.alpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyWindow::ClearImage(QImage *img){
|
||||||
|
unsigned char* empty_val = (unsigned char*)malloc(4);
|
||||||
|
empty_val[0] = 0;
|
||||||
|
empty_val[1] = 0;
|
||||||
|
empty_val[2] = 0;
|
||||||
|
empty_val[3] = 255;
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
for(int i = 0; i < img->width(); i++){
|
||||||
|
for(int j = 0; j < img->height(); j++){
|
||||||
|
memcpy(ptr + 4 * (i + j * img->width()), empty_val, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
135
QT/2d-transformations/mywindow.h
Normal file
135
QT/2d-transformations/mywindow.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// Plik naglowkowy klasy MyWindow
|
||||||
|
// Obiekt tej klasy to glowne okno naszej aplikacji
|
||||||
|
// Szkielet tego pliku jest tworzony przez QtCreator
|
||||||
|
// Mozemy do niego dodac deklaracje wlasnych pol i metod
|
||||||
|
|
||||||
|
#ifndef MYWINDOW_H
|
||||||
|
#define MYWINDOW_H
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy QMainWindow,
|
||||||
|
// Klasa QMainWindow posiada swoj wlasny layout.
|
||||||
|
// latwo mozna do niej dodac pasek menu, widzety dokujace,
|
||||||
|
// pasek narzedzi i pasek statusu. Na srodku okna
|
||||||
|
// wyswietlanego przez QMainWindow znajduje sie obszar,
|
||||||
|
// ktory mozna wypelnic roznymi widgetami.
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
// QPainter to klasa umozliwiajaca niskopoziomowe rysowanie
|
||||||
|
// na elementach GUI
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
// QImage to klasa pozwalajaca na niezalezna od sprzetu reprezentacje obrazu.
|
||||||
|
// Pozwala na bezposredni dostep do poszczegolnych pikseli,
|
||||||
|
// Bedziemy jej uzywali do tworzenia i przechowywania
|
||||||
|
// naszych rysunkow
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
// QMouseEvent to klasa obslugujaca zdarzenia zwiazane z myszka
|
||||||
|
// klikniecia, ruch myszka itp.
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h> // for float,double macros
|
||||||
|
|
||||||
|
enum Mode {Line, Circle, Fill};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MyWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MyWindow jest podklasa klasy QMainWindow.
|
||||||
|
class MyWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
// Q_OBJECT jest to makro, ktore musi sie znajdowac
|
||||||
|
// we wszystkich klasach definiujacych wlasne sygnaly i sloty
|
||||||
|
// W naszej klasie nie jest ono potrzebne,
|
||||||
|
// ale QtCreator dodaje je automatycznie do kazdej klasy.
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Typowa deklaracja konstruktora w Qt.
|
||||||
|
// Parametr "parent" okresla rodzica komponenetu.
|
||||||
|
// W przypadku naszej klasy parametr ten wskazuje na null
|
||||||
|
// co oznacza, ze komponenet nie ma rodzica, jest to
|
||||||
|
// komponenet najwyzszego poziomu
|
||||||
|
explicit MyWindow(QWidget *parent = 0);
|
||||||
|
|
||||||
|
// Deklaracja destruktora
|
||||||
|
~MyWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// QtCreator pozwala na tworzenie GUI za pomoca graficznego kreatora.
|
||||||
|
// Skladniki interfejsu i ich wlasciwosci zapisane sa wowczas
|
||||||
|
// w pliku XML "nazwa_klasy.ui"
|
||||||
|
// Do poszczegolnych elementow GUI odwolujemy sie za pomoca zmiennej "ui"
|
||||||
|
Ui::MyWindow *ui;
|
||||||
|
|
||||||
|
Mode mode;
|
||||||
|
|
||||||
|
// Pole przechowujace obrazek
|
||||||
|
QImage *img;
|
||||||
|
|
||||||
|
QImage *loaded_img;
|
||||||
|
|
||||||
|
// Pole przechowujace obrazek
|
||||||
|
QImage *img_tmp;
|
||||||
|
|
||||||
|
QImage *active_img;
|
||||||
|
|
||||||
|
// Pola przechowujace szerokosc i wysokosc rysunku
|
||||||
|
// oraz wspolrzedne jego lewego gornego naroznika
|
||||||
|
int szer;
|
||||||
|
int wys;
|
||||||
|
int poczX;
|
||||||
|
int poczY;
|
||||||
|
int startX, startY;
|
||||||
|
bool draw_finished;
|
||||||
|
int segment_count;
|
||||||
|
|
||||||
|
float rotation_angle;
|
||||||
|
std::vector<float> scale_vec;
|
||||||
|
std::vector<float> translation_vec;
|
||||||
|
std::vector<float> sh_vec;
|
||||||
|
|
||||||
|
int tmp_point_id = 0;
|
||||||
|
int tmp_shape_id = 0;
|
||||||
|
|
||||||
|
// Deklaracje funkcji
|
||||||
|
void czysc();
|
||||||
|
void rysuj1();
|
||||||
|
void rysuj2();
|
||||||
|
|
||||||
|
|
||||||
|
void UpdateTempImage();
|
||||||
|
void ApplyTempImage();
|
||||||
|
|
||||||
|
void ClearImage(QImage *img);
|
||||||
|
void DrawB(int b);
|
||||||
|
void DrawR(int r);
|
||||||
|
void DrawG(int g);
|
||||||
|
void DrawH(float h);
|
||||||
|
void DrawS(float s);
|
||||||
|
void DrawV(float v);
|
||||||
|
|
||||||
|
QColor GetPixel(QImage* img, int x, int y);
|
||||||
|
void DrawPixel(QImage* img, int x, int y, QColor color);
|
||||||
|
QColor GetInterpolatedColor(float x, float y);
|
||||||
|
void UpdateImage();
|
||||||
|
|
||||||
|
// Deklaracje slotow, czyli funkcji wywolywanych
|
||||||
|
// po wystapieniu zdarzen zwiazanych z GUI
|
||||||
|
// np. klikniecie na przycisk, ruch myszka
|
||||||
|
private slots:
|
||||||
|
void on_exitButton_clicked();
|
||||||
|
void paintEvent(QPaintEvent*);
|
||||||
|
void on_slider_tx_valueChanged(int val);
|
||||||
|
void on_slider_ty_valueChanged(int val);
|
||||||
|
void on_slider_sx_valueChanged(int val);
|
||||||
|
void on_slider_sy_valueChanged(int val);
|
||||||
|
void on_slider_shx_valueChanged(int val);
|
||||||
|
void on_slider_shy_valueChanged(int val);
|
||||||
|
void on_slider_a_valueChanged(int val);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MYWINDOW_H
|
345
QT/2d-transformations/mywindow.ui
Normal file
345
QT/2d-transformations/mywindow.ui
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MyWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MyWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>883</width>
|
||||||
|
<height>583</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="mouseTracking">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MyWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<widget class="QFrame" name="rysujFrame">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="mouseTracking">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>630</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>241</width>
|
||||||
|
<height>421</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>Opcje</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="exitButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>30</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Wyjście</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_tx">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>120</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_ty">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>110</x>
|
||||||
|
<y>120</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_shx">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>120</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_sx">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>290</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_sy">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>110</x>
|
||||||
|
<y>290</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_shy">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>290</y>
|
||||||
|
<width>31</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>200</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TX</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>110</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TY</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SHX</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>250</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SX</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>110</x>
|
||||||
|
<y>250</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SY</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>190</x>
|
||||||
|
<y>250</y>
|
||||||
|
<width>41</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>25</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SHY</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_a">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>660</x>
|
||||||
|
<y>450</y>
|
||||||
|
<width>191</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>883</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
BIN
QT/2d-transformations/p.jpg
Normal file
BIN
QT/2d-transformations/p.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
QT/2d-transformations/p.png
Normal file
BIN
QT/2d-transformations/p.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
29
QT/2d-transformations/p.svg
Normal file
29
QT/2d-transformations/p.svg
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<svg width="506" height="86" viewBox="0 0 506 86" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M144 55.3119V69.1575H153.668V55.9167C153.668 54.6315 154.172 53.3895 155.085 52.4823C155.988 51.5751 157.223 51.0567 158.501 51.0567H168.416C173.035 51.0567 177.471 49.2099 180.737 45.9159C184.002 42.6327 185.839 38.1723 185.839 33.5284C185.839 28.8844 184.002 24.424 180.737 21.13C177.471 17.8468 173.035 16 168.405 16H144V33.3016H153.668V25.1476H167.761C169.952 25.1476 172.047 26.0224 173.593 27.5776C175.14 29.1328 176.01 31.2388 176.01 33.442C176.01 35.6452 175.14 37.7511 173.593 39.3063C172.047 40.8615 169.952 41.7363 167.761 41.7363H157.524C155.751 41.7363 153.99 42.0819 152.357 42.7731C150.714 43.4535 149.231 44.4579 147.974 45.7215C146.718 46.9851 145.729 48.4863 145.042 50.1279C144.354 51.7587 144 53.5299 144 55.3119Z" fill="#1B1340"/>
|
||||||
|
<path d="M187.332 69.1574V48.0651C187.332 39.4575 192.327 32.6103 202.328 32.6103C203.928 32.5887 205.529 32.7615 207.097 33.1395V41.8119C205.958 41.7363 204.981 41.7363 204.519 41.7363C199.223 41.7363 196.946 44.1771 196.946 49.1235V69.1574H187.332Z" fill="#1B1340"/>
|
||||||
|
<path d="M209.975 51.2728C209.975 40.6889 217.924 32.6213 228.988 32.6213C240.052 32.6213 248.001 40.6889 248.001 51.2728C248.001 61.8568 240.052 70 228.988 70C217.924 70 209.975 61.846 209.975 51.2728ZM238.527 51.2728C238.527 45.2573 234.51 40.9913 228.988 40.9913C223.456 40.9913 219.45 45.2465 219.45 51.2728C219.45 57.364 223.467 61.5544 228.988 61.5544C234.52 61.5544 238.527 57.3532 238.527 51.2728Z" fill="#1B1340"/>
|
||||||
|
<path d="M278.744 51.2728C278.744 40.6889 286.693 32.6213 297.757 32.6213C308.81 32.6213 316.759 40.6889 316.759 51.2728C316.759 61.8568 308.81 70 297.757 70C286.693 70 278.744 61.846 278.744 51.2728ZM307.285 51.2728C307.285 45.2573 303.268 40.9913 297.746 40.9913C292.225 40.9913 288.208 45.2465 288.208 51.2728C288.208 57.364 292.225 61.5544 297.746 61.5544C303.268 61.5544 307.285 57.3532 307.285 51.2728Z" fill="#1B1340"/>
|
||||||
|
<path d="M321.754 69.1576V48.8321C321.754 39.3929 327.738 32.6105 338.415 32.6105C349.017 32.6105 355 39.3821 355 48.8321V69.1576H345.461V49.5881C345.461 44.3393 343.109 41.0561 338.415 41.0561C333.721 41.0561 331.368 44.3285 331.368 49.5881V69.1576H321.754Z" fill="#1B1340"/>
|
||||||
|
<path d="M275.865 41.0663H265.489V54.3935C265.489 59.0375 267.154 61.1651 271.923 61.1651C272.374 61.1651 273.513 61.1651 274.952 61.0895V68.9303C272.987 69.4595 271.247 69.7727 269.345 69.7727C261.321 69.7727 255.864 64.9019 255.864 55.6895V41.0663H249.419V33.3768H251.031C251.664 33.3768 252.298 33.2472 252.878 33.0096C253.469 32.7612 253.995 32.4048 254.446 31.9512C254.898 31.4976 255.252 30.9684 255.499 30.3744C255.746 29.7804 255.864 29.154 255.864 28.5168V21.27H265.478V33.3768H275.855V41.0663H275.865Z" fill="#1B1340"/>
|
||||||
|
<path d="M374 17.3717H387.505L400.164 48.4366C401.292 51.0397 402.257 53.6969 403.071 56.4081H403.201C404.014 53.6969 404.98 51.0289 406.108 48.4366L418.767 17.3717H432.271V69.1754H422.487V34.4704C422.476 33.3254 422.531 32.1805 422.65 31.0463H422.487C422.183 32.2669 421.782 33.4658 421.272 34.6216L407.247 68.5705H399.133L385.064 34.6216C384.554 33.455 384.12 32.2669 383.773 31.0463H383.621C383.73 32.1805 383.784 33.3254 383.773 34.4704V69.1862H374V17.3717Z" fill="#6D4AFF"/>
|
||||||
|
<path d="M465.735 34.9997C468.566 36.4795 470.909 38.7478 472.482 41.5238C474.163 44.5374 475.009 47.9507 474.944 51.3963V69.1755H466.375L465.768 63.8396C464.65 65.773 463.012 67.35 461.038 68.4086C458.923 69.4995 456.558 70.0504 454.172 69.9964C451.124 70.0288 448.13 69.2187 445.516 67.6525C442.869 66.0539 440.721 63.7639 439.289 61.042C437.727 58.0392 436.946 54.7016 437.012 51.3207C436.968 47.9939 437.825 44.721 439.485 41.8262C441.112 39.0179 443.466 36.7064 446.318 35.1402C449.269 33.5091 452.588 32.6666 455.962 32.7098C459.357 32.645 462.719 33.4335 465.735 34.9997ZM462.6 58.9141C464.466 57.1427 465.388 54.6475 465.388 51.3207C465.507 48.5987 464.542 45.9416 462.72 43.9217C461.852 43.0144 460.81 42.3015 459.65 41.8046C458.489 41.3078 457.253 41.0593 455.994 41.0593C454.736 41.0593 453.489 41.3078 452.339 41.8046C451.178 42.3015 450.137 43.0144 449.269 43.9217C447.533 45.9956 446.579 48.6095 446.579 51.3099C446.579 54.0103 447.533 56.6242 449.269 58.6981C450.126 59.627 451.167 60.3507 452.339 60.8476C453.499 61.3336 454.758 61.5821 456.016 61.5497C457.231 61.5713 458.446 61.3444 459.585 60.8908C460.702 60.4479 461.732 59.7674 462.6 58.9141Z" fill="#6D4AFF"/>
|
||||||
|
<path d="M480.227 26.0777C479.652 25.5485 479.197 24.9112 478.882 24.1983C478.567 23.4854 478.415 22.7185 478.426 21.9408C478.415 21.1631 478.578 20.3854 478.882 19.6617C479.197 18.938 479.652 18.2899 480.227 17.7606C481.366 16.6373 482.906 16 484.512 16C486.117 16 487.657 16.6373 488.796 17.7606C489.371 18.3007 489.827 18.9488 490.13 19.6617C490.434 20.3854 490.597 21.1523 490.586 21.9408C490.597 22.7185 490.445 23.4854 490.13 24.1983C489.827 24.9112 489.371 25.5485 488.796 26.0777C487.646 27.1795 486.106 27.7952 484.512 27.7952C482.906 27.7952 481.377 27.1795 480.227 26.0777ZM489.339 69.1754H479.706V33.4767H489.339V69.1754Z" fill="#6D4AFF"/>
|
||||||
|
<path d="M506 69.1754H496.357V17.3717H506V69.1754Z" fill="#6D4AFF"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M83.4613 16.1551V86H95.0393C101.094 86 106 81.026 106 74.9015V2.47101C106 0.378398 103.596 -0.761032 102.003 0.575608L83.4613 16.1551Z" fill="url(#paint0_linear_11985_190892)"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M67.3128 29.7407L46.1604 48.6618C42.5538 51.8829 37.1709 51.9596 33.4777 48.848L0 20.6691V2.482C0 0.38939 2.40441 -0.760996 3.99653 0.575643L45.998 35.8761C50.0595 39.2944 55.9514 39.2944 60.0129 35.8761L67.3128 29.7407Z" fill="url(#paint1_linear_11985_190892)"/>
|
||||||
|
<path d="M83.4613 16.1661L67.3128 29.7407L67.3236 29.7406L46.1604 48.6618C42.5538 51.8829 37.1709 51.9596 33.4777 48.848L0 20.6691V74.9015C0 81.0259 4.9063 86 10.9607 86L83.4613 86V16.1661Z" fill="url(#paint2_radial_11985_190892)"/>
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="paint0_linear_11985_190892" x1="265.975" y1="141.754" x2="244.3" y2="-73.4041" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0.271" stop-color="#E3D9FF"/>
|
||||||
|
<stop offset="1" stop-color="#7341FF"/>
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient id="paint1_linear_11985_190892" x1="62.6346" y1="86.7984" x2="18.553" y2="-87.2799" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop stop-color="#E3D9FF"/>
|
||||||
|
<stop offset="1" stop-color="#7341FF"/>
|
||||||
|
</linearGradient>
|
||||||
|
<radialGradient id="paint2_radial_11985_190892" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(105.538 10.5272) scale(123.614 125.045)">
|
||||||
|
<stop offset="0.5561" stop-color="#6D4AFF"/>
|
||||||
|
<stop offset="0.9944" stop-color="#AA8EFF"/>
|
||||||
|
</radialGradient>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.5 KiB |
20
QT/alpha-blending/alpha-blending.pro
Normal file
20
QT/alpha-blending/alpha-blending.pro
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2015-03-03T00:14:51
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = alpha-blending
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
OUTPUT += Console
|
||||||
|
SOURCES += main.cpp\
|
||||||
|
mywindow.cpp
|
||||||
|
|
||||||
|
HEADERS += mywindow.h
|
||||||
|
|
||||||
|
FORMS += mywindow.ui
|
BIN
QT/alpha-blending/f.png
Normal file
BIN
QT/alpha-blending/f.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
33
QT/alpha-blending/main.cpp
Normal file
33
QT/alpha-blending/main.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Glowny plik aplikacji, utworzony automatycznie przez QtCreator
|
||||||
|
// W wiekszosci przypadkow nie musimy tu nic zmieniac
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy QApplication
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy glownego widgetu (okna) aplikacji
|
||||||
|
#include "mywindow.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
|
||||||
|
// Tworzymy objekt QApplication. Zarzadza on zasobami calej aplikacji
|
||||||
|
// i jest niezbedny do stworzenia jakiejkolwiek aplikacji Qt posiadajacej GUI.
|
||||||
|
// Przekazujemy mu dwa argumenty argc i argv, poniewaz Qt moze rowniez
|
||||||
|
// przyjmowac argumenty z linii komend.
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
// Tworzymy obiekt klasy MyWindow - glownego okna naszej aplikacji.
|
||||||
|
// Jest to klasa zdefiniowana przez nas.
|
||||||
|
// Jej definicja znajduje sie w plikach mainwindow.h i mainwindow.cpp
|
||||||
|
MyWindow w;
|
||||||
|
|
||||||
|
// w.setMouseTracking(true);
|
||||||
|
// Pokazujemy glowne okno aplikacji na ekranie. Domyslnie jest ono niewidoczne.
|
||||||
|
// Wszystkie widgety (elementy GUI) zawarte w glownym oknie beda rowniez widoczne.
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
// Przekazujemy kontrole nad aplikacja do Qt. Program wchodzi w petle zdarzen
|
||||||
|
// tzn. zaczyna oczekiwac na akcje uzytkownika - klikniecia przycisku myszy,
|
||||||
|
// lub klawisza klawiatury itp.
|
||||||
|
return a.exec();
|
||||||
|
}
|
303
QT/alpha-blending/mywindow.cpp
Normal file
303
QT/alpha-blending/mywindow.cpp
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
// Dolaczamy plik naglowkowy naszej klasy MyWindow
|
||||||
|
#include "mywindow.h"
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy zawierajacy definicje GUI
|
||||||
|
// Plik ten jest generowany automatycznie
|
||||||
|
// z pliku XML "mywindow.ui"
|
||||||
|
#include "ui_mywindow.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <iostream>
|
||||||
|
#include <float.h> // for float,double macros
|
||||||
|
#include <string.h>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define PI 3.1415
|
||||||
|
|
||||||
|
std::vector<float> matrixMul(std::vector<float> p, std::vector<float> m)
|
||||||
|
{
|
||||||
|
std::vector<float> res(3);
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
res.push_back(0);
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
res[i] += m[i * 3 + j] * p[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> matrixMul3x3(std::vector<float> m1, std::vector<float> m2)
|
||||||
|
{
|
||||||
|
std::vector<float> res(9, 0);
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < 3; k++)
|
||||||
|
{
|
||||||
|
res[i * 3 + j] += m1[i * 3 + k] * m2[k * 3 + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor mul(float v, QColor c){
|
||||||
|
int red = (int)(c.red() * v);
|
||||||
|
if(red > 255) red = 255;
|
||||||
|
int green = (int)(c.green() * v);
|
||||||
|
if(green > 255) green = 255;
|
||||||
|
int blue = (int)(c.blue() * v);
|
||||||
|
if(blue > 255) blue = 255;
|
||||||
|
return QColor(red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor add(QColor c1, QColor c2){
|
||||||
|
int red = (int)(c1.red() + c2.red());
|
||||||
|
if(red > 255) red = 255;
|
||||||
|
int green = (int)(c1.green() + c2.green());
|
||||||
|
if(green > 255) green = 255;
|
||||||
|
int blue = (int)(c1.blue() + c2.blue());
|
||||||
|
if(blue > 255) blue = 255;
|
||||||
|
return QColor(red, green, blue);
|
||||||
|
}
|
||||||
|
// Definicja konstruktora, wywolujemy najpierw
|
||||||
|
// konstruktor klasy nadrzednej, nastepnie tworzymy
|
||||||
|
// obiekt klasy Ui_MyWindow reprezentujacy GUI
|
||||||
|
MyWindow::MyWindow(QWidget *parent) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
ui(new Ui::MyWindow)
|
||||||
|
{
|
||||||
|
// Wywolujemy funkcje tworzaca elementy GUI
|
||||||
|
// Jej definicja znajduje sie w pliku "ui_mywindow.h"
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Pobieramy wymiary i wspolrzedne lewego gornego naroznika ramki
|
||||||
|
// i ustawiamy wartosci odpowiednich pol
|
||||||
|
// Uwaga: ramke "rysujFrame" wykorzystujemy tylko do
|
||||||
|
// wygodnego ustaiwenia tych wymiarow. Rysunek bedziemy wyswietlac
|
||||||
|
// bezposrednio w glownym oknie aplikacji.
|
||||||
|
szer = ui->rysujFrame->width();
|
||||||
|
wys = ui->rysujFrame->height();
|
||||||
|
poczX = ui->rysujFrame->x();
|
||||||
|
poczY = ui->rysujFrame->y();
|
||||||
|
|
||||||
|
// Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci
|
||||||
|
// i wysokosci. Ustawiamy format bitmapy na 32 bitowe RGB
|
||||||
|
// (0xffRRGGBB).
|
||||||
|
img = new QImage(szer,wys,QImage::Format_RGB32);
|
||||||
|
|
||||||
|
loaded_img1 = new QImage("/Users/dawidpietrykowski/Desktop/projects/umk/GK/QT/alpha-blending/p.png");
|
||||||
|
loaded_img2 = new QImage("/Users/dawidpietrykowski/Desktop/projects/umk/GK/QT/alpha-blending/f.png");
|
||||||
|
|
||||||
|
rotation_angle = 0;
|
||||||
|
|
||||||
|
|
||||||
|
UpdateImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definicja destruktora
|
||||||
|
MyWindow::~MyWindow()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funkcja (slot) wywolywana po nacisnieciu przycisku "Wyjscie" (exitButton)
|
||||||
|
// Uwaga: polaczenie tej funkcji z sygnalem "clicked"
|
||||||
|
// emitowanym przez przycisk jest realizowane
|
||||||
|
// za pomoca funkcji QMetaObject::connectSlotsByName(MyWindow)
|
||||||
|
// znajdujacej sie w automatycznie generowanym pliku "ui_mywindow.h"
|
||||||
|
// Nie musimy wiec sami wywolywac funkcji "connect"
|
||||||
|
void MyWindow::on_exitButton_clicked()
|
||||||
|
{
|
||||||
|
// qApp to globalny wskaznik do obiektu reprezentujacego aplikacje
|
||||||
|
// quit() to funkcja (slot) powodujaca zakonczenie aplikacji z kodem 0 (brak bledu)
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_mode_valueChanged(int val){
|
||||||
|
mode = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::on_slider_a_valueChanged(int val){
|
||||||
|
alpha = (float) val / 100.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor Normal(QColor c1, QColor c2){
|
||||||
|
return c2;
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Multiply(QColor c1, QColor c2){
|
||||||
|
return QColor(
|
||||||
|
(c1.red() * c2.red()) >> 8,
|
||||||
|
(c1.green() * c2.green()) >> 8,
|
||||||
|
(c1.blue() * c2.blue()) >> 8,
|
||||||
|
(c1.alpha() * c2.alpha()) >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Screen(QColor c1, QColor c2){
|
||||||
|
return QColor(
|
||||||
|
255 - (((255 - c1.red()) * (255 - c2.red())) >> 8),
|
||||||
|
255 - (((255 - c1.green()) * (255 - c2.green())) >> 8),
|
||||||
|
255 - (((255 - c1.blue()) * (255 - c2.blue())) >> 8),
|
||||||
|
255 - (((255 - c1.alpha()) * (255 - c2.alpha())) >> 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Overlay(QColor c1, QColor c2){
|
||||||
|
int r = c1.red() < 128 ? (c1.red() * c2.red()) >> 7 : 255 - (((255 - c1.red()) * (255 - c2.red())) >> 7);
|
||||||
|
int g = c1.green() < 128 ? (c1.green() * c2.green()) >> 7 : 255 - (((255 - c1.green()) * (255 - c2.green())) >> 7);
|
||||||
|
int b = c1.blue() < 128 ? (c1.blue() * c2.blue()) >> 7 : 255 - (((255 - c1.blue()) * (255 - c2.blue())) >> 7);
|
||||||
|
int a = c1.alpha() < 128 ? (c1.alpha() * c2.alpha()) >> 7 : 255 - (((255 - c1.alpha()) * (255 - c2.alpha())) >> 7);
|
||||||
|
return QColor(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Darken(QColor c1, QColor c2){
|
||||||
|
int r = c1.red() < c2.red() ? c1.red() : c2.red();
|
||||||
|
int g = c1.green() < c2.green() ? c1.green() : c2.green();
|
||||||
|
int b = c1.blue() < c2.blue() ? c1.blue() : c2.blue();
|
||||||
|
int a = c1.alpha() < c2.alpha() ? c1.alpha() : c2.alpha();
|
||||||
|
return QColor(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Lighten(QColor c1, QColor c2){
|
||||||
|
int r = c1.red() > c2.red() ? c1.red() : c2.red();
|
||||||
|
int g = c1.green() > c2.green() ? c1.green() : c2.green();
|
||||||
|
int b = c1.blue() > c2.blue() ? c1.blue() : c2.blue();
|
||||||
|
int a = c1.alpha() > c2.alpha() ? c1.alpha() : c2.alpha();
|
||||||
|
return QColor(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Blend(QColor c1, QColor c2, float a, int p){
|
||||||
|
switch (p) {
|
||||||
|
case 0:
|
||||||
|
return add(mul(a, Normal(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
return add(mul(a, Multiply(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return add(mul(a, Screen(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
return add(mul(a, Overlay(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
return add(mul(a, Darken(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
return add(mul(a, Lighten(c1, c2)), mul((1.0f - a), c1));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWindow::UpdateImage(){
|
||||||
|
for(int x = 0; x < szer; x++)
|
||||||
|
for(int y = 0; y < wys; y++){
|
||||||
|
float xw = (float) x / (float)szer;
|
||||||
|
float yh = (float) y / (float) wys;
|
||||||
|
DrawPixel(img, x, y,
|
||||||
|
Blend(GetInterpolatedColor(loaded_img1, xw, yh),
|
||||||
|
GetInterpolatedColor(loaded_img2, xw, yh), alpha, mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor MyWindow::GetPixel(QImage* img, int x, int y){
|
||||||
|
QColor res;
|
||||||
|
int width = img->width();
|
||||||
|
int height = img->height();
|
||||||
|
if(x >= width || y >= height || x < 0 || y < 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
|
||||||
|
res.setBlue(ptr[width*4*y + 4*x]);
|
||||||
|
res.setGreen(ptr[width*4*y + 4*x + 1]);
|
||||||
|
res.setRed(ptr[width*4*y + 4*x + 2]);
|
||||||
|
res.setAlpha(ptr[width*4*y + 4*x + 3]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor MyWindow::GetInterpolatedColor(QImage* img, float x, float y){
|
||||||
|
float width = img->width();
|
||||||
|
float height = img->height();
|
||||||
|
float xw = (x * width);
|
||||||
|
float yw = (y * height);
|
||||||
|
int x_f = (int) (x * width);
|
||||||
|
int y_f = (int) (y * height);
|
||||||
|
int x_c = ceil(x * width);
|
||||||
|
int y_c = ceil(y * height);
|
||||||
|
float a = (xw - (float) x_f);
|
||||||
|
float b = ((yw) - (float) y_f);
|
||||||
|
|
||||||
|
QColor P1 = GetPixel(img, x_f, y_c);
|
||||||
|
QColor P2 = GetPixel(img, x_c, y_c);
|
||||||
|
QColor P3 = GetPixel(img, x_c, y_f);
|
||||||
|
QColor P4 = GetPixel(img, x_f, y_f);
|
||||||
|
|
||||||
|
QColor v1 = mul(1.0f - a, P1);
|
||||||
|
QColor v2 = mul(a, P2);
|
||||||
|
QColor v3 = mul(a, P3);
|
||||||
|
QColor v4 = mul(1.0f - a, P4);
|
||||||
|
QColor top = add(v1, v2);
|
||||||
|
QColor bottom = add(v3, v4);
|
||||||
|
QColor btop = mul(b, top);
|
||||||
|
QColor bbottom = mul(1.0f - b, bottom);
|
||||||
|
QColor res = add(btop, bbottom);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funkcja "odmalowujaca" komponent
|
||||||
|
void MyWindow::paintEvent(QPaintEvent*)
|
||||||
|
{
|
||||||
|
// Obiekt klasy QPainter pozwala nam rysowac na komponentach
|
||||||
|
QPainter p(this);
|
||||||
|
|
||||||
|
|
||||||
|
UpdateImage();
|
||||||
|
// Rysuje obrazek "img" w punkcie (poczX,poczY)
|
||||||
|
// (tu bedzie lewy gorny naroznik)
|
||||||
|
p.drawImage(poczX,poczY,*img);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyWindow::DrawPixel(QImage* img, int x, int y, QColor color){
|
||||||
|
if(x >= szer || y >= wys || x < 0 || y < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
|
||||||
|
ptr[szer*4*y + 4*x] = color.blue();
|
||||||
|
ptr[szer*4*y + 4*x + 1] = color.green();
|
||||||
|
ptr[szer*4*y + 4*x + 2] = color.red();
|
||||||
|
ptr[szer*4*y + 4*x + 3] = color.alpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyWindow::ClearImage(QImage *img){
|
||||||
|
unsigned char* empty_val = (unsigned char*)malloc(4);
|
||||||
|
empty_val[0] = 0;
|
||||||
|
empty_val[1] = 0;
|
||||||
|
empty_val[2] = 0;
|
||||||
|
empty_val[3] = 255;
|
||||||
|
unsigned char* ptr = img->bits();
|
||||||
|
for(int i = 0; i < img->width(); i++){
|
||||||
|
for(int j = 0; j < img->height(); j++){
|
||||||
|
memcpy(ptr + 4 * (i + j * img->width()), empty_val, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
126
QT/alpha-blending/mywindow.h
Normal file
126
QT/alpha-blending/mywindow.h
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
// Plik naglowkowy klasy MyWindow
|
||||||
|
// Obiekt tej klasy to glowne okno naszej aplikacji
|
||||||
|
// Szkielet tego pliku jest tworzony przez QtCreator
|
||||||
|
// Mozemy do niego dodac deklaracje wlasnych pol i metod
|
||||||
|
|
||||||
|
#ifndef MYWINDOW_H
|
||||||
|
#define MYWINDOW_H
|
||||||
|
|
||||||
|
// Dolaczamy plik naglowkowy klasy QMainWindow,
|
||||||
|
// Klasa QMainWindow posiada swoj wlasny layout.
|
||||||
|
// latwo mozna do niej dodac pasek menu, widzety dokujace,
|
||||||
|
// pasek narzedzi i pasek statusu. Na srodku okna
|
||||||
|
// wyswietlanego przez QMainWindow znajduje sie obszar,
|
||||||
|
// ktory mozna wypelnic roznymi widgetami.
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
// QPainter to klasa umozliwiajaca niskopoziomowe rysowanie
|
||||||
|
// na elementach GUI
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
// QImage to klasa pozwalajaca na niezalezna od sprzetu reprezentacje obrazu.
|
||||||
|
// Pozwala na bezposredni dostep do poszczegolnych pikseli,
|
||||||
|
// Bedziemy jej uzywali do tworzenia i przechowywania
|
||||||
|
// naszych rysunkow
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
// QMouseEvent to klasa obslugujaca zdarzenia zwiazane z myszka
|
||||||
|
// klikniecia, ruch myszka itp.
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h> // for float,double macros
|
||||||
|
|
||||||
|
enum Mode {Line, Circle, Fill};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MyWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MyWindow jest podklasa klasy QMainWindow.
|
||||||
|
class MyWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
// Q_OBJECT jest to makro, ktore musi sie znajdowac
|
||||||
|
// we wszystkich klasach definiujacych wlasne sygnaly i sloty
|
||||||
|
// W naszej klasie nie jest ono potrzebne,
|
||||||
|
// ale QtCreator dodaje je automatycznie do kazdej klasy.
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Typowa deklaracja konstruktora w Qt.
|
||||||
|
// Parametr "parent" okresla rodzica komponenetu.
|
||||||
|
// W przypadku naszej klasy parametr ten wskazuje na null
|
||||||
|
// co oznacza, ze komponenet nie ma rodzica, jest to
|
||||||
|
// komponenet najwyzszego poziomu
|
||||||
|
explicit MyWindow(QWidget *parent = 0);
|
||||||
|
|
||||||
|
// Deklaracja destruktora
|
||||||
|
~MyWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// QtCreator pozwala na tworzenie GUI za pomoca graficznego kreatora.
|
||||||
|
// Skladniki interfejsu i ich wlasciwosci zapisane sa wowczas
|
||||||
|
// w pliku XML "nazwa_klasy.ui"
|
||||||
|
// Do poszczegolnych elementow GUI odwolujemy sie za pomoca zmiennej "ui"
|
||||||
|
Ui::MyWindow *ui;
|
||||||
|
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
// Pole przechowujace obrazek
|
||||||
|
QImage *img;
|
||||||
|
|
||||||
|
QImage *loaded_img1;
|
||||||
|
QImage *loaded_img2;
|
||||||
|
|
||||||
|
// Pole przechowujace obrazek
|
||||||
|
QImage *img_tmp;
|
||||||
|
|
||||||
|
QImage *active_img;
|
||||||
|
|
||||||
|
// Pola przechowujace szerokosc i wysokosc rysunku
|
||||||
|
// oraz wspolrzedne jego lewego gornego naroznika
|
||||||
|
int szer;
|
||||||
|
int wys;
|
||||||
|
int poczX;
|
||||||
|
int poczY;
|
||||||
|
int startX, startY;
|
||||||
|
bool draw_finished;
|
||||||
|
int segment_count;
|
||||||
|
float alpha;
|
||||||
|
|
||||||
|
float rotation_angle;
|
||||||
|
std::vector<float> scale_vec;
|
||||||
|
std::vector<float> translation_vec;
|
||||||
|
std::vector<float> sh_vec;
|
||||||
|
|
||||||
|
int tmp_point_id = 0;
|
||||||
|
int tmp_shape_id = 0;
|
||||||
|
|
||||||
|
// Deklaracje funkcji
|
||||||
|
void czysc();
|
||||||
|
void rysuj1();
|
||||||
|
void rysuj2();
|
||||||
|
|
||||||
|
|
||||||
|
void UpdateTempImage();
|
||||||
|
void ApplyTempImage();
|
||||||
|
|
||||||
|
void ClearImage(QImage *img);
|
||||||
|
|
||||||
|
QColor GetPixel(QImage* img, int x, int y);
|
||||||
|
void DrawPixel(QImage* img, int x, int y, QColor color);
|
||||||
|
QColor GetInterpolatedColor(QImage* img, float x, float y);
|
||||||
|
void UpdateImage();
|
||||||
|
|
||||||
|
// Deklaracje slotow, czyli funkcji wywolywanych
|
||||||
|
// po wystapieniu zdarzen zwiazanych z GUI
|
||||||
|
// np. klikniecie na przycisk, ruch myszka
|
||||||
|
private slots:
|
||||||
|
void on_exitButton_clicked();
|
||||||
|
void paintEvent(QPaintEvent*);
|
||||||
|
void on_slider_mode_valueChanged(int val);
|
||||||
|
void on_slider_a_valueChanged(int val);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MYWINDOW_H
|
205
QT/alpha-blending/mywindow.ui
Normal file
205
QT/alpha-blending/mywindow.ui
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MyWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MyWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>883</width>
|
||||||
|
<height>583</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="mouseTracking">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MyWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<widget class="QFrame" name="rysujFrame">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>100</width>
|
||||||
|
<height>100</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="mouseTracking">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>630</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>241</width>
|
||||||
|
<height>201</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>Opcje</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="exitButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Wyjście</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_mode">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>191</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="pageStep">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QSlider" name="slider_a">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>140</y>
|
||||||
|
<width>191</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Normal</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>50</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Multiply</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>100</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Screen</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>140</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Overlay</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>180</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Darken</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>100</x>
|
||||||
|
<y>170</y>
|
||||||
|
<width>58</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Alpha</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>883</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
BIN
QT/alpha-blending/p.png
Normal file
BIN
QT/alpha-blending/p.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
Loading…
Reference in New Issue
Block a user