Mandelbrot: Implement changing sets.

This commit is contained in:
Augustin Cavalier 2016-05-27 21:57:21 -04:00
parent d25186e7a0
commit 29781d2641
3 changed files with 48 additions and 2 deletions

View File

@ -40,6 +40,16 @@ FractalEngine::~FractalEngine()
void FractalEngine::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case MSG_CHANGE_SET:
switch (msg->GetUInt8("set", 0)) {
case 0: fDoSet = &FractalEngine::DoSet_Mandelbrot; break;
case 1: fDoSet = &FractalEngine::DoSet_BurningShip; break;
case 2: fDoSet = &FractalEngine::DoSet_Tricorn; break;
case 3: fDoSet = &FractalEngine::DoSet_Julia; break;
case 4: fDoSet = &FractalEngine::DoSet_OrbitTrap; break;
case 5: fDoSet = &FractalEngine::DoSet_Multibrot; break;
}
break;
case MSG_SET_PALETTE:
switch (msg->GetUInt8("palette", 0)) {
case 0: fColorset = Colorset_Royal; break;

View File

@ -19,7 +19,8 @@ class BBitmap;
class FractalEngine : public BLooper {
public:
enum {
MSG_SET_PALETTE = 'Frct',
MSG_CHANGE_SET = 'Frct',
MSG_SET_PALETTE,
MSG_RESIZE,
MSG_RENDER,
MSG_RENDER_COMPLETE,

View File

@ -162,7 +162,14 @@ class MandelbrotWindow : public BWindow
{
public:
enum {
MSG_ROYAL_PALETTE = 'MndW',
MSG_MANDELBROT_SET = 'MndW',
MSG_BURNINGSHIP_SET,
MSG_TRICORN_SET,
MSG_JULIA_SET,
MSG_ORBITTRAP_SET,
MSG_MULTIBROT_SET,
MSG_ROYAL_PALETTE,
MSG_DEEPFROST_PALETTE,
MSG_FROST_PALETTE,
MSG_FIRE_PALETTE,
@ -192,11 +199,21 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
SetPulseRate(250000); // pulse twice per second
BMenuBar* menuBar = new BMenuBar("MenuBar");
BMenu* setMenu;
BMenu* paletteMenu;
BLayoutBuilder::Menu<>(menuBar)
.AddMenu(B_TRANSLATE("File"))
.AddItem(B_TRANSLATE("Quit"), B_QUIT_REQUESTED, 'Q')
.End()
.AddMenu(B_TRANSLATE("Set"))
.GetMenu(setMenu)
.AddItem(B_TRANSLATE("Mandelbrot"), MSG_MANDELBROT_SET)
.AddItem(B_TRANSLATE("Burning Ship"), MSG_BURNINGSHIP_SET)
.AddItem(B_TRANSLATE("Tricorn"), MSG_TRICORN_SET)
.AddItem(B_TRANSLATE("Julia"), MSG_JULIA_SET)
.AddItem(B_TRANSLATE("Orbit Trap"), MSG_ORBITTRAP_SET)
.AddItem(B_TRANSLATE("Multibrot"), MSG_MULTIBROT_SET)
.End()
.AddMenu(B_TRANSLATE("Palette"))
.GetMenu(paletteMenu)
.AddItem(B_TRANSLATE("Royal"), MSG_ROYAL_PALETTE)
@ -210,6 +227,8 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
.AddItem(B_TRANSLATE("High contrast"), MSG_HIGHCONTRAST_PALETTE)
.End()
.End();
setMenu->SetRadioMode(true);
setMenu->FindItem(MSG_MANDELBROT_SET)->SetMarked(true);
paletteMenu->SetRadioMode(true);
paletteMenu->FindItem(MSG_ROYAL_PALETTE)->SetMarked(true);
@ -221,6 +240,14 @@ MandelbrotWindow::MandelbrotWindow(BRect frame)
}
#define HANDLE_SET(uiwhat, id) \
case uiwhat: { \
BMessage msg(FractalEngine::MSG_CHANGE_SET); \
msg.AddUInt8("set", id); \
fFractalView->fFractalEngine->PostMessage(&msg); \
fFractalView->RedrawFractal(); \
break; \
}
#define HANDLE_PALETTE(uiwhat, id) \
case uiwhat: { \
BMessage msg(FractalEngine::MSG_SET_PALETTE); \
@ -233,6 +260,13 @@ void
MandelbrotWindow::MessageReceived(BMessage* msg)
{
switch (msg->what) {
HANDLE_SET(MSG_MANDELBROT_SET, 0)
HANDLE_SET(MSG_BURNINGSHIP_SET, 1)
HANDLE_SET(MSG_TRICORN_SET, 2)
HANDLE_SET(MSG_JULIA_SET, 3)
HANDLE_SET(MSG_ORBITTRAP_SET, 4)
HANDLE_SET(MSG_MULTIBROT_SET, 5)
HANDLE_PALETTE(MSG_ROYAL_PALETTE, 0)
HANDLE_PALETTE(MSG_DEEPFROST_PALETTE, 1)
HANDLE_PALETTE(MSG_FROST_PALETTE, 2)
@ -248,6 +282,7 @@ MandelbrotWindow::MessageReceived(BMessage* msg)
break;
}
}
#undef HANDLE_SET
#undef HANDLE_PALETTE