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

Committer:
ofrasier
Date:
2018-12-07
Revision:
3:835c035b8b1c
Parent:
1:a1d80c69e1f0

File content as of revision 3:835c035b8b1c:

#ifndef BUTTONHANDLERS_CPP
#define BUTTONHANDLERS_CPP

// For converting int to string: C++03 has no std::to_string
#include <string>
#include <sstream>
#include "kernels.h"
#include "buttonhandlers.h"
    
void changeMaxIters(Button *self, DmTftBase *screen)
{
    if (brot->maxiters < 4096) {
        brot->maxiters *= 2;
    } else {
        brot->maxiters = 256;
    }
    
    std::ostringstream stringStream;
    stringStream << brot->maxiters;
    self->text = stringStream.str();
        
    self->draw(screen);
}

void changeKernel(Button *self, DmTftBase *screen)
{
    if (brot->kernel == drawASM) {
        brot->kernel = drawCInt;
        self->text = "Integer";
    } else if (brot->kernel == drawCInt) {
        brot->kernel = drawCFlt;
        self->text = "Float";
    } else { // brot->kernel == drawCFlt
        brot->kernel = drawASM;
        self->text = "ASM";        
    }
    self->draw(screen);
}

void reDraw(Button *self, DmTftBase *screen)
{
    brot->draw(screen);
}

void resetView(Button *self, DmTftBase *screen)
{
    brot->centerX = 0.0f;
    brot->centerY = 0.0f;
    brot->zoom = 1;
    brot->draw(screen);
}

void zoomOut(Button *self, DmTftBase *screen)
{
    if (brot->zoom > 1) {
        brot->zoom /= 2;
    }
    brot->draw(screen);
}

#endif