Add a Mandelbrot set program

This commit is contained in:
Markus Gans 2015-05-25 23:39:09 +02:00
parent fe19574153
commit 5c6a8dfc54
8 changed files with 200 additions and 31 deletions

View File

@ -1,5 +1,6 @@
2015-24-05 Markus Gans <guru.mail@muenster.de> 2015-24-05 Markus Gans <guru.mail@muenster.de>
* Bug fix in FLineEdit (ypos from the label) * Bug fix in FLineEdit (ypos from the label)
* Bug fix in FDialog onWindowActive (status bar check)
2015-15-05 Markus Gans <guru.mail@muenster.de> 2015-15-05 Markus Gans <guru.mail@muenster.de>
* Remove never read value from code * Remove never read value from code

View File

@ -552,7 +552,8 @@ void FDialog::onWindowActive (FEvent*)
{ {
focus_widget->setFocus(); focus_widget->setFocus();
focus_widget->redraw(); focus_widget->redraw();
statusBar()->drawMessage(); if ( statusBar() )
statusBar()->drawMessage();
} }
else else
focusFirstChild(); focusFirstChild();

View File

@ -9,6 +9,7 @@ noinst_PROGRAMS = \
hello \ hello \
dialog \ dialog \
input-dialog \ input-dialog \
mandelbrot \
fstring \ fstring \
timer \ timer \
ui ui
@ -16,6 +17,7 @@ noinst_PROGRAMS = \
hello_SOURCES = hello.cpp hello_SOURCES = hello.cpp
dialog_SOURCES = dialog.cpp dialog_SOURCES = dialog.cpp
input_dialog_SOURCES = input-dialog.cpp input_dialog_SOURCES = input-dialog.cpp
mandelbrot_SOURCES = mandelbrot.cpp
fstring_SOURCES = fstring.cpp fstring_SOURCES = fstring.cpp
timer_SOURCES = timer.cpp timer_SOURCES = timer.cpp
ui_SOURCES = ui.cpp ui_SOURCES = ui.cpp

View File

