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 25 static float sampleX[]= {0,.05,.15,.7,.725,.8,.825,.85,.950,1.0}; 26 static float sampleY[]= {0,.05,.90,.95,.966,.975,1.0}; 27 28 29 inline BPoint 30 scale2(int x, int y,BRect area) 31 { 32 return scale_direct(sampleX[x],sampleY[y],area); 33 } 34 35 36 inline BRect 37 scale2(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 43 PreviewView::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 51 PreviewView::~PreviewView() 52 { 53 } 54 55 56 BView* 57 PreviewView::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 69 BView* 70 PreviewView::RemovePreview() 71 { 72 if (fSaverView != NULL) 73 RemoveChild(fSaverView); 74 75 return fSaverView; 76 } 77 78 79 void 80 PreviewView::Draw(BRect update) 81 { 82 SetHighColor(184, 184, 184); 83 FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);// Outer shape 84 FillRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline 85 86 SetHighColor(96, 96, 96); 87 StrokeRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline 88 StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4); // Outline outer shape 89 SetHighColor(kBlack); 90 FillRect(scale2(1,8,1,2,Bounds())); 91 92 SetHighColor(184, 184, 184); 93 BRect outerShape = scale2(2,7,2,6,Bounds()); 94 outerShape.InsetBy(1,1); 95 FillRoundRect(outerShape,4,4);// Outer shape 96 97 SetHighColor(0, 255, 0); 98 FillRect(scale2(3,4,4,5,Bounds())); 99 SetHighColor(96,96,96); 100 FillRect(scale2(5,6,4,5,Bounds())); 101 } 102 103