Updated fileheaders and styled files using astyle.

This commit is contained in:
t-moe
2015-06-08 11:00:52 +02:00
parent 7e61a129a3
commit fceb2d15b2
63 changed files with 6045 additions and 4691 deletions

View File

@@ -1,3 +1,29 @@
/**************************************************************************************************************************************
* Project: discoverpixy
* Website: https://github.com/t-moe/discoverpixy
* Authors: Aaron Schmocker, Timo Lang
* Institution: BFH Bern University of Applied Sciences
* File: emulator/qt/mainwindow.cpp
*
* Version History:
* Date Autor Email SHA Changes
* 2015-04-03 timolang@gmail.com 51089aa Refactored Project Structure for use with emulator
* 2015-04-03 timolang@gmail.com 1f2af9f Added more tft functions to common and emulator. Fixed eventloop.
* 2015-04-03 timolang@gmail.com c570bda Fixed bug in color conversion
* 2015-04-03 timolang@gmail.com 867f766 Some gui changes.
* 2015-04-03 timolang@gmail.com 1aa9194 Fixed Drawing of rects in Emulator. Got frames from pixy to emulator. Slooooow.
* 2015-04-04 timolang@gmail.com 0636381 Improved tff_draw_bitmap_unscaled in emulator.
* 2015-04-27 timolang@gmail.com 259d446 Added touch support to emulator. Implemented basic touch function.
* 2015-04-27 aaron@duckpond.ch aed90ef Drawcircle added (emulator)
* 2015-04-27 timolang@gmail.com e249fb2 Added font support
* 2015-05-09 timolang@gmail.com c652b6b Improved Emulator Gui
* 2015-05-25 timolang@gmail.com 911760e Added "Mouse Position"-Label to Emulator.
* 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
* 2015-06-07 timolang@gmail.com 4b5768c Improved Comments in whole emulator. Finalized emulator section in docu.
* 2015-06-07 timolang@gmail.com 8752356 Started with tests in docu. fixed a small bug in emulator when drawing a rectangle.
*
**************************************************************************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
@@ -6,33 +32,36 @@
#include <QMouseEvent>
extern "C" {
#include "touch.h"
#include "tft.h"
#include "touch.h"
#include "tft.h"
}
#define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240
//function to calculate QColor out of a RGB565 16bit color
QColor QColorFromRGB565(uint16_t color) {
QColor QColorFromRGB565(uint16_t color)
{
//interpolate colors
int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5);
int G8 = (int) floor( ((color>>5)&0x3F) * 255.0 / 63.0 + 0.5);
int B8 = (int) floor( (color&0x1F) * 255.0 / 31.0 + 0.5);
return QColor::fromRgb(R8,G8,B8);
int R8 = (int) floor((color >> (5 + 6)) * 255.0 / 31.0 + 0.5);
int G8 = (int) floor(((color >> 5) & 0x3F) * 255.0 / 63.0 + 0.5);
int B8 = (int) floor((color & 0x1F) * 255.0 / 31.0 + 0.5);
return QColor::fromRgb(R8, G8, B8);
}
//function to calculate QRgb out of a RGB565 16bit color
QRgb QRgbFromRGB565(uint16_t color) {
QRgb QRgbFromRGB565(uint16_t color)
{
//interpolate colors
int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5);
int G8 = (int) floor( ((color>>5)&0x3F) * 255.0 / 63.0 + 0.5);
int B8 = (int) floor( (color&0x1F) * 255.0 / 31.0 + 0.5);
return qRgb(R8,G8,B8);
int R8 = (int) floor((color >> (5 + 6)) * 255.0 / 31.0 + 0.5);
int G8 = (int) floor(((color >> 5) & 0x3F) * 255.0 / 63.0 + 0.5);
int B8 = (int) floor((color & 0x1F) * 255.0 / 31.0 + 0.5);
return qRgb(R8, G8, B8);
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), image(DISPLAY_WIDTH,DISPLAY_HEIGHT, QImage::Format_RGB16), ui(new Ui::MainWindow){
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), image(DISPLAY_WIDTH, DISPLAY_HEIGHT, QImage::Format_RGB16), ui(new Ui::MainWindow)
{
ui->setupUi(this);
image.fill(Qt::black); //clear display buffer
currentScale = 1; //start with scale factor 1
@@ -44,13 +73,13 @@ void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, u
{
QPainter painter(&(image));
painter.setPen(QColorFromRGB565(color));
painter.drawLine(x1,y1,x2,y2);
painter.drawLine(x1, y1, x2, y2);
update();
}
void MainWindow::draw_pixel(uint16_t x, uint16_t y, uint16_t color)
{
image.setPixel(x,y,QRgbFromRGB565(color));
image.setPixel(x, y, QRgbFromRGB565(color));
update();
}
@@ -64,31 +93,32 @@ void MainWindow::draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t
{
QPainter painter(&(image));
painter.setPen(QColorFromRGB565(color));
painter.drawRect(qMin(x1,x2),qMin(y1,y2),abs((int)x2-(int)x1),abs((int)y2-(int)y1));
painter.drawRect(qMin(x1, x2), qMin(y1, y2), abs((int)x2 - (int)x1), abs((int)y2 - (int)y1));
update();
}
void MainWindow::fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
QPainter painter(&(image));
painter.fillRect(qMin(x1,x2),qMin(y1,y2),abs((int)x2-(int)x1)+1,abs((int)y2-(int)y1)+1,QColorFromRGB565(color));
painter.fillRect(qMin(x1, x2), qMin(y1, y2), abs((int)x2 - (int)x1) + 1, abs((int)y2 - (int)y1) + 1, QColorFromRGB565(color));
update();
}
void MainWindow::draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat)
void MainWindow::draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat)
{
//Creating a new image and access it directly is faster than setPixel
QImage img(width,height,QImage::Format_RGB32); //create a new image
QImage img(width, height, QImage::Format_RGB32); //create a new image
for(int yi=0; yi<height; yi++) { //for each line
for (int yi = 0; yi < height; yi++) { //for each line
uint32_t* line = (uint32_t*)img.scanLine(yi); //get the pointer to the imagedata of the current line
for(int xi=0; xi<width; xi++) { //for each column
*line++=QRgbFromRGB565(dat[yi*width+xi]); //set pixel
for (int xi = 0; xi < width; xi++) { //for each column
*line++ = QRgbFromRGB565(dat[yi * width + xi]); //set pixel
}
}
QPainter p(&image);
p.drawImage(x,y,img); //draw created image
p.drawImage(x, y, img); //draw created image
update();
}
@@ -96,7 +126,7 @@ void MainWindow::draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
{
QPainter painter(&(image));
painter.setPen(QColorFromRGB565(color));
painter.drawEllipse(QPoint(x,y), r, r);
painter.drawEllipse(QPoint(x, y), r, r);
update();
}
@@ -105,67 +135,70 @@ void MainWindow::draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgco
QPainter painter(&(image));
painter.setFont(font);
if(bgcolor!=TRANSPARENT) { //background color is not transparent
painter.setBackgroundMode(Qt::OpaqueMode);
painter.setBackground(QColorFromRGB565(bgcolor)); //set text background
if (bgcolor != TRANSPARENT) { //background color is not transparent
painter.setBackgroundMode(Qt::OpaqueMode);
painter.setBackground(QColorFromRGB565(bgcolor)); //set text background
}
painter.setPen(QColorFromRGB565(color)); //set fontcolor
y+=QFontMetrics(font).ascent(); //use y pos as highest point of char, instead of baseline
painter.drawText(QPoint(x,y), QString(QChar(c))); //draw char
y += QFontMetrics(font).ascent(); //use y pos as highest point of char, instead of baseline
painter.drawText(QPoint(x, y), QString(QChar(c))); //draw char
update();
}
void MainWindow::paintEvent(QPaintEvent *)
void MainWindow::paintEvent(QPaintEvent*)
{
//this method is called whenever the window needs to be redrawn (or after update() is called)
QPainter painter(this);
//this method is called whenever the window needs to be redrawn (or after update() is called)
QPainter painter(this);
//Create a QRectF which represents the rectangle to draw the buffered image to
QRectF imgRect (ui->widgetDisplay->geometry().topLeft(),QSizeF(DISPLAY_WIDTH*currentScale,DISPLAY_HEIGHT*currentScale));
//Create a QRectF which represents the rectangle to draw the buffered image to
QRectF imgRect(ui->widgetDisplay->geometry().topLeft(), QSizeF(DISPLAY_WIDTH * currentScale, DISPLAY_HEIGHT * currentScale));
painter.drawImage(imgRect,image); //draw buffer
painter.setPen(QPen(Qt::green,2)); //set border color
painter.drawRect(imgRect.adjusted(-1,-1,1,1)); //draw border
painter.drawImage(imgRect, image); //draw buffer
painter.setPen(QPen(Qt::green, 2)); //set border color
painter.drawRect(imgRect.adjusted(-1, -1, 1, 1)); //draw border
}
void MainWindow::mousePressEvent(QMouseEvent *evt)
void MainWindow::mousePressEvent(QMouseEvent* evt)
{
//the mouse was pressed
checkAndSendEvent(evt->pos(),true);
checkAndSendEvent(evt->pos(), true);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *evt)
void MainWindow::mouseReleaseEvent(QMouseEvent* evt)
{
//the mouse was released
checkAndSendEvent(evt->pos(),false);
checkAndSendEvent(evt->pos(), false);
}
void MainWindow::mouseMoveEvent(QMouseEvent *evt)
void MainWindow::mouseMoveEvent(QMouseEvent* evt)
{
//the mouse was released
checkAndSendEvent(evt->pos(),true);
checkAndSendEvent(evt->pos(), true);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *evt)
bool MainWindow::eventFilter(QObject* obj, QEvent* evt)
{
if(obj==ui->widgetDisplay) { //we received a redirect event from the target rectangle
switch(evt->type()) {
case QEvent::MouseMove: //it's a mouse move event
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(evt); //get mouse event
QPoint p = (mouseEvent->pos()-QPoint(1,1))/currentScale; //calculate correct corrdinates (undo scale)
if(p.x()<DISPLAY_WIDTH && p.y()<DISPLAY_HEIGHT) { //mouse position not out of bounds
//set mouse position text
ui->txtMousePos->setText(QString("Mouse Position: (%1,%2)").arg(p.x()).arg(p.y()));
}
if (obj == ui->widgetDisplay) { //we received a redirect event from the target rectangle
switch (evt->type()) {
case QEvent::MouseMove: { //it's a mouse move event
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(evt); //get mouse event
QPoint p = (mouseEvent->pos() - QPoint(1, 1)) / currentScale; //calculate correct corrdinates (undo scale)
if (p.x() < DISPLAY_WIDTH && p.y() < DISPLAY_HEIGHT) { //mouse position not out of bounds
//set mouse position text
ui->txtMousePos->setText(QString("Mouse Position: (%1,%2)").arg(p.x()).arg(p.y()));
}
break;
default: break;
}
}
return false;
break;
default:
break;
}
}
return false;
}
@@ -177,15 +210,18 @@ MainWindow::~MainWindow()
void MainWindow::checkAndSendEvent(QPoint pos, bool down)
{
QPoint p = pos - ui->widgetDisplay->geometry().topLeft(); //make coordinate relative to target area (0,0)
p/=currentScale; //undo scaling
if(p.x()<0 || p.y()<0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) return; //abort if out of bounds
p /= currentScale; //undo scaling
touch_add_raw_event(p.x(),p.y(),down?TOUCH_DOWN:TOUCH_UP); //submit touch event to touch module (common)
if (p.x() < 0 || p.y() < 0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) {
return; //abort if out of bounds
}
touch_add_raw_event(p.x(), p.y(), down ? TOUCH_DOWN : TOUCH_UP); //submit touch event to touch module (common)
}
void MainWindow::on_cboZoom_currentIndexChanged(int index)
{
currentScale=index+1; //zoom factor 1 is the 0th entry, zoom factor 2 is the 1st entry, zoom factor 3 is the 2nd entry
currentScale = index + 1; //zoom factor 1 is the 0th entry, zoom factor 2 is the 1st entry, zoom factor 3 is the 2nd entry
update(); //force redraw
}