screen_savers: Initial import of GLife
* Donated to Haiku by author (Aaron Hill) under the MIT license. * Resources conveted to rdef * Headers cleaned up * Jamfile created
This commit is contained in:
parent
8ea0100184
commit
0b4c5624c6
@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons screen_savers ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers butterfly ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers debugnow ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers flurry ;
|
||||
#SubInclude HAIKU_TOP src add-ons screen_savers glife ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers haiku ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers icons ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers ifs ;
|
||||
|
69
src/add-ons/screen_savers/glife/GLife.rdef
Normal file
69
src/add-ons/screen_savers/glife/GLife.rdef
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
resource app_signature "application/x-vnd.Haiku-GLifeScreensaver";
|
||||
|
||||
resource app_name_catalog_entry "x-vnd.Haiku-GLifeScreensaver:System name:GLife";
|
||||
|
||||
resource app_version {
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
variety = 0,
|
||||
internal = 0,
|
||||
short_info = "1.0.0",
|
||||
long_info = "A GL 'Game of Life' Screensaver"
|
||||
};
|
||||
|
||||
|
||||
resource large_icon array {
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000FFFFFF"
|
||||
$"FFFFFFFF3939FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFF00FFFF"
|
||||
$"FFFFFF3934343939FFFFFFFFFFFFFFFFFFFFFFFF00FF000000FFFFFFFFFF00FF"
|
||||
$"FFFF3934343434343939FFFFFFFFFFFFFFFFFFFF00FFFFFF00FF000000FF00FF"
|
||||
$"FF393434343434349FDF3939FFFFFFFFFFFFFFFF00FFFF00FFFFFFFF00FF00FF"
|
||||
$"394F34343434349F9F3934343939FFFFFFFFFFFF00FF000000FFFF00FFFF00FF"
|
||||
$"39374F4F34349F9F3934343434343939FFFFFFFF00FFFFFFFFFF000000FF00FF"
|
||||
$"393737374F9F9F393434343434349FDFFFFFFFFFFF00FFFFFFFFFFFFFFFF00FF"
|
||||
$"39373737379F394F34343434349F9FDFFFFFFFFFFFFF00000000000000FF00FF"
|
||||
$"39393737379F39374F4F34349F9F9FDFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FF"
|
||||
$"FFFF3939379F393737374F9F9F9F9FDFFFFFFFFFFFFF3939FFFFFFFFFFFF00FF"
|
||||
$"FFFFFFFF39DF39373737379F9F9FDFFFFFFFFFFFFF3934343939FFFFFFFFFFFF"
|
||||
$"FFFFFF39343439393737379F9FDFFFFF3939FFFF3934343434343939FFFFFFFF"
|
||||
$"FFFF3934343434343939379FDFFFFF39343439393434343434349FDFFFFFFFFF"
|
||||
$"FF393434343434349FDF39DFFFFF39343434394F34343434349F9FDFFFFFFFFF"
|
||||
$"394F34343434349F9F393434FF393434343439374F4F34349F9F9FDFFFFFFFFF"
|
||||
$"39374F4F34349F9F39343434394F34343434393737374F9F9F9F9FDFFFFFFFFF"
|
||||
$"393737374F9F9F393434343439374F4F343439373737379F9F9FDFDFFFFFFFFF"
|
||||
$"39373737379F394F34343434393737374F9F39393737379F9FDF9FDFFFFFFFFF"
|
||||
$"39393737379F39374F4F343439373737379F39373939379FDF9F9FDFFFFFFFFF"
|
||||
$"FFFF3939379F393737374F9F39393737379F3937373739DF9F9F9FDFFFFFFFFF"
|
||||
$"FFFFFFFF39DF39373737379F9F9F3939379F393737374F9F9F9F9FDF10FFFFFF"
|
||||
$"FFFFFFFFFFFF39393737379F9FDF101039DF39373737379F9F9FDFDF101010FF"
|
||||
$"FFFFFFFFFFFFFFFF3939379FDF1010FFFFFF39393737379F9FDF9FDF10101010"
|
||||
$"FFFFFFFFFFFFFFFFFFFF39DF1010FFFFFFFF39373939379FDF9F9FDF10101010"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3937373739DF9F9F9FDF101010FF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF393737374F9F9F9F9FDF1010FFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF39373737379F9F9FDF1010FFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF39393737379F9FDF1010FFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3939379FDF1010FFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF39DF1010FFFFFFFFFFFF"
|
||||
};
|
||||
|
||||
resource mini_icon array {
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFF000000FFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFF00FF000000FF"
|
||||
$"FFFFFFFFFFFFFFFFFF00FFFFFFFF00FF"
|
||||
$"FFFFFFFFFFFFFFFF000000FFFF00FFFF"
|
||||
$"FFFFFFFF3939FFFFFFFFFFFF000000FF"
|
||||
$"FFFFFF3934343939FFFFFFFFFFFFFFFF"
|
||||
$"FFFF3934343434343939FFFFFFFFFFFF"
|
||||
$"FF393434343434349FDFFFFFFFFFFFFF"
|
||||
$"394F34343434349F9FDF10FFFFFFFFFF"
|
||||
$"39374F4F34349F9F9FDF1010FFFFFFFF"
|
||||
$"393737374F9F9F9F9FDF1010FFFFFFFF"
|
||||
$"39373737379F9F9FDF1010FFFFFFFFFF"
|
||||
$"39393737379F9FDF1010FFFFFFFFFFFF"
|
||||
$"FFFF3939379FDF1010FFFFFFFFFFFFFF"
|
||||
$"FFFFFFFF39DF1010FFFFFFFFFFFFFFFF"
|
||||
};
|
110
src/add-ons/screen_savers/glife/GLifeConfig.cpp
Normal file
110
src/add-ons/screen_savers/glife/GLifeConfig.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Slider.h>
|
||||
#include <StringView.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "GLifeState.hpp"
|
||||
#include "GLifeConfig.hpp"
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeConfig Class Constructor Definition
|
||||
GLifeConfig::GLifeConfig( BRect rFrame, GLifeState* pglsState )
|
||||
: BView( rFrame, "", B_FOLLOW_NONE, B_WILL_DRAW ),
|
||||
m_pglsState( pglsState )
|
||||
{
|
||||
// Static Labels
|
||||
AddChild( new BStringView( BRect(10, 0, 240, 12), B_EMPTY_STRING,
|
||||
"Open GL \"Game of Life\" Screen Saver" ) );
|
||||
AddChild( new BStringView( BRect(16, 14, 240, 26), B_EMPTY_STRING,
|
||||
"by Aaron Hill" ) );
|
||||
|
||||
// Sliders
|
||||
m_pbsGridWidth = new BSlider( BRect(10, 34, 234, 84), "GridWidth",
|
||||
"Width of Grid : ",
|
||||
new BMessage( e_midGridWidth ),
|
||||
10, 100, B_BLOCK_THUMB );
|
||||
m_pbsGridWidth->SetHashMarks( B_HASH_MARKS_BOTTOM );
|
||||
m_pbsGridWidth->SetLimitLabels( "10", "100" );
|
||||
m_pbsGridWidth->SetValue( pglsState->GridWidth() );
|
||||
m_pbsGridWidth->SetHashMarkCount( 10 );
|
||||
AddChild( m_pbsGridWidth );
|
||||
|
||||
m_pbsGridHeight = new BSlider( BRect(10, 86, 234, 136), "GridHeight",
|
||||
"Height of Grid : ",
|
||||
new BMessage( e_midGridHeight ),
|
||||
10, 100, B_BLOCK_THUMB );
|
||||
m_pbsGridHeight->SetHashMarks( B_HASH_MARKS_BOTTOM );
|
||||
m_pbsGridHeight->SetLimitLabels( "10", "100" );
|
||||
m_pbsGridHeight->SetValue( pglsState->GridHeight() );
|
||||
m_pbsGridHeight->SetHashMarkCount( 10 );
|
||||
AddChild( m_pbsGridHeight );
|
||||
|
||||
m_pbsBorder = new BSlider( BRect(10, 138, 234, 188), "Border",
|
||||
"Overlap Border : ",
|
||||
new BMessage( e_midBorder ),
|
||||
0, 10, B_BLOCK_THUMB );
|
||||
m_pbsBorder->SetHashMarks( B_HASH_MARKS_BOTTOM );
|
||||
m_pbsBorder->SetLimitLabels( "0", "10" );
|
||||
m_pbsBorder->SetValue( pglsState->Border() );
|
||||
m_pbsBorder->SetHashMarkCount( 11 );
|
||||
AddChild( m_pbsBorder );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeConfig Class AttachedToWindow Definition
|
||||
void GLifeConfig::AttachedToWindow( void )
|
||||
{
|
||||
SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
|
||||
|
||||
m_pbsGridWidth->SetTarget( this );
|
||||
m_pbsGridHeight->SetTarget( this );
|
||||
m_pbsBorder->SetTarget( this );
|
||||
|
||||
#ifdef _USE_ASYNCHRONOUS
|
||||
|
||||
m_uiWindowFlags = Window()->Flags();
|
||||
Window()->SetFlags( m_uiWindowFlags | B_ASYNCHRONOUS_CONTROLS );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeConfig Class MessageReceived Definition
|
||||
void GLifeConfig::MessageReceived( BMessage* pbmMessage )
|
||||
{
|
||||
char szNewLabel[64];
|
||||
int32 iValue;
|
||||
|
||||
switch( pbmMessage->what )
|
||||
{
|
||||
case e_midGridWidth:
|
||||
m_pglsState->GridWidth() = ( iValue = m_pbsGridWidth->Value() );
|
||||
sprintf( szNewLabel, "Width of Grid : %li", iValue );
|
||||
m_pbsGridWidth->SetLabel( szNewLabel );
|
||||
break;
|
||||
case e_midGridHeight:
|
||||
m_pglsState->GridHeight() = ( iValue = m_pbsGridHeight->Value() );
|
||||
sprintf( szNewLabel, "Height of Grid : %li", iValue );
|
||||
m_pbsGridHeight->SetLabel( szNewLabel );
|
||||
break;
|
||||
case e_midBorder:
|
||||
m_pglsState->Border() = ( iValue = m_pbsBorder->Value() );
|
||||
sprintf( szNewLabel, "Overlap Border : %li", iValue );
|
||||
m_pbsBorder->SetLabel( szNewLabel );
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived( pbmMessage );
|
||||
break;
|
||||
}
|
||||
}
|
45
src/add-ons/screen_savers/glife/GLifeConfig.hpp
Normal file
45
src/add-ons/screen_savers/glife/GLifeConfig.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
#ifndef _GLIFE_GLIFECONFIG_HPP
|
||||
#define _GLIFE_GLIFECONFIG_HPP
|
||||
|
||||
|
||||
#include <Slider.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "GLifeState.hpp"
|
||||
|
||||
|
||||
// Message IDs
|
||||
enum {
|
||||
e_midGridWidth = 'grdw',
|
||||
e_midGridHeight = 'grdh',
|
||||
e_midBorder = 'bord'
|
||||
};
|
||||
|
||||
|
||||
// GLifeConfig Class Declaration
|
||||
class GLifeConfig : public BView
|
||||
{
|
||||
private:
|
||||
GLifeState* m_pglsState;
|
||||
|
||||
uint32 m_uiWindowFlags;
|
||||
|
||||
BSlider* m_pbsGridWidth;
|
||||
BSlider* m_pbsGridHeight;
|
||||
BSlider* m_pbsBorder;
|
||||
|
||||
public:
|
||||
GLifeConfig( BRect, GLifeState* );
|
||||
|
||||
void AttachedToWindow( void );
|
||||
void MessageReceived( BMessage* );
|
||||
};
|
||||
|
||||
#endif /* _GLIFE_GLIFECONFIG_HPP */
|
86
src/add-ons/screen_savers/glife/GLifeGrid.cpp
Normal file
86
src/add-ons/screen_savers/glife/GLifeGrid.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include "GLifeGrid.hpp"
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeGrid Class Neighbors Definition
|
||||
inline int32 GLifeGrid::Neighbors( int32 iRow, int32 iColumn )
|
||||
{
|
||||
return ( Occupied( iRow - 1, iColumn - 1 ) ? 1 : 0 ) +
|
||||
( Occupied( iRow - 1, iColumn ) ? 1 : 0 ) +
|
||||
( Occupied( iRow - 1, iColumn + 1 ) ? 1 : 0 ) +
|
||||
( Occupied( iRow , iColumn - 1 ) ? 1 : 0 ) +
|
||||
( Occupied( iRow , iColumn + 1 ) ? 1 : 0 ) +
|
||||
( Occupied( iRow + 1, iColumn - 1 ) ? 1 : 0 ) +
|
||||
( Occupied( iRow + 1, iColumn ) ? 1 : 0 ) +
|
||||
( Occupied( iRow + 1, iColumn + 1 ) ? 1 : 0 );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeGrid Class Constructor Definition
|
||||
GLifeGrid::GLifeGrid( int32 iWidth, int32 iHeight )
|
||||
: m_iWidth( iWidth ), m_iHeight( iHeight )
|
||||
{
|
||||
m_pbGrid = new bool[iWidth * iHeight];
|
||||
|
||||
// Randomize new grid
|
||||
for( int32 iRow = 0; iRow < iHeight; ++iRow )
|
||||
{
|
||||
for( int32 iColumn = 0; iColumn < iWidth; ++iColumn )
|
||||
{
|
||||
// TODO: Allow for customized randomization level
|
||||
m_pbGrid[ ( iRow * iWidth ) + iColumn ] = ( (rand() % 6 ) == 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeGrid Class Destructor Definition
|
||||
GLifeGrid::~GLifeGrid( void )
|
||||
{
|
||||
delete m_pbGrid;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeGrid Class Generation Definition
|
||||
void GLifeGrid::Generation( void )
|
||||
{
|
||||
bool* pbTemp = new bool[m_iWidth * m_iHeight];
|
||||
|
||||
for( int32 iRow = 0; iRow < m_iHeight; ++iRow )
|
||||
{
|
||||
for( int32 iColumn = 0; iColumn < m_iWidth; ++iColumn )
|
||||
{
|
||||
int32 iNum = Neighbors( iRow, iColumn );
|
||||
pbTemp[ ( iRow * m_iWidth ) + iColumn ] =
|
||||
( ( iNum == 3 ) ||
|
||||
( Occupied( iRow, iColumn ) && iNum >= 2 && iNum <= 3 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
delete m_pbGrid;
|
||||
m_pbGrid = pbTemp;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeGrid Class Occupied Definition
|
||||
bool GLifeGrid::Occupied( int32 iRow, int32 iColumn )
|
||||
{
|
||||
int32 iNewRow = ( iRow % m_iHeight ), iNewColumn = ( iColumn % m_iWidth );
|
||||
while( iNewRow < 0 ) iNewRow += m_iHeight;
|
||||
while( iNewColumn < 0 ) iNewColumn += m_iWidth;
|
||||
return m_pbGrid[ ( iNewRow * m_iWidth ) + iNewColumn ];
|
||||
}
|
32
src/add-ons/screen_savers/glife/GLifeGrid.hpp
Normal file
32
src/add-ons/screen_savers/glife/GLifeGrid.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
#ifndef _GLIFE_GLIFEGRID_HPP
|
||||
#define _GLIFE_GLIFEGRID_HPP
|
||||
|
||||
|
||||
// GLifeGrid Class Declaration
|
||||
class GLifeGrid
|
||||
{
|
||||
private:
|
||||
bool* m_pbGrid;
|
||||
int32 m_iWidth;
|
||||
int32 m_iHeight;
|
||||
|
||||
int32 Neighbors( int32, int32 );
|
||||
|
||||
public:
|
||||
// Constructor & Destructor
|
||||
GLifeGrid( int32, int32 );
|
||||
~GLifeGrid( void );
|
||||
// Public Methods
|
||||
void Generation( void );
|
||||
// Accessor Methods
|
||||
bool Occupied( int32, int32 );
|
||||
};
|
||||
|
||||
#endif /* _GLIFE_GLIFEGRID_HPP */
|
113
src/add-ons/screen_savers/glife/GLifeSaver.cpp
Normal file
113
src/add-ons/screen_savers/glife/GLifeSaver.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GLView.h>
|
||||
#include <ScreenSaver.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "GLifeGrid.hpp"
|
||||
#include "GLifeState.hpp"
|
||||
#include "GLifeConfig.hpp"
|
||||
#include "GLifeView.hpp"
|
||||
#include "GLifeSaver.hpp"
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class Constructor Definition
|
||||
GLifeSaver::GLifeSaver( BMessage* pbmPrefs, image_id iidImage )
|
||||
: BScreenSaver( pbmPrefs, iidImage )
|
||||
{
|
||||
// Check for preferences
|
||||
if ( !( pbmPrefs->IsEmpty() ) )
|
||||
RestoreState( pbmPrefs );
|
||||
|
||||
// Seed random number generator
|
||||
srandom( system_time() );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class SaveState Definition
|
||||
status_t GLifeSaver::SaveState( BMessage* pbmPrefs ) const
|
||||
{
|
||||
return m_glsState.SaveState( pbmPrefs );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class RestoreState Definition
|
||||
void GLifeSaver::RestoreState( BMessage* pbmPrefs )
|
||||
{
|
||||
m_glsState.RestoreState( pbmPrefs );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class StartConfig Definition
|
||||
void GLifeSaver::StartConfig( BView* pbvView )
|
||||
{
|
||||
// Setup the "config" class
|
||||
GLifeConfig* pglcConfig = new GLifeConfig( pbvView->Bounds(),
|
||||
&m_glsState );
|
||||
pbvView->AddChild( pglcConfig );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class StartSaver Definition
|
||||
status_t GLifeSaver::StartSaver( BView* pbvView, bool bPreview )
|
||||
{
|
||||
if ( bPreview )
|
||||
{
|
||||
// We do not use the preview option
|
||||
m_pglvViewport = 0;
|
||||
return B_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTickSize( c_iTickSize );
|
||||
|
||||
m_pglvViewport = new GLifeView( pbvView->Bounds(),
|
||||
"GLifeView",
|
||||
B_FOLLOW_NONE,
|
||||
BGL_RGB | BGL_DEPTH | BGL_DOUBLE,
|
||||
&m_glsState );
|
||||
pbvView->AddChild( m_pglvViewport );
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class StopSaver Definition
|
||||
void GLifeSaver::StopSaver( void )
|
||||
{
|
||||
if ( m_pglvViewport )
|
||||
m_pglvViewport->EnableDirectMode( false );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class DirectConnected Definition
|
||||
void GLifeSaver::DirectConnected( direct_buffer_info* pdbiInfo )
|
||||
{
|
||||
m_pglvViewport->DirectConnected( pdbiInfo );
|
||||
m_pglvViewport->EnableDirectMode( true );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeSaver Class DirectDraw Definition
|
||||
void GLifeSaver::DirectDraw( int32 iFrame )
|
||||
{
|
||||
m_pglvViewport->Advance();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Main Instantiation Function
|
||||
extern "C" _EXPORT BScreenSaver*
|
||||
instantiate_screen_saver( BMessage* pbmPrefs, image_id iidImage )
|
||||
{
|
||||
return new GLifeSaver( pbmPrefs, iidImage );
|
||||
}
|
48
src/add-ons/screen_savers/glife/GLifeSaver.hpp
Normal file
48
src/add-ons/screen_savers/glife/GLifeSaver.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
#ifndef _GLIFE_GLIFESAVER_HPP
|
||||
#define _GLIFE_GLIFESAVER_HPP
|
||||
|
||||
|
||||
// Required Includes
|
||||
// #include <ScreenSaver.h>
|
||||
// #include <View.h>
|
||||
|
||||
|
||||
// Constants
|
||||
const int32 c_iTickSize = 50000;
|
||||
|
||||
|
||||
// GLifeSaver Class Declaration
|
||||
class GLifeSaver : public BScreenSaver
|
||||
{
|
||||
private:
|
||||
GLifeState m_glsState;
|
||||
|
||||
GLifeView* m_pglvViewport;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
GLifeSaver( BMessage*, image_id );
|
||||
|
||||
// State/Preferences Methods
|
||||
status_t SaveState( BMessage* ) const;
|
||||
void RestoreState( BMessage* );
|
||||
void StartConfig( BView* );
|
||||
|
||||
// Start/Stop Methods
|
||||
status_t StartSaver( BView*, bool );
|
||||
void StopSaver( void );
|
||||
|
||||
// Graphics Methods
|
||||
void DirectConnected( direct_buffer_info* );
|
||||
void DirectDraw( int32 );
|
||||
};
|
||||
|
||||
|
||||
#endif /* _GLIFE_GLIFESAVER_HPP */
|
63
src/add-ons/screen_savers/glife/GLifeState.hpp
Normal file
63
src/add-ons/screen_savers/glife/GLifeState.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
#ifndef _GLIFE_GLIFESTATE_HPP
|
||||
#define _GLIFE_GLIFESTATE_HPP
|
||||
|
||||
|
||||
// Constants
|
||||
const int32 c_iDefGridWidth = 60;
|
||||
const int32 c_iDefGridHeight = 40;
|
||||
const int32 c_iDefBorder = 0;
|
||||
|
||||
// GLifeState Class Declaration & Definition
|
||||
class GLifeState
|
||||
{
|
||||
private:
|
||||
int32 m_iGridWidth;
|
||||
int32 m_iGridHeight;
|
||||
int32 m_iBorder;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
GLifeState( void ) : m_iGridWidth(c_iDefGridWidth),
|
||||
m_iGridHeight(c_iDefGridHeight),
|
||||
m_iBorder(c_iDefBorder) { };
|
||||
|
||||
// Save/Restore State Methods
|
||||
status_t SaveState( BMessage* pbmPrefs ) const
|
||||
{
|
||||
// Store current preferences
|
||||
pbmPrefs->AddInt32( "m_iGridWidth", m_iGridWidth );
|
||||
pbmPrefs->AddInt32( "m_iGridHeight", m_iGridHeight );
|
||||
pbmPrefs->AddInt32( "m_iBorder", m_iBorder );
|
||||
|
||||
return B_OK;
|
||||
};
|
||||
|
||||
void RestoreState( BMessage* pbmPrefs )
|
||||
{
|
||||
// Retrieve preferences, substituting defaults
|
||||
if ( pbmPrefs->FindInt32( "m_iGridWidth",
|
||||
&m_iGridWidth ) != B_OK )
|
||||
m_iGridWidth = c_iDefGridWidth;
|
||||
if ( pbmPrefs->FindInt32( "m_iGridHeight",
|
||||
&m_iGridHeight ) != B_OK )
|
||||
m_iGridHeight = c_iDefGridHeight;
|
||||
if ( pbmPrefs->FindInt32( "m_iBorder",
|
||||
&m_iBorder ) != B_OK )
|
||||
m_iBorder = c_iDefBorder;
|
||||
};
|
||||
|
||||
// Accessor Methods
|
||||
int32& GridWidth( void ) { return m_iGridWidth; };
|
||||
int32& GridHeight( void ) { return m_iGridHeight; };
|
||||
int32& Border( void ) { return m_iBorder; };
|
||||
};
|
||||
|
||||
|
||||
#endif /* _GLIFE_GLIFESTATE_HPP */
|
184
src/add-ons/screen_savers/glife/GLifeView.cpp
Normal file
184
src/add-ons/screen_savers/glife/GLifeView.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GLView.h>
|
||||
|
||||
#include "GLifeGrid.hpp"
|
||||
#include "GLifeState.hpp"
|
||||
#include "GLifeView.hpp"
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeView Class Constructor Definition
|
||||
GLifeView::GLifeView(BRect rect, char* name, ulong resizingMode,
|
||||
ulong options, GLifeState* pglsState)
|
||||
:
|
||||
BGLView(rect, name, resizingMode, 0, options),
|
||||
m_pglsState(pglsState)
|
||||
{
|
||||
// Setup the grid
|
||||
m_pglgGrid = new GLifeGrid( pglsState->GridWidth(), pglsState->GridHeight() );
|
||||
|
||||
LockGL();
|
||||
|
||||
glClearDepth( 1.0 );
|
||||
glDepthFunc( GL_LESS );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
|
||||
#if 0
|
||||
glShadeModel( GL_SMOOTH );
|
||||
#endif
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( 45.0, rect.Width() / rect.Height(), 2.0, 20000.0 );
|
||||
glTranslatef( 0.0, 0.0, -50.0 );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
|
||||
UnlockGL();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeView Class Destructor Definition
|
||||
GLifeView::~GLifeView( void )
|
||||
{
|
||||
delete m_pglgGrid;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeView Class AttachedToWindow Definition
|
||||
void GLifeView::AttachedToWindow( void )
|
||||
{
|
||||
LockGL();
|
||||
BGLView::AttachedToWindow();
|
||||
UnlockGL();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeView Class Draw Definition
|
||||
void GLifeView::Draw(BRect updateRect)
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
// TODO: Dynamic colors or user-specified coloring
|
||||
GLfloat glfGreen[] = { 0.05, 0.8, 0.15, 1.0 };
|
||||
GLfloat glfOrange[] = { 0.65, 0.3, 0.05, 1.0 };
|
||||
|
||||
// Border control
|
||||
bool bColor;
|
||||
|
||||
int32 iWidth = m_pglsState->GridWidth();
|
||||
int32 iHeight = m_pglsState->GridHeight();
|
||||
int32 iBorder = m_pglsState->Border();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glRotatef( m_glfDelta * 3, 1.0, 0.0, 0.0 );
|
||||
glRotatef( m_glfDelta * 1, 0.0, 0.0, 1.0 );
|
||||
glRotatef( m_glfDelta * 2, 0.0, 1.0, 0.0 );
|
||||
|
||||
for( int32 iRow = ( 0 - iBorder ); iRow < ( iHeight + iBorder ); ++iRow )
|
||||
{
|
||||
GLfloat glfY = (GLfloat) iRow - ( (GLfloat) iHeight / 2 );
|
||||
|
||||
for( int32 iColumn = ( 0 - iBorder ); iColumn < ( iWidth + iBorder ); ++iColumn )
|
||||
{
|
||||
GLfloat glfX = (GLfloat) iColumn - ( (GLfloat) iWidth / 2 );
|
||||
|
||||
bColor = (iColumn < 0) || (iColumn >= iWidth) || (iRow < 0) || (iRow >= iHeight);
|
||||
|
||||
if ( m_pglgGrid->Occupied( iRow, iColumn ) )
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef( glfX, glfY, 0.0 );
|
||||
glScalef( 0.45, 0.45, 0.45 );
|
||||
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
if (bColor)
|
||||
glColor3f( 0.65, 0.3, 0.05 );
|
||||
else
|
||||
glColor3f( 0.05, 0.8, 0.15 );
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, bColor ? glfOrange : glfGreen);
|
||||
glNormal3f( 0.0, 1.0, 0.0 );
|
||||
glVertex3f( 1.0, 1.0, -1.0 );
|
||||
glVertex3f( -1.0, 1.0, -1.0 );
|
||||
glVertex3f( 1.0, 1.0, 1.0 );
|
||||
glVertex3f( -1.0, 1.0, 1.0 );
|
||||
|
||||
glNormal3f( 0.0, 0.0, 1.0 );
|
||||
glVertex3f( -1.0, 1.0, 1.0 );
|
||||
glVertex3f( 1.0, 1.0, 1.0 );
|
||||
glVertex3f( -1.0, -1.0, 1.0 );
|
||||
glVertex3f( 1.0, -1.0, 1.0 );
|
||||
|
||||
glNormal3f( 0.0, -1.0, 0.0 );
|
||||
glVertex3f( -1.0, -1.0, 1.0 );
|
||||
glVertex3f( 1.0, -1.0, 1.0 );
|
||||
glVertex3f( -1.0, -1.0, -1.0 );
|
||||
glVertex3f( 1.0, -1.0, -1.0 );
|
||||
glEnd();
|
||||
|
||||
glBegin( GL_QUAD_STRIP);
|
||||
if (bColor)
|
||||
glColor3f( 0.65, 0.3, 0.05 );
|
||||
else
|
||||
glColor3f( 0.05, 0.8, 0.15 );
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, bColor ? glfOrange : glfGreen);
|
||||
glNormal3f( -1.0, 0.0, 0.0 );
|
||||
glVertex3f( -1.0, 1.0, 1.0 );
|
||||
glVertex3f( -1.0, -1.0, 1.0 );
|
||||
glVertex3f( -1.0, 1.0, -1.0 );
|
||||
glVertex3f( -1.0, -1.0, -1.0 );
|
||||
|
||||
glNormal3f( 0.0, 0.0, -1.0 );
|
||||
glVertex3f( -1.0, 1.0, -1.0 );
|
||||
glVertex3f( -1.0, -1.0, -1.0 );
|
||||
glVertex3f( 1.0, 1.0, -1.0 );
|
||||
glVertex3f( 1.0, -1.0, -1.0 );
|
||||
|
||||
glNormal3f( 1.0, 0.0, 0.0 );
|
||||
glVertex3f( 1.0, 1.0, -1.0 );
|
||||
glVertex3f( 1.0, -1.0, -1.0 );
|
||||
glVertex3f( 1.0, 1.0, 1.0 );
|
||||
glVertex3f( 1.0, -1.0, 1.0 );
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeView Class Advance Definition
|
||||
void GLifeView::Advance( void )
|
||||
{
|
||||
if ( ( ++m_glfDelta ) > 360.0)
|
||||
m_glfDelta -= 360.0;
|
||||
// TODO: Allow for customized intervals
|
||||
if ( ( ++m_iStep ) > 4 )
|
||||
{
|
||||
m_iStep = 0;
|
||||
m_pglgGrid->Generation();
|
||||
}
|
||||
LockGL();
|
||||
BRect location(0,0,0,0);
|
||||
Draw(location);
|
||||
SwapBuffers();
|
||||
UnlockGL();
|
||||
}
|
36
src/add-ons/screen_savers/glife/GLifeView.hpp
Normal file
36
src/add-ons/screen_savers/glife/GLifeView.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
*/
|
||||
#ifndef _GLIFE_GLIFEVIEW_HPP
|
||||
#define _GLIFE_GLIFEVIEW_HPP
|
||||
|
||||
|
||||
#include <GLView.h>
|
||||
#include "GLifeState.hpp"
|
||||
|
||||
|
||||
// GLifeView Class Declaration
|
||||
class GLifeView : public BGLView {
|
||||
public:
|
||||
// Constructor & Destructor
|
||||
GLifeView( BRect, char*, ulong, ulong, GLifeState* );
|
||||
~GLifeView( void );
|
||||
|
||||
// Public Methods
|
||||
void AttachedToWindow( void );
|
||||
virtual void Draw(BRect updateRect);
|
||||
void Advance( void );
|
||||
|
||||
private:
|
||||
GLifeState* m_pglsState;
|
||||
GLifeGrid* m_pglgGrid;
|
||||
|
||||
GLfloat m_glfDelta;
|
||||
int32 m_iStep;
|
||||
};
|
||||
|
||||
#endif /* _GLIFE_GLIFEVIEW_HPP */
|
36
src/add-ons/screen_savers/glife/Jamfile
Normal file
36
src/add-ons/screen_savers/glife/Jamfile
Normal file
@ -0,0 +1,36 @@
|
||||
SubDir HAIKU_TOP src add-ons screen_savers glife ;
|
||||
SubDirSysHdrs $(HAIKU_MESA_HEADERS) ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
# For GCC2
|
||||
if $(HAIKU_GCC_VERSION[1]) < 3 {
|
||||
SubDirC++Flags --no-warnings ;
|
||||
}
|
||||
|
||||
UsePrivateHeaders screen_saver ;
|
||||
# For BuildScreenSaverDefaultSettingsView
|
||||
|
||||
local sources =
|
||||
GLifeSaver.cpp
|
||||
GLifeView.cpp
|
||||
GLifeGrid.cpp
|
||||
GLifeConfig.cpp
|
||||
;
|
||||
|
||||
Includes [ FGristFiles $(sources) ] : $(HAIKU_MESA_HEADERS_DEPENDENCY) ;
|
||||
# Dependency needed to trigger downloading/unzipping the package before
|
||||
# compiling the files.
|
||||
|
||||
AddResources GLife : GLife.rdef ;
|
||||
|
||||
ScreenSaver GLife :
|
||||
$(sources) :
|
||||
be screensaver GL $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
||||
DoCatalogs GLife :
|
||||
x-vnd.Haiku-GLifeScreensaver
|
||||
:
|
||||
$(sources)
|
||||
;
|
Loading…
Reference in New Issue
Block a user