1/* 2 3 ChartView.cpp 4 5 by Pierre Raynaud-Richard. 6 7*/ 8 9/* 10 Copyright 1999, Be Incorporated. All Rights Reserved. 11 This file may be used under the terms of the Be Sample Code License. 12*/ 13 14#include "ChartView.h" 15#include "ChartWindow.h" 16 17 18ChartView::ChartView(BRect rect) 19 : 20 BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) 21{ 22} 23 24 25/* The drawing function just draw the offscreen if it exists and is used */ 26void 27ChartView::Draw(BRect rect) 28{ 29 ChartWindow *window = dynamic_cast<ChartWindow *>(Window()); 30 if (window == NULL) 31 return; 32 33 if ((window->fOffscreen != 0) && (window->fCurrentSettings.display == DISPLAY_BITMAP)) 34 DrawBitmap(window->fOffscreen, rect, rect); 35} 36 37 38/* Send a message to the window if the user click anywhere in the animation 39 view. This is used to go out of fullscreen demo mode. */ 40void 41ChartView::MouseDown(BPoint where) 42{ 43 Window()->PostMessage(BACK_DEMO_MSG); 44} 45 46 47/* Another straightforward constructor. The default target setting for the 48 frames/s vue-meter is 5 (as 5 * 12 = 60 frames/s) */ 49InstantView::InstantView(BRect rect) 50 : 51 BView(rect, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) 52{ 53 step = 5; 54} 55 56 57/* Draw the colored bars of the vue-meter depending the current framerate 58 of the window animation. The color coding depends of the target framerate 59 as encoded by step. */ 60void 61InstantView::Draw(BRect rect) 62{ 63 ChartWindow *window = dynamic_cast<ChartWindow *>(Window()); 64 if (window == NULL) 65 return; 66 67 for (int32 i = 0; i < window->fInstantLoadLevel; i++) { 68 if (i < step) 69 SetHighColor(255, 90, 90); 70 else if ((i / step) & 1) 71 SetHighColor(90, 255, 90); 72 else 73 SetHighColor(40, 200, 40); 74 FillRect(BRect(3 + i * 4, 2, 5 + i * 4, 19)); 75 } 76 Flush(); 77} 78 79 80ChartColorControl::ChartColorControl(BPoint start, BMessage *message) 81 : 82 BColorControl(start, B_CELLS_32x8, 8.0, "", message) 83{ 84} 85 86 87/* We overwrite SetValue to send a message to the target everytime 88 the setting change and not only at the end. */ 89void 90ChartColorControl::SetValue(int32 colorValue) 91{ 92 BLooper *looper; 93 94 BColorControl::SetValue(colorValue); 95 Target(&looper); 96 if (looper) { 97 BMessage msg(*Message()); 98 msg.AddInt32("be:value", colorValue); 99 looper->PostMessage(&msg); 100 } 101} 102