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