void tft_t::rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c) { if (!h || !w) return; uint16_t yt, bMask; if (!transform()) goto disp; if (!portrait()) { swap(x, y); swap(w, h); } yt = vsTransformBack(y); if ((int16_t)yt < (int16_t)topEdge() && \ (int16_t)(yt + h) >= (int16_t)topEdge()) { // Top edge clipping h -= topEdge() - yt; y = upperEdge(); yt = vsTransformBack(y); } else if (yt < bottomEdge() && yt + h >= bottomEdge()) // Bottom edge clipping h = bottomEdge() - yt; if (y + h > bottomEdge()) // Transform edge split if (y < bottomEdge()) { if (!portrait()) { rectangle(y, x, bottomEdge() - y, w, c); rectangle(topEdge(), x, h - (bottomEdge() - y), w, c); } else { rectangle(x, y, w, bottomEdge() - y, c); rectangle(x, topEdge(), w, h - (bottomEdge() - y), c); } return; } if (yt < topMask()) { if (yt + h < topMask()) return; h -= topMask() - yt; y = vsTransform(topMask()); } bMask = vsMaximum() - bottomMask(); if (yt >= bMask) return; if (yt + h > bMask) h -= yt + h - bMask; if (!portrait()) { area(y, x, h, w); goto draw; } disp: area(x, y, w, h); draw: start(); while (h--) for (uint16_t xx = 0; xx < w; xx++) write16(c); }
// Alternative initialization routine that sets the orientation // of the screen. By default the orientation is Portrait. void Canvas::init(int mode){ this->init(); if(mode = TFT_PORTRAIT) portrait(); if(mode = TFT_LANDSCAPE) landscape(); }
void tft_t::putch(char ch) { #ifndef NO_CHECK if ((int16_t)x() >= (int16_t)width() || (int16_t)y() >= (int16_t)height()) return; #endif if ((int16_t)(x() + FONT_WIDTH * zoom()) < 0) return; uint8_t h = FONT_HEIGHT * zoom(), w = FONT_WIDTH * zoom(); // Display coordinate, start coordinate uint16_t xx = x(), x0 = x(); uint16_t yy = y(), y0 = y(); uint8_t xStart = 0, xStop = w; uint8_t yStart = 0, yStop = h; #if 1 if (transform()) { if (!portrait()) { yy = xx; y0 = x0; yStop = xStop; swap(w, h); } uint16_t yt = vsTransformBack(yy); if ((int16_t)yt < (int16_t)topEdge() && \ (int16_t)(yt + h) >= (int16_t)topEdge()) { // Top edge clipping yStart = topEdge() - yt; yy = upperEdge(); y0 = yy - yStart; yt = vsTransformBack(yy); } else if (yt < bottomEdge() && yt + h >= bottomEdge()) // Bottom edge clipping yStop = bottomEdge() - yt; if (yt < topMask()) { if (yt + yStop - yStart < topMask()) return; yy = vsTransform(topMask()); yStart += topMask() - yt; y0 = yy - yStart; } uint16_t bMask = vsMaximum() - bottomMask(); if (yt >= bMask) return; if (yt + yStop - yStart > bMask) yStop -= yt + yStop - yStart - bMask; if (!portrait()) { swap(w, h); xx = yy; x0 = y0; xStart = yStart; xStop = yStop; yy = y(); y0 = y(); yStart = 0; yStop = h; } } #else if (transform()) { uint16_t xt = vsTransformBack(xx); if ((int16_t)xt < (int16_t)topEdge() && \ (int16_t)(xt + w) >= (int16_t)topEdge()) { // Top edge clipping xStart = topEdge() - xt; xx = upperEdge(); x0 = xx - xStart; xt = vsTransformBack(xx); } else if (xt < bottomEdge() && xt + w >= bottomEdge()) // Bottom edge clipping xStop = bottomEdge() - xt; if (xt < topMask()) { if (xt + xStop - xStart < topMask()) return; xx = vsTransform(topMask()); xStart += topMask() - xt; x0 = xx - xStart; } uint16_t bMask = vsMaximum() - bottomMask(); if (xt >= bMask) return; if (xt + xStop - xStart > bMask) xStop -= xt + xStop - xStart - bMask; } #endif bool xTransform = transform() && !portrait() && x0 < bottomEdge() && x0 + xStop - xStart > bottomEdge(); bool yTransform = transform() && portrait() && y0 < bottomEdge() && y0 + yStop - yStart > bottomEdge(); uint8_t xEnd = xTransform ? bottomEdge() - xx : xStop; draw: area(xx, yy, xEnd - xStart, h); start(); for (uint8_t i = yStart; i < yStop; i++) { if (yTransform && y0 + i == bottomEdge()) { area(x(), topEdge(), w, h); start(); yTransform = false; } unsigned char c; c = pgm_read_byte(&(ascii[ch - ' '][i / zoom()])) << (xStart / zoom()); for (uint8_t j = xStart; j < xEnd; j++) { if (c & 0x80) write16(foreground()); else write16(background()); if (j % zoom() == zoom() - 1) c <<= 1; } } if (xTransform) { xx = topEdge(); xStart = xEnd; xEnd = xStop; xTransform = false; goto draw; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close())); //connect(ui.actionExport_Accessed_Files, SIGNAL(triggered()), this, SLOT(exportAccessedFiles())); connect(ui.actionRun, SIGNAL(triggered()), this, SLOT(sendRun())); connect(ui.actionRotate_Left, SIGNAL(triggered()), this, SLOT(rotateLeft())); connect(ui.actionRotate_Right, SIGNAL(triggered()), this, SLOT(rotateRight())); connect(ui.actionPortrait, SIGNAL(triggered()), this, SLOT(portrait())); connect(ui.actionPortrait_Upside_Down, SIGNAL(triggered()), this, SLOT(portraitUpsideDown())); connect(ui.actionLandscape_Left, SIGNAL(triggered()), this, SLOT(landscapeLeft())); connect(ui.actionLandscape_Right, SIGNAL(triggered()), this, SLOT(landscapeRight())); connect(ui.action15_fps, SIGNAL(triggered()), this, SLOT(action15_fps())); connect(ui.action30_fps, SIGNAL(triggered()), this, SLOT(action30_fps())); connect(ui.action60_fps, SIGNAL(triggered()), this, SLOT(action60_fps())); connect(ui.actionUnlimited, SIGNAL(triggered()), this, SLOT(actionUnlimited())); connect(ui.action320x480, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action768x1024, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action640x960, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action1536x2048, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action320x568, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action640x1136, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action480x800, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action240x320, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action540x960, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action480x854, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action240x400, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action360x640, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action800x1280, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action600x1024, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action600x800, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action768x1366, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action720x1280, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.action1080x1920, SIGNAL(triggered()), this, SLOT(actionResolution())); connect(ui.actionQuarter, SIGNAL(triggered()), this, SLOT(actionScale())); connect(ui.actionHalf, SIGNAL(triggered()), this, SLOT(actionScale())); connect(ui.actionOriginal, SIGNAL(triggered()), this, SLOT(actionScale())); orientationGroup_ = new QActionGroup(this); orientationGroup_->addAction(ui.actionPortrait); orientationGroup_->addAction(ui.actionPortrait_Upside_Down); orientationGroup_->addAction(ui.actionLandscape_Left); orientationGroup_->addAction(ui.actionLandscape_Right); resolutionGroup_ = new QActionGroup(this); resolutionGroup_->addAction(ui.action320x480); resolutionGroup_->addAction(ui.action768x1024); resolutionGroup_->addAction(ui.action640x960); resolutionGroup_->addAction(ui.action1536x2048); resolutionGroup_->addAction(ui.action320x568); resolutionGroup_->addAction(ui.action640x1136); resolutionGroup_->addAction(ui.action480x800); resolutionGroup_->addAction(ui.action240x320); resolutionGroup_->addAction(ui.action540x960); resolutionGroup_->addAction(ui.action480x854); resolutionGroup_->addAction(ui.action240x400); resolutionGroup_->addAction(ui.action360x640); resolutionGroup_->addAction(ui.action800x1280); resolutionGroup_->addAction(ui.action600x1024); resolutionGroup_->addAction(ui.action600x800); resolutionGroup_->addAction(ui.action768x1366); resolutionGroup_->addAction(ui.action720x1280); resolutionGroup_->addAction(ui.action1080x1920); zoomGroup_ = new QActionGroup(this); zoomGroup_->addAction(ui.actionQuarter); zoomGroup_->addAction(ui.actionHalf); zoomGroup_->addAction(ui.actionOriginal); connect(ui.actionAlways_on_Top, SIGNAL(triggered(bool)), this, SLOT(alwaysOnTop(bool))); QSettings settings; QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint(); QSize size = settings.value("size", QSize(1, 1)).toSize(); resize(size); move(pos); bool alwaysOnTop = settings.value("alwaysOnTop").toBool(); if (alwaysOnTop) { setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); show(); } ui.actionAlways_on_Top->setChecked(alwaysOnTop); QTimer::singleShot(0, this, SLOT(afterInitialization())); int resolution = settings.value("resolution", 320).toInt(); switch (resolution) { case 320: ui.action320x480->setChecked(true); break; case 768: ui.action768x1024->setChecked(true); break; case 640: ui.action640x960->setChecked(true); break; case 1536: ui.action1536x2048->setChecked(true); break; case 320+1: ui.action320x568->setChecked(true); break; case 640+1: ui.action640x1136->setChecked(true); break; case 480: ui.action480x800->setChecked(true); break; case 240: ui.action240x320->setChecked(true); break; case 540: ui.action540x960->setChecked(true); break; case 480+1: ui.action480x854->setChecked(true); break; case 240+1: ui.action240x400->setChecked(true); break; case 360: ui.action360x640->setChecked(true); break; case 800: ui.action800x1280->setChecked(true); break; case 600: ui.action600x1024->setChecked(true); break; case 600+1: ui.action600x800->setChecked(true); break; case 768+1: ui.action768x1366->setChecked(true); break; case 720: ui.action720x1280->setChecked(true); break; case 1080: ui.action1080x1920->setChecked(true); break; } switch (settings.value("scale", 1).toInt()) { case 1: ui.actionOriginal->setChecked(true); break; case 2: ui.actionHalf->setChecked(true); break; case 4: ui.actionQuarter->setChecked(true); break; } ui.glCanvas->setScale(scale()); ui.glCanvas->setFixedSize(hardwareWidth()/scale(), hardwareHeight()/scale()); ui.glCanvas->setResolution(hardwareWidth(), hardwareHeight()); Orientation orientation = static_cast<Orientation>(settings.value("orientation", ePortrait).toInt()); switch (orientation) { case ePortrait: portrait(); ui.actionPortrait->setChecked(true); break; case eLandscapeLeft: landscapeLeft(); ui.actionLandscape_Left->setChecked(true); break; case ePortraitUpsideDown: portraitUpsideDown(); ui.actionPortrait_Upside_Down->setChecked(true); break; case eLandscapeRight: landscapeRight(); ui.actionLandscape_Right->setChecked(true); break; } int fps = settings.value("fps2", 60).toInt(); if (fps == 15) action15_fps(); else if (fps == 30) action30_fps(); else if (fps == 60) action60_fps(); else actionUnlimited(); connect(ui.glCanvas, SIGNAL(projectNameChanged(const QString&)), this, SLOT(projectNameChanged(const QString&))); }