glife: Enhance controls
* Re-organize controls to fit small ScreenSaver window * Add life delay factor slider * Make control labels more dynamic * Style cleanup
This commit is contained in:
parent
c81caff900
commit
05779cd9e3
@ -37,48 +37,64 @@ GLifeConfig::GLifeConfig(BRect frame, GLifeState* pglsState)
|
||||
"by Aaron Hill", B_FOLLOW_LEFT);
|
||||
|
||||
// Sliders
|
||||
fGridDelay = new BSlider(frame, "GridDelay",
|
||||
"Grid Life Delay: ",
|
||||
new BMessage(kGridDelay),
|
||||
0, 4, B_BLOCK_THUMB);
|
||||
|
||||
fGridDelay->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fGridDelay->SetLimitLabels("None", "4x");
|
||||
fGridDelay->SetValue(pglsState->GridDelay());
|
||||
fGridDelay->SetHashMarkCount(5);
|
||||
|
||||
fGridBorder = new BSlider(frame, "GridBorder",
|
||||
"Grid Border: ",
|
||||
new BMessage(kGridBorder),
|
||||
0, 10, B_BLOCK_THUMB);
|
||||
|
||||
fGridBorder->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fGridBorder->SetLimitLabels("0", "10");
|
||||
fGridBorder->SetValue(pglsState->GridBorder());
|
||||
fGridBorder->SetHashMarkCount(11);
|
||||
|
||||
fGridWidth = new BSlider(frame, "GridWidth",
|
||||
"Width of Grid: ",
|
||||
new BMessage(e_midGridWidth),
|
||||
"Grid Width: ",
|
||||
new BMessage(kGridWidth),
|
||||
10, 100, B_BLOCK_THUMB);
|
||||
|
||||
fGridWidth->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fGridWidth->SetLimitLabels("10", "100");
|
||||
//fGridWidth->SetLimitLabels("10", "100");
|
||||
fGridWidth->SetValue(pglsState->GridWidth());
|
||||
fGridWidth->SetHashMarkCount(10);
|
||||
|
||||
fGridHeight = new BSlider(frame, "GridHeight",
|
||||
"Height of Grid: ",
|
||||
new BMessage(e_midGridHeight),
|
||||
"Grid Height: ",
|
||||
new BMessage(kGridHeight),
|
||||
10, 100, B_BLOCK_THUMB);
|
||||
|
||||
fGridHeight->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fGridHeight->SetLimitLabels("10", "100");
|
||||
//fGridHeight->SetLimitLabels("10", "100");
|
||||
fGridHeight->SetValue(pglsState->GridHeight());
|
||||
fGridHeight->SetHashMarkCount(10);
|
||||
|
||||
fBorder = new BSlider(frame, "Border",
|
||||
"Overlap Border: ",
|
||||
new BMessage(e_midBorder),
|
||||
0, 10, B_BLOCK_THUMB);
|
||||
|
||||
fBorder->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fBorder->SetLimitLabels("0", "10");
|
||||
fBorder->SetValue(pglsState->Border());
|
||||
fBorder->SetHashMarkCount(11);
|
||||
|
||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
||||
.Add(BGroupLayoutBuilder(B_VERTICAL, 0)
|
||||
.Add(name)
|
||||
.Add(author)
|
||||
)
|
||||
.AddGlue()
|
||||
.Add(fGridDelay)
|
||||
.Add(fGridBorder)
|
||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
|
||||
.Add(fGridWidth)
|
||||
.Add(fGridHeight)
|
||||
.Add(fBorder)
|
||||
)
|
||||
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
|
||||
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
|
||||
);
|
||||
|
||||
// Do our first label update
|
||||
_UpdateLabels();
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +105,8 @@ GLifeConfig::AttachedToWindow(void)
|
||||
{
|
||||
fGridWidth->SetTarget(this);
|
||||
fGridHeight->SetTarget(this);
|
||||
fBorder->SetTarget(this);
|
||||
fGridBorder->SetTarget(this);
|
||||
fGridDelay->SetTarget(this);
|
||||
|
||||
#ifdef _USE_ASYNCHRONOUS
|
||||
|
||||
@ -100,33 +117,51 @@ GLifeConfig::AttachedToWindow(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GLifeConfig::_UpdateLabels()
|
||||
{
|
||||
char newLabel[64];
|
||||
snprintf(newLabel, sizeof(newLabel), "Grid Width: %li",
|
||||
fGridWidth->Value());
|
||||
fGridWidth->SetLabel(newLabel);
|
||||
snprintf(newLabel, sizeof(newLabel), "Grid Height: %li",
|
||||
fGridHeight->Value());
|
||||
fGridHeight->SetLabel(newLabel);
|
||||
snprintf(newLabel, sizeof(newLabel), "Grid Border: %li",
|
||||
fGridBorder->Value());
|
||||
fGridBorder->SetLabel(newLabel);
|
||||
|
||||
char delay[16];
|
||||
if (fGridDelay->Value() <= 0)
|
||||
sprintf(delay, "none");
|
||||
else
|
||||
sprintf(delay, "%" B_PRId32 "x", fGridDelay->Value());
|
||||
snprintf(newLabel, sizeof(newLabel), "Grid Life Delay: %s", delay);
|
||||
fGridDelay->SetLabel(newLabel);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// GLifeConfig Class MessageReceived Definition
|
||||
void
|
||||
GLifeConfig::MessageReceived(BMessage* pbmMessage)
|
||||
{
|
||||
char szNewLabel[64];
|
||||
int32 iValue;
|
||||
|
||||
switch(pbmMessage->what) {
|
||||
case e_midGridWidth:
|
||||
m_pglsState->GridWidth() = (iValue = fGridWidth->Value());
|
||||
sprintf(szNewLabel, "Width of Grid: %li", iValue);
|
||||
fGridWidth->SetLabel(szNewLabel);
|
||||
case kGridWidth:
|
||||
m_pglsState->GridWidth() = fGridWidth->Value();
|
||||
break;
|
||||
case e_midGridHeight:
|
||||
m_pglsState->GridHeight() = (iValue = fGridHeight->Value());
|
||||
sprintf(szNewLabel, "Height of Grid: %li", iValue);
|
||||
fGridHeight->SetLabel(szNewLabel);
|
||||
case kGridHeight:
|
||||
m_pglsState->GridHeight() = fGridHeight->Value();
|
||||
break;
|
||||
case e_midBorder:
|
||||
m_pglsState->Border() = (iValue = fBorder->Value());
|
||||
sprintf(szNewLabel, "Overlap Border: %li", iValue);
|
||||
fBorder->SetLabel(szNewLabel);
|
||||
case kGridBorder:
|
||||
m_pglsState->GridBorder() = fGridBorder->Value();
|
||||
break;
|
||||
case kGridDelay:
|
||||
m_pglsState->GridDelay() = fGridDelay->Value();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(pbmMessage);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
_UpdateLabels();
|
||||
}
|
||||
|
@ -17,9 +17,10 @@
|
||||
|
||||
// Message IDs
|
||||
enum {
|
||||
e_midGridWidth = 'grdw',
|
||||
e_midGridHeight = 'grdh',
|
||||
e_midBorder = 'bord'
|
||||
kGridWidth = 'grdw',
|
||||
kGridHeight = 'grdh',
|
||||
kGridBorder = 'bord',
|
||||
kGridDelay = 'dely'
|
||||
};
|
||||
|
||||
|
||||
@ -33,7 +34,9 @@ private:
|
||||
|
||||
BSlider* fGridWidth;
|
||||
BSlider* fGridHeight;
|
||||
BSlider* fBorder;
|
||||
BSlider* fGridBorder;
|
||||
BSlider* fGridDelay;
|
||||
void _UpdateLabels();
|
||||
|
||||
public:
|
||||
GLifeConfig(BRect, GLifeState*);
|
||||
|
@ -10,32 +10,35 @@
|
||||
|
||||
|
||||
// Constants
|
||||
const int32 c_iDefGridWidth = 60;
|
||||
const int32 c_iDefGridHeight = 40;
|
||||
const int32 c_iDefBorder = 0;
|
||||
const int32 kDefGridWidth = 60;
|
||||
const int32 kDefGridHeight = 40;
|
||||
const int32 kDefGridBorder = 0;
|
||||
const int32 kDefGridDelay = 2;
|
||||
|
||||
|
||||
// GLifeState Class Declaration & Definition
|
||||
class GLifeState
|
||||
{
|
||||
private:
|
||||
int32 m_iGridWidth;
|
||||
int32 m_iGridHeight;
|
||||
int32 m_iBorder;
|
||||
int32 fGridWidth;
|
||||
int32 fGridHeight;
|
||||
int32 fGridBorder;
|
||||
int32 fGridDelay;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
GLifeState( void ) : m_iGridWidth(c_iDefGridWidth),
|
||||
m_iGridHeight(c_iDefGridHeight),
|
||||
m_iBorder(c_iDefBorder) { };
|
||||
GLifeState( void ) : fGridWidth(kDefGridWidth),
|
||||
fGridHeight(kDefGridHeight),
|
||||
fGridBorder(kDefGridBorder),
|
||||
fGridDelay(kDefGridDelay) { };
|
||||
|
||||
// Save/Restore State Methods
|
||||
status_t SaveState( BMessage* pbmPrefs ) const
|
||||
{
|
||||
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 );
|
||||
pbmPrefs->AddInt32("gridWidth", fGridWidth);
|
||||
pbmPrefs->AddInt32("gridHeight", fGridHeight);
|
||||
pbmPrefs->AddInt32("gridBorder", fGridBorder);
|
||||
pbmPrefs->AddInt32("gridDelay", fGridDelay);
|
||||
|
||||
return B_OK;
|
||||
};
|
||||
@ -43,21 +46,21 @@ public:
|
||||
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;
|
||||
if (pbmPrefs->FindInt32("gridWidth", &fGridWidth) != B_OK)
|
||||
fGridWidth = kDefGridWidth;
|
||||
if (pbmPrefs->FindInt32("gridHeight", &fGridHeight) != B_OK)
|
||||
fGridHeight = kDefGridHeight;
|
||||
if (pbmPrefs->FindInt32("gridBorder", &fGridBorder) != B_OK)
|
||||
fGridBorder = kDefGridBorder;
|
||||
if (pbmPrefs->FindInt32("gridDelay", &fGridDelay) != B_OK)
|
||||
fGridDelay = kDefGridDelay;
|
||||
};
|
||||
|
||||
// Accessor Methods
|
||||
int32& GridWidth( void ) { return m_iGridWidth; };
|
||||
int32& GridHeight( void ) { return m_iGridHeight; };
|
||||
int32& Border( void ) { return m_iBorder; };
|
||||
int32& GridWidth(void) { return fGridWidth; };
|
||||
int32& GridHeight(void) { return fGridHeight; };
|
||||
int32& GridBorder(void) { return fGridBorder; };
|
||||
int32& GridDelay(void) { return fGridDelay; };
|
||||
};
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
*
|
||||
* Authors:
|
||||
* Aaron Hill <serac@hillvisions.com>
|
||||
* Alexander von Gluck <kallisti5@unixzen.com>
|
||||
*/
|
||||
|
||||
|
||||
@ -87,7 +88,7 @@ GLifeView::Draw(BRect updateRect)
|
||||
|
||||
int32 iWidth = m_pglsState->GridWidth();
|
||||
int32 iHeight = m_pglsState->GridHeight();
|
||||
int32 iBorder = m_pglsState->Border();
|
||||
int32 iBorder = m_pglsState->GridBorder();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
@ -182,8 +183,9 @@ GLifeView::Advance(void)
|
||||
{
|
||||
if (m_glfDelta++ > 360.0)
|
||||
m_glfDelta -= 360.0;
|
||||
// TODO: Allow for customized intervals
|
||||
if (m_iStep++ > 4) {
|
||||
|
||||
int32 gridDelay = m_pglsState->GridDelay();
|
||||
if (m_iStep++ > gridDelay) {
|
||||
m_iStep = 0;
|
||||
m_pglgGrid->Generation();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user