After declaring an instance of FractalFrame, I would like to start plotting the fractal. My intention is that, once every 10 iterations or so, the program escapes the iterative cycle, draws the new processed image, and then enter the iterative cycle again.
FractalFrame is supposed to always be computing iterations; that's where the problem might arise: when the user asks the window to close, it will be iterating. I thought of putting this cycle inside the constructor of FractalFrame, but I have a feeling it would not go as well as expected.
Here's the important part of the code:
main.cpp:
Code: Select all
#include <wx/wx.h>
#include "FractalFrame.h"
class MyApp: public wxApp{
public:
virtual bool OnInit(){
FractalFrame* frame = new FractalFrame();
frame->Show(true);
return true;
}
};
wxIMPLEMENT_APP(MyApp);
Code: Select all
#ifndef FRACTALFRAME_H_INCLUDED
#define FRACTALFRAME_H_INCLUDED
#include <wx/wx.h>
#include "FractalPanel.h"
#include "InfoPanel.h"
class FractalFrame: public wxFrame{
public:
FractalFrame();
private:
FractalPanel* fractalPanel;
InfoPanel* infoPanel;
void OnChangeSettings(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
#endif // FRACTALFRAME_H_INCLUDED
Code: Select all
#include "FractalFrame.h"
wxPoint WindowInitPos (250, 50);
wxSize FractalPanelInitSz (1280, 720);
wxSize InfoPanelInitSz (1280, 70);
///Event enumeration
enum{
ID_ChangeSettings = 1
};
///Functions
FractalFrame::FractalFrame():wxFrame(nullptr, wxID_ANY, "Mandelbrot set plotter", WindowInitPos){
///Menu
wxMenu* menuSettings = new wxMenu;
menuSettings->Append(ID_ChangeSettings, "&Change Settings");
wxMenuBar* menuBar = new wxMenuBar;
menuBar->Append(menuSettings, "&Settings");
this->SetMenuBar(menuBar);
///FractalPanel
fractalPanel = new FractalPanel(this, FractalPanelInitSz);
///InfoPanel
infoPanel = new InfoPanel(this, InfoPanelInitSz);
///Sizer
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(fractalPanel, 1, wxEXPAND, 0);
sizer->Add( infoPanel, 0, wxEXPAND, 0);
sizer->SetSizeHints(this);
this->SetSizer(sizer);
}
void FractalFrame::OnChangeSettings(wxCommandEvent& event){
std::cout << "OnChangeSettings" << std::endl;
}
wxBEGIN_EVENT_TABLE(FractalFrame, wxFrame)
EVT_MENU(ID_ChangeSettings, FractalFrame::OnChangeSettings)
wxEND_EVENT_TABLE()
1) Put the cycle in FractalFrame's constructor (which doesn't seem like a great idea);
2) Put the cycle after I declare FractalFrame in MyApp::OnInit
3) Put the cycle in a public member function of FractalFrame, and call it after declaring FractalFrame in MyApp::OnInit
Is there a standard procedure for dealing with this kind of situation, or at least a viable way to make it work?