1/*
2 * Copyright 2003-2006, 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
11#include "PreviewView.h"
12#include "Constants.h"
13#include "Utility.h"
14
15#include <Point.h>
16#include <Rect.h>
17#include <Screen.h>
18#include <ScreenSaver.h>
19#include <Shape.h>
20#include <String.h>
21
22#include <iostream>
23
24
25static float sampleX[]= {0,.05,.15,.7,.725,.8,.825,.85,.950,1.0};
26static float sampleY[]= {0,.05,.90,.95,.966,.975,1.0};
27
28
29inline BPoint
30scale2(int x, int y,BRect area)
31{
32	return scale_direct(sampleX[x],sampleY[y],area);
33}
34
35
36inline BRect
37scale2(int x1, int x2, int y1, int y2,BRect area)
38{
39	return scale_direct(sampleX[x1],sampleX[x2],sampleY[y1],sampleY[y2],area);
40}
41
42
43PreviewView::PreviewView(BRect frame, const char *name)
44	: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
45	fSaverView(NULL)
46{
47	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
48}
49
50
51PreviewView::~PreviewView()
52{
53}
54
55
56BView*
57PreviewView::AddPreview()
58{
59	BRect rect = scale2(1,8,1,2,Bounds());
60	rect.InsetBy(1, 1);
61	fSaverView = new BView(rect, "preview", B_FOLLOW_NONE, B_WILL_DRAW);
62	fSaverView->SetViewColor(0, 0, 0);
63	AddChild(fSaverView);
64
65	return fSaverView;
66}
67
68
69BView*
70PreviewView::RemovePreview()
71{
72	if (fSaverView != NULL)
73		RemoveChild(fSaverView);
74
75	BView* saverView = fSaverView;
76	fSaverView = NULL;
77	return saverView;
78}
79
80
81void
82PreviewView::Draw(BRect update)
83{
84	SetHighColor(184, 184, 184);
85	FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);// Outer shape
86	FillRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
87
88	SetHighColor(96, 96, 96);
89	StrokeRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
90	StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4); // Outline outer shape
91	SetHighColor(kBlack);
92	FillRect(scale2(1,8,1,2,Bounds()));
93
94	SetHighColor(184, 184, 184);
95	BRect outerShape = scale2(2,7,2,6,Bounds());
96	outerShape.InsetBy(1,1);
97	FillRoundRect(outerShape,4,4);// Outer shape
98
99	SetHighColor(0, 255, 0);
100	FillRect(scale2(3,4,4,5,Bounds()));
101	SetHighColor(96,96,96);
102	FillRect(scale2(5,6,4,5,Bounds()));
103}
104