xref: /haiku/src/servers/app/stackandtile/SATDecorator.cpp (revision 40e20c10768c3dcfc54074b8886e3e91455332e1)
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 static const rgb_color kHighlightFrameColors[6] = {
33 	{ 52, 52, 52, 255 },
34 	{ 140, 140, 140, 255 },
35 	{ 124, 124, 124, 255 },
36 	{ 108, 108, 108, 255 },
37 	{ 52, 52, 52, 255 },
38 	{ 8, 8, 8, 255 }
39 };
40 
41 static const rgb_color kTabColor = {255, 203, 0, 255};
42 static const rgb_color kHighlightTabColor = tint_color(kTabColor,
43 	B_DARKEN_2_TINT);
44 static const rgb_color kHighlightTabColorLight = tint_color(kHighlightTabColor,
45 	(B_LIGHTEN_MAX_TINT + B_LIGHTEN_2_TINT) / 2);
46 static const rgb_color kHighlightTabColorBevel = tint_color(kHighlightTabColor,
47 	B_LIGHTEN_2_TINT);
48 static const rgb_color kHighlightTabColorShadow = tint_color(kHighlightTabColor,
49 	(B_DARKEN_1_TINT + B_NO_TINT) / 2);
50 
51 
52 SATDecorator::SATDecorator(DesktopSettings& settings, BRect frame)
53 	:
54 	DefaultDecorator(settings, frame)
55 {
56 
57 }
58 
59 
60 void
61 SATDecorator::GetComponentColors(Component component, uint8 highlight,
62 	ComponentColors _colors, Decorator::Tab* _tab)
63 {
64 	DefaultDecorator::Tab* tab = static_cast<DefaultDecorator::Tab*>(_tab);
65 	// we handle only our own highlights
66 	if (highlight != HIGHLIGHT_STACK_AND_TILE) {
67 		DefaultDecorator::GetComponentColors(component, highlight,
68 			_colors, tab);
69 		return;
70 	}
71 
72 	if (tab && tab->isHighlighted == false
73 		&& (component == COMPONENT_TAB || component == COMPONENT_CLOSE_BUTTON
74 			|| component == COMPONENT_ZOOM_BUTTON)) {
75 		DefaultDecorator::GetComponentColors(component, highlight,
76 			_colors, tab);
77 		return;
78 	}
79 
80 	switch (component) {
81 		case COMPONENT_TAB:
82 			_colors[COLOR_TAB_FRAME_LIGHT] = kFrameColors[0];
83 			_colors[COLOR_TAB_FRAME_DARK] = kFrameColors[3];
84 			_colors[COLOR_TAB] = kHighlightTabColor;
85 			_colors[COLOR_TAB_LIGHT] = kHighlightTabColorLight;
86 			_colors[COLOR_TAB_BEVEL] = kHighlightTabColorBevel;
87 			_colors[COLOR_TAB_SHADOW] = kHighlightTabColorShadow;
88 			_colors[COLOR_TAB_TEXT] = kFocusTextColor;
89 			break;
90 
91 		case COMPONENT_CLOSE_BUTTON:
92 		case COMPONENT_ZOOM_BUTTON:
93 			_colors[COLOR_BUTTON] = kHighlightTabColor;
94 			_colors[COLOR_BUTTON_LIGHT] = kHighlightTabColorLight;
95 			break;
96 
97 		case COMPONENT_LEFT_BORDER:
98 		case COMPONENT_RIGHT_BORDER:
99 		case COMPONENT_TOP_BORDER:
100 		case COMPONENT_BOTTOM_BORDER:
101 		case COMPONENT_RESIZE_CORNER:
102 		default:
103 			_colors[0] = kHighlightFrameColors[0];
104 			_colors[1] = kHighlightFrameColors[1];
105 			_colors[2] = kHighlightFrameColors[2];
106 			_colors[3] = kHighlightFrameColors[3];
107 			_colors[4] = kHighlightFrameColors[4];
108 			_colors[5] = kHighlightFrameColors[5];
109 			break;
110 	}
111 }
112 
113 
114 SATWindowBehaviour::SATWindowBehaviour(Window* window, StackAndTile* sat)
115 	:
116 	DefaultWindowBehaviour(window),
117 
118 	fStackAndTile(sat)
119 {
120 }
121 
122 
123 bool
124 SATWindowBehaviour::AlterDeltaForSnap(Window* window, BPoint& delta,
125 	bigtime_t now)
126 {
127 	if (DefaultWindowBehaviour::AlterDeltaForSnap(window, delta, now) == true)
128 		return true;
129 
130 	SATWindow* satWindow = fStackAndTile->GetSATWindow(window);
131 	if (satWindow == NULL)
132 		return false;
133 	SATGroup* group = satWindow->GetGroup();
134 	if (group == NULL)
135 		return false;
136 
137 	BRect groupFrame = group->WindowAt(0)->CompleteWindowFrame();
138 	for (int32 i = 1; i < group->CountItems(); i++)
139 		groupFrame = groupFrame | group->WindowAt(i)->CompleteWindowFrame();
140 
141 	return fMagneticBorder.AlterDeltaForSnap(window->Screen(),
142 		groupFrame, delta, now);
143 }
144