SpiderSaver: Style fixes, move SpiderView into own files
Fixes after rebase to make the thing work, along with some style fixes that got mixed in.
This commit is contained in:
@@ -8,6 +8,7 @@ ScreenSaver Spider :
|
|||||||
Polygon.cpp
|
Polygon.cpp
|
||||||
PolygonQueue.cpp
|
PolygonQueue.cpp
|
||||||
SpiderSaver.cpp
|
SpiderSaver.cpp
|
||||||
|
SpiderView.cpp
|
||||||
|
|
||||||
: be libscreensaver.so localestub [ TargetLibsupc++ ]
|
: be libscreensaver.so localestub [ TargetLibsupc++ ]
|
||||||
;
|
;
|
||||||
@@ -16,4 +17,5 @@ DoCatalogs Spider :
|
|||||||
x-vnd.Haiku-SpiderScreensaver
|
x-vnd.Haiku-SpiderScreensaver
|
||||||
:
|
:
|
||||||
SpiderSaver.cpp
|
SpiderSaver.cpp
|
||||||
|
SpiderView.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007-2009, Haiku, Inc. All rights reserved.
|
* Copyright 2007-2014 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SpiderSaver.h"
|
#include "SpiderSaver.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -15,115 +17,101 @@
|
|||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Menu.h>
|
|
||||||
#include <MenuField.h>
|
|
||||||
#include <MenuItem.h>
|
|
||||||
#include <Slider.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
|
|
||||||
#include "Polygon.h"
|
#include "Polygon.h"
|
||||||
#include "PolygonQueue.h"
|
#include "PolygonQueue.h"
|
||||||
|
#include "SpiderView.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "Screensaver Spider"
|
#define B_TRANSLATION_CONTEXT "Screensaver Spider"
|
||||||
|
|
||||||
enum {
|
|
||||||
MSG_QUEUE_NUMBER = 'qunm',
|
|
||||||
MSG_POLY_NUMBER = 'plnm',
|
|
||||||
MSG_QUEUE_DEPTH = 'qudp',
|
|
||||||
MSG_COLOR = 'colr',
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MIN_POLY_POINTS 3
|
// #pragma mark - Instantiation function
|
||||||
#define MAX_POLY_POINTS 10
|
|
||||||
#define MIN_QUEUE_DEPTH 40
|
|
||||||
#define MAX_QUEUE_DEPTH 160
|
|
||||||
#define MAX_QUEUE_NUMBER 40
|
|
||||||
|
|
||||||
enum {
|
|
||||||
RED = 1,
|
|
||||||
GREEN = 2,
|
|
||||||
BLUE = 3,
|
|
||||||
YELLOW = 4,
|
|
||||||
PURPLE = 5,
|
|
||||||
CYAN = 6,
|
|
||||||
GRAY = 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
// MAIN INSTANTIATION FUNCTION
|
|
||||||
extern "C" _EXPORT BScreenSaver*
|
extern "C" _EXPORT BScreenSaver*
|
||||||
instantiate_screen_saver(BMessage *message, image_id image)
|
instantiate_screen_saver(BMessage* message, image_id image)
|
||||||
{
|
{
|
||||||
return new SpiderSaver(message, image);
|
return new SpiderSaver(message, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
SpiderSaver::SpiderSaver(BMessage *message, image_id id)
|
// #pragma mark - SpiderSaver
|
||||||
: BScreenSaver(message, id),
|
|
||||||
fBackBitmap(NULL),
|
|
||||||
fBackView(NULL),
|
SpiderSaver::SpiderSaver(BMessage* message, image_id id)
|
||||||
fQueues(new PolygonQueue*[MAX_QUEUE_NUMBER]),
|
:
|
||||||
fQueueNumber(20),
|
BScreenSaver(message, id),
|
||||||
fMaxPolyPoints(MAX_POLY_POINTS),
|
fBackBitmap(NULL),
|
||||||
fMaxQueueDepth(MAX_QUEUE_DEPTH),
|
fBackView(NULL),
|
||||||
fColor(RED),
|
fQueues(new PolygonQueue*[MAX_QUEUE_NUMBER]),
|
||||||
fPreview(false)
|
fQueueNumber(20),
|
||||||
|
fMaxPolyPoints(MAX_POLY_POINTS),
|
||||||
|
fMaxQueueDepth(MAX_QUEUE_DEPTH),
|
||||||
|
fColor(RED),
|
||||||
|
fPreview(false)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < MAX_QUEUE_NUMBER; i++)
|
for (int32 i = 0; i < MAX_QUEUE_NUMBER; i++)
|
||||||
fQueues[i] = NULL;
|
fQueues[i] = NULL;
|
||||||
if (message) {
|
|
||||||
|
if (message != NULL) {
|
||||||
int32 value;
|
int32 value;
|
||||||
if (message->FindInt32("queue number", &value) == B_OK)
|
if (message->FindInt32("queue number", &value) == B_OK)
|
||||||
fQueueNumber = value;
|
fQueueNumber = value;
|
||||||
|
|
||||||
if (message->FindInt32("poly points", &value) == B_OK)
|
if (message->FindInt32("poly points", &value) == B_OK)
|
||||||
fMaxPolyPoints = value;
|
fMaxPolyPoints = value;
|
||||||
|
|
||||||
if (message->FindInt32("queue depth", &value) == B_OK)
|
if (message->FindInt32("queue depth", &value) == B_OK)
|
||||||
fMaxQueueDepth = value;
|
fMaxQueueDepth = value;
|
||||||
|
|
||||||
if (message->FindInt32("color", &value) == B_OK)
|
if (message->FindInt32("color", &value) == B_OK)
|
||||||
fColor = value;
|
fColor = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
srand48((long int)system_time());
|
srand48((long int)system_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
SpiderSaver::~SpiderSaver()
|
SpiderSaver::~SpiderSaver()
|
||||||
{
|
{
|
||||||
_Cleanup();
|
_Cleanup();
|
||||||
delete[] fQueues;
|
delete[] fQueues;
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartConfig
|
|
||||||
void
|
void
|
||||||
SpiderSaver::StartConfig(BView *view)
|
SpiderSaver::StartConfig(BView* view)
|
||||||
{
|
{
|
||||||
SpiderView* configView = new SpiderView(view->Bounds(), this,
|
SpiderView* configView = new SpiderView(view->Bounds(), this,
|
||||||
fQueueNumber, fMaxPolyPoints, fMaxQueueDepth, fColor);
|
fQueueNumber, fMaxPolyPoints, fMaxQueueDepth, fColor);
|
||||||
view->AddChild(configView);
|
view->AddChild(configView);
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartSaver
|
|
||||||
status_t
|
status_t
|
||||||
SpiderSaver::StartSaver(BView *v, bool preview)
|
SpiderSaver::StartSaver(BView* view, bool preview)
|
||||||
{
|
{
|
||||||
SetTickSize(50000);
|
SetTickSize(50000);
|
||||||
|
|
||||||
fPreview = preview;
|
fPreview = preview;
|
||||||
fBounds = v->Bounds();
|
fBounds = view->Bounds();
|
||||||
_Init(fBounds);
|
_Init(fBounds);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopSaver
|
|
||||||
void
|
void
|
||||||
SpiderSaver::StopSaver()
|
SpiderSaver::StopSaver()
|
||||||
{
|
{
|
||||||
_Cleanup();
|
_Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw
|
|
||||||
void
|
void
|
||||||
SpiderSaver::Draw(BView *view, int32 frame)
|
SpiderSaver::Draw(BView* view, int32 frame)
|
||||||
{
|
{
|
||||||
fLocker.Lock();
|
fLocker.Lock();
|
||||||
for (uint32 i = 0; i < fQueueNumber; i++) {
|
for (uint32 i = 0; i < fQueueNumber; i++) {
|
||||||
@@ -141,21 +129,23 @@ SpiderSaver::Draw(BView *view, int32 frame)
|
|||||||
fLocker.Unlock();
|
fLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveState
|
|
||||||
status_t
|
status_t
|
||||||
SpiderSaver::SaveState(BMessage* into) const
|
SpiderSaver::SaveState(BMessage* into) const
|
||||||
{
|
{
|
||||||
if (into) {
|
if (into != NULL) {
|
||||||
into->AddInt32("queue number", (int32)fQueueNumber);
|
into->AddInt32("queue number", (int32)fQueueNumber);
|
||||||
into->AddInt32("poly points", (int32)fMaxPolyPoints);
|
into->AddInt32("poly points", (int32)fMaxPolyPoints);
|
||||||
into->AddInt32("queue depth", (int32)fMaxQueueDepth);
|
into->AddInt32("queue depth", (int32)fMaxQueueDepth);
|
||||||
into->AddInt32("color", (int32)fColor);
|
into->AddInt32("color", (int32)fColor);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetQueueNumber
|
|
||||||
void
|
void
|
||||||
SpiderSaver::SetQueueNumber(uint32 number)
|
SpiderSaver::SetQueueNumber(uint32 number)
|
||||||
{
|
{
|
||||||
@@ -166,7 +156,7 @@ SpiderSaver::SetQueueNumber(uint32 number)
|
|||||||
fLocker.Unlock();
|
fLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetQueueDepth
|
|
||||||
void
|
void
|
||||||
SpiderSaver::SetQueueDepth(uint32 maxDepth)
|
SpiderSaver::SetQueueDepth(uint32 maxDepth)
|
||||||
{
|
{
|
||||||
@@ -177,7 +167,7 @@ SpiderSaver::SetQueueDepth(uint32 maxDepth)
|
|||||||
fLocker.Unlock();
|
fLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPolyPoints
|
|
||||||
void
|
void
|
||||||
SpiderSaver::SetPolyPoints(uint32 maxPoints)
|
SpiderSaver::SetPolyPoints(uint32 maxPoints)
|
||||||
{
|
{
|
||||||
@@ -188,7 +178,7 @@ SpiderSaver::SetPolyPoints(uint32 maxPoints)
|
|||||||
fLocker.Unlock();
|
fLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetColor
|
|
||||||
void
|
void
|
||||||
SpiderSaver::SetColor(uint32 color)
|
SpiderSaver::SetColor(uint32 color)
|
||||||
{
|
{
|
||||||
@@ -199,7 +189,10 @@ SpiderSaver::SetColor(uint32 color)
|
|||||||
fLocker.Unlock();
|
fLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _Init
|
|
||||||
|
// #pragma mark - SpiderSaver private methods
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_Init(BRect bounds)
|
SpiderSaver::_Init(BRect bounds)
|
||||||
{
|
{
|
||||||
@@ -208,18 +201,20 @@ SpiderSaver::_Init(BRect bounds)
|
|||||||
uint32 maxPoints = fMaxPolyPoints;
|
uint32 maxPoints = fMaxPolyPoints;
|
||||||
uint32 minQueueDepth = fMaxQueueDepth / 2;
|
uint32 minQueueDepth = fMaxQueueDepth / 2;
|
||||||
uint32 maxQueueDepth = fMaxQueueDepth;
|
uint32 maxQueueDepth = fMaxQueueDepth;
|
||||||
|
|
||||||
if (fPreview) {
|
if (fPreview) {
|
||||||
minQueueDepth /= 4;
|
minQueueDepth /= 4;
|
||||||
maxQueueDepth /= 4;
|
maxQueueDepth /= 4;
|
||||||
}
|
}
|
||||||
for (uint32 i = 0; i < fQueueNumber; i++)
|
|
||||||
|
for (uint32 i = 0; i < fQueueNumber; i++) {
|
||||||
fQueues[i] = new PolygonQueue(new Polygon(bounds,
|
fQueues[i] = new PolygonQueue(new Polygon(bounds,
|
||||||
minPoints + lrand48() % (maxPoints - minPoints)),
|
minPoints + lrand48() % (maxPoints - minPoints)),
|
||||||
minQueueDepth + lrand48() % (maxQueueDepth - minQueueDepth));
|
minQueueDepth + lrand48() % (maxQueueDepth - minQueueDepth));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _Cleanup
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_Cleanup()
|
SpiderSaver::_Cleanup()
|
||||||
{
|
{
|
||||||
@@ -231,7 +226,6 @@ SpiderSaver::_Cleanup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _AllocBackBitmap
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_AllocBackBitmap(float width, float height)
|
SpiderSaver::_AllocBackBitmap(float width, float height)
|
||||||
{
|
{
|
||||||
@@ -261,7 +255,6 @@ SpiderSaver::_AllocBackBitmap(float width, float height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _FreeBackBitmap
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_FreeBackBitmap()
|
SpiderSaver::_FreeBackBitmap()
|
||||||
{
|
{
|
||||||
@@ -273,30 +266,35 @@ SpiderSaver::_FreeBackBitmap()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _DrawInto
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_DrawInto(BView *view)
|
SpiderSaver::_DrawInto(BView* view)
|
||||||
{
|
{
|
||||||
for (uint32 i = 0; i < fQueueNumber; i++) {
|
for (uint32 i = 0; i < fQueueNumber; i++) {
|
||||||
switch (fColor) {
|
switch (fColor) {
|
||||||
case GREEN:
|
case GREEN:
|
||||||
view->SetHighColor(1, 2, 1, 255);
|
view->SetHighColor(1, 2, 1, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BLUE:
|
case BLUE:
|
||||||
view->SetHighColor(1, 1, 2, 255);
|
view->SetHighColor(1, 1, 2, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case YELLOW:
|
case YELLOW:
|
||||||
view->SetHighColor(2, 2, 1, 255);
|
view->SetHighColor(2, 2, 1, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PURPLE:
|
case PURPLE:
|
||||||
view->SetHighColor(2, 1, 2, 255);
|
view->SetHighColor(2, 1, 2, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CYAN:
|
case CYAN:
|
||||||
view->SetHighColor(1, 2, 2, 255);
|
view->SetHighColor(1, 2, 2, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GRAY:
|
case GRAY:
|
||||||
view->SetHighColor(2, 2, 2, 255);
|
view->SetHighColor(2, 2, 2, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RED:
|
case RED:
|
||||||
default:
|
default:
|
||||||
view->SetHighColor(2, 1, 1, 255);
|
view->SetHighColor(2, 1, 1, 255);
|
||||||
@@ -310,6 +308,7 @@ SpiderSaver::_DrawInto(BView *view)
|
|||||||
view->SetDrawingMode(B_OP_ADD);
|
view->SetDrawingMode(B_OP_ADD);
|
||||||
_DrawPolygon(p, view);
|
_DrawPolygon(p, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Polygon* p = fQueues[i]->Tail()) {
|
if (Polygon* p = fQueues[i]->Tail()) {
|
||||||
view->SetDrawingMode(B_OP_SUBTRACT);
|
view->SetDrawingMode(B_OP_SUBTRACT);
|
||||||
_DrawPolygon(p, view);
|
_DrawPolygon(p, view);
|
||||||
@@ -317,9 +316,9 @@ SpiderSaver::_DrawInto(BView *view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _DrawPolygon
|
|
||||||
void
|
void
|
||||||
SpiderSaver::_DrawPolygon(Polygon* polygon, BView *view)
|
SpiderSaver::_DrawPolygon(Polygon* polygon, BView* view)
|
||||||
{
|
{
|
||||||
int32 pointCount = polygon->CountPoints();
|
int32 pointCount = polygon->CountPoints();
|
||||||
if (pointCount > 1) {
|
if (pointCount > 1) {
|
||||||
@@ -327,163 +326,7 @@ SpiderSaver::_DrawPolygon(Polygon* polygon, BView *view)
|
|||||||
view->MovePenTo(p);
|
view->MovePenTo(p);
|
||||||
for (int32 i = 1; i < pointCount; i++)
|
for (int32 i = 1; i < pointCount; i++)
|
||||||
view->StrokeLine(polygon->PointAt(i));
|
view->StrokeLine(polygon->PointAt(i));
|
||||||
|
|
||||||
view->StrokeLine(p);
|
view->StrokeLine(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
SpiderView::SpiderView(BRect frame, SpiderSaver* saver,
|
|
||||||
uint32 queueNumber, uint32 maxPolyPoints,
|
|
||||||
uint32 maxQueueDepth, uint32 color)
|
|
||||||
: BView(frame, "spider view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
|
|
||||||
fSaver(saver)
|
|
||||||
{
|
|
||||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
|
|
||||||
frame.OffsetTo(0.0, 0.0);
|
|
||||||
frame.InsetBy(10.0, 5.0);
|
|
||||||
|
|
||||||
float viewHeight = floorf(frame.Height() / 5.0);
|
|
||||||
|
|
||||||
// title stuff
|
|
||||||
font_height fh;
|
|
||||||
be_bold_font->GetHeight(&fh);
|
|
||||||
float fontHeight = fh.ascent + fh.descent + 5.0;
|
|
||||||
frame.bottom = frame.top + fontHeight;
|
|
||||||
BStringView* title = new BStringView(frame, B_EMPTY_STRING,
|
|
||||||
B_TRANSLATE("Spider by stippi"));
|
|
||||||
title->SetFont(be_bold_font);
|
|
||||||
AddChild(title);
|
|
||||||
|
|
||||||
be_plain_font->GetHeight(&fh);
|
|
||||||
fontHeight = fh.ascent + fh.descent + 5.0;
|
|
||||||
frame.top = frame.bottom;
|
|
||||||
frame.bottom = frame.top + fontHeight;
|
|
||||||
title = new BStringView(frame, B_EMPTY_STRING, B_TRANSLATE("for bonefish"));
|
|
||||||
BFont font(be_plain_font);
|
|
||||||
font.SetShear(110.0);
|
|
||||||
title->SetFont(&font);
|
|
||||||
title->SetAlignment(B_ALIGN_CENTER);
|
|
||||||
AddChild(title);
|
|
||||||
|
|
||||||
// controls
|
|
||||||
frame.top = 10.0;
|
|
||||||
frame.bottom = frame.top + viewHeight;
|
|
||||||
frame.OffsetBy(0.0, viewHeight);
|
|
||||||
fQueueNumberS = new BSlider(frame, "queue number",
|
|
||||||
B_TRANSLATE("Max. polygon count"), new BMessage(MSG_QUEUE_NUMBER),
|
|
||||||
1, MAX_QUEUE_NUMBER);
|
|
||||||
fQueueNumberS->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
|
||||||
fQueueNumberS->SetHashMarkCount((MAX_QUEUE_NUMBER - 1) / 2 + 1);
|
|
||||||
fQueueNumberS->SetValue(queueNumber);
|
|
||||||
AddChild(fQueueNumberS);
|
|
||||||
frame.OffsetBy(0.0, viewHeight);
|
|
||||||
fPolyNumberS = new BSlider(frame, "poly points",
|
|
||||||
B_TRANSLATE("Max. points per polygon"), new BMessage(MSG_POLY_NUMBER),
|
|
||||||
MIN_POLY_POINTS, MAX_POLY_POINTS);
|
|
||||||
fPolyNumberS->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
|
||||||
fPolyNumberS->SetHashMarkCount(MAX_POLY_POINTS - MIN_POLY_POINTS + 1);
|
|
||||||
fPolyNumberS->SetValue(maxPolyPoints);
|
|
||||||
AddChild(fPolyNumberS);
|
|
||||||
frame.OffsetBy(0.0, viewHeight);
|
|
||||||
fQueueDepthS = new BSlider(frame, "queue depth", B_TRANSLATE("Trail depth"),
|
|
||||||
new BMessage(MSG_QUEUE_DEPTH), MIN_QUEUE_DEPTH, MAX_QUEUE_DEPTH);
|
|
||||||
fQueueDepthS->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
|
||||||
fQueueDepthS->SetHashMarkCount((MAX_QUEUE_DEPTH - MIN_QUEUE_DEPTH) / 4 + 1);
|
|
||||||
fQueueDepthS->SetValue(maxQueueDepth);
|
|
||||||
AddChild(fQueueDepthS);
|
|
||||||
|
|
||||||
BMenu* menu = new BMenu(B_TRANSLATE("Color"));
|
|
||||||
BMessage* message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", RED);
|
|
||||||
BMenuItem* item = new BMenuItem(B_TRANSLATE("Red"), message);
|
|
||||||
if (color == RED)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", GREEN);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Green"), message);
|
|
||||||
if (color == GREEN)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", BLUE);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Blue"), message);
|
|
||||||
if (color == BLUE)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", YELLOW);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Yellow"), message);
|
|
||||||
if (color == YELLOW)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", PURPLE);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Purple"), message);
|
|
||||||
if (color == PURPLE)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", CYAN);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Cyan"), message);
|
|
||||||
if (color == CYAN)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
message = new BMessage(MSG_COLOR);
|
|
||||||
message->AddInt32("color", GRAY);
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Gray"), message);
|
|
||||||
if (color == GRAY)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
|
|
||||||
menu->SetLabelFromMarked(true);
|
|
||||||
menu->SetRadioMode(true);
|
|
||||||
|
|
||||||
frame.OffsetBy(0.0, viewHeight);
|
|
||||||
fColorMF = new BMenuField(frame, "color", B_TRANSLATE("Color"), menu);
|
|
||||||
fColorMF->SetDivider(fColorMF->StringWidth(B_TRANSLATE("Color")) + 5.0);
|
|
||||||
AddChild(fColorMF);
|
|
||||||
}
|
|
||||||
|
|
||||||
// destructor
|
|
||||||
SpiderView::~SpiderView()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// AttachedToWindow
|
|
||||||
void
|
|
||||||
SpiderView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
fQueueNumberS->SetTarget(this);
|
|
||||||
fPolyNumberS->SetTarget(this);
|
|
||||||
fQueueDepthS->SetTarget(this);
|
|
||||||
fColorMF->Menu()->SetTargetForItems(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageReceived
|
|
||||||
void
|
|
||||||
SpiderView::MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
switch (message->what) {
|
|
||||||
case MSG_QUEUE_NUMBER:
|
|
||||||
fSaver->SetQueueNumber(fQueueNumberS->Value());
|
|
||||||
break;
|
|
||||||
case MSG_POLY_NUMBER:
|
|
||||||
fSaver->SetPolyPoints(fPolyNumberS->Value());
|
|
||||||
break;
|
|
||||||
case MSG_QUEUE_DEPTH:
|
|
||||||
fSaver->SetQueueDepth(fQueueDepthS->Value());
|
|
||||||
break;
|
|
||||||
case MSG_COLOR: {
|
|
||||||
uint32 color;
|
|
||||||
if (message->FindInt32("color", (int32*)&color) == B_OK)
|
|
||||||
fSaver->SetColor(color);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
BView::MessageReceived(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Haiku Inc. All rights reserved.
|
* Copyright 2007-2014 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef SPIDER_SAVER_H
|
#ifndef SPIDER_SAVER_H
|
||||||
#define SPIDER_SAVER_H
|
#define SPIDER_SAVER_H
|
||||||
|
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <ScreenSaver.h>
|
#include <ScreenSaver.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
RED = 1,
|
||||||
|
GREEN = 2,
|
||||||
|
BLUE = 3,
|
||||||
|
YELLOW = 4,
|
||||||
|
PURPLE = 5,
|
||||||
|
CYAN = 6,
|
||||||
|
GRAY = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define MIN_POLY_POINTS 3
|
||||||
|
#define MAX_POLY_POINTS 10
|
||||||
|
#define MIN_QUEUE_DEPTH 40
|
||||||
|
#define MAX_QUEUE_DEPTH 160
|
||||||
|
#define MAX_QUEUE_NUMBER 40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BSlider;
|
class BSlider;
|
||||||
class BMenuField;
|
class BMenuField;
|
||||||
class Polygon;
|
class Polygon;
|
||||||
class PolygonQueue;
|
class PolygonQueue;
|
||||||
class SpiderView;
|
class SpiderView;
|
||||||
|
|
||||||
|
|
||||||
class SpiderSaver : public BScreenSaver {
|
class SpiderSaver : public BScreenSaver {
|
||||||
public:
|
public:
|
||||||
SpiderSaver(BMessage *message,
|
SpiderSaver(BMessage *message,
|
||||||
image_id image);
|
image_id image);
|
||||||
virtual ~SpiderSaver();
|
virtual ~SpiderSaver();
|
||||||
@@ -37,7 +59,7 @@ class SpiderSaver : public BScreenSaver {
|
|||||||
void SetPolyPoints(uint32 maxPoints);
|
void SetPolyPoints(uint32 maxPoints);
|
||||||
void SetColor(uint32 color);
|
void SetColor(uint32 color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init(BRect bounds);
|
void _Init(BRect bounds);
|
||||||
void _Cleanup();
|
void _Cleanup();
|
||||||
void _AllocBackBitmap(float width, float height);
|
void _AllocBackBitmap(float width, float height);
|
||||||
@@ -45,42 +67,20 @@ class SpiderSaver : public BScreenSaver {
|
|||||||
void _DrawInto(BView *view);
|
void _DrawInto(BView *view);
|
||||||
void _DrawPolygon(Polygon* polygon, BView *view);
|
void _DrawPolygon(Polygon* polygon, BView *view);
|
||||||
|
|
||||||
BBitmap* fBackBitmap;
|
BBitmap* fBackBitmap;
|
||||||
BView* fBackView;
|
BView* fBackView;
|
||||||
|
|
||||||
PolygonQueue** fQueues;
|
PolygonQueue** fQueues;
|
||||||
uint32 fQueueNumber;
|
uint32 fQueueNumber;
|
||||||
uint32 fMaxPolyPoints;
|
uint32 fMaxPolyPoints;
|
||||||
uint32 fMaxQueueDepth;
|
uint32 fMaxQueueDepth;
|
||||||
uint32 fColor;
|
uint32 fColor;
|
||||||
|
|
||||||
bool fPreview;
|
bool fPreview;
|
||||||
BRect fBounds;
|
BRect fBounds;
|
||||||
|
|
||||||
BLocker fLocker;
|
BLocker fLocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpiderView : public BView {
|
|
||||||
public:
|
|
||||||
SpiderView(BRect frame,
|
|
||||||
SpiderSaver* saver,
|
|
||||||
uint32 queueNumber,
|
|
||||||
uint32 maxPolyPoints,
|
|
||||||
uint32 maxQueueDepth,
|
|
||||||
uint32 color);
|
|
||||||
virtual ~SpiderView();
|
|
||||||
|
|
||||||
// BView
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
|
||||||
|
|
||||||
private:
|
|
||||||
SpiderSaver* fSaver;
|
|
||||||
|
|
||||||
BSlider* fQueueNumberS;
|
|
||||||
BSlider* fPolyNumberS;
|
|
||||||
BSlider* fQueueDepthS;
|
|
||||||
BMenuField* fColorMF;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SPIDER_SAVER_H
|
#endif // SPIDER_SAVER_H
|
||||||
|
|||||||
@@ -0,0 +1,214 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2014 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Stephan Aßmus, [email protected]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SpiderView.h"
|
||||||
|
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Menu.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Slider.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
|
#include "SpiderSaver.h"
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "SpiderView"
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 kMsgQueueNumber = 'qunm';
|
||||||
|
static const uint32 kMsgPolyNumber = 'plnm';
|
||||||
|
static const uint32 kMsgQueueDepth = 'qudp';
|
||||||
|
static const uint32 kMsgColor = 'colr';
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma - SpiderView
|
||||||
|
|
||||||
|
|
||||||
|
SpiderView::SpiderView(BRect frame, SpiderSaver* saver, uint32 queueNumber,
|
||||||
|
uint32 maxPolyPoints, uint32 maxQueueDepth, uint32 color)
|
||||||
|
:
|
||||||
|
BView(frame, "spider view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
|
||||||
|
fSaver(saver)
|
||||||
|
{
|
||||||
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
frame.OffsetTo(0.0, 0.0);
|
||||||
|
frame.InsetBy(10.0, 5.0);
|
||||||
|
|
||||||
|
float viewHeight = floorf(frame.Height() / 5.0);
|
||||||
|
|
||||||
|
// title stuff
|
||||||
|
font_height fh;
|
||||||
|
be_bold_font->GetHeight(&fh);
|
||||||
|
float fontHeight = fh.ascent + fh.descent + 5.0;
|
||||||
|
frame.bottom = frame.top + fontHeight;
|
||||||
|
BStringView* title = new BStringView(frame, B_EMPTY_STRING,
|
||||||
|
B_TRANSLATE("Spider by stippi"));
|
||||||
|
title->SetFont(be_bold_font);
|
||||||
|
AddChild(title);
|
||||||
|
|
||||||
|
be_plain_font->GetHeight(&fh);
|
||||||
|
fontHeight = fh.ascent + fh.descent + 5.0;
|
||||||
|
frame.top = frame.bottom;
|
||||||
|
frame.bottom = frame.top + fontHeight;
|
||||||
|
title = new BStringView(frame, B_EMPTY_STRING,
|
||||||
|
B_TRANSLATE("for bonefish"));
|
||||||
|
BFont font(be_plain_font);
|
||||||
|
font.SetShear(110.0);
|
||||||
|
title->SetFont(&font);
|
||||||
|
title->SetAlignment(B_ALIGN_CENTER);
|
||||||
|
AddChild(title);
|
||||||
|
|
||||||
|
// controls
|
||||||
|
frame.top = 10.0f;
|
||||||
|
frame.bottom = frame.top + viewHeight;
|
||||||
|
|
||||||
|
// queue slider
|
||||||
|
frame.OffsetBy(0.0f, viewHeight);
|
||||||
|
fQueueNumberSlider = new BSlider(frame, "queue number",
|
||||||
|
B_TRANSLATE("Max. polygon count"), new BMessage(kMsgQueueNumber),
|
||||||
|
1, MAX_QUEUE_NUMBER);
|
||||||
|
fQueueNumberSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||||
|
fQueueNumberSlider->SetHashMarkCount((MAX_QUEUE_NUMBER - 1) / 2 + 1);
|
||||||
|
fQueueNumberSlider->SetValue(queueNumber);
|
||||||
|
AddChild(fQueueNumberSlider);
|
||||||
|
|
||||||
|
// poly sliders
|
||||||
|
frame.OffsetBy(0.0f, viewHeight);
|
||||||
|
fPolyNumberSlider = new BSlider(frame, "poly points",
|
||||||
|
B_TRANSLATE("Max. points per polygon"), new BMessage(kMsgPolyNumber),
|
||||||
|
MIN_POLY_POINTS, MAX_POLY_POINTS);
|
||||||
|
fPolyNumberSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||||
|
fPolyNumberSlider->SetHashMarkCount(MAX_POLY_POINTS - MIN_POLY_POINTS + 1);
|
||||||
|
fPolyNumberSlider->SetValue(maxPolyPoints);
|
||||||
|
AddChild(fPolyNumberSlider);
|
||||||
|
|
||||||
|
// queue depth slider
|
||||||
|
frame.OffsetBy(0.0f, viewHeight);
|
||||||
|
fQueueDepthSlider = new BSlider(frame, "queue depth",
|
||||||
|
B_TRANSLATE("Trail depth"), new BMessage(kMsgQueueDepth),
|
||||||
|
MIN_QUEUE_DEPTH, MAX_QUEUE_DEPTH);
|
||||||
|
fQueueDepthSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||||
|
fQueueDepthSlider->SetHashMarkCount(
|
||||||
|
(MAX_QUEUE_DEPTH - MIN_QUEUE_DEPTH) / 4 + 1);
|
||||||
|
fQueueDepthSlider->SetValue(maxQueueDepth);
|
||||||
|
AddChild(fQueueDepthSlider);
|
||||||
|
|
||||||
|
// color menu field
|
||||||
|
BMenu* menu = new BMenu(B_TRANSLATE("Color"));
|
||||||
|
BMenuItem* item;
|
||||||
|
BMessage* message;
|
||||||
|
|
||||||
|
// red
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", RED);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Red"), message);
|
||||||
|
item->SetMarked(color == RED);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// green
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", GREEN);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Green"), message);
|
||||||
|
item->SetMarked(color == GREEN);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// blue
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", BLUE);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Blue"), message);
|
||||||
|
item->SetMarked(color == BLUE);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// yellow
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", YELLOW);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Yellow"), message);
|
||||||
|
item->SetMarked(color == YELLOW);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// purple
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", PURPLE);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Purple"), message);
|
||||||
|
item->SetMarked(color == PURPLE);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// cyan
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", CYAN);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Cyan"), message);
|
||||||
|
item->SetMarked(color == CYAN);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
// gray
|
||||||
|
message = new BMessage(kMsgColor);
|
||||||
|
message->AddInt32("color", GRAY);
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Gray"), message);
|
||||||
|
item->SetMarked(color == GRAY);
|
||||||
|
menu->AddItem(item);
|
||||||
|
|
||||||
|
menu->SetLabelFromMarked(true);
|
||||||
|
menu->SetRadioMode(true);
|
||||||
|
|
||||||
|
frame.OffsetBy(0.0f, viewHeight);
|
||||||
|
fColorMenuField = new BMenuField(frame, "color", B_TRANSLATE("Color"),
|
||||||
|
menu);
|
||||||
|
fColorMenuField->SetDivider(fColorMenuField->StringWidth(
|
||||||
|
B_TRANSLATE("Color")) + 5.0f);
|
||||||
|
AddChild(fColorMenuField);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpiderView::~SpiderView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpiderView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
fQueueNumberSlider->SetTarget(this);
|
||||||
|
fPolyNumberSlider->SetTarget(this);
|
||||||
|
fQueueDepthSlider->SetTarget(this);
|
||||||
|
fColorMenuField->Menu()->SetTargetForItems(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpiderView::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case kMsgQueueNumber:
|
||||||
|
fSaver->SetQueueNumber(fQueueNumberSlider->Value());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgPolyNumber:
|
||||||
|
fSaver->SetPolyPoints(fPolyNumberSlider->Value());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgQueueDepth:
|
||||||
|
fSaver->SetQueueDepth(fQueueDepthSlider->Value());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgColor: {
|
||||||
|
uint32 color;
|
||||||
|
if (message->FindInt32("color", (int32*)&color) == B_OK)
|
||||||
|
fSaver->SetColor(color);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-2014 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Stephan Aßmus, [email protected]
|
||||||
|
*/
|
||||||
|
#ifndef SPIDER_VIEW_H
|
||||||
|
#define SPIDER_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BRect;
|
||||||
|
class BMenuField;
|
||||||
|
class BMessage;
|
||||||
|
class BSlider;
|
||||||
|
class SpiderSaver;
|
||||||
|
|
||||||
|
|
||||||
|
class SpiderView : public BView {
|
||||||
|
public:
|
||||||
|
SpiderView(BRect frame, SpiderSaver* saver,
|
||||||
|
uint32 queueNumber,
|
||||||
|
uint32 maxPolyPoints,
|
||||||
|
uint32 maxQueueDepth,
|
||||||
|
uint32 color);
|
||||||
|
virtual ~SpiderView();
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SpiderSaver* fSaver;
|
||||||
|
|
||||||
|
BSlider* fQueueNumberSlider;
|
||||||
|
BSlider* fPolyNumberSlider;
|
||||||
|
BSlider* fQueueDepthSlider;
|
||||||
|
BMenuField* fColorMenuField;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SPIDER_VIEW_H
|
||||||
Reference in New Issue
Block a user