* Fixed build under GCC 4, thanks to Ioan Molnar!
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21022 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e5bc3cb9b4
commit
cd563ed67d
@ -4,8 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
Application Mandelbrot :
|
||||
main.cpp
|
||||
Mandelbrot.cpp
|
||||
tsb.cpp
|
||||
: be
|
||||
: Mandelbrot.rdef ;
|
||||
|
||||
|
201
src/apps/mandelbrot/Mandelbrot.cpp
Normal file
201
src/apps/mandelbrot/Mandelbrot.cpp
Normal file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
Copyright 1993-1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include "tsb.h"
|
||||
|
||||
#include <Debug.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <OS.h>
|
||||
#include <Roster.h>
|
||||
#include <ScrollView.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* Those are the menu item id's of the main window */
|
||||
#define P1 0x60
|
||||
#define P2 0x61
|
||||
#define P3 0x62
|
||||
#define P4 0x63
|
||||
|
||||
class TMainWindow : public BWindow {
|
||||
public:
|
||||
TMainWindow(BRect bound, char* name, window_type type,
|
||||
long flags);
|
||||
virtual ~TMainWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
void UpdateScrollBars();
|
||||
|
||||
private:
|
||||
TShowBit* fView;
|
||||
};
|
||||
|
||||
|
||||
TMainWindow::TMainWindow(BRect bound, char* name, window_type type, long flags)
|
||||
: BWindow(bound, name, type, flags)
|
||||
{
|
||||
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 1000, 15), "MB");
|
||||
BMenuItem* item;
|
||||
BMenu* menu;
|
||||
|
||||
menu = new BMenu("File");
|
||||
menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
menu = new BMenu("Palette");
|
||||
menu->AddItem(new BMenuItem("Palette1", new BMessage(P1)));
|
||||
menu->AddItem(new BMenuItem("Palette2", new BMessage(P2)));
|
||||
menu->AddItem(item = new BMenuItem("Palette3", new BMessage(P3)));
|
||||
menu->AddItem(new BMenuItem("Palette4", new BMessage(P4)));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
item->SetMarked(true);
|
||||
menu->SetRadioMode(true);
|
||||
|
||||
menu = new BMenu("Iterations");
|
||||
menu->AddItem(new BMenuItem("128", new BMessage(128)));
|
||||
menu->AddItem(item = new BMenuItem("256", new BMessage(256)));
|
||||
menu->AddItem(new BMenuItem("384", new BMessage(384)));
|
||||
menu->AddItem(new BMenuItem("512", new BMessage(512)));
|
||||
menu->AddItem(new BMenuItem("768", new BMessage(768)));
|
||||
menu->AddItem(new BMenuItem("1024", new BMessage(1024)));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
item->SetMarked(true);
|
||||
menu->SetRadioMode(true);
|
||||
|
||||
AddChild(menuBar);
|
||||
float barHeight = menuBar->Bounds().Height();
|
||||
|
||||
fView = new TShowBit(BRect(0, barHeight + 1, 188 - B_V_SCROLL_BAR_WIDTH,
|
||||
188 - B_H_SCROLL_BAR_HEIGHT), B_FOLLOW_ALL | B_WILL_DRAW);
|
||||
BScrollView *scrollView = new BScrollView("scroll view", fView,
|
||||
B_FOLLOW_ALL, B_WILL_DRAW, true, true, B_NO_BORDER);
|
||||
AddChild(scrollView);
|
||||
|
||||
SetSizeLimits(80, size_x + 13, 80 + 20, size_y + barHeight + 1 + 13);
|
||||
ResizeTo(size_x + 13, size_y + barHeight + 1 + 13);
|
||||
SetPulseRate(150000);
|
||||
UpdateScrollBars();
|
||||
}
|
||||
|
||||
|
||||
TMainWindow::~TMainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMainWindow::UpdateScrollBars()
|
||||
{
|
||||
BScrollView* scrollview;
|
||||
BScrollBar* scrollbar;
|
||||
BRect visible_extent;
|
||||
BRect total_extent;
|
||||
BRect bound;
|
||||
BRect my_bounds;
|
||||
long max;
|
||||
|
||||
Lock();
|
||||
if ((scrollview = (BScrollView*)FindView("scroll view"))) {
|
||||
bound.Set(0, 0, size_x, size_y);
|
||||
my_bounds = Bounds();
|
||||
|
||||
visible_extent = bound & my_bounds;
|
||||
total_extent = bound | my_bounds;
|
||||
|
||||
scrollbar = scrollview->ScrollBar(B_HORIZONTAL);
|
||||
max = (long) (bound.Width() - my_bounds.Width());
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
scrollbar->SetRange(0, max);
|
||||
scrollbar->SetProportion(visible_extent.Width() / total_extent.Width());
|
||||
|
||||
scrollbar = scrollview->ScrollBar(B_VERTICAL);
|
||||
max = (long) (bound.Height() - my_bounds.Height());
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
scrollbar->SetRange(0, max);
|
||||
scrollbar->SetProportion(visible_extent.Height() / total_extent.Height());
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMainWindow::FrameResized(float, float)
|
||||
{
|
||||
UpdateScrollBars();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TMainWindow::QuitRequested()
|
||||
{
|
||||
if (fView->busy) {
|
||||
fView->exit_now = true;
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
return false;
|
||||
}
|
||||
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMainWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case P1:
|
||||
case P2:
|
||||
case P3:
|
||||
case P4:
|
||||
fView->set_palette(message->what - P1);
|
||||
break;
|
||||
|
||||
case 128:
|
||||
case 256:
|
||||
case 384:
|
||||
case 512:
|
||||
case 768:
|
||||
case 1024:
|
||||
fView->set_iter(message->what);
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int, char**)
|
||||
{
|
||||
BApplication* app = new BApplication("application/x-vnd.Be-MAND");
|
||||
|
||||
BWindow* window = new TMainWindow(BRect(100, 100, 288, 288), "Mandelbrot",
|
||||
B_DOCUMENT_WINDOW, B_WILL_ACCEPT_FIRST_CLICK);
|
||||
window->Show();
|
||||
|
||||
app->Run();
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
//******************************************************************************
|
||||
//
|
||||
// File: main.cpp
|
||||
//
|
||||
//******************************************************************************
|
||||
|
||||
/*
|
||||
Copyright 1993-1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include <Debug.h>
|
||||
|
||||
#ifndef _OS_H
|
||||
#include <OS.h>
|
||||
#endif
|
||||
#ifndef _APPLICATION_H
|
||||
#include <Application.h>
|
||||
#endif
|
||||
#ifndef _ROSTER_H
|
||||
#include <Roster.h>
|
||||
#endif
|
||||
#ifndef _BITMAP_H
|
||||
#include <Bitmap.h>
|
||||
#endif
|
||||
#ifndef _MENU_ITEM_H
|
||||
#include <MenuItem.h>
|
||||
#endif
|
||||
#ifndef _MENU_H
|
||||
#include <Menu.h>
|
||||
#endif
|
||||
#ifndef _MENU_BAR_H
|
||||
#include <MenuBar.h>
|
||||
#endif
|
||||
#ifndef _SCROLL_VIEW_H
|
||||
#include <ScrollView.h>
|
||||
#endif
|
||||
#ifndef _ALERT_H
|
||||
#include <Alert.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "tsb.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
/* Those are the menu item id's of the main window */
|
||||
|
||||
#define P1 0x60
|
||||
#define P2 0x61
|
||||
#define P3 0x62
|
||||
#define P4 0x63
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
class TMainWindow : public BWindow {
|
||||
public:
|
||||
TMainWindow(BRect bound, char *name, window_type type,
|
||||
long flags);
|
||||
virtual void MessageReceived(BMessage *an_event);
|
||||
virtual void FrameResized(float, float);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
virtual void UpdateScrollBars();
|
||||
|
||||
private:
|
||||
TShowBit *the_view;
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
TMainWindow::TMainWindow(BRect bound, char *name, window_type type, long flags)
|
||||
: BWindow(bound, name, type, flags)
|
||||
{
|
||||
BMenu *a_menu;
|
||||
BRect a_rect;
|
||||
BScrollView *scroll_view;
|
||||
BMenuBar *menubar;
|
||||
TShowBit *my_view;
|
||||
BMenuItem *item;
|
||||
|
||||
Lock();
|
||||
|
||||
a_rect.Set( 0, 0, 1000, 15);
|
||||
menubar = new BMenuBar(a_rect, "MB");
|
||||
|
||||
a_menu = new BMenu("File");
|
||||
a_menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||
menubar->AddItem(a_menu);
|
||||
|
||||
a_menu = new BMenu("Palette");
|
||||
a_menu->AddItem(new BMenuItem("Palette1", new BMessage(P1)));
|
||||
a_menu->AddItem(new BMenuItem("Palette2", new BMessage(P2)));
|
||||
a_menu->AddItem(item = new BMenuItem("Palette3", new BMessage(P3)));
|
||||
a_menu->AddItem(new BMenuItem("Palette4", new BMessage(P4)));
|
||||
menubar->AddItem(a_menu);
|
||||
|
||||
item->SetMarked(TRUE);
|
||||
a_menu->SetRadioMode(TRUE);
|
||||
|
||||
a_menu = new BMenu("Iterations");
|
||||
a_menu->AddItem(new BMenuItem("128", new BMessage(128)));
|
||||
a_menu->AddItem(item = new BMenuItem("256", new BMessage(256)));
|
||||
a_menu->AddItem(new BMenuItem("384", new BMessage(384)));
|
||||
a_menu->AddItem(new BMenuItem("512", new BMessage(512)));
|
||||
a_menu->AddItem(new BMenuItem("768", new BMessage(768)));
|
||||
a_menu->AddItem(new BMenuItem("1024", new BMessage(1024)));
|
||||
menubar->AddItem(a_menu);
|
||||
|
||||
item->SetMarked(TRUE);
|
||||
a_menu->SetRadioMode(TRUE);
|
||||
|
||||
AddChild(menubar);
|
||||
float mb_height = menubar->Bounds().Height();
|
||||
|
||||
a_rect.Set(0, mb_height + 1, 188 - B_V_SCROLL_BAR_WIDTH,
|
||||
188 - B_H_SCROLL_BAR_HEIGHT);
|
||||
the_view = my_view = new TShowBit(a_rect, B_FOLLOW_ALL | B_WILL_DRAW);
|
||||
scroll_view = new BScrollView("scroll view", my_view, B_FOLLOW_ALL, B_WILL_DRAW,
|
||||
TRUE, TRUE, B_NO_BORDER);
|
||||
// my_view->ResizeBy(-1, -1);
|
||||
AddChild(scroll_view);
|
||||
SetSizeLimits(80, size_x + 13, 80 + 20, size_y + mb_height + 1 + 13);
|
||||
ResizeTo(size_x + 13, size_y + mb_height + 1 + 13);
|
||||
SetPulseRate(150000);
|
||||
UpdateScrollBars();
|
||||
Show();
|
||||
Unlock();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
void TMainWindow::UpdateScrollBars()
|
||||
{
|
||||
BScrollView* scrollview;
|
||||
BScrollBar* scrollbar;
|
||||
BRect visible_extent;
|
||||
BRect total_extent;
|
||||
BRect bound;
|
||||
BRect my_bounds;
|
||||
long max;
|
||||
|
||||
Lock();
|
||||
if ((scrollview = (BScrollView*)FindView("scroll view"))) {
|
||||
bound.Set(0, 0, size_x, size_y);
|
||||
my_bounds = Bounds();
|
||||
|
||||
visible_extent = bound & my_bounds;
|
||||
total_extent = bound | my_bounds;
|
||||
|
||||
scrollbar = scrollview->ScrollBar(B_HORIZONTAL);
|
||||
max = (long) (bound.Width() - my_bounds.Width());
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
scrollbar->SetRange(0, max);
|
||||
scrollbar->SetProportion(visible_extent.Width() / total_extent.Width());
|
||||
|
||||
scrollbar = scrollview->ScrollBar(B_VERTICAL);
|
||||
max = (long) (bound.Height() - my_bounds.Height());
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
scrollbar->SetRange(0, max);
|
||||
scrollbar->SetProportion(visible_extent.Height() / total_extent.Height());
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
void TMainWindow::FrameResized(float, float)
|
||||
{
|
||||
UpdateScrollBars();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
bool TMainWindow::QuitRequested()
|
||||
{
|
||||
if (the_view->busy) {
|
||||
the_view->exit_now = TRUE;
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
void TMainWindow::MessageReceived(BMessage *an_event)
|
||||
{
|
||||
|
||||
switch(an_event->what) {
|
||||
case P1 :
|
||||
case P2 :
|
||||
case P3 :
|
||||
case P4 :
|
||||
the_view->set_palette(an_event->what - P1);
|
||||
break;
|
||||
|
||||
case 128 :
|
||||
case 256 :
|
||||
case 384 :
|
||||
case 512 :
|
||||
case 768 :
|
||||
case 1024 :
|
||||
the_view->set_iter(an_event->what);
|
||||
break;
|
||||
|
||||
default:
|
||||
inherited::MessageReceived(an_event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
BApplication *my_app;
|
||||
TMainWindow *a_window;
|
||||
BRect a_rect;
|
||||
|
||||
set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY);
|
||||
|
||||
my_app = new BApplication("application/x-vnd.Be-MAND");
|
||||
|
||||
a_rect.Set(100, 100, 288, 288);
|
||||
a_window = new TMainWindow(a_rect, "Mandelbrot", B_DOCUMENT_WINDOW,
|
||||
B_WILL_ACCEPT_FIRST_CLICK);
|
||||
my_app->Run();
|
||||
|
||||
delete my_app;
|
||||
}
|
Loading…
Reference in New Issue
Block a user