diff --git a/SSD1306Ui.cpp b/SSD1306Ui.cpp index c2c6e4a2a1c216f406284a3e2d11efa55f55594d..198e3d2e11744ba22b7014d657516e1a92c4cf8f 100644 --- a/SSD1306Ui.cpp +++ b/SSD1306Ui.cpp @@ -63,13 +63,13 @@ void SSD1306Ui::setInactiveSymbole(const char* symbole) { void SSD1306Ui::setFrameAnimation(AnimationDirection dir) { this->frameAnimationDirection = dir; } -void SSD1306Ui::setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount) { +void SSD1306Ui::setFrames(FrameCallback* frameFunctions, int frameCount) { this->frameCount = frameCount; this->frameFunctions = frameFunctions; } // -/----- Overlays ------\- -void SSD1306Ui::setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount){ +void SSD1306Ui::setOverlays(OverlayCallback* overlayFunctions, int overlayCount){ this->overlayCount = overlayCount; this->overlayFunctions = overlayFunctions; } @@ -176,12 +176,12 @@ void SSD1306Ui::drawFrame(){ int dir = frameTransitionDirection >= 0 ? 1 : -1; x *= dir; y *= dir; x1 *= dir; y1 *= dir; - this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y); - this->dirty |= (*this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1); + this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y); + this->dirty |= (this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1); break; } case FIXED: - this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0); + this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0); break; } } @@ -200,12 +200,12 @@ void SSD1306Ui::drawIndicator() { for (byte i = 0; i < this->frameCount; i++) { - const char *xbm; + const char *image; if (posOfCurrentFrame == i) { - xbm = this->activeSymbole; + image = this->activeSymbole; } else { - xbm = this->inactiveSymbole; + image = this->inactiveSymbole; } int x,y; @@ -228,13 +228,13 @@ void SSD1306Ui::drawIndicator() { break; } - this->display->drawXbm(x, y, 8, 8, xbm); + this->display->drawFastImage(x, y, 8, 8, image); } } void SSD1306Ui::drawOverlays() { for (int i=0;i<this->overlayCount;i++){ - this->dirty |= (*this->overlayFunctions[i])(this->display, &this->state); + this->dirty |= (this->overlayFunctions[i])(this->display, &this->state); } } diff --git a/SSD1306Ui.h b/SSD1306Ui.h index d3595fea6facb7eabd3aefc917d95ef6cf6a2a9a..703d47b6bd20551ddd8415abe711b4c63f35a32a 100644 --- a/SSD1306Ui.h +++ b/SSD1306Ui.h @@ -70,6 +70,9 @@ struct SSD1306UiState { int currentFrame = 0; }; +typedef bool (*FrameCallback)(SSD1306 *display, SSD1306UiState* state, int x, int y); +typedef bool (*OverlayCallback)(SSD1306 *display, SSD1306UiState* state); + class SSD1306Ui { private: SSD1306 *display; @@ -94,11 +97,11 @@ class SSD1306Ui { bool autoTransition = true; - bool (**frameFunctions)(SSD1306 *display, SSD1306UiState* state, int x, int y); + FrameCallback* frameFunctions; int frameCount = 0; // Values for Overlays - bool (**overlayFunctions)(SSD1306 *display, SSD1306UiState* state); + OverlayCallback* overlayFunctions; int overlayCount = 0; // UI State @@ -185,14 +188,14 @@ class SSD1306Ui { /** * Add frame drawing functions */ - void setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount); + void setFrames(FrameCallback* frameFunctions, int frameCount); // Overlay /** * Add overlays drawing functions that are draw independent of the Frames */ - void setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount); + void setOverlays(OverlayCallback* overlayFunctions, int overlayCount); // Manuell Controll void nextFrame();