xref: /haiku/src/preferences/screensaver/PreviewView.cpp (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*
2  * Copyright 2003-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *              Michael Phipps
7  *              J�r�me Duval, jerome.duval@free.fr
8  */
9 
10 #include "PreviewView.h"
11 #include "Constants.h"
12 #include <Rect.h>
13 #include <Point.h>
14 #include <Shape.h>
15 #include <iostream>
16 #include <ScreenSaver.h>
17 #include <Errors.h>
18 #include <Screen.h>
19 #include <String.h>
20 
21 static float sampleX[]= {0,.05,.15,.7,.725,.8,.825,.85,.950,1.0};
22 static float sampleY[]= {0,.05,.90,.95,.966,.975,1.0};
23 inline BPoint
24 scale2(int x, int y,BRect area)
25 {
26 	return scaleDirect(sampleX[x],sampleY[y],area);
27 }
28 
29 
30 inline BRect
31 scale2(int x1, int x2, int y1, int y2,BRect area)
32 {
33 	return scaleDirect(sampleX[x1],sampleX[x2],sampleY[y1],sampleY[y2],area);
34 }
35 
36 
37 PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
38 	: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
39   	fSaver(NULL),
40 	fConfigView(NULL),
41 	fSst(NULL),
42 	fThreadID(-1),
43 	fPrefPtr(prefp)
44 {
45 	SetViewColor(216,216,216);
46 }
47 
48 
49 PreviewView::~PreviewView()
50 {
51 	if (fThreadID>=0)
52 		kill_thread(fThreadID);
53 	delete fSst;
54 }
55 
56 
57 void
58 PreviewView::SetScreenSaver(BString name)
59 {
60 	if (fThreadID>=0) {
61 		kill_thread(fThreadID);
62 		fThreadID = -1;
63 	}
64 	if (fSst)
65 		delete fSst;
66 	if (fConfigView) {
67 		RemoveChild(fConfigView);
68 		delete fConfigView;
69 	}
70 
71 	fConfigView = new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
72 	fConfigView->SetViewColor(0,0,0);
73 	AddChild(fConfigView);
74 
75 	fSst = new ScreenSaverThread(Window(),fConfigView,fPrefPtr);
76 	fSaver = fSst->LoadAddOn();
77 	if (fSaver) {
78 		fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc, "ScreenSaverRenderer", B_LOW_PRIORITY, fSst);
79 		resume_thread(fThreadID);
80 	}
81 
82 }
83 
84 void
85 PreviewView::Draw(BRect update)
86 {
87 	SetViewColor(216,216,216);
88 
89 	SetHighColor(184,184,184);
90 	FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);// Outer shape
91 	FillRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
92 
93 	SetHighColor(96,96,96);
94 	StrokeRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
95 	StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4); // Outline outer shape
96 	SetHighColor(kBlack);
97 
98 	SetHighColor(184,184,184);
99 	BRect outerShape = scale2(2,7,2,6,Bounds());
100 	outerShape.InsetBy(1,1);
101 	FillRoundRect(outerShape,4,4);// Outer shape
102 
103 	SetHighColor(0,255,0);
104 	FillRect(scale2(3,4,4,5,Bounds()));
105 	SetHighColor(96,96,96);
106 	FillRect(scale2(5,6,4,5,Bounds()));
107 }
108