Minor tweaks and improvements to the DefaultDecorator

Made toggle for RootLayer debug output
Optimization for ViewDriver::CopyRegion with 1-rectangle regions
Fixes and tweaks to WinBorder::MouseMoved()
Toggled debug output in ServerApp
More useful comments in code in general


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4517 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2003-09-06 21:09:11 +00:00
parent dbb3d1fc5b
commit d7f34b0231
8 changed files with 304 additions and 280 deletions
+119 -175
View File
@@ -58,78 +58,82 @@ DefaultDecorator::DefaultDecorator(BRect rect, int32 wlook, int32 wfeel, int32 w
framecolors[3].SetColor(136,136,136); framecolors[3].SetColor(136,136,136);
framecolors[4].SetColor(96,96,96); framecolors[4].SetColor(96,96,96);
// Set appropriate colors based on the current focus value. In this case, each decorator
// defaults to not having the focus.
_SetFocus(); _SetFocus();
// Do initial decorator setup
_DoLayout(); _DoLayout();
// This flag is used to determine whether or not we're moving the tab // This flag is used to determine whether or not we're moving the tab
slidetab=false; slidetab=false;
// tab_highcol=_colors->window_tab; #ifdef DEBUG_DECORATOR
// tab_lowcol=_colors->window_tab; printf("DefaultDecorator:\n");
printf("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",rect.left,rect.top,rect.right,rect.bottom);
#ifdef DEBUG_DECORATOR #endif
printf("DefaultDecorator:\n");
printf("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",rect.left,rect.top,rect.right,rect.bottom);
#endif
} }
DefaultDecorator::~DefaultDecorator(void) DefaultDecorator::~DefaultDecorator(void)
{ {
#ifdef DEBUG_DECORATOR #ifdef DEBUG_DECORATOR
printf("DefaultDecorator: ~DefaultDecorator()\n"); printf("DefaultDecorator: ~DefaultDecorator()\n");
#endif #endif
delete [] framecolors; delete [] framecolors;
} }
click_type DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers) click_type DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers)
{ {
#ifdef DEBUG_DECORATOR #ifdef DEBUG_DECORATOR
printf("DefaultDecorator: Clicked\n"); printf("DefaultDecorator: Clicked\n");
printf("\tPoint: (%.1f,%.1f)\n",pt.x,pt.y); printf("\tPoint: (%.1f,%.1f)\n",pt.x,pt.y);
printf("\tButtons:\n"); printf("\tButtons:\n");
if(buttons==0) if(buttons==0)
printf("\t\tNone\n"); printf("\t\tNone\n");
else else
{ {
if(buttons & B_PRIMARY_MOUSE_BUTTON) if(buttons & B_PRIMARY_MOUSE_BUTTON)
printf("\t\tPrimary\n"); printf("\t\tPrimary\n");
if(buttons & B_SECONDARY_MOUSE_BUTTON) if(buttons & B_SECONDARY_MOUSE_BUTTON)
printf("\t\tSecondary\n"); printf("\t\tSecondary\n");
if(buttons & B_TERTIARY_MOUSE_BUTTON) if(buttons & B_TERTIARY_MOUSE_BUTTON)
printf("\t\tTertiary\n"); printf("\t\tTertiary\n");
} }
printf("\tModifiers:\n"); printf("\tModifiers:\n");
if(modifiers==0) if(modifiers==0)
printf("\t\tNone\n"); printf("\t\tNone\n");
else else
{ {
if(modifiers & B_CAPS_LOCK) if(modifiers & B_CAPS_LOCK)
printf("\t\tCaps Lock\n"); printf("\t\tCaps Lock\n");
if(modifiers & B_NUM_LOCK) if(modifiers & B_NUM_LOCK)
printf("\t\tNum Lock\n"); printf("\t\tNum Lock\n");
if(modifiers & B_SCROLL_LOCK) if(modifiers & B_SCROLL_LOCK)
printf("\t\tScroll Lock\n"); printf("\t\tScroll Lock\n");
if(modifiers & B_LEFT_COMMAND_KEY) if(modifiers & B_LEFT_COMMAND_KEY)
printf("\t\t Left Command\n"); printf("\t\t Left Command\n");
if(modifiers & B_RIGHT_COMMAND_KEY) if(modifiers & B_RIGHT_COMMAND_KEY)
printf("\t\t Right Command\n"); printf("\t\t Right Command\n");
if(modifiers & B_LEFT_CONTROL_KEY) if(modifiers & B_LEFT_CONTROL_KEY)
printf("\t\tLeft Control\n"); printf("\t\tLeft Control\n");
if(modifiers & B_RIGHT_CONTROL_KEY) if(modifiers & B_RIGHT_CONTROL_KEY)
printf("\t\tRight Control\n"); printf("\t\tRight Control\n");
if(modifiers & B_LEFT_OPTION_KEY) if(modifiers & B_LEFT_OPTION_KEY)
printf("\t\tLeft Option\n"); printf("\t\tLeft Option\n");
if(modifiers & B_RIGHT_OPTION_KEY) if(modifiers & B_RIGHT_OPTION_KEY)
printf("\t\tRight Option\n"); printf("\t\tRight Option\n");
if(modifiers & B_LEFT_SHIFT_KEY) if(modifiers & B_LEFT_SHIFT_KEY)
printf("\t\tLeft Shift\n"); printf("\t\tLeft Shift\n");
if(modifiers & B_RIGHT_SHIFT_KEY) if(modifiers & B_RIGHT_SHIFT_KEY)
printf("\t\tRight Shift\n"); printf("\t\tRight Shift\n");
if(modifiers & B_MENU_KEY) if(modifiers & B_MENU_KEY)
printf("\t\tMenu\n"); printf("\t\tMenu\n");
} }
#endif #endif
// In checking for hit test stuff, we start with the smallest rectangles the user might
// be clicking on and gradually work our way out into larger rectangles.
if(_closerect.Contains(pt)) if(_closerect.Contains(pt))
return CLICK_CLOSE; return CLICK_CLOSE;
@@ -143,8 +147,6 @@ else
if(_tabrect.Contains(pt)) if(_tabrect.Contains(pt))
{ {
// Here's part of our window management stuff // Here's part of our window management stuff
// if(buttons==B_PRIMARY_MOUSE_BUTTON && !GetFocus())
// return CLICK_MOVETOFRONT;
if(buttons==B_SECONDARY_MOUSE_BUTTON) if(buttons==B_SECONDARY_MOUSE_BUTTON)
return CLICK_MOVETOBACK; return CLICK_MOVETOBACK;
return CLICK_DRAG; return CLICK_DRAG;
@@ -168,10 +170,10 @@ else
void DefaultDecorator::_DoLayout(void) void DefaultDecorator::_DoLayout(void)
{ {
//debugger(""); #ifdef DEBUG_DECORATOR
#ifdef DEBUG_DECORATOR printf("DefaultDecorator: Do Layout\n");
printf("DefaultDecorator: Do Layout\n"); #endif
#endif
// Here we determine the size of every rectangle that we use // Here we determine the size of every rectangle that we use
// internally when we are given the size of the client rectangle. // internally when we are given the size of the client rectangle.
@@ -185,6 +187,7 @@ printf("DefaultDecorator: Do Layout\n");
// and there *are* apps which do this // and there *are* apps which do this
// borderwidth=3; // borderwidth=3;
// break; // break;
case B_BORDERED_WINDOW_LOOK: case B_BORDERED_WINDOW_LOOK:
case B_TITLED_WINDOW_LOOK: case B_TITLED_WINDOW_LOOK:
case B_DOCUMENT_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK:
@@ -194,21 +197,17 @@ printf("DefaultDecorator: Do Layout\n");
borderwidth = 0; borderwidth = 0;
} }
// Current version simply makes everything fit inside the rect // distance from one item of the tab bar to another. In this case the text and close/zoom rects
// instead of building around it. This will change.
// IT did :-)
// distance from one item of the tab bar to another. In this case the text and close/zoom rects
textoffset = (_look==B_FLOATING_WINDOW_LOOK) ? 7 : 10; textoffset = (_look==B_FLOATING_WINDOW_LOOK) ? 7 : 10;
// calculate or tab rect // calculate our tab rect
_tabrect.Set( _frame.left - borderwidth, _tabrect.Set( _frame.left - borderwidth,
_frame.top - borderwidth - 19.0, _frame.top - borderwidth - 19.0,
((_frame.right - _frame.left) < 35.0 ? ((_frame.right - _frame.left) < 35.0 ?
_frame.left + 35.0 : _frame.right) + borderwidth, _frame.left + 35.0 : _frame.right) + borderwidth,
_frame.top - (borderwidth-1) ); _frame.top - (borderwidth-1) );
// make it text width sensitive // make it text width sensitive
if(strlen(GetTitle())>1) if(strlen(GetTitle())>1)
{ {
if(_driver) if(_driver)
@@ -216,10 +215,10 @@ printf("DefaultDecorator: Do Layout\n");
else else
titlepixelwidth=10; titlepixelwidth=10;
int32 tabLength = 14 + // _closerect width int32 tabLength = int32(14 + // _closerect width
textoffset + titlepixelwidth + textoffset + textoffset + titlepixelwidth + textoffset +
14 + // _zoomrect width 14 + // _zoomrect width
8; // margins 8); // margins
int32 tabWidth = (int32)_tabrect.Width(); int32 tabWidth = (int32)_tabrect.Width();
if ( tabLength < tabWidth ) if ( tabLength < tabWidth )
_tabrect.right = _tabrect.left + tabLength; _tabrect.right = _tabrect.left + tabLength;
@@ -227,7 +226,7 @@ printf("DefaultDecorator: Do Layout\n");
else else
_tabrect.right = _tabrect.left + _tabrect.Width()/2; _tabrect.right = _tabrect.left + _tabrect.Width()/2;
// calculate left/top/right/bottom borders // calculate left/top/right/bottom borders
if ( borderwidth != 0 ){ if ( borderwidth != 0 ){
_borderrect = _frame.InsetByCopy( -borderwidth, -borderwidth ); _borderrect = _frame.InsetByCopy( -borderwidth, -borderwidth );
leftborder.Set( _borderrect.left, _frame.top - borderwidth, leftborder.Set( _borderrect.left, _frame.top - borderwidth,
@@ -240,7 +239,7 @@ printf("DefaultDecorator: Do Layout\n");
_borderrect.right, _borderrect.bottom ); _borderrect.right, _borderrect.bottom );
} }
else{ else{
// no border ... (?) useful when displaying windows that are just images // no border ... (?) useful when displaying windows that are just images
_borderrect = _frame; _borderrect = _frame;
leftborder.Set( 0.0, 0.0, -1.0, -1.0 ); leftborder.Set( 0.0, 0.0, -1.0, -1.0 );
rightborder.Set( 0.0, 0.0, -1.0, -1.0 ); rightborder.Set( 0.0, 0.0, -1.0, -1.0 );
@@ -248,89 +247,31 @@ printf("DefaultDecorator: Do Layout\n");
bottomborder.Set( 0.0, 0.0, -1.0, -1.0 ); bottomborder.Set( 0.0, 0.0, -1.0, -1.0 );
} }
// calculate resize rect // calculate resize rect
_resizerect.Set( _borderrect.right - 19.0, _borderrect.bottom - 19.0, _resizerect.Set( _borderrect.right - 19.0, _borderrect.bottom - 19.0,
_borderrect.right, _borderrect.bottom); _borderrect.right, _borderrect.bottom);
// format tab rect for a floating window - make te rect smaller // format tab rect for a floating window - make the rect smaller
if ( _look == B_FLOATING_WINDOW_LOOK ){ if ( _look == B_FLOATING_WINDOW_LOOK ){
_tabrect.InsetBy( 0, 2 ); _tabrect.InsetBy( 0, 2 );
_tabrect.OffsetBy( 0, 2 ); _tabrect.OffsetBy( 0, 2 );
} }
// calulate close rect based on the tab rectangle // calulate close rect based on the tab rectangle
_closerect.Set( _tabrect.left + 4.0, _tabrect.top + 4.0, _closerect.Set( _tabrect.left + 4.0, _tabrect.top + 4.0,
_tabrect.left + 4.0 + 13.0, _tabrect.top + 4.0 + 13.0 ); _tabrect.left + 4.0 + 13.0, _tabrect.top + 4.0 + 13.0 );
// calulate zoom rect based on the tab rectangle // calulate zoom rect based on the tab rectangle
_zoomrect.Set( _tabrect.right - 4.0 - 13.0, _tabrect.top + 4.0, _zoomrect.Set( _tabrect.right - 4.0 - 13.0, _tabrect.top + 4.0,
_tabrect.right - 4.0, _tabrect.top + 4.0 + 13.0 ); _tabrect.right - 4.0, _tabrect.top + 4.0 + 13.0 );
// fromat close and zoom rects for a floating window - make rectangles smaller // format close and zoom rects for a floating window - make rectangles smaller
if ( _look == B_FLOATING_WINDOW_LOOK ){ if ( _look == B_FLOATING_WINDOW_LOOK ){
_closerect.InsetBy( 1, 1 ); _closerect.InsetBy( 1, 1 );
_zoomrect.InsetBy( 1, 1 ); _zoomrect.InsetBy( 1, 1 );
_closerect.OffsetBy( 0, -2 ); _closerect.OffsetBy( 0, -2 );
_zoomrect.OffsetBy( 0, -2 ); _zoomrect.OffsetBy( 0, -2 );
} }
// Old version...
/*
_tabrect=_frame;
_resizerect=_frame;
_borderrect=_frame;
_closerect=_frame;
textoffset=(_look==B_FLOATING_WINDOW_LOOK)?5:7;
_closerect.left+=(_look==B_FLOATING_WINDOW_LOOK)?2:4;
_closerect.top+=(_look==B_FLOATING_WINDOW_LOOK)?6:4;
_closerect.right=_closerect.left+10;
_closerect.bottom=_closerect.top+10;
_borderrect.top+=19;
if(borderwidth)
{
// Set up the border rectangles to handle the window's frame
rightborder=leftborder=topborder=bottomborder=_borderrect;
// We want the rectangles to intersect because of the beveled intersections, so all
// that is necessary is to set the short dimension of each side
leftborder.right=leftborder.left+borderwidth;
rightborder.left=rightborder.right-borderwidth;
topborder.bottom=topborder.top+borderwidth;
bottomborder.top=bottomborder.bottom-borderwidth;
}
_resizerect.top=_resizerect.bottom-18;
_resizerect.left=_resizerect.right-18;
_tabrect.bottom=_tabrect.top+18;
if(strlen(GetTitle())>1)
{
if(_driver)
titlepixelwidth=_driver->StringWidth(GetTitle(),_TitleWidth(), &_layerdata);
else
titlepixelwidth=10;
if(_closerect.right+textoffset+titlepixelwidth+35< _frame.Width()-1)
_tabrect.right=_tabrect.left+titlepixelwidth;
}
else
_tabrect.right=_tabrect.left+_tabrect.Width()/2;
if(_look==B_FLOATING_WINDOW_LOOK)
_tabrect.top+=4;
_zoomrect=_tabrect;
_zoomrect.top+=(_look==B_FLOATING_WINDOW_LOOK)?2:4;
_zoomrect.right-=4;
_zoomrect.bottom-=4;
_zoomrect.left=_zoomrect.right-10;
_zoomrect.bottom=_zoomrect.top+10;
*/
} }
void DefaultDecorator::MoveBy(float x, float y) void DefaultDecorator::MoveBy(float x, float y)
@@ -340,9 +281,10 @@ void DefaultDecorator::MoveBy(float x, float y)
void DefaultDecorator::MoveBy(BPoint pt) void DefaultDecorator::MoveBy(BPoint pt)
{ {
#ifdef DEBUG_DECORATOR #ifdef DEBUG_DECORATOR
printf("DefaultDecorator: Move By (%.1f, %.1f)\n",pt.x,pt.y); printf("DefaultDecorator: Move By (%.1f, %.1f)\n",pt.x,pt.y);
#endif #endif
// Move all internal rectangles the appropriate amount // Move all internal rectangles the appropriate amount
_frame.OffsetBy(pt); _frame.OffsetBy(pt);
_closerect.OffsetBy(pt); _closerect.OffsetBy(pt);
@@ -355,15 +297,14 @@ printf("DefaultDecorator: Move By (%.1f, %.1f)\n",pt.x,pt.y);
rightborder.OffsetBy(pt); rightborder.OffsetBy(pt);
topborder.OffsetBy(pt); topborder.OffsetBy(pt);
bottomborder.OffsetBy(pt); bottomborder.OffsetBy(pt);
// Draw( _borderrect );
} }
BRegion * DefaultDecorator::GetFootprint(void) BRegion * DefaultDecorator::GetFootprint(void)
{ {
#ifdef DEBUG_DECORATOR #ifdef DEBUG_DECORATOR
printf("DefaultDecorator: Get Footprint\n"); printf("DefaultDecorator: Get Footprint\n");
#endif #endif
// This function calculates the decorator's footprint in coordinates // This function calculates the decorator's footprint in coordinates
// relative to the layer. This is most often used to set a WinBorder // relative to the layer. This is most often used to set a WinBorder
// object's visible region. // object's visible region.
@@ -380,7 +321,10 @@ BRect DefaultDecorator::SlideTab(float dx, float dy=0){
void DefaultDecorator::_DrawTitle(BRect r) void DefaultDecorator::_DrawTitle(BRect r)
{ {
printf("_DrawTitle(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom); #ifdef DEBUG_DECORATOR
printf("_DrawTitle(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
#endif
// Designed simply to redraw the title when it has changed on // Designed simply to redraw the title when it has changed on
// the client side. // the client side.
_layerdata.highcolor=_colors->window_tab_text; _layerdata.highcolor=_colors->window_tab_text;
@@ -395,8 +339,15 @@ printf("_DrawTitle(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
titlestr+="..."; titlestr+="...";
titlecount+=2; titlecount+=2;
} }
// The text position needs tweaked when working as a floating window because the closerect placement
// is a little different. If it isn't moved, title placement looks really funky
if(_look==B_FLOATING_WINDOW_LOOK)
_driver->DrawString(titlestr.String(),titlecount, _driver->DrawString(titlestr.String(),titlecount,
BPoint(_closerect.right+textoffset,_closerect.bottom-1),&_layerdata); BPoint(_closerect.right+textoffset,_closerect.bottom+1),&_layerdata);
else
_driver->DrawString(titlestr.String(),titlecount,
BPoint(_closerect.right+textoffset,_closerect.bottom),&_layerdata);
} }
void DefaultDecorator::_SetFocus(void) void DefaultDecorator::_SetFocus(void)
@@ -404,40 +355,30 @@ void DefaultDecorator::_SetFocus(void)
// SetFocus() performs necessary duties for color swapping and // SetFocus() performs necessary duties for color swapping and
// other things when a window is deactivated or activated. // other things when a window is deactivated or activated.
// Removed Adi's short-term color hack and replaced with a more palatable substitute for the old,
// dark colors
if(GetFocus()) if(GetFocus())
{ {
// ADI: a temporary hack - the colors were TOO dark button_highcol.SetColor(tint_color(_colors->window_tab.GetColor32(),B_LIGHTEN_2_TINT));
// button_highcol.SetColor(tint_color(_colors->window_tab.GetColor32(),B_LIGHTEN_2_TINT)); button_lowcol.SetColor(tint_color(_colors->window_tab.GetColor32(),B_DARKEN_1_TINT));
// button_lowcol.SetColor(tint_color(_colors->window_tab.GetColor32(),B_DARKEN_2_TINT));
button_highcol.SetColor( RGBColor( 255, 255, 0 ) );
button_lowcol.SetColor( RGBColor( 234, 181, 0) );
textcol=_colors->window_tab_text; textcol=_colors->window_tab_text;
} }
else else
{ {
// ADI: a temporary hack - the colors were TOO dark button_highcol.SetColor(tint_color(_colors->inactive_window_tab.GetColor32(),B_LIGHTEN_2_TINT));
// button_highcol.SetColor(tint_color(_colors->inactive_window_tab.GetColor32(),B_LIGHTEN_2_TINT)); button_lowcol.SetColor(tint_color(_colors->inactive_window_tab.GetColor32(),B_DARKEN_1_TINT));
// button_lowcol.SetColor(tint_color(_colors->inactive_window_tab.GetColor32(),B_DARKEN_2_TINT));
button_highcol.SetColor( RGBColor(234, 181, 0) );
button_lowcol.SetColor( RGBColor( 255, 255, 0 ) );
textcol=_colors->inactive_window_tab_text; textcol=_colors->inactive_window_tab_text;
} }
} }
void DefaultDecorator::Draw(BRect update) void DefaultDecorator::Draw(BRect update)
{ {
#ifdef DEBUG_DECORATOR #ifdef DEBUG_DECORATOR
printf("DefaultDecorator: Draw(%.1f,%.1f,%.1f,%.1f)\n",update.left,update.top,update.right,update.bottom); printf("DefaultDecorator: Draw(%.1f,%.1f,%.1f,%.1f)\n",update.left,update.top,update.right,update.bottom);
#endif #endif
// We need to draw a few things: the tab, the resize thumb, the borders, // We need to draw a few things: the tab, the resize thumb, the borders,
// and the buttons // and the buttons
// Draw the top view's client area - just a hack :)
_layerdata.highcolor=_colors->document_background;
/*
if(_borderrect.Intersects(update))
_driver->FillRect(_borderrect & update,&_layerdata,pat_solidhigh);
*/
_DrawFrame(update); _DrawFrame(update);
_DrawTab(update); _DrawTab(update);
} }
@@ -447,19 +388,16 @@ void DefaultDecorator::Draw(void)
// Easy way to draw everything - no worries about drawing only certain // Easy way to draw everything - no worries about drawing only certain
// things // things
// Draw the top view's client area - just a hack :)
// _layerdata.highcolor=_colors->document_background;
// _driver->FillRect(_borderrect,&_layerdata,pat_solidhigh);
_DrawFrame(_borderrect); _DrawFrame(_borderrect);
_DrawTab(_tabrect); _DrawTab(_tabrect);
} }
void DefaultDecorator::_DrawZoom(BRect r) void DefaultDecorator::_DrawZoom(BRect r)
{ {
printf("_DrawZoom(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom); #ifdef DEBUG_DECORATOR
printf("_DrawZoom(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
#endif
// If this has been implemented, then the decorator has a Zoom button // If this has been implemented, then the decorator has a Zoom button
// which should be drawn based on the state of the member zoomstate // which should be drawn based on the state of the member zoomstate
BRect zr( r ); BRect zr( r );
@@ -476,14 +414,20 @@ printf("_DrawZoom(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
void DefaultDecorator::_DrawClose(BRect r) void DefaultDecorator::_DrawClose(BRect r)
{ {
printf("_DrawClose(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom); #ifdef DEBUG_DECORATOR
printf("_DrawClose(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
#endif
// Just like DrawZoom, but for a close button // Just like DrawZoom, but for a close button
DrawBlendedRect( r, GetClose()); DrawBlendedRect( r, GetClose());
} }
void DefaultDecorator::_DrawTab(BRect r) void DefaultDecorator::_DrawTab(BRect r)
{ {
printf("_DrawTab(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom); #ifdef DEBUG_DECORATOR
printf("_DrawTab(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom);
#endif
// If a window has a tab, this will draw it and any buttons which are // If a window has a tab, this will draw it and any buttons which are
// in it. // in it.
if(_look==B_NO_BORDER_WINDOW_LOOK) if(_look==B_NO_BORDER_WINDOW_LOOK)
+6 -3
View File
@@ -398,17 +398,20 @@ void Layer::Invalidate(BRegion& region)
All children of the layer also receive this call, so only 1 Invalidate call is All children of the layer also receive this call, so only 1 Invalidate call is
needed to set a section as invalid on the screen. needed to set a section as invalid on the screen.
*/ */
void Layer::Invalidate(BRect rect) void Layer::Invalidate(const BRect &rect)
{ {
// Make our own section dirty and pass it on to any children, if necessary.... // Make our own section dirty and pass it on to any children, if necessary....
// YES, WE ARE SHARING DIRT! Mudpies anyone? :D // YES, WE ARE SHARING DIRT! Mudpies anyone? :D
if(TestRectIntersection(Frame(),rect)) if(TestRectIntersection(Bounds(),rect))
{ {
// Clip the rectangle to the _visible region of the layer // Clip the rectangle to the _visible region of the layer
if(TestRegionIntersection(_visible,rect)) if(TestRegionIntersection(_visible,rect))
{ {
BRegion reg(*_visible); BRegion reg(*_visible);
IntersectRegionWith(&reg,rect); BRegion rectreg(rect);
// IntersectRegionWith(&reg,rect);
reg.IntersectWith(&rectreg);
if(reg.CountRects()>0) if(reg.CountRects()>0)
{ {
_is_dirty=true; _is_dirty=true;
+1 -1
View File
@@ -72,7 +72,7 @@ public:
const char *GetName(void) { return (_name)?_name->String():NULL; } const char *GetName(void) { return (_name)?_name->String():NULL; }
LayerData *GetLayerData(void) { return _layerdata; } LayerData *GetLayerData(void) { return _layerdata; }
void Invalidate(BRect rect); void Invalidate(const BRect &rect);
void Invalidate(BRegion& region); void Invalidate(BRegion& region);
void RebuildRegions(bool include_children=true); void RebuildRegions(bool include_children=true);
virtual void RequestDraw(const BRect &r); virtual void RequestDraw(const BRect &r);
+7
View File
@@ -35,6 +35,9 @@
#include <stdio.h> #include <stdio.h>
//#define DISPLAYDRIVER_TEST_HACK
//#define DEBUG_ROOTLAYER
/*! /*!
\brief Sets up internal variables needed by the RootLayer \brief Sets up internal variables needed by the RootLayer
\param rect Frame of the root layer \param rect Frame of the root layer
@@ -78,9 +81,12 @@ void RootLayer::RequestDraw(void)
// Redraw the base // Redraw the base
if(_invalid) if(_invalid)
{ {
#ifdef DEBUG_ROOTLAYER
printf("ROOTLAYER: "); printf("ROOTLAYER: ");
_invalid->PrintToStream(); _invalid->PrintToStream();
printf("===========\n"); printf("===========\n");
#endif
for(int32 i=0; _invalid->CountRects();i++) for(int32 i=0; _invalid->CountRects();i++)
{ {
if(_invalid->RectAt(i).IsValid()) if(_invalid->RectAt(i).IsValid())
@@ -101,6 +107,7 @@ void RootLayer::RequestDraw(void)
} }
_is_dirty=false; _is_dirty=false;
#ifdef DISPLAYDRIVER_TEST_HACK #ifdef DISPLAYDRIVER_TEST_HACK
int8 pattern[8]; int8 pattern[8];
int8 pattern2[8]; int8 pattern2[8];
+1 -1
View File
@@ -50,7 +50,7 @@
#include "LayerData.h" #include "LayerData.h"
#include "Utils.h" #include "Utils.h"
#define DEBUG_SERVERAPP //#define DEBUG_SERVERAPP
/*! /*!
\brief Constructor \brief Constructor
+20 -6
View File
@@ -212,7 +212,6 @@ void VDView::MouseUp(BPoint pt)
void VDView::MessageReceived(BMessage *msg) void VDView::MessageReceived(BMessage *msg)
{ {
printf("message received\n");
switch(msg->what) switch(msg->what)
{ {
#ifdef ENABLE_INPUT_SERVER_EMULATION #ifdef ENABLE_INPUT_SERVER_EMULATION
@@ -658,10 +657,26 @@ void ViewDriver::CopyRegion(BRegion *src, const BPoint &lefttop)
printf("ViewDriver:: CopyRegion not completely tested\n"); printf("ViewDriver:: CopyRegion not completely tested\n");
#endif #endif
screenwin->Lock(); screenwin->Lock();
framebuffer->Lock(); framebuffer->Lock();
// Check for cases where the region is only 1 rectangle and call CopyBits in
// such a case. While in this particular case CopyBits is not HW-accelerated,
// other DisplayDriver derivatives, like AccelerantDriver, can take advantage of
// such things, cutting speed significantly in such cases
if(src->CountRects()==1)
{
BRect srect(src->RectAt(0)),drect(src->RectAt(0).OffsetToCopy(lefttop));
drawview->CopyBits(srect,drect);
drawview->Sync();
screenwin->view->Invalidate(srect);
screenwin->view->Invalidate(drect);
framebuffer->Unlock();
screenwin->Unlock();
return;
}
// Check for overlap // Check for overlap
bool overlap=false; bool overlap=false;
@@ -675,9 +690,11 @@ printf("ViewDriver:: CopyRegion not completely tested\n");
if(TestRectIntersection(regframe,src->Frame()) && src->CountRects()>1) if(TestRectIntersection(regframe,src->Frame()) && src->CountRects()>1)
overlap=true; overlap=true;
if(overlap) if(overlap)
{ {
printf("Overlap\n");
// If overlap, get the inverse of the region passed to us and save the // If overlap, get the inverse of the region passed to us and save the
// inverse region's frame // inverse region's frame
inverse=src->Frame(); inverse=src->Frame();
@@ -1064,9 +1081,6 @@ void ViewDriver::StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors,
drawview->SetHighColor(col); drawview->SetHighColor(col);
drawview->StrokeLine(pt1,pt2,B_SOLID_HIGH); drawview->StrokeLine(pt1,pt2,B_SOLID_HIGH);
printf("\tLine (%.1f,%.1f)-(%.1f,%.1f) in color (%d,%d,%d)\n",pt1.x,pt1.y,pt2.x,pt2.y,
col.red,col.green,col.blue);
} }
drawview->Sync(); drawview->Sync();
screenwin->view->Invalidate(); screenwin->view->Invalidate();
+149 -91
View File
@@ -39,9 +39,12 @@
// TODO: Document this file completely // TODO: Document this file completely
#define DEBUG_WINBORDER // Toggle general function call output
//#define DEBUG_WINBORDER
// toggle
//#define DEBUG_WINBORDER_MOUSE //#define DEBUG_WINBORDER_MOUSE
#define DEBUG_WINBORDER_CLICK //#define DEBUG_WINBORDER_CLICK
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
#include <stdio.h> #include <stdio.h>
@@ -84,7 +87,9 @@ WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const i
_mbuttons=0; _mbuttons=0;
_kmodifiers=0; _kmodifiers=0;
_win=win; _win=win;
if(_win)
_frame=_win->_frame;
_clientframe=_frame;
_mousepos.Set(0,0); _mousepos.Set(0,0);
_update=false; _update=false;
@@ -93,15 +98,15 @@ WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const i
_vresizewin=false; _vresizewin=false;
_driver=GetGfxDriver(ActiveScreen()); _driver=GetGfxDriver(ActiveScreen());
_decorator=new_decorator(r,name,look,feel,flags,GetGfxDriver(ActiveScreen())); _decorator=new_decorator(r,name,look,feel,flags,GetGfxDriver(ActiveScreen()));
// WinBorder must also include the right/left/top/bottom Decorator'
// rects - given by _decorator::GetBorderRect() - to be able to draw the borders // We need to do this because GetFootprint is supposed to generate a new BRegion.
_frame = _decorator->GetBorderRect(); // I suppose the call probably ought to be void GetFootprint(BRegion *recipient), but we can
_visible->Set( _frame ); // change that later.
_visible->Include( _decorator->GetTabRect() );
_full->Set( _frame ); if(_visible)
_full->Include( _decorator->GetTabRect() ); delete _visible;
_invalid->Set( _frame ); _visible=_decorator->GetFootprint();
_invalid->Include( _decorator->GetTabRect() ); *_full=*_visible;
_decorator->SetDriver(_driver); _decorator->SetDriver(_driver);
_decorator->SetTitle(name); _decorator->SetTitle(name);
@@ -147,43 +152,48 @@ void WinBorder::MouseDown(int8 *buffer)
{ {
case CLICK_MOVETOBACK: case CLICK_MOVETOBACK:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: MoveToBack\n"); printf("Click: MoveToBack\n");
#endif #endif
MakeTopChild(); MakeTopChild();
break; break;
} }
case CLICK_MOVETOFRONT: case CLICK_MOVETOFRONT:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: MoveToFront\n"); printf("Click: MoveToFront\n");
#endif #endif
MakeBottomChild(); MakeBottomChild();
break; break;
} }
case CLICK_CLOSE: case CLICK_CLOSE:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Close\n"); printf("Click: Close\n");
#endif #endif
_decorator->SetClose(true); _decorator->SetClose(true);
_decorator->DrawClose(); _decorator->DrawClose();
break; break;
} }
case CLICK_ZOOM: case CLICK_ZOOM:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Zoom\n"); printf("Click: Zoom\n");
#endif #endif
_decorator->SetZoom(true); _decorator->SetZoom(true);
_decorator->DrawZoom(); _decorator->DrawZoom();
break; break;
} }
case CLICK_MINIMIZE: case CLICK_MINIMIZE:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Minimize\n"); printf("Click: Minimize\n");
#endif #endif
_decorator->SetMinimize(true); _decorator->SetMinimize(true);
_decorator->DrawMinimize(); _decorator->DrawMinimize();
break; break;
@@ -192,27 +202,30 @@ printf("Click: Minimize\n");
{ {
if(buttons==B_PRIMARY_MOUSE_BUTTON) if(buttons==B_PRIMARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Drag\n"); printf("Click: Drag\n");
#endif #endif
MakeBottomChild(); MakeBottomChild();
set_is_moving_window(true); set_is_moving_window(true);
} }
if(buttons==B_SECONDARY_MOUSE_BUTTON) if(buttons==B_SECONDARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: MoveToBack\n"); printf("Click: MoveToBack\n");
#endif #endif
MakeTopChild(); MakeTopChild();
} }
break; break;
} }
case CLICK_SLIDETAB: case CLICK_SLIDETAB:
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Slide Tab\n"); printf("Click: Slide Tab\n");
#endif #endif
set_is_sliding_tab(true); set_is_sliding_tab(true);
break; break;
} }
@@ -220,9 +233,10 @@ printf("Click: Slide Tab\n");
{ {
if(buttons==B_PRIMARY_MOUSE_BUTTON) if(buttons==B_PRIMARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("Click: Resize\n"); printf("Click: Resize\n");
#endif #endif
set_is_resizing_window(true); set_is_resizing_window(true);
} }
break; break;
@@ -273,9 +287,10 @@ void WinBorder::MouseMoved(int8 *buffer)
if(is_sliding_tab()) if(is_sliding_tab())
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("ClickMove: Slide Tab\n"); printf("ClickMove: Slide Tab\n");
#endif #endif
float dx=pt.x-_mousepos.x; float dx=pt.x-_mousepos.x;
float dy=pt.y-_mousepos.y; float dy=pt.y-_mousepos.y;
@@ -295,40 +310,67 @@ printf("ClickMove: Slide Tab\n");
if(is_moving_window()) if(is_moving_window())
{ {
#ifdef DEBUG_WINBORDER_CLICK // We are moving the window. Because speed is of the essence, we need to handle a lot
printf("ClickMove: Drag\n"); // of stuff which we might otherwise not need to.
#endif
//debugger(""); #ifdef DEBUG_WINBORDER_CLICK
printf("ClickMove: Drag\n");
#endif
// 1) Get deltas
float dx=pt.x-_mousepos.x, float dx=pt.x-_mousepos.x,
dy=pt.y-_mousepos.y; dy=pt.y-_mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0)) if(buttons!=0 && (dx!=0 || dy!=0))
{ {
BRect oldmoveframe=_win->_frame; // 2) Offset necessary data members
_clientframe.OffsetBy(pt); _clientframe.OffsetBy(dx,dy);
_win->Lock(); _win->Lock();
_win->_frame.OffsetBy(dx,dy); _win->_frame.OffsetBy(dx,dy);
_win->Unlock(); _win->Unlock();
lock_layers(); lock_layers();
// Move the window decorator's footprint and remove the area occupied
// by the new location so we know what areas to invalidate.
// The original location
BRegion *reg=_decorator->GetFootprint(); BRegion *reg=_decorator->GetFootprint();
// TODO: we get an error here!!! - this method is untested
// TODO: we really need to enable this method to avoid lots of drawings. // The new location
//_driver->CopyRegion(reg,_win->_frame.LeftTop()); BRegion reg2(*reg);
reg2.OffsetBy((int32)dx, (int32)dy);
MoveBy(dx,dy);
_decorator->MoveBy(BPoint(dx, dy));
// 3) quickly move the window
_driver->CopyRegion(reg,reg2.Frame().LeftTop());
// 4) Invalidate only the areas which we can't redraw directly
for(int32 i=0; i<reg2.CountRects();i++)
reg->Exclude(reg2.RectAt(i));
// TODO: DW's notes to self
// As of right now, dragging the window is extremely slow despite the use
// of CopyRegion. The reason is because of the redraw taken. When Invalidate() is
// called the RootLayer invalidates things properly for itself, but the area which
// should be invalidated for the first of the two windows in my test case is not
// made dirty, so the entire first window is redrawn with RequestDraw being
// restructured as it is. Additionally, the second window is redrawn for the same reason
// when in fact it shouldn't be redrawn at all.
// Solution:
// Figure out what the exact usage of Layer::Invalidate() should be (parent coordinates,
// layer's coordinates, etc) and set things right. Secondly, nuke the invalid region
// in this call so that when RequestDraw is called, this WinBorder doesn't redraw itself
_parent->Invalidate(*reg); _parent->Invalidate(*reg);
_decorator->MoveBy(BPoint(dx, dy));
MoveBy(dx,dy);
// ADI: what do those do???
BRegion reg2(oldmoveframe);
reg->OffsetBy((int32)dx, (int32)dy);
reg2.Exclude(reg);
_parent->RebuildRegions(); _parent->RebuildRegions();
printf("WinBorder: calling parent = %s::RequestDraw()\n", _parent->_name->String());
_parent->RequestDraw(); _parent->RequestDraw();
delete reg; delete reg;
unlock_layers(); unlock_layers();
} }
@@ -337,13 +379,14 @@ printf("ClickMove: Drag\n");
if(is_resizing_window()) if(is_resizing_window())
{ {
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
printf("ClickMove: Resize\n"); printf("ClickMove: Resize\n");
#endif #endif
float dx=pt.x-_mousepos.x, float dx=pt.x-_mousepos.x,
dy=pt.y-_mousepos.y; dy=pt.y-_mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0)) if(buttons!=0 && (dx!=0 || dy!=0))
{ {
_clientframe.right+=dx; _clientframe.right+=dx;
_clientframe.bottom+=dy; _clientframe.bottom+=dy;
@@ -378,9 +421,6 @@ void WinBorder::MouseUp(int8 *buffer)
int32 modifiers=*((int32*)index); int32 modifiers=*((int32*)index);
BPoint pt(x,y); BPoint pt(x,y);
#ifdef DEBUG_WINBORDER_MOUSE
printf("WinBorder %s: MouseUp unimplemented\n",_title->String());
#endif
_mbuttons=0; _mbuttons=0;
_kmodifiers=modifiers; _kmodifiers=modifiers;
@@ -399,6 +439,9 @@ printf("WinBorder %s: MouseUp unimplemented\n",_title->String());
_decorator->DrawClose(); _decorator->DrawClose();
// call close window stuff here // call close window stuff here
#ifdef DEBUG_WINBORDER_MOUSE
printf("WinBorder %s: MouseUp:CLICK_CLOSE unimplemented\n",_title->String());
#endif
break; break;
} }
@@ -408,6 +451,9 @@ printf("WinBorder %s: MouseUp unimplemented\n",_title->String());
_decorator->DrawZoom(); _decorator->DrawZoom();
// call zoom stuff here // call zoom stuff here
#ifdef DEBUG_WINBORDER_MOUSE
printf("WinBorder %s: MouseUp:CLICK_ZOOM unimplemented\n",_title->String());
#endif
break; break;
} }
@@ -417,6 +463,9 @@ printf("WinBorder %s: MouseUp unimplemented\n",_title->String());
_decorator->DrawMinimize(); _decorator->DrawMinimize();
// call minimize stuff here // call minimize stuff here
#ifdef DEBUG_WINBORDER_MOUSE
printf("WinBorder %s: MouseUp:CLICK_MINIMIZE unimplemented\n",_title->String());
#endif
} }
default: default:
@@ -438,10 +487,11 @@ void WinBorder::SetFocus(const bool &active)
void WinBorder::RequestDraw(const BRect &r) void WinBorder::RequestDraw(const BRect &r)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: RequestDraw(BRect)\n",_title->String()); printf("WinBorder %s: RequestDraw(BRect)\n",_title->String());
PrintToStream(); PrintToStream();
#endif #endif
_decorator->Draw(r); _decorator->Draw(r);
delete _invalid; delete _invalid;
_invalid = NULL; _invalid = NULL;
@@ -449,13 +499,21 @@ PrintToStream();
void WinBorder::RequestDraw(void) void WinBorder::RequestDraw(void)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s::RequestDraw()\n",_title->String()); printf("WinBorder %s::RequestDraw()\n",_title->String());
PrintToStream(); PrintToStream();
#endif #endif
_decorator->Draw();
delete _invalid; if(_invalid)
_invalid = NULL; {
for(int32 i=0;i<_invalid->CountRects();i++)
_decorator->Draw(_invalid->RectAt(i));
delete _invalid;
_invalid = NULL;
}
else
_decorator->Draw();
} }
/* /*
void WinBorder::MoveBy(BPoint pt) void WinBorder::MoveBy(BPoint pt)
@@ -476,28 +534,28 @@ void WinBorder::ResizeBy(float x, float y)
*/ */
void WinBorder::UpdateColors(void) void WinBorder::UpdateColors(void)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: UpdateColors\n",_title->String()); printf("WinBorder %s: UpdateColors\n",_title->String());
#endif #endif
} }
void WinBorder::UpdateDecorator(void) void WinBorder::UpdateDecorator(void)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: UpdateDecorator\n",_title->String()); printf("WinBorder %s: UpdateDecorator\n",_title->String());
#endif #endif
} }
void WinBorder::UpdateFont(void) void WinBorder::UpdateFont(void)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: UpdateFont\n",_title->String()); printf("WinBorder %s: UpdateFont\n",_title->String());
#endif #endif
} }
void WinBorder::UpdateScreen(void) void WinBorder::UpdateScreen(void)
{ {
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: UpdateScreen\n",_title->String()); printf("WinBorder %s: UpdateScreen\n",_title->String());
#endif #endif
} }
+1 -3
View File
@@ -63,9 +63,7 @@ protected:
BString *_title; BString *_title;
Decorator *_decorator; Decorator *_decorator;
int32 _flags; int32 _flags;
// !!! HERE we do have a problem... _frame is also defined in Layer.h BRect _clientframe;
// BRect _frame, _clientframe;
BRect _clientframe;
int32 _mbuttons,_kmodifiers; int32 _mbuttons,_kmodifiers;
BPoint _mousepos; BPoint _mousepos;
bool _update; bool _update;