xref: /haiku/src/servers/app/stackandtile/SATDecorator.cpp (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
1 /*
2  * Copyright 2010, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Clemens Zeidler <haiku@clemens-zeidler.de>
7  *		Ingo Weinhold <ingo_weinhold@gmx.de>
8  */
9 
10 
11 #include "SATDecorator.h"
12 
13 #include <new>
14 
15 #include <GradientLinear.h>
16 #include <WindowPrivate.h>
17 
18 #include "DrawingEngine.h"
19 #include "SATWindow.h"
20 
21 
22 //#define DEBUG_SATDECORATOR
23 #ifdef DEBUG_SATDECORATOR
24 #	define STRACE(x) debug_printf x
25 #else
26 #	define STRACE(x) ;
27 #endif
28 
29 
30 static const float kResizeKnobSize = 18.0;
31 
32 
33 static const rgb_color kFrameColors[4] = {
34 	{ 152, 152, 152, 255 },
35 	{ 240, 240, 240, 255 },
36 	{ 152, 152, 152, 255 },
37 	{ 108, 108, 108, 255 }
38 };
39 
40 static const rgb_color kHighlightFrameColors[6] = {
41 	{ 52, 52, 52, 255 },
42 	{ 140, 140, 140, 255 },
43 	{ 124, 124, 124, 255 },
44 	{ 108, 108, 108, 255 },
45 	{ 52, 52, 52, 255 },
46 	{ 8, 8, 8, 255 }
47 };
48 
49 static const rgb_color kTabColor = {255, 203, 0, 255};
50 static const rgb_color kHighlightTabColor = tint_color(kTabColor,
51 	B_DARKEN_2_TINT);
52 static const rgb_color kHighlightTabColorLight = tint_color(kHighlightTabColor,
53 	(B_LIGHTEN_MAX_TINT + B_LIGHTEN_2_TINT) / 2);
54 static const rgb_color kHighlightTabColorBevel = tint_color(kHighlightTabColor,
55 	B_LIGHTEN_2_TINT);
56 static const rgb_color kHighlightTabColorShadow = tint_color(kHighlightTabColor,
57 	(B_DARKEN_1_TINT + B_NO_TINT) / 2);
58 
59 
60 SATDecorator::SATDecorator(DesktopSettings& settings, BRect frame)
61 	:
62 	DefaultDecorator(settings, frame)
63 {
64 
65 }
66 
67 
68 void
69 SATDecorator::GetComponentColors(Component component, uint8 highlight,
70 	ComponentColors _colors, Decorator::Tab* _tab)
71 {
72 	DefaultDecorator::Tab* tab = static_cast<DefaultDecorator::Tab*>(_tab);
73 	// we handle only our own highlights
74 	if (highlight != HIGHLIGHT_STACK_AND_TILE) {
75 		DefaultDecorator::GetComponentColors(component, highlight,
76 			_colors, tab);
77 		return;
78 	}
79 
80 	if (tab && tab->isHighlighted == false
81 		&& (component == COMPONENT_TAB || component == COMPONENT_CLOSE_BUTTON
82 			|| component == COMPONENT_ZOOM_BUTTON)) {
83 		DefaultDecorator::GetComponentColors(component, highlight,
84 			_colors, tab);
85 		return;
86 	}
87 
88 	switch (component) {
89 		case COMPONENT_TAB:
90 			_colors[COLOR_TAB_FRAME_LIGHT] = kFrameColors[0];
91 			_colors[COLOR_TAB_FRAME_DARK] = kFrameColors[3];
92 			_colors[COLOR_TAB] = kHighlightTabColor;
93 			_colors[COLOR_TAB_LIGHT] = kHighlightTabColorLight;
94 			_colors[COLOR_TAB_BEVEL] = kHighlightTabColorBevel;
95 			_colors[COLOR_TAB_SHADOW] = kHighlightTabColorShadow;
96 			_colors[COLOR_TAB_TEXT] = kFocusTextColor;
97 			break;
98 
99 		case COMPONENT_CLOSE_BUTTON:
100 		case COMPONENT_ZOOM_BUTTON:
101 			_colors[COLOR_BUTTON] = kHighlightTabColor;
102 			_colors[COLOR_BUTTON_LIGHT] = kHighlightTabColorLight;
103 			break;
104 
105 		case COMPONENT_LEFT_BORDER:
106 		case COMPONENT_RIGHT_BORDER:
107 		case COMPONENT_TOP_BORDER:
108 		case COMPONENT_BOTTOM_BORDER:
109 		case COMPONENT_RESIZE_CORNER:
110 		default:
111 			_colors[0] = kHighlightFrameColors[0];
112 			_colors[1] = kHighlightFrameColors[1];
113 			_colors[2] = kHighlightFrameColors[2];
114 			_colors[3] = kHighlightFrameColors[3];
115 			_colors[4] = kHighlightFrameColors[4];
116 			_colors[5] = kHighlightFrameColors[5];
117 			break;
118 	}
119 }
120 
121 
122 SATWindowBehaviour::SATWindowBehaviour(Window* window, StackAndTile* sat)
123 	:
124 	DefaultWindowBehaviour(window),
125 
126 	fStackAndTile(sat)
127 {
128 }
129 
130 
131 bool
132 SATWindowBehaviour::AlterDeltaForSnap(Window* window, BPoint& delta,
133 	bigtime_t now)
134 {
135 	if (DefaultWindowBehaviour::AlterDeltaForSnap(window, delta, now) == true)
136 		return true;
137 
138 	SATWindow* satWindow = fStackAndTile->GetSATWindow(window);
139 	if (satWindow == NULL)
140 		return false;
141 	SATGroup* group = satWindow->GetGroup();
142 	if (group == NULL)
143 		return false;
144 
145 	BRect groupFrame = group->WindowAt(0)->CompleteWindowFrame();
146 	for (int32 i = 1; i < group->CountItems(); i++)
147 		groupFrame = groupFrame | group->WindowAt(i)->CompleteWindowFrame();
148 
149 	return fMagneticBorder.AlterDeltaForSnap(window->Screen(),
150 		groupFrame, delta, now);
151 }
152