xref: /haiku/src/tests/kits/game/chart/ChartView.cpp (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
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 /* Straightforward constructor */
18 ChartView::ChartView(BRect rect) :
19 BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) {;}
20 
21 /* The drawing function just draw the offscreen if it exists and is used */
22 void ChartView::Draw(BRect r)
23 {
24 	ChartWindow		*w;
25 
26 	w = dynamic_cast<ChartWindow *>(Window());
27 	if ((w->fOffscreen != 0) && (w->fCurrentSettings.display == DISPLAY_BITMAP))
28 		DrawBitmap(w->fOffscreen, r, r);
29 }
30 
31 /* Send a message to the window if the user click anywhere in the animation
32    view. This is used to go out of fullscreen demo mode. */
33 void ChartView::MouseDown(BPoint where)
34 {
35 	Window()->PostMessage(BACK_DEMO_MSG);
36 }
37 
38 /* Another straightforward constructor. The default target setting for the
39    frames/s vue-meter is 5 (as 5 * 12 = 60 frames/s) */
40 InstantView::InstantView(BRect rect) :
41 BView(rect, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW)
42 {
43 	step = 5;
44 }
45 
46 /* Draw the colored bars of the vue-meter depending the current framerate
47    of the window animation. The color coding depends of the target framerate
48    as encoded by step. */
49 void InstantView::Draw(BRect r)
50 {
51 	ChartWindow *w = dynamic_cast<ChartWindow *>(Window());
52 	for (int32 i=0; i< w->fInstantLoadLevel; i++) {
53 		if (i<step) SetHighColor(255.0, 90.0, 90.0);
54 		else if ((i/step) & 1) SetHighColor(90.0, 255.0, 90.0);
55 		else SetHighColor(40.0, 200.0, 40.0);
56 		FillRect(BRect(3+i*4, 2, 5+i*4, 19));
57 	}
58 	Flush();
59 }
60 
61 /* Straightforward constructor */
62 ChartColorControl::ChartColorControl(BPoint start, BMessage *message) :
63 BColorControl(start, B_CELLS_32x8, 8.0, "", message)
64 {
65 }
66 
67 /* We overwrite SetValue to send a message to the target everytime
68    the setting change and not only at the end. */
69 void ChartColorControl::SetValue(int32 color_value)
70 {
71 	BLooper		*looper;
72 
73 	BColorControl::SetValue(color_value);
74 	Target(&looper);
75 	if (looper) {
76 		BMessage msg(*Message());
77 		msg.AddInt32("be:value", color_value);
78 		looper->PostMessage(&msg);
79 	}
80 }
81