void Framebuffer::setPixel(int16_t x, int16_t y, uint16_t color) { translateCoordinates(&x, &y); if (x < 0 || x >= _width || y < 0 || y >= _height) { return; } uint8_t pcol = color & 0xFF; uint32_t pos = y * _width + x; bufferWrite(pos, pcol); if (x < _minX) _minX = x; if (x > _maxX) _maxX = x; if (y < _minY) _minY = y; if (y > _maxY) _maxY = y; }
void Framebuffer::copyRect(int16_t dx, int16_t dy, int16_t sx, int16_t sy, uint16_t w, uint16_t h) { uint32_t dpos; uint32_t spos; translateCoordinates(&dx, &dy); for (int y = 0; y < w; y++) { for (int x = 0; x < h; x++) { if (sx > dx && sy > dy) { dpos = (y + dy) * _width + (x + dx); spos = (y + sy) * _width + (x + sx); } else if(sx <= dx && sy > dy) { dpos = (y + dy) * _width + ((w - x) + dx); spos = (y + sy) * _width + ((w - x) + sx); } else if(sx > dx && sy <= dy) { dpos = ((h - y) + dy) * _width + (x + dx); spos = ((h - y) + sy) * _width + (x + sx); } else if(sx <= dx && sy <= dy) { dpos = ((h - y) + dy) * _width + ((w - x) + dx); spos = ((h - y) + sy) * _width + ((w - x) + sx); } bufferWrite(dpos, bufferRead(spos)); } } }
pp_int32 EnvelopeEditorControl::dispatchEvent(PPEvent* event) { if (eventListener == NULL) return -1; switch (event->getID()) { case eRMouseDown: { PPPoint* p = (PPPoint*)event->getDataPtr(); if (!hScrollbar->hit(*p)) invokeContextMenu(*p); else { if (controlCaughtByLMouseButton) break; controlCaughtByRMouseButton = true; caughtControl = hScrollbar; caughtControl->dispatchEvent(event); } break; } case eLMouseDown: { hasDragged = false; selectionTicker = 0; PPPoint* p = (PPPoint*)event->getDataPtr(); // Clicked on horizontal scrollbar -> route event to scrollbar and catch scrollbar control if (hScrollbar->hit(*p)) { if (controlCaughtByRMouseButton) break; controlCaughtByLMouseButton = true; caughtControl = hScrollbar; caughtControl->dispatchEvent(event); } // Clicked in client area else { PPPoint cp = *p; translateCoordinates(cp); if (cp.x > visibleWidth) break; if (cp.y > visibleHeight) break; pp_int32 rx = (pp_int32)(cp.x + startPos); pp_int32 ry = (pp_int32)((visibleHeight - cp.y)); pp_int32 i = selectEnvelopePoint(rx, ry); if (i != -1) { envelopeEditor->startSelectionDragging(i); } else { updateCurrentPosition(cp); } parentScreen->paintControl(this); } break; } case eMouseLeft: { currentPosition.x = currentPosition.y = -1; parentScreen->paintControl(this); break; } case eMouseMoved: { PPPoint* p = (PPPoint*)event->getDataPtr(); PPPoint cp = *p; translateCoordinates(cp); if (cp.y < 0 || cp.x > visibleWidth || cp.y < 0 || cp.y > visibleHeight) break; updateCurrentPosition(cp); parentScreen->paintControl(this); break; } case eRMouseUp: { controlCaughtByRMouseButton = false; if (caughtControl && !controlCaughtByLMouseButton && !controlCaughtByRMouseButton) { caughtControl->dispatchEvent(event); caughtControl = NULL; break; } break; } case eLMouseUp: if (envelopeEditor->isSelectionDragging()) envelopeEditor->endSelectionDragging(); controlCaughtByLMouseButton = false; if (caughtControl == NULL) break; if (!controlCaughtByLMouseButton && !controlCaughtByRMouseButton) { caughtControl->dispatchEvent(event); caughtControl = NULL; } break; case eLMouseDrag: { if (caughtControl && controlCaughtByLMouseButton) { caughtControl->dispatchEvent(event); break; } hasDragged = true; if (!envelopeEditor->isSelectionDragging()) break; PPPoint* p = (PPPoint*)event->getDataPtr(); PPPoint cp = *p; translateCoordinates(cp); setEnvelopePoint(envelopeEditor->getSelectionIndex(), cp.x + startPos, visibleHeight - cp.y); updateCurrentPosition(cp); adjustScrollbars(); parentScreen->paintControl(this); break; } case eLMouseRepeat: { if (caughtControl && controlCaughtByLMouseButton) { caughtControl->dispatchEvent(event); break; } // for slowing down mouse pressed events selectionTicker++; // no selection has been made or mouse hasn't been dragged if (!envelopeEditor->isSelectionDragging() || !hasDragged) { // mouse hasn't been dragged and selection ticker has reached threshold value if (!hasDragged && selectionTicker > 0) { PPPoint* p = (PPPoint*)event->getDataPtr(); if (!hScrollbar->hit(*p)) invokeContextMenu(*p); } } break; } case eRMouseDrag: { if (caughtControl && controlCaughtByRMouseButton) caughtControl->dispatchEvent(event); break; } case eRMouseRepeat: { if (caughtControl && controlCaughtByRMouseButton) caughtControl->dispatchEvent(event); break; } // mouse wheel case eMouseWheelMoved: { TMouseWheelEventParams* params = (TMouseWheelEventParams*)event->getDataPtr(); if (params->delta > 0) { setScale(xScale << 1); parentScreen->paintControl(this); } else if (params->delta < 0) { setScale(xScale >> 1); parentScreen->paintControl(this); } event->cancel(); break; } default: if (caughtControl == NULL) break; caughtControl->dispatchEvent(event); break; }