2 * Copyright (c) 1997 by Massimino Pascal <Pascal.Massimon@ens.fr>
3 * Copyright 2006-2014, Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT License.
8 * Stephan Aßmus, superstippi@gmx.de
9 * Massimino Pascal, Pascal.Massimon@ens.fr
10 * John Scipione, jscipione@gmail.com
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "Screensaver IFS"
27 static const uint32 kMsgToggleAdditive
= 'tgad';
28 static const uint32 kMsgSetSpeed
= 'stsp';
31 // #pragma mark - Instantiation function
34 extern "C" _EXPORT BScreenSaver
*
35 instantiate_screen_saver(BMessage
*message
, image_id image
)
37 return new IFSSaver(message
, image
);
41 // #pragma mark - IFSSaver
44 IFSSaver::IFSSaver(BMessage
* message
, image_id id
)
46 BScreenSaver(message
, id
),
47 BHandler("IFS Saver"),
54 fDirectInfo
.bits
= NULL
;
55 fDirectInfo
.bytesPerRow
= 0;
60 if (message
->FindBool("IFS additive", &fAdditive
) != B_OK
)
62 if (message
->FindInt32("IFS speed", &fSpeed
) != B_OK
)
70 Looper()->RemoveHandler(this);
77 IFSSaver::StartConfig(BView
* view
)
79 BRect bounds
= view
->Bounds();
80 bounds
.InsetBy(10.0f
, 10.0f
);
81 BRect
frame(0.0f
, 0.0f
, bounds
.Width(), 20.0f
);
83 // the additive check box
84 fAdditiveCB
= new BCheckBox(frame
, "additive setting",
85 B_TRANSLATE("Render dots additive"), new BMessage(kMsgToggleAdditive
),
86 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
);
88 fAdditiveCB
->SetValue(fAdditive
);
90 fAdditiveCB
->ResizeToPreferred();
91 bounds
.bottom
-= fAdditiveCB
->Bounds().Height() * 2.0f
;
92 fAdditiveCB
->MoveTo(bounds
.LeftBottom());
94 view
->AddChild(fAdditiveCB
);
96 // the additive check box
97 fSpeedS
= new BSlider(frame
, "speed setting",
98 B_TRANSLATE("Morphing speed:"), new BMessage(kMsgSetSpeed
), 1, 12,
99 B_BLOCK_THUMB
, B_FOLLOW_LEFT_RIGHT
| B_FOLLOW_BOTTOM
);
101 fSpeedS
->SetValue(fSpeed
);
102 fSpeedS
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
103 fSpeedS
->SetHashMarkCount(12);
105 fSpeedS
->ResizeToPreferred();
106 bounds
.bottom
-= fSpeedS
->Bounds().Height() + 15.0f
;
107 fSpeedS
->MoveTo(bounds
.LeftBottom());
109 view
->AddChild(fSpeedS
);
111 // the info text view
112 BRect textRect
= bounds
;
113 textRect
.OffsetTo(0.0, 0.0);
114 BTextView
* textView
= new BTextView(bounds
, B_EMPTY_STRING
, textRect
,
115 B_FOLLOW_ALL
, B_WILL_DRAW
);
116 textView
->SetViewColor(view
->ViewColor());
118 BString
aboutScreenSaver(B_TRANSLATE("%screenSaverName%\n\n"
119 B_UTF8_COPYRIGHT
" 1997 Massimino Pascal\n\n"
120 "xscreensaver port by Stephan Aßmus\n"
121 "<stippi@yellowbites.com>"));
122 BString
screenSaverName(B_TRANSLATE("Iterated Function System"));
124 aboutScreenSaver
.ReplaceFirst("%screenSaverName%", screenSaverName
);
125 textView
->Insert(aboutScreenSaver
);
127 textView
->SetStylable(true);
128 textView
->SetFontAndColor(0, screenSaverName
.Length(), be_bold_font
);
130 textView
->MakeEditable(false);
132 view
->AddChild(textView
);
134 // make sure we receive messages from the views we added
135 if (BWindow
* window
= view
->Window())
136 window
->AddHandler(this);
138 fAdditiveCB
->SetTarget(this);
139 fSpeedS
->SetTarget(this);
144 IFSSaver::StartSaver(BView
* view
, bool preview
)
147 BScreen
screen(B_MAIN_SCREEN_ID
);
148 screen
.GetMode(&mode
);
149 float totalSize
= mode
.timing
.h_total
* mode
.timing
.v_total
;
150 float fps
= mode
.timing
.pixel_clock
* 1000.0f
/ totalSize
;
152 SetTickSize((bigtime_t
)floor(1000000.0 / fps
+ 0.5));
154 fIsPreview
= preview
;
159 _Init(view
->Bounds());
163 fIFS
->SetAdditive(fAdditive
|| fIsPreview
);
164 fIFS
->SetSpeed(fSpeed
);
171 IFSSaver::StopSaver()
178 IFSSaver::DirectConnected(direct_buffer_info
* info
)
180 int32 request
= info
->buffer_state
& B_DIRECT_MODE_MASK
;
184 fDirectInfo
.bits
= info
->bits
;
185 fDirectInfo
.bytesPerRow
= info
->bytes_per_row
;
186 fDirectInfo
.bits_per_pixel
= info
->bits_per_pixel
;
187 fDirectInfo
.format
= info
->pixel_format
;
188 fDirectInfo
.bounds
= info
->window_bounds
;
192 fDirectInfo
.bits
= NULL
;
199 IFSSaver::Draw(BView
* view
, int32 frame
)
202 fLastDrawnFrame
= -1;
203 view
->SetHighColor(0, 0, 0);
204 view
->FillRect(view
->Bounds());
207 int32 frames
= frame
- fLastDrawnFrame
;
208 if ((fIsPreview
|| fDirectInfo
.bits
== NULL
) && fLocker
.Lock()) {
209 fIFS
->Draw(view
, NULL
, frames
);
211 fLastDrawnFrame
= frame
;
218 IFSSaver::DirectDraw(int32 frame
)
221 fLastDrawnFrame
= -1;
223 if (!fIsPreview
&& fDirectInfo
.bits
!= NULL
) {
224 fIFS
->Draw(NULL
, &fDirectInfo
, frame
- fLastDrawnFrame
);
225 fLastDrawnFrame
= frame
;
231 IFSSaver::SaveState(BMessage
* into
) const
233 status_t ret
= B_BAD_VALUE
;
235 ret
= into
->AddBool("IFS additive", fAdditive
);
237 ret
= into
->AddInt32("IFS speed", fSpeed
);
245 IFSSaver::MessageReceived(BMessage
* message
)
247 switch (message
->what
) {
248 case kMsgToggleAdditive
:
249 if (fLocker
.Lock() && fIFS
!= NULL
) {
250 fAdditive
= fAdditiveCB
->Value() == B_CONTROL_ON
;
251 fIFS
->SetAdditive(fAdditive
|| fIsPreview
);
257 if (fLocker
.Lock() && fIFS
!= NULL
) {
258 fSpeed
= fSpeedS
->Value();
259 fIFS
->SetSpeed(fSpeed
);
265 BHandler::MessageReceived(message
);
271 IFSSaver::_Init(BRect bounds
)
273 if (fLocker
.Lock()) {
275 fIFS
= new IFS(bounds
);
284 if (fLocker
.Lock()) {