xref: /haiku/src/add-ons/control_look/BeControlLook/BeControlLook.cpp (revision 9bb9cc8896854f6a0a28f586f6025e8eb2623f0b)
1 /*
2  * Copyright 2019 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus, superstippi@gmx.de
7  *		DarkWyrm, bpmagic@columbus.rr.com
8  *		John Scipione, jscipione@gmail.com
9  *		Clemens Zeidler, haiku@clemens-zeidler.de
10  */
11 
12 
13 /*! BControlLook resembling BeOS R5 */
14 
15 
16 #include "BeControlLook.h"
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <new>
21 #include <stdio.h>
22 
23 #include <WindowPrivate.h>
24 
25 #include <Autolock.h>
26 #include <Debug.h>
27 #include <GradientLinear.h>
28 #include <Rect.h>
29 #include <Region.h>
30 #include <View.h>
31 
32 
33 //#define DEBUG_CONTROL_LOOK
34 #ifdef DEBUG_CONTROL_LOOK
35 #	define STRACE(x) printf x
36 #else
37 #	define STRACE(x) ;
38 #endif
39 
40 
41 BeControlLook::BeControlLook(image_id id)
42 	: HaikuControlLook()
43 {
44 }
45 
46 
47 BeControlLook::~BeControlLook()
48 {
49 }
50 
51 
52 void
53 BeControlLook::DrawMenuBarBackground(BView* view, BRect& rect,
54 	const BRect& updateRect, const rgb_color& base, uint32 flags,
55 	uint32 borders)
56 {
57 	if (!rect.IsValid() || !rect.Intersects(updateRect))
58 		return;
59 
60 	// the surface edges
61 
62 	// colors
63 	float topTint;
64 	float bottomTint;
65 
66 	if ((flags & B_ACTIVATED) != 0) {
67 		rgb_color bevelColor1 = tint_color(base, 1.40);
68 		rgb_color bevelColor2 = tint_color(base, 1.25);
69 
70 		topTint = 1.25;
71 		bottomTint = 1.20;
72 
73 		_DrawFrame(view, rect,
74 			bevelColor1, bevelColor1,
75 			bevelColor2, bevelColor2,
76 			borders & B_TOP_BORDER);
77 	} else {
78 		rgb_color cornerColor = tint_color(base, 0.9);
79 		rgb_color bevelColorTop = tint_color(base, 0.5);
80 		rgb_color bevelColorLeft = tint_color(base, 0.7);
81 		rgb_color bevelColorRightBottom = tint_color(base, 1.08);
82 
83 		topTint = 0.69;
84 		bottomTint = 1.03;
85 
86 		_DrawFrame(view, rect,
87 			bevelColorLeft, bevelColorTop,
88 			bevelColorRightBottom, bevelColorRightBottom,
89 			cornerColor, cornerColor,
90 			borders);
91 	}
92 
93 	// draw surface top
94 	//_FillGradient(view, rect, base, topTint, bottomTint);
95 	view->SetLowColor(base);
96 	view->FillRect(rect, B_SOLID_LOW);
97 }
98 
99 
100 void
101 BeControlLook::DrawMenuItemBackground(BView* view, BRect& rect,
102 	const BRect& updateRect, const rgb_color& base, uint32 flags,
103 	uint32 borders)
104 {
105 	if (!rect.IsValid() || !rect.Intersects(updateRect))
106 		return;
107 
108 	// surface edges
109 	float topTint;
110 	float bottomTint;
111 	rgb_color selectedColor = base;
112 
113 	if ((flags & B_ACTIVATED) != 0) {
114 		topTint = 0.9;
115 		bottomTint = 1.05;
116 	} else if ((flags & B_DISABLED) != 0) {
117 		topTint = 0.80;
118 		bottomTint = 1.07;
119 	} else {
120 		topTint = 0.6;
121 		bottomTint = 1.12;
122 	}
123 
124 	rgb_color bevelLightColor = tint_color(selectedColor, topTint);
125 	rgb_color bevelShadowColor = tint_color(selectedColor, bottomTint);
126 
127 	// draw surface edges
128 	_DrawFrame(view, rect,
129 		bevelLightColor, bevelLightColor,
130 		bevelShadowColor, bevelShadowColor,
131 		borders);
132 
133 	// draw surface top
134 	view->SetLowColor(selectedColor);
135 	//_FillGradient(view, rect, selectedColor, topTint, bottomTint);
136 	view->FillRect(rect, B_SOLID_LOW);
137 }
138 
139 
140 extern "C" BControlLook* (instantiate_control_look)(image_id id)
141 {
142 	return new (std::nothrow)BeControlLook(id);
143 }
144 
145