2005-07-01 10:53:07 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Haiku Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
2005-11-04 18:54:16 +03:00
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
2005-07-01 10:53:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ColorSet.h>
|
2005-07-08 04:38:52 +04:00
|
|
|
#include <WindowPrivate.h>
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "AppServer.h"
|
|
|
|
#include "DrawingEngine.h"
|
|
|
|
#include "RootLayer.h"
|
|
|
|
#include "WinBorder.h"
|
|
|
|
#include "Workspace.h"
|
|
|
|
|
|
|
|
#include "WorkspacesLayer.h"
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
WorkspacesLayer::WorkspacesLayer(BRect frame, const char* name,
|
2005-11-04 18:23:54 +03:00
|
|
|
int32 token, uint32 resizeMode, uint32 flags, DrawingEngine* driver)
|
2005-07-01 10:53:07 +04:00
|
|
|
: Layer(frame, name, token, resizeMode, flags, driver)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorkspacesLayer::~WorkspacesLayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkspacesLayer::_GetGrid(int32& columns, int32& rows)
|
|
|
|
{
|
|
|
|
int32 count = GetRootLayer()->WorkspaceCount();
|
|
|
|
|
|
|
|
rows = 1;
|
|
|
|
for (int32 i = 2; i < count; i++) {
|
|
|
|
if (count % i == 0)
|
|
|
|
rows = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
columns = count / rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRect
|
|
|
|
WorkspacesLayer::_WorkspaceAt(int32 i)
|
|
|
|
{
|
|
|
|
int32 columns, rows;
|
|
|
|
_GetGrid(columns, rows);
|
|
|
|
|
|
|
|
int32 width = fFrame.IntegerWidth() / columns;
|
|
|
|
int32 height = fFrame.IntegerHeight() / rows;
|
|
|
|
|
|
|
|
int32 column = i % columns;
|
|
|
|
int32 row = i / columns;
|
|
|
|
|
|
|
|
BRect rect(column * width, row * height, (column + 1) * width, (row + 1) * height);
|
|
|
|
|
|
|
|
// make sure there is no gap anywhere
|
|
|
|
if (column == columns - 1)
|
|
|
|
rect.right = fFrame.right;
|
|
|
|
if (row == rows - 1)
|
|
|
|
rect.bottom = fFrame.bottom;
|
|
|
|
|
|
|
|
rect.OffsetBy(ConvertToTop(BPoint(0, 0)));
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRect
|
|
|
|
WorkspacesLayer::_WindowFrame(const BRect& workspaceFrame,
|
|
|
|
const BRect& screenFrame, const BRect& windowFrame)
|
|
|
|
{
|
|
|
|
BRect frame = windowFrame;
|
|
|
|
|
|
|
|
float factor = workspaceFrame.Width() / screenFrame.Width();
|
2005-07-01 11:58:22 +04:00
|
|
|
frame.left = rintf(frame.left * factor);
|
|
|
|
frame.right = rintf(frame.right * factor);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
factor = workspaceFrame.Height() / screenFrame.Height();
|
2005-07-01 11:58:22 +04:00
|
|
|
frame.top = rintf(frame.top * factor);
|
|
|
|
frame.bottom = rintf(frame.bottom * factor);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
frame.OffsetBy(workspaceFrame.LeftTop());
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkspacesLayer::_DrawWindow(const BRect& workspaceFrame,
|
2005-07-01 11:58:22 +04:00
|
|
|
const BRect& screenFrame, WinBorder* window,
|
2005-07-21 15:43:11 +04:00
|
|
|
BRegion& backgroundRegion, bool active)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
2005-07-08 04:38:52 +04:00
|
|
|
if (window->Feel() == kDesktopWindowFeel)
|
|
|
|
return;
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
BRect frame = _WindowFrame(workspaceFrame, screenFrame, window->Frame());
|
|
|
|
BRect tabFrame = _WindowFrame(workspaceFrame, screenFrame,
|
|
|
|
window->GetDecorator()->GetTabRect());
|
|
|
|
|
|
|
|
// ToDo: let decorator do this!
|
|
|
|
RGBColor yellow = window->GetDecorator()->GetColors().window_tab;
|
2005-07-21 15:43:11 +04:00
|
|
|
RGBColor gray(180, 180, 180);
|
|
|
|
RGBColor white(255, 255, 255);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
_DarkenColor(yellow);
|
|
|
|
_DarkenColor(gray);
|
|
|
|
_DarkenColor(white);
|
|
|
|
}
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
if (tabFrame.left < frame.left)
|
|
|
|
tabFrame.left = frame.left;
|
|
|
|
if (tabFrame.right >= frame.right)
|
|
|
|
tabFrame.right = frame.right - 1;
|
|
|
|
|
|
|
|
tabFrame.top = frame.top - 1;
|
|
|
|
tabFrame.bottom = frame.top - 1;
|
|
|
|
|
|
|
|
backgroundRegion.Exclude(tabFrame);
|
|
|
|
backgroundRegion.Exclude(frame);
|
|
|
|
|
|
|
|
fDriver->StrokeLine(tabFrame.LeftTop(), tabFrame.RightBottom(), yellow);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
fDriver->StrokeRect(frame, gray);
|
|
|
|
|
|
|
|
frame.InsetBy(1, 1);
|
|
|
|
fDriver->FillRect(frame, white);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkspacesLayer::_DrawWorkspace(int32 index)
|
|
|
|
{
|
|
|
|
BRect rect = _WorkspaceAt(index);
|
|
|
|
|
|
|
|
Workspace* workspace = GetRootLayer()->WorkspaceAt(index);
|
2005-07-21 15:43:11 +04:00
|
|
|
bool active = workspace == GetRootLayer()->ActiveWorkspace();
|
|
|
|
if (active) {
|
2005-07-01 10:53:07 +04:00
|
|
|
// draw active frame
|
|
|
|
RGBColor black(0, 0, 0);
|
|
|
|
fDriver->StrokeRect(rect, black);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw background
|
|
|
|
|
|
|
|
rect.InsetBy(1, 1);
|
|
|
|
RGBColor color;
|
|
|
|
|
|
|
|
// ToDo: fix me - workspaces must always exist, not only on first visit!
|
|
|
|
if (workspace != NULL)
|
|
|
|
color = workspace->BGColor();
|
|
|
|
else
|
|
|
|
color.SetColor(51, 102, 152);
|
|
|
|
|
2005-07-21 15:43:11 +04:00
|
|
|
if (!active) {
|
|
|
|
_DarkenColor(color);
|
|
|
|
}
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
// draw windows
|
|
|
|
|
2005-07-02 14:37:53 +04:00
|
|
|
BRegion backgroundRegion = VisibleRegion();
|
2005-11-07 22:01:12 +03:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
// ToDo: would be nice to get the real update region here
|
|
|
|
|
|
|
|
if (workspace != NULL) {
|
|
|
|
WinBorder* windows[256];
|
|
|
|
int32 count = 256;
|
|
|
|
if (!workspace->GetWinBorderList((void **)&windows, &count))
|
|
|
|
return;
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
uint16 width, height;
|
|
|
|
uint32 colorSpace;
|
|
|
|
float frequency;
|
2005-10-31 14:05:52 +03:00
|
|
|
GetRootLayer()->GetDesktop()->ScreenAt(0)->GetMode(width, height, colorSpace, frequency);
|
2005-07-01 11:58:22 +04:00
|
|
|
BRect screenFrame(0, 0, width - 1, height - 1);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
BRegion workspaceRegion(rect);
|
|
|
|
backgroundRegion.IntersectWith(&workspaceRegion);
|
|
|
|
fDriver->ConstrainClippingRegion(&backgroundRegion);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
for (int32 i = count; i-- > 0;) {
|
2005-07-21 15:43:11 +04:00
|
|
|
_DrawWindow(rect, screenFrame, windows[i], backgroundRegion, active);
|
2005-07-01 11:58:22 +04:00
|
|
|
}
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
2005-07-01 11:58:22 +04:00
|
|
|
|
|
|
|
fDriver->ConstrainClippingRegion(&backgroundRegion);
|
|
|
|
fDriver->FillRect(rect, color);
|
2005-07-02 14:37:53 +04:00
|
|
|
|
|
|
|
// TODO: ConstrainClippingRegion() should accept a const parameter !!
|
|
|
|
BRegion cRegion(VisibleRegion());
|
|
|
|
fDriver->ConstrainClippingRegion(&cRegion);
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-21 15:43:11 +04:00
|
|
|
void
|
|
|
|
WorkspacesLayer::_DarkenColor(RGBColor& color) const
|
|
|
|
{
|
|
|
|
color = tint_color(color.GetColor32(), B_DARKEN_2_TINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
void
|
|
|
|
WorkspacesLayer::Draw(const BRect& updateRect)
|
|
|
|
{
|
|
|
|
// ToDo: either draw into an off-screen bitmap, or turn off flickering...
|
|
|
|
|
|
|
|
int32 columns, rows;
|
|
|
|
_GetGrid(columns, rows);
|
|
|
|
|
|
|
|
// draw grid
|
|
|
|
// horizontal lines
|
|
|
|
|
|
|
|
BRect frame = fFrame;
|
|
|
|
frame.OffsetBy(ConvertToTop(BPoint(0, 0)));
|
|
|
|
|
|
|
|
fDriver->StrokeLine(BPoint(frame.left, frame.top),
|
|
|
|
BPoint(frame.right, frame.top), ViewColor());
|
|
|
|
|
|
|
|
for (int32 row = 0; row < rows; row++) {
|
|
|
|
BRect rect = _WorkspaceAt(row * columns);
|
|
|
|
fDriver->StrokeLine(BPoint(frame.left, rect.bottom),
|
|
|
|
BPoint(frame.right, rect.bottom), ViewColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
// vertical lines
|
|
|
|
|
|
|
|
fDriver->StrokeLine(BPoint(frame.left, frame.top),
|
|
|
|
BPoint(frame.left, frame.bottom), ViewColor());
|
|
|
|
|
|
|
|
for (int32 column = 0; column < columns; column++) {
|
|
|
|
BRect rect = _WorkspaceAt(column);
|
|
|
|
fDriver->StrokeLine(BPoint(rect.right, frame.top),
|
|
|
|
BPoint(rect.right, frame.bottom), ViewColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw workspaces
|
|
|
|
|
|
|
|
int32 count = GetRootLayer()->WorkspaceCount();
|
|
|
|
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
_DrawWorkspace(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|