@ -12,13 +12,14 @@ MAKEFILE = -f Makefile.clang
LDFLAGS = -L../src -lfinal LDFLAGS = -L../src -lfinal
INCLUDES = -I../src INCLUDES = -I../src
RM = rm -f RM = rm -f
PROGS = hello dialog input-dialog fstring timer ui PROGS = hello dialog input-dialog mandelbrot fstring timer ui
OBJS1 = hello.o OBJS1 = hello.o
OBJS2 = dialog.o OBJS2 = dialog.o
OBJS3 = input-dialog.o OBJS3 = input-dialog.o
OBJS4 = fstring.o OBJS4 = mandelbrot.o
OBJS5 = timer.o OBJS5 = fstring.o
OBJS6 = ui.o OBJS6 = timer.o
OBJS7 = ui.o
ifdef DEBUG ifdef DEBUG
OPTIMIZE = -O0 OPTIMIZE = -O0
@ -44,14 +45,17 @@ dialog: $(OBJS2)
input-dialog: $(OBJS3) input-dialog: $(OBJS3)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o input-dialog $(OBJS3) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o input-dialog $(OBJS3)
fstring: $(OBJS4) mandelbrot: $(OBJS4)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o fstring $(OBJS4) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o mandelbrot $(OBJS4)
timer: $(OBJS5) fstring: $(OBJS5)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o timer $(OBJS5) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o fstring $(OBJS5)
ui: $(OBJS6) timer: $(OBJS6)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o ui $(OBJS6) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o timer $(OBJS6)
ui: $(OBJS7)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o ui $(OBJS7)
debug: debug:
$(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -W -Wall -Weverything -Wpadded -pedantic" $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -W -Wall -Weverything -Wpadded -pedantic"
@ -61,7 +65,7 @@ profile:
.PHONY: clean dep .PHONY: clean dep
clean: clean:
$(RM) $(PROGS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS6) .depend *.gch *.plist *~ $(RM) $(PROGS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS6) $(OBJS7) .depend *.gch *.plist *~
dep: dep:
$(CXX) -MM $(INCLUDES) *.cpp >.depend $(CXX) -MM $(INCLUDES) *.cpp >.depend

View File

@ -12,13 +12,14 @@ MAKEFILE = -f Makefile.gcc
LDFLAGS = -L../src -lfinal LDFLAGS = -L../src -lfinal
INCLUDES = -I../src INCLUDES = -I../src
RM = rm -f RM = rm -f
PROGS = hello dialog input-dialog fstring timer ui PROGS = hello dialog input-dialog mandelbrot fstring timer ui
OBJS1 = hello.o OBJS1 = hello.o
OBJS2 = dialog.o OBJS2 = dialog.o
OBJS3 = input-dialog.o OBJS3 = input-dialog.o
OBJS4 = fstring.o OBJS4 = mandelbrot.o
OBJS5 = timer.o OBJS5 = fstring.o
OBJS6 = ui.o OBJS6 = timer.o
OBJS7 = ui.o
ifdef DEBUG ifdef DEBUG
OPTIMIZE = -O0 OPTIMIZE = -O0
@ -44,14 +45,17 @@ dialog: $(OBJS2)
input-dialog: $(OBJS3) input-dialog: $(OBJS3)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o input-dialog $(OBJS3) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o input-dialog $(OBJS3)
fstring: $(OBJS4) mandelbrot: $(OBJS4)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o fstring $(OBJS4) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o mandelbrot $(OBJS4)
timer: $(OBJS5) fstring: $(OBJS5)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o timer $(OBJS5) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o fstring $(OBJS5)
ui: $(OBJS6) timer: $(OBJS6)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o ui $(OBJS6) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o timer $(OBJS6)
ui: $(OBJS7)
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o ui $(OBJS7)
debug: debug:
$(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -W -Wall -pedantic" $(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG -W -Wall -pedantic"
@ -61,7 +65,7 @@ profile:
.PHONY: clean dep .PHONY: clean dep
clean: clean:
$(RM) $(PROGS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS6) .depend *~ $(RM) $(PROGS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS6) $(OBJ6) .depend *~
dep: dep:
$(CXX) -MM $(INCLUDES) *.cpp >.depend $(CXX) -MM $(INCLUDES) *.cpp >.depend

View File

@ -83,7 +83,8 @@ POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \ noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \
fstring$(EXEEXT) timer$(EXEEXT) ui$(EXEEXT) mandelbrot$(EXEEXT) fstring$(EXEEXT) timer$(EXEEXT) \
ui$(EXEEXT)
subdir = test subdir = test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/depcomp $(top_srcdir)/depcomp
@ -114,6 +115,9 @@ hello_LDADD = $(LDADD)
am_input_dialog_OBJECTS = input-dialog.$(OBJEXT) am_input_dialog_OBJECTS = input-dialog.$(OBJEXT)
input_dialog_OBJECTS = $(am_input_dialog_OBJECTS) input_dialog_OBJECTS = $(am_input_dialog_OBJECTS)
input_dialog_LDADD = $(LDADD) input_dialog_LDADD = $(LDADD)
am_mandelbrot_OBJECTS = mandelbrot.$(OBJEXT)
mandelbrot_OBJECTS = $(am_mandelbrot_OBJECTS)
mandelbrot_LDADD = $(LDADD)
am_timer_OBJECTS = timer.$(OBJEXT) am_timer_OBJECTS = timer.$(OBJEXT)
timer_OBJECTS = $(am_timer_OBJECTS) timer_OBJECTS = $(am_timer_OBJECTS)
timer_LDADD = $(LDADD) timer_LDADD = $(LDADD)
@ -155,9 +159,11 @@ am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 = am__v_CXXLD_1 =
SOURCES = $(dialog_SOURCES) $(fstring_SOURCES) $(hello_SOURCES) \ SOURCES = $(dialog_SOURCES) $(fstring_SOURCES) $(hello_SOURCES) \
$(input_dialog_SOURCES) $(timer_SOURCES) $(ui_SOURCES) $(input_dialog_SOURCES) $(mandelbrot_SOURCES) $(timer_SOURCES) \
$(ui_SOURCES)
DIST_SOURCES = $(dialog_SOURCES) $(fstring_SOURCES) $(hello_SOURCES) \ DIST_SOURCES = $(dialog_SOURCES) $(fstring_SOURCES) $(hello_SOURCES) \
$(input_dialog_SOURCES) $(timer_SOURCES) $(ui_SOURCES) $(input_dialog_SOURCES) $(mandelbrot_SOURCES) $(timer_SOURCES) \
$(ui_SOURCES)
am__can_run_installinfo = \ am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \ case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \ n|no|NO) false;; \
@ -309,6 +315,7 @@ AM_CPPFLAGS = -Wall -Werror -I$(top_srcdir)/src
hello_SOURCES = hello.cpp hello_SOURCES = hello.cpp
dialog_SOURCES = dialog.cpp dialog_SOURCES = dialog.cpp
input_dialog_SOURCES = input-dialog.cpp input_dialog_SOURCES = input-dialog.cpp
mandelbrot_SOURCES = mandelbrot.cpp
fstring_SOURCES = fstring.cpp fstring_SOURCES = fstring.cpp
timer_SOURCES = timer.cpp timer_SOURCES = timer.cpp
ui_SOURCES = ui.cpp ui_SOURCES = ui.cpp
@ -372,6 +379,10 @@ input-dialog$(EXEEXT): $(input_dialog_OBJECTS) $(input_dialog_DEPENDENCIES) $(EX
@rm -f input-dialog$(EXEEXT) @rm -f input-dialog$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(input_dialog_OBJECTS) $(input_dialog_LDADD) $(LIBS) $(AM_V_CXXLD)$(CXXLINK) $(input_dialog_OBJECTS) $(input_dialog_LDADD) $(LIBS)
mandelbrot$(EXEEXT): $(mandelbrot_OBJECTS) $(mandelbrot_DEPENDENCIES) $(EXTRA_mandelbrot_DEPENDENCIES)
@rm -f mandelbrot$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(mandelbrot_OBJECTS) $(mandelbrot_LDADD) $(LIBS)
timer$(EXEEXT): $(timer_OBJECTS) $(timer_DEPENDENCIES) $(EXTRA_timer_DEPENDENCIES) timer$(EXEEXT): $(timer_OBJECTS) $(timer_DEPENDENCIES) $(EXTRA_timer_DEPENDENCIES)
@rm -f timer$(EXEEXT) @rm -f timer$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(timer_OBJECTS) $(timer_LDADD) $(LIBS) $(AM_V_CXXLD)$(CXXLINK) $(timer_OBJECTS) $(timer_LDADD) $(LIBS)
@ -390,6 +401,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hello.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hello.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-dialog.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-dialog.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@

145
test/mandelbrot.cpp Normal file
View File

@ -0,0 +1,145 @@
// mandelbrot.cpp
#include "fapp.h"
#include "fdialog.h"
#include "fmessagebox.h"
//----------------------------------------------------------------------
// class Mandelbrot
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class Mandelbrot : public FDialog
{
private:
virtual void draw();
public:
Mandelbrot (FWidget* parent=0); // constructor
~Mandelbrot(); // destructor
void onAccel (FAccelEvent*);
void onClose (FCloseEvent*);
protected:
void adjustSize();
};
#pragma pack(pop)
//----------------------------------------------------------------------
Mandelbrot::Mandelbrot (FWidget* parent) : FDialog(parent)
{
setText ("Mandelbrot set");
}
//----------------------------------------------------------------------
Mandelbrot::~Mandelbrot()
{
}
//----------------------------------------------------------------------
void Mandelbrot::draw()
{
int iter, max_iter;
int Cols, Lines, xoffset, yoffset, current_line;
double x, y, xtemp, x0, y0, dX, dY;
double x_min, x_max, y_min, y_max;
FDialog::draw();
if ( Encoding == fc::VT100 )
unsetVT100altChar();
x_min = -2.20;
x_max = 1.0;
y_min = -1.05;
y_max = 1.05;
max_iter = 99;
xoffset = xpos+xmin;
yoffset = ypos+ymin;
Cols = getClientWidth();
Lines = getClientHeight();
current_line = 1;
dX = (x_max - x_min) / (Cols - 1);
dY = (y_max - y_min) / Lines;
for (y0=y_min; y0 < y_max && current_line-1 < Lines; y0+=dY)
{
gotoxy (xoffset, yoffset+current_line);
for (x0=x_min; x0 < x_max; x0+=dX)
{
x = 0.0;
y = 0.0;
iter = 0;
while ( x*x + y*y < 4 && iter < max_iter )
{
xtemp = x*x - y*y + x0;
y = 2*x*y + y0;
x = xtemp;
iter++;
}
if ( iter < max_iter )
setColor(fc::Black, iter%16);
else
setColor(fc::Black, 0);
print(' ');
}
current_line++;
}
setUpdateVTerm(true);
}
//----------------------------------------------------------------------
void Mandelbrot::onAccel (FAccelEvent* ev)
{
close();
ev->accept();
}
//----------------------------------------------------------------------
void Mandelbrot::onClose (FCloseEvent* event)
{
int ret = FMessageBox::info ( this, "Quit",
"Do you really want\n"
"to quit the program ?",
FMessageBox::Yes,
FMessageBox::No );
if ( ret == FMessageBox::Yes )
event->accept();
else
event->ignore();
}
//----------------------------------------------------------------------
void Mandelbrot::adjustSize()
{
int h = parentWidget()->getHeight() - 1;
int w = parentWidget()->getWidth() - 10;
setGeometry(6, 1, w, h, false);
FDialog::adjustSize();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
// Create the application object
FApplication app(argc, argv);
// Create a simple dialog box
Mandelbrot mb(&app);
mb.setGeometry (6, 1, 70, 23);
mb.addAccelerator('q'); // press 'q' to quit
mb.setShadow();
app.setMainWidget(&mb);
mb.show();
return app.exec();
}

View File

@ -408,11 +408,11 @@ MyDialog::~MyDialog()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::onClose (FCloseEvent* event) void MyDialog::onClose (FCloseEvent* event)
{ {
int ret = FMessageBox::info (this, "Quit", int ret = FMessageBox::info ( this, "Quit",
"Do you really want\n" "Do you really want\n"
"to quit the program ?", "to quit the program ?",
FMessageBox::Yes, FMessageBox::Yes,
FMessageBox::No); FMessageBox::No );
if ( ret == FMessageBox::Yes ) if ( ret == FMessageBox::Yes )
event->accept(); event->accept();
else else