Mandelbrot set viewer for the ARM Mbed platform
Dependencies: mbed DmTftLibrary
Mbed Mandelbrot Viewer
Touch-based mandelbrot set viewer for the ARM Mbed platform. Designed with the NXP LPC1768 and the DisplayModule DM-TFT28-116. It should be easy to adapt for any DisplayModule product, especially if it has an I2C touch controller.
On screen options allow the user to switch between 256*(2^n) maxiters up to 4096, and three rendering kernels using floats, integers, and integers in ARMv7 ASM.
src/buttonhandlers.cpp@3:835c035b8b1c, 2018-12-07 (annotated)
- Committer:
- ofrasier
- Date:
- Fri Dec 07 01:00:54 2018 +0000
- Revision:
- 3:835c035b8b1c
- Parent:
- 1:a1d80c69e1f0
Combined ADD-LSL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ofrasier | 1:a1d80c69e1f0 | 1 | #ifndef BUTTONHANDLERS_CPP |
ofrasier | 1:a1d80c69e1f0 | 2 | #define BUTTONHANDLERS_CPP |
ofrasier | 1:a1d80c69e1f0 | 3 | |
ofrasier | 1:a1d80c69e1f0 | 4 | // For converting int to string: C++03 has no std::to_string |
ofrasier | 1:a1d80c69e1f0 | 5 | #include <string> |
ofrasier | 1:a1d80c69e1f0 | 6 | #include <sstream> |
ofrasier | 1:a1d80c69e1f0 | 7 | #include "kernels.h" |
ofrasier | 1:a1d80c69e1f0 | 8 | #include "buttonhandlers.h" |
ofrasier | 1:a1d80c69e1f0 | 9 | |
ofrasier | 1:a1d80c69e1f0 | 10 | void changeMaxIters(Button *self, DmTftBase *screen) |
ofrasier | 1:a1d80c69e1f0 | 11 | { |
ofrasier | 1:a1d80c69e1f0 | 12 | if (brot->maxiters < 4096) { |
ofrasier | 1:a1d80c69e1f0 | 13 | brot->maxiters *= 2; |
ofrasier | 1:a1d80c69e1f0 | 14 | } else { |
ofrasier | 1:a1d80c69e1f0 | 15 | brot->maxiters = 256; |
ofrasier | 1:a1d80c69e1f0 | 16 | } |
ofrasier | 1:a1d80c69e1f0 | 17 | |
ofrasier | 1:a1d80c69e1f0 | 18 | std::ostringstream stringStream; |
ofrasier | 1:a1d80c69e1f0 | 19 | stringStream << brot->maxiters; |
ofrasier | 1:a1d80c69e1f0 | 20 | self->text = stringStream.str(); |
ofrasier | 1:a1d80c69e1f0 | 21 | |
ofrasier | 1:a1d80c69e1f0 | 22 | self->draw(screen); |
ofrasier | 1:a1d80c69e1f0 | 23 | } |
ofrasier | 1:a1d80c69e1f0 | 24 | |
ofrasier | 1:a1d80c69e1f0 | 25 | void changeKernel(Button *self, DmTftBase *screen) |
ofrasier | 1:a1d80c69e1f0 | 26 | { |
ofrasier | 1:a1d80c69e1f0 | 27 | if (brot->kernel == drawASM) { |
ofrasier | 1:a1d80c69e1f0 | 28 | brot->kernel = drawCInt; |
ofrasier | 1:a1d80c69e1f0 | 29 | self->text = "Integer"; |
ofrasier | 1:a1d80c69e1f0 | 30 | } else if (brot->kernel == drawCInt) { |
ofrasier | 1:a1d80c69e1f0 | 31 | brot->kernel = drawCFlt; |
ofrasier | 1:a1d80c69e1f0 | 32 | self->text = "Float"; |
ofrasier | 1:a1d80c69e1f0 | 33 | } else { // brot->kernel == drawCFlt |
ofrasier | 1:a1d80c69e1f0 | 34 | brot->kernel = drawASM; |
ofrasier | 1:a1d80c69e1f0 | 35 | self->text = "ASM"; |
ofrasier | 1:a1d80c69e1f0 | 36 | } |
ofrasier | 1:a1d80c69e1f0 | 37 | self->draw(screen); |
ofrasier | 1:a1d80c69e1f0 | 38 | } |
ofrasier | 1:a1d80c69e1f0 | 39 | |
ofrasier | 1:a1d80c69e1f0 | 40 | void reDraw(Button *self, DmTftBase *screen) |
ofrasier | 1:a1d80c69e1f0 | 41 | { |
ofrasier | 1:a1d80c69e1f0 | 42 | brot->draw(screen); |
ofrasier | 1:a1d80c69e1f0 | 43 | } |
ofrasier | 1:a1d80c69e1f0 | 44 | |
ofrasier | 1:a1d80c69e1f0 | 45 | void resetView(Button *self, DmTftBase *screen) |
ofrasier | 1:a1d80c69e1f0 | 46 | { |
ofrasier | 1:a1d80c69e1f0 | 47 | brot->centerX = 0.0f; |
ofrasier | 1:a1d80c69e1f0 | 48 | brot->centerY = 0.0f; |
ofrasier | 1:a1d80c69e1f0 | 49 | brot->zoom = 1; |
ofrasier | 1:a1d80c69e1f0 | 50 | brot->draw(screen); |
ofrasier | 1:a1d80c69e1f0 | 51 | } |
ofrasier | 1:a1d80c69e1f0 | 52 | |
ofrasier | 1:a1d80c69e1f0 | 53 | void zoomOut(Button *self, DmTftBase *screen) |
ofrasier | 1:a1d80c69e1f0 | 54 | { |
ofrasier | 1:a1d80c69e1f0 | 55 | if (brot->zoom > 1) { |
ofrasier | 1:a1d80c69e1f0 | 56 | brot->zoom /= 2; |
ofrasier | 1:a1d80c69e1f0 | 57 | } |
ofrasier | 1:a1d80c69e1f0 | 58 | brot->draw(screen); |
ofrasier | 1:a1d80c69e1f0 | 59 | } |
ofrasier | 1:a1d80c69e1f0 | 60 | |
ofrasier | 1:a1d80c69e1f0 | 61 | #endif |