void parseRcvdMessage(long rcvdMessage) { *(unsigned long*)&message = rcvdMessage; if((message.start == STARTNIBBLE) && (message.pixelId == PIXELID || message.pixelId == 0)) { switch(message.function) { case COLORS: Serial.println("got color"); paintPixel(); break; case IR: Serial.println("got IR"); toggleIR(message.red); break; default: break; } } // clean up *(unsigned long*)&message = 0x00000000; }
void BigCharWidget::keyPressEvent(QKeyEvent *event) { event->accept(); auto&& state = State::getInstance(); int increment_x = state->shouldBeDisplayedInMulticolor() ? 2 : 1; switch (event->key()) { case Qt::Key_Left: _cursorPos += {-increment_x,0}; break; case Qt::Key_Right: _cursorPos += {+increment_x,0}; break; case Qt::Key_Down: _cursorPos += {0,+1}; break; case Qt::Key_Up: _cursorPos += {0,-1}; break; case Qt::Key_1: paintPixel(_cursorPos.x(), _cursorPos.y(), State::PEN_BACKGROUND); break; case Qt::Key_2: paintPixel(_cursorPos.x(), _cursorPos.y(), State::PEN_FOREGROUND); break; case Qt::Key_3: if (state->shouldBeDisplayedInMulticolor()) paintPixel(_cursorPos.x(), _cursorPos.y(), State::PEN_MULTICOLOR1); break; case Qt::Key_4: if (state->shouldBeDisplayedInMulticolor()) paintPixel(_cursorPos.x(), _cursorPos.y(), State::PEN_MULTICOLOR2); break; case Qt::Key_Space: cyclePixel(_cursorPos.x(), _cursorPos.y()); break; default: QWidget::keyPressEvent(event); } _cursorPos = {qBound(0, _cursorPos.x(), 8*_tileProperties.size.width()-1), qBound(0, _cursorPos.y(), 8*_tileProperties.size.height()-1)}; // redraw cursor update(); }
/* GfxCanvas::brushCanvas * Finds all the pixels under the brush, and paints them. *******************************************************************/ void GfxCanvas::brushCanvas(int x, int y) { if (brush == nullptr) return; point2_t coord = imageCoords(x, y); for (int i = -4; i < 5; ++i) for (int j = -4; j < 5; ++j) if (brush->getPixel(i, j)) paintPixel(coord.x + i, coord.y + j); }
void paint(RenderContext ctx, Scene scene, RenderStats* stats){ for (int i = scene.height- 1; i >= 0 ; i--) { for (int j = 0; j < scene.width; j++) { paintPixel(j, i, scene.width, scene.height, renderAntiAliasedPixel(j, i, scene, stats),ctx); if (scene.height > 10 && i%(scene.height/10) == 0 && j == 0) { printf("\nrender: %i/%i, traced: %zu", i, scene.height, stats->raysTraced); updateScreen(ctx); } } } }
void BigCharWidget::mousePressEvent(QMouseEvent * event) { event->accept(); auto pos = event->localPos(); int x = pos.x() / _pixelSize.width(); int y = pos.y() / _pixelSize.height(); if( x>=8*_tileProperties.size.width() || y>=8*_tileProperties.size.height()) return; _cursorPos = {x,y}; auto&& state = State::getInstance(); int selectedPen = state->getSelectedPen(); if (event->button() == Qt::LeftButton) paintPixel(x, y, selectedPen); else if(event->button() == Qt::RightButton) paintPixel(x, y, State::PEN_BACKGROUND); _commandMergeable = true; }
void BigCharWidget::cyclePixel(int x, int y) { auto&& state = State::getInstance(); int pen = state->tileGetPen(_tileIndex, QPoint(x, y)); int nextPenMC[] = {State::PEN_FOREGROUND, State::PEN_MULTICOLOR2, State::PEN_BACKGROUND, State::PEN_MULTICOLOR1}; int nextPenHR[] = {State::PEN_FOREGROUND, State::PEN_BACKGROUND}; if (state->shouldBeDisplayedInMulticolor()) pen = nextPenMC[pen]; else pen = nextPenHR[pen]; paintPixel(x, y, pen); }
void CFbAccel::paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col) { #if HAVE_TRIPLEDRAGON setColor(col); dfbdest->DrawLine(dfbdest, xa, ya, xb, yb); #elif defined(USE_NEVIS_GXA) OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex); /* draw a single vertical line from point xa/ya to xb/yb */ unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA; setColor(col); _write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */ _write_gxa(gxa_base, cmd, GXA_POINT(xb, yb)); /* end point */ _write_gxa(gxa_base, cmd, GXA_POINT(xa, ya)); /* start point */ #else int dx = abs (xa - xb); int dy = abs (ya - yb); if (dy == 0) /* horizontal line */ { /* paintRect actually is 1 pixel short to the right, * but that's bug-compatibility with the GXA code */ paintRect(xa, ya, xb - xa, 1, col); return; } if (dx == 0) /* vertical line */ { paintRect(xa, ya, 1, yb - ya, col); return; } int x; int y; int End; int step; if (dx > dy) { int p = 2 * dy - dx; int twoDy = 2 * dy; int twoDyDx = 2 * (dy-dx); if (xa > xb) { x = xb; y = yb; End = xa; step = ya < yb ? -1 : 1; } else { x = xa; y = ya; End = xb; step = yb < ya ? -1 : 1; } paintPixel(x, y, col); while (x < End) { x++; if (p < 0) p += twoDy; else { y += step; p += twoDyDx; } paintPixel(x, y, col); } } else { int p = 2 * dx - dy; int twoDx = 2 * dx; int twoDxDy = 2 * (dx-dy); if (ya > yb) { x = xb; y = yb; End = ya; step = xa < xb ? -1 : 1; } else { x = xa; y = ya; End = yb; step = xb < xa ? -1 : 1; } paintPixel(x, y, col); while (y < End) { y++; if (p < 0) p += twoDx; else { x += step; p += twoDxDy; } paintPixel(x, y, col); } } #endif }