Added to Utils a function to compute polygon boundaries

Moved Utils to libappserver - DisplaySupport needs it
Tweaked PicturePlayer to match polygon function tweaks
Added Shape, Region, and Polygon handling to ServerWindow
Removed ServerWindow::DispatchGraphicsMessage
Numerous small tweaks to DisplayDriver


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8991 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2004-09-17 10:27:58 +00:00
parent c33ef86b1d
commit 98ecc9715d
8 changed files with 306 additions and 187 deletions

View File

@ -98,8 +98,14 @@ void DisplayDriver::Shutdown(void)
If the destination is not the same size as the source, the source should be scaled to fit. If the destination is not the same size as the source, the source should be scaled to fit.
*/ */
void DisplayDriver::CopyBits(const BRect &src, const BRect &dest) void DisplayDriver::CopyBits(const BRect &src, const BRect &dest, const DrawData *d)
{ {
if(!d)
return;
Lock();
Blit(src,dest,d);
Unlock();
} }
/*! /*!
@ -109,6 +115,7 @@ void DisplayDriver::CopyBits(const BRect &src, const BRect &dest)
*/ */
void DisplayDriver::CopyRegion(BRegion *src, const BPoint &lefttop) void DisplayDriver::CopyRegion(BRegion *src, const BPoint &lefttop)
{ {
// TODO: Implement DisplayDriver;:CopyRegion
} }
/*! /*!
@ -566,8 +573,7 @@ void DisplayDriver::DrawString(const char *string, const int32 &length, const BP
previous=glyph_index; previous=glyph_index;
} }
// TODO: implement properly // TODO: implement calculation of invalid rectangle in DisplayDriver::DrawString properly
// calculate the invalid rectangle
BRect r; BRect r;
r.left=MIN(point.x,pen.x>>6); r.left=MIN(point.x,pen.x>>6);
r.right=MAX(point.x,pen.x>>6); r.right=MAX(point.x,pen.x>>6);
@ -670,6 +676,8 @@ void DisplayDriver::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
destindex+=destinc; destindex+=destinc;
} }
ReleaseBuffer(); ReleaseBuffer();
// TODO: test to see if Invalidate calls should be made in DisplayDriver::BlitMono2RGB32
Invalidate(BRect(pt.x, pt.y, pt.x + srcwidth, pt.y + srcheight)); Invalidate(BRect(pt.x, pt.y, pt.x + srcwidth, pt.y + srcheight));
} }
@ -792,6 +800,7 @@ void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
destindex+=destinc; destindex+=destinc;
} }
ReleaseBuffer(); ReleaseBuffer();
// TODO: test to see if Invalidate calls should be made in DisplayDriver::BlitGray2RGB32
Invalidate(BRect(pt.x, pt.y, pt.x + srcwidth, pt.y + srcheight)); Invalidate(BRect(pt.x, pt.y, pt.x + srcwidth, pt.y + srcheight));
} }
@ -1164,6 +1173,7 @@ void DisplayDriver::FillArc(const BRect &r, const float &angle, const float &spa
} }
} }
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -1527,6 +1537,7 @@ void DisplayDriver::FillArc(const BRect &r, const float &angle, const float &spa
} }
} }
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -1535,7 +1546,7 @@ void DisplayDriver::FillBezier(BPoint *pts, const RGBColor &color)
Lock(); Lock();
BezierCurve curve(pts); BezierCurve curve(pts);
FillPolygon(curve.GetPointArray(), curve.points.CountItems(), color); FillPolygon(curve.GetPointArray(), curve.points.CountItems(), curve.Frame(), color);
Unlock(); Unlock();
} }
@ -1551,7 +1562,7 @@ void DisplayDriver::FillBezier(BPoint *pts, const DrawData *d)
Lock(); Lock();
BezierCurve curve(pts); BezierCurve curve(pts);
FillPolygon(curve.GetPointArray(), curve.points.CountItems(), d); FillPolygon(curve.GetPointArray(), curve.points.CountItems(), curve.Frame(), d);
Unlock(); Unlock();
} }
@ -1685,6 +1696,7 @@ void DisplayDriver::FillEllipse(const BRect &r, const DrawData *d)
StrokeLine(BPoint(xc-x,yc-y),BPoint(xc+x,yc-y),&data); StrokeLine(BPoint(xc-x,yc-y),BPoint(xc+x,yc-y),&data);
StrokeLine(BPoint(xc-x,yc+y),BPoint(xc+x,yc+y),&data); StrokeLine(BPoint(xc-x,yc+y),BPoint(xc+x,yc+y),&data);
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -1694,7 +1706,7 @@ void DisplayDriver::FillEllipse(const BRect &r, const DrawData *d)
\param numpts Number of points in the BPoint array. \param numpts Number of points in the BPoint array.
\param color The color of the polygon \param color The color of the polygon
*/ */
void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &color) void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const RGBColor &color)
{ {
/* Here's the plan. Record all line segments in polygon. If a line segments crosses /* Here's the plan. Record all line segments in polygon. If a line segments crosses
the y-value of a point not in the segment, split the segment into 2 segments. the y-value of a point not in the segment, split the segment into 2 segments.
@ -1721,7 +1733,8 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &co
maxX = ROUND(ptlist[0].x); maxX = ROUND(ptlist[0].x);
minY = ROUND(ptlist[0].y); minY = ROUND(ptlist[0].y);
maxY = ROUND(ptlist[0].y); maxY = ROUND(ptlist[0].y);
/* Generate the segment list */
// Generate the segment list
currentPoint = ptlist; currentPoint = ptlist;
currentIndex = 0; currentIndex = 0;
nextPoint = &ptlist[1]; nextPoint = &ptlist[1];
@ -1776,7 +1789,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &co
} }
} }
/* Selection sort the segments. Probably should replace this later. */ // Selection sort the segments. Probably should replace this later.
for (i=0; i<numSegments; i++) for (i=0; i<numSegments; i++)
{ {
bestIndex = i; bestIndex = i;
@ -1791,7 +1804,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &co
segmentArray[i].Swap(segmentArray[bestIndex]); segmentArray[i].Swap(segmentArray[bestIndex]);
} }
/* Draw the lines */ // Draw the lines
for (y=minY; y<=maxY; y++) for (y=minY; y<=maxY; y++)
{ {
i = 0; i = 0;
@ -1824,6 +1837,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &co
} }
delete[] segmentArray; delete[] segmentArray;
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -1834,7 +1848,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const RGBColor &co
\param numpts Number of points in the BPoint array. \param numpts Number of points in the BPoint array.
\param d The 50 bazillion drawing options (inluding clip region) \param d The 50 bazillion drawing options (inluding clip region)
*/ */
void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d) void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const DrawData *d)
{ {
/* Here's the plan. Record all line segments in polygon. If a line segments crosses /* Here's the plan. Record all line segments in polygon. If a line segments crosses
the y-value of a point not in the segment, split the segment into 2 segments. the y-value of a point not in the segment, split the segment into 2 segments.
@ -1861,7 +1875,8 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d)
maxX = ROUND(ptlist[0].x); maxX = ROUND(ptlist[0].x);
minY = ROUND(ptlist[0].y); minY = ROUND(ptlist[0].y);
maxY = ROUND(ptlist[0].y); maxY = ROUND(ptlist[0].y);
/* Generate the segment list */
// Generate the segment list
currentPoint = ptlist; currentPoint = ptlist;
currentIndex = 0; currentIndex = 0;
nextPoint = &ptlist[1]; nextPoint = &ptlist[1];
@ -1916,7 +1931,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d)
} }
} }
/* Selection sort the segments. Probably should replace this later. */ // Selection sort the segments. Probably should replace this later.
for (i=0; i<numSegments; i++) for (i=0; i<numSegments; i++)
{ {
bestIndex = i; bestIndex = i;
@ -1933,7 +1948,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d)
if ( !d->clipReg ) if ( !d->clipReg )
{ {
/* Draw the lines */ // Draw the lines
for (y=minY; y<=maxY; y++) for (y=minY; y<=maxY; y++)
{ {
i = 0; i = 0;
@ -1985,7 +2000,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d)
yStart = MAX(minY,ROUND(clipRect.top)); yStart = MAX(minY,ROUND(clipRect.top));
yEnd = MIN(maxY,ROUND(clipRect.bottom)); yEnd = MIN(maxY,ROUND(clipRect.bottom));
/* Draw the lines */ // Draw the lines
for (y=yStart; y<=yEnd; y++) for (y=yStart; y<=yEnd; y++)
{ {
i = 0; i = 0;
@ -2035,6 +2050,7 @@ void DisplayDriver::FillPolygon(BPoint *ptlist, int32 numpts, const DrawData *d)
} }
} }
delete[] segmentArray; delete[] segmentArray;
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -2077,6 +2093,7 @@ void DisplayDriver::FillRect(const BRect &r, const DrawData *d)
} }
else else
FillPatternRect(r,d); FillPatternRect(r,d);
Invalidate(r);
Unlock(); Unlock();
} }
@ -2094,7 +2111,7 @@ void DisplayDriver::FillRegion(BRegion& r, const RGBColor &color)
numRects = r.CountRects(); numRects = r.CountRects();
for(int32 i=0; i<numRects;i++) for(int32 i=0; i<numRects;i++)
FillSolidRect(r.RectAt(i),color); FillSolidRect(r.RectAt(i),color);
Invalidate(r.Frame());
Unlock(); Unlock();
} }
@ -2131,7 +2148,7 @@ void DisplayDriver::FillRegion(BRegion& r, const DrawData *d)
for(int32 i=0; i<numRects;i++) for(int32 i=0; i<numRects;i++)
FillPatternRect(r.RectAt(i),d); FillPatternRect(r.RectAt(i),d);
} }
Invalidate(r.Frame());
Unlock(); Unlock();
} }
@ -2150,6 +2167,7 @@ void DisplayDriver::FillRoundRect(const BRect &r, const float &xrad, const float
StrokeSolidLine(ROUND(r.left+xrad-arc_x), ROUND(r.bottom-yrad+i), ROUND(r.right-xrad+arc_x), ROUND(r.bottom-yrad+i),color); StrokeSolidLine(ROUND(r.left+xrad-arc_x), ROUND(r.bottom-yrad+i), ROUND(r.right-xrad+arc_x), ROUND(r.bottom-yrad+i),color);
} }
FillSolidRect(BRect(r.left,r.top+yrad,r.right,r.bottom-yrad),color); FillSolidRect(BRect(r.left,r.top+yrad,r.right,r.bottom-yrad),color);
Invalidate(r);
Unlock(); Unlock();
} }
@ -2209,14 +2227,18 @@ void DisplayDriver::FillRoundRect(const BRect &r, const float &xrad, const float
} }
} }
FillPatternRect(BRect(r.left,r.top+yrad,r.right,r.bottom-yrad),d); FillPatternRect(BRect(r.left,r.top+yrad,r.right,r.bottom-yrad),d);
Invalidate(r);
Unlock(); Unlock();
} }
//void DisplayDriver::FillShape(SShape *sh, const DrawData *d, const Pattern &pat) void DisplayDriver::FillShape(const BRect &bounds, const int32 &opcount, const int32 *oplist,
//{ const int32 &ptcount, const BPoint *ptlist, const DrawData *d)
//} {
// TODO: Implement DisplayDriver::FillShape. How, though? AGG backend?
printf("DisplayDriver::FillShape unimplemented\n");
}
void DisplayDriver::FillTriangle(BPoint *pts, const RGBColor &color) void DisplayDriver::FillTriangle(BPoint *pts, const BRect &bounds, const RGBColor &color)
{ {
if ( !pts ) if ( !pts )
return; return;
@ -2306,7 +2328,9 @@ void DisplayDriver::FillTriangle(BPoint *pts, const RGBColor &color)
for(i=(int32)second.y; i<=third.y; i++) for(i=(int32)second.y; i<=third.y; i++)
StrokeSolidLine(ROUND(lineC.GetX(i)), i, ROUND(lineB.GetX(i)), i, color); StrokeSolidLine(ROUND(lineC.GetX(i)), i, ROUND(lineB.GetX(i)), i, color);
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -2315,7 +2339,7 @@ void DisplayDriver::FillTriangle(BPoint *pts, const RGBColor &color)
\param pts Array of 3 BPoints. Always non-NULL. \param pts Array of 3 BPoints. Always non-NULL.
\param setLine Horizontal line drawing routine which handles things like color and pattern. \param setLine Horizontal line drawing routine which handles things like color and pattern.
*/ */
void DisplayDriver::FillTriangle(BPoint *pts, const DrawData *d) void DisplayDriver::FillTriangle(BPoint *pts, const BRect &bounds, const DrawData *d)
{ {
if ( !pts ) if ( !pts )
return; return;
@ -2326,7 +2350,7 @@ void DisplayDriver::FillTriangle(BPoint *pts, const DrawData *d)
{ {
// For now, cop out and use FillPolygon // For now, cop out and use FillPolygon
// Need to investigate if Triangle specific code would save processing time // Need to investigate if Triangle specific code would save processing time
FillPolygon(pts,3,d); FillPolygon(pts,3,bounds,d);
} }
else else
{ {
@ -2415,7 +2439,9 @@ void DisplayDriver::FillTriangle(BPoint *pts, const DrawData *d)
for(i=(int32)second.y; i<=third.y; i++) for(i=(int32)second.y; i<=third.y; i++)
StrokePatternLine(ROUND(lineC.GetX(i)), i, ROUND(lineB.GetX(i)), i, d); StrokePatternLine(ROUND(lineC.GetX(i)), i, ROUND(lineB.GetX(i)), i, d);
} }
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -2775,7 +2801,7 @@ void DisplayDriver::StrokeArc(const BRect &r, const float &angle, const float &s
(shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) ) (shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) )
StrokePoint(BPoint(xc+x,yc+y),color); StrokePoint(BPoint(xc+x,yc+y),color);
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -2938,7 +2964,7 @@ void DisplayDriver::StrokeArc(const BRect &r, const float &angle, const float &s
(shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) ) (shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) )
StrokePoint(BPoint(xc+x,yc+y),d); StrokePoint(BPoint(xc+x,yc+y),d);
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -2957,6 +2983,7 @@ void DisplayDriver::StrokeBezier(BPoint *pts, const RGBColor &color)
numLines = curve.points.CountItems()-1; numLines = curve.points.CountItems()-1;
for (i=0; i<numLines; i++) for (i=0; i<numLines; i++)
StrokeLine(*((BPoint*)curve.points.ItemAt(i)),*((BPoint*)curve.points.ItemAt(i+1)),color); StrokeLine(*((BPoint*)curve.points.ItemAt(i)),*((BPoint*)curve.points.ItemAt(i+1)),color);
Invalidate(curve.Frame());
Unlock(); Unlock();
} }
@ -2975,6 +3002,7 @@ void DisplayDriver::StrokeBezier(BPoint *pts, const DrawData *d)
numLines = curve.points.CountItems()-1; numLines = curve.points.CountItems()-1;
for (i=0; i<numLines; i++) for (i=0; i<numLines; i++)
StrokeLine(*((BPoint*)curve.points.ItemAt(i)),*((BPoint*)curve.points.ItemAt(i+1)),d); StrokeLine(*((BPoint*)curve.points.ItemAt(i)),*((BPoint*)curve.points.ItemAt(i+1)),d);
Invalidate(curve.Frame());
Unlock(); Unlock();
} }
@ -3045,7 +3073,7 @@ void DisplayDriver::StrokeEllipse(const BRect &r, const RGBColor &color)
StrokeLine(BPoint(xc-lastx,yc+lasty),BPoint(xc-x,yc+y),color); StrokeLine(BPoint(xc-lastx,yc+lasty),BPoint(xc-x,yc+y),color);
StrokeLine(BPoint(xc+lastx,yc+lasty),BPoint(xc+x,yc+y),color); StrokeLine(BPoint(xc+lastx,yc+lasty),BPoint(xc+x,yc+y),color);
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -3116,7 +3144,7 @@ void DisplayDriver::StrokeEllipse(const BRect &r, const DrawData *d)
StrokeLine(BPoint(xc-lastx,yc+lasty),BPoint(xc-x,yc+y),d); StrokeLine(BPoint(xc-lastx,yc+lasty),BPoint(xc-x,yc+y),d);
StrokeLine(BPoint(xc+lastx,yc+lasty),BPoint(xc+x,yc+y),d); StrokeLine(BPoint(xc+lastx,yc+lasty),BPoint(xc+x,yc+y),d);
} }
Invalidate(r);
Unlock(); Unlock();
} }
@ -3130,6 +3158,7 @@ void DisplayDriver::StrokeLine(const BPoint &start, const BPoint &end, const RGB
{ {
Lock(); Lock();
StrokeSolidLine(ROUND(start.x),ROUND(start.y),ROUND(end.x),ROUND(end.y),color); StrokeSolidLine(ROUND(start.x),ROUND(start.y),ROUND(end.x),ROUND(end.y),color);
Invalidate(BRect(start,end));
Unlock(); Unlock();
} }
@ -3234,9 +3263,10 @@ void DisplayDriver::StrokeLine(const BPoint &start, const BPoint &end, const Dra
corners[3].x += xoffset; corners[3].x += xoffset;
corners[3].y += yoffset; corners[3].y += yoffset;
} }
FillPolygon(corners,4,d); FillPolygon(corners,4,BRect(start,end),d);
} }
} }
Invalidate(BRect(start,end));
Unlock(); Unlock();
} }
@ -3273,19 +3303,22 @@ void DisplayDriver::StrokeLine(const BPoint &start, const BPoint &end, DisplayDr
y += yInc; y += yInc;
(driver->*setPixel)(ROUND(x),ROUND(y)); (driver->*setPixel)(ROUND(x),ROUND(y));
} }
Invalidate(BRect(start,end));
} }
void DisplayDriver::StrokePoint(const BPoint& pt, const RGBColor &color) void DisplayDriver::StrokePoint(const BPoint& pt, const RGBColor &color)
{ {
StrokeLine(pt, pt, color); StrokeLine(pt, pt, color);
Invalidate(BRect(pt,pt));
} }
void DisplayDriver::StrokePoint(const BPoint& pt, const DrawData *d) void DisplayDriver::StrokePoint(const BPoint& pt, const DrawData *d)
{ {
StrokeLine(pt, pt, d); StrokeLine(pt, pt, d);
Invalidate(BRect(pt,pt));
} }
void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const RGBColor &color, bool is_closed) void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const RGBColor &color, bool is_closed)
{ {
if(!ptlist) if(!ptlist)
return; return;
@ -3295,6 +3328,7 @@ void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const RGBColor &
StrokeLine(ptlist[i],ptlist[i+1],color); StrokeLine(ptlist[i],ptlist[i+1],color);
if(is_closed) if(is_closed)
StrokeLine(ptlist[numpts-1],ptlist[0],color); StrokeLine(ptlist[numpts-1],ptlist[0],color);
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -3304,7 +3338,7 @@ void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const RGBColor &
\param numpts Number of points in the BPoint array. \param numpts Number of points in the BPoint array.
\param d DrawData containing all of the other options \param d DrawData containing all of the other options
*/ */
void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const DrawData *d, bool is_closed) void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const DrawData *d, bool is_closed)
{ {
if(!ptlist) if(!ptlist)
return; return;
@ -3314,6 +3348,7 @@ void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const DrawData *
StrokeLine(ptlist[i],ptlist[i+1],d); StrokeLine(ptlist[i],ptlist[i+1],d);
if(is_closed) if(is_closed)
StrokeLine(ptlist[numpts-1],ptlist[0],d); StrokeLine(ptlist[numpts-1],ptlist[0],d);
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -3326,10 +3361,8 @@ void DisplayDriver::StrokePolygon(BPoint *ptlist, int32 numpts, const DrawData *
void DisplayDriver::StrokeRect(const BRect &r, const RGBColor &color) void DisplayDriver::StrokeRect(const BRect &r, const RGBColor &color)
{ {
Lock(); Lock();
StrokeLine(r.LeftTop(),r.RightTop(),color); StrokeSolidRect(r,color);
StrokeLine(r.LeftTop(),r.LeftBottom(),color); Invalidate(r);
StrokeLine(r.RightTop(),r.RightBottom(),color);
StrokeLine(r.LeftBottom(),r.RightBottom(),color);
Unlock(); Unlock();
} }
@ -3340,6 +3373,7 @@ void DisplayDriver::StrokeRect(const BRect &r, const DrawData *d)
StrokeLine(r.LeftTop(),r.LeftBottom(),d); StrokeLine(r.LeftTop(),r.LeftBottom(),d);
StrokeLine(r.RightTop(),r.RightBottom(),d); StrokeLine(r.RightTop(),r.RightBottom(),d);
StrokeLine(r.LeftBottom(),r.RightBottom(),d); StrokeLine(r.LeftBottom(),r.RightBottom(),d);
Invalidate(r);
Unlock(); Unlock();
} }
@ -3356,7 +3390,7 @@ void DisplayDriver::StrokeRegion(BRegion& r, const RGBColor &color)
for(int32 i=0; i<r.CountRects();i++) for(int32 i=0; i<r.CountRects();i++)
StrokeRect(r.RectAt(i),color); StrokeRect(r.RectAt(i),color);
Invalidate(r.Frame());
Unlock(); Unlock();
} }
@ -3366,7 +3400,7 @@ void DisplayDriver::StrokeRegion(BRegion& r, const DrawData *d)
for(int32 i=0; i<r.CountRects();i++) for(int32 i=0; i<r.CountRects();i++)
StrokeRect(r.RectAt(i),d); StrokeRect(r.RectAt(i),d);
Invalidate(r.Frame());
Unlock(); Unlock();
} }
@ -3397,6 +3431,7 @@ void DisplayDriver::StrokeRoundRect(const BRect &r, const float &xrad, const flo
StrokeArc(BRect(bRight,bBottom,r.right,r.bottom), 270, 90, color); StrokeArc(BRect(bRight,bBottom,r.right,r.bottom), 270, 90, color);
StrokeLine(BPoint(r.right, vBottom), BPoint(r.right, vTop), color); StrokeLine(BPoint(r.right, vBottom), BPoint(r.right, vTop), color);
Invalidate(r);
Unlock(); Unlock();
} }
@ -3434,34 +3469,39 @@ void DisplayDriver::StrokeRoundRect(const BRect &r, const float &xrad, const flo
StrokeArc(BRect(bRight,bBottom,r.right,r.bottom), 270, 90, d); StrokeArc(BRect(bRight,bBottom,r.right,r.bottom), 270, 90, d);
StrokeLine(BPoint(r.right, vBottom), BPoint(r.right, vTop), d); StrokeLine(BPoint(r.right, vBottom), BPoint(r.right, vTop), d);
Invalidate(r);
Unlock(); Unlock();
} }
//void DisplayDriver::StrokeShape(SShape *sh, const DrawData *d, const Pattern &pat) void DisplayDriver::StrokeShape(const BRect &bounds, const int32 &opcount, const int32 *oplist,
//{ const int32 &ptcount, const BPoint *ptlist, const DrawData *d)
//} {
// TODO: Implement DisplayDriver::StrokeShape. ShapeIterator subclass?
printf("DisplayDriver::StrokeShape unimplemented\n");
}
/*! /*!
\brief Called for all BView::StrokeTriangle calls \brief Called for all BView::StrokeTriangle calls
\param pts Array of 3 BPoints. Always non-NULL. \param pts Array of 3 BPoints. Always non-NULL.
\param pensize The line thickness
\param color The color of the lines \param color The color of the lines
*/ */
void DisplayDriver::StrokeTriangle(BPoint *pts, const RGBColor &color) void DisplayDriver::StrokeTriangle(BPoint *pts, const BRect &bounds, const RGBColor &color)
{ {
Lock(); Lock();
StrokeLine(pts[0],pts[1],color); StrokeLine(pts[0],pts[1],color);
StrokeLine(pts[1],pts[2],color); StrokeLine(pts[1],pts[2],color);
StrokeLine(pts[2],pts[0],color); StrokeLine(pts[2],pts[0],color);
Invalidate(bounds);
Unlock(); Unlock();
} }
void DisplayDriver::StrokeTriangle(BPoint *pts, const DrawData *d) void DisplayDriver::StrokeTriangle(BPoint *pts, const BRect &bounds, const DrawData *d)
{ {
Lock(); Lock();
StrokeLine(pts[0],pts[1],d); StrokeLine(pts[0],pts[1],d);
StrokeLine(pts[1],pts[2],d); StrokeLine(pts[1],pts[2],d);
StrokeLine(pts[2],pts[0],d); StrokeLine(pts[2],pts[0],d);
Invalidate(bounds);
Unlock(); Unlock();
} }
@ -3486,6 +3526,8 @@ void DisplayDriver::StrokeLineArray(BPoint *pts, const int32 &numlines, const Dr
StrokeLine(pts[i<<1],pts[i<<1+1],&data); StrokeLine(pts[i<<1],pts[i<<1+1],&data);
} }
// TODO: calculate invalid region for DisplayDriver::StrokeLineArray
Unlock(); Unlock();
} }
@ -3699,6 +3741,7 @@ float DisplayDriver::StringHeight(const char *string, int32 length, const DrawDa
void DisplayDriver::GetBoundingBoxes(const char *string, int32 count, void DisplayDriver::GetBoundingBoxes(const char *string, int32 count,
font_metric_mode mode, escapement_delta *delta, BRect *rectarray, const DrawData *d) font_metric_mode mode, escapement_delta *delta, BRect *rectarray, const DrawData *d)
{ {
// TODO: Implement DisplayDriver::GetBoundingBoxes
} }
/*! /*!
@ -3717,6 +3760,7 @@ void DisplayDriver::GetBoundingBoxes(const char *string, int32 count,
void DisplayDriver::GetEscapements(const char *string, int32 charcount, void DisplayDriver::GetEscapements(const char *string, int32 charcount,
escapement_delta *delta, escapement_delta *escapements, escapement_delta *offsets, const DrawData *d) escapement_delta *delta, escapement_delta *escapements, escapement_delta *offsets, const DrawData *d)
{ {
// TODO: Implement DisplayDriver::GetEscapements
} }
/*! /*!
@ -3730,6 +3774,7 @@ void DisplayDriver::GetEscapements(const char *string, int32 charcount,
*/ */
void DisplayDriver::GetEdges(const char *string, int32 charcount, edge_info *edgearray, const DrawData *d) void DisplayDriver::GetEdges(const char *string, int32 charcount, edge_info *edgearray, const DrawData *d)
{ {
// TODO: Implement DisplayDriver::GetEdges
} }
/*! /*!
@ -3742,6 +3787,7 @@ void DisplayDriver::GetEdges(const char *string, int32 charcount, edge_info *edg
*/ */
void DisplayDriver::GetHasGlyphs(const char *string, int32 charcount, bool *hasarray) void DisplayDriver::GetHasGlyphs(const char *string, int32 charcount, bool *hasarray)
{ {
// TODO: Implement DisplayDriver::GetHasGlyphs
} }
/*! /*!
@ -3758,6 +3804,7 @@ void DisplayDriver::GetHasGlyphs(const char *string, int32 charcount, bool *hasa
void DisplayDriver::GetTruncatedStrings(const char **instrings,const int32 &stringcount, void DisplayDriver::GetTruncatedStrings(const char **instrings,const int32 &stringcount,
const uint32 &mode, const float &maxwidth, char **outstrings) const uint32 &mode, const float &maxwidth, char **outstrings)
{ {
// TODO: Implement DisplayDriver::GetTruncatedStrings
} }
/*! /*!
@ -4043,7 +4090,7 @@ void DisplayDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, cons
{ {
} }
/* Draws a line with pensize 1. Coordinates are guarenteed to be in bounds */ // Draws a line with pensize 1. Coordinates are guarenteed to be in bounds
void DisplayDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) void DisplayDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d)
{ {
} }

View File

@ -7,6 +7,7 @@ BezierCurve::BezierCurve(BPoint* pts)
pointArray = NULL; pointArray = NULL;
for (i=0; i<4; i++) for (i=0; i<4; i++)
points.AddItem(new BPoint(pts[i])); points.AddItem(new BPoint(pts[i]));
GenerateFrame(pts);
GeneratePoints(0); GeneratePoints(0);
} }
@ -35,6 +36,25 @@ BPoint* BezierCurve::GetPointArray()
return pointArray; return pointArray;
} }
void BezierCurve::GenerateFrame(BPoint *pts)
{
// shamelessly stolen from Marc's BPolygon code and tweaked to fit. :P
fFrame = BRect(pointArray[0], pointArray[0]);
for (int32 i = 1; i < 4; i++)
{
if (pts[i].x < fFrame.left)
fFrame.left = pts[i].x;
if (pts[i].y < fFrame.top)
fFrame.top = pts[i].y;
if (pts[i].x > fFrame.right)
fFrame.right = pts[i].x;
if (pts[i].y > fFrame.bottom)
fFrame.bottom = pts[i].y;
}
}
int BezierCurve::GeneratePoints(int startPos) int BezierCurve::GeneratePoints(int startPos)
{ {
double slopeAB, slopeBC, slopeCD; double slopeAB, slopeBC, slopeCD;

View File

@ -31,6 +31,7 @@ SharedLibrary appserver :
SysCursor.cpp SysCursor.cpp
SystemPalette.cpp SystemPalette.cpp
TokenHandler.cpp TokenHandler.cpp
Utils.cpp
; ;
LinkSharedOSLibs libappserver.so : root be LinkSharedOSLibs libappserver.so : root be
@ -43,7 +44,6 @@ Server app_server :
FMWList.cpp FMWList.cpp
PicturePlayer.cpp PicturePlayer.cpp
PNGDump.cpp PNGDump.cpp
Utils.cpp
# Manager Classes # Manager Classes
AppServer.cpp AppServer.cpp

View File

@ -28,6 +28,7 @@
#include "PicturePlayer.h" #include "PicturePlayer.h"
#include "PictureProtocol.h" #include "PictureProtocol.h"
#include "Utils.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
#include <ServerBitmap.h> #include <ServerBitmap.h>
#include <stdio.h> #include <stdio.h>
@ -202,7 +203,7 @@ status_t PicturePlayer::Play(int32 tableEntries,void *userData, LayerData *d)
BPoint *points = new BPoint[numPoints]; BPoint *points = new BPoint[numPoints];
GetData(points, numPoints * sizeof(BPoint)); GetData(points, numPoints * sizeof(BPoint));
bool isClosed = GetBool(); bool isClosed = GetBool();
fdriver->StrokePolygon(points,numPoints,&fldata,isClosed); fdriver->StrokePolygon(points,numPoints,CalculatePolygonBounds(points,numPoints),&fldata,isClosed);
delete points; delete points;
break; break;
} }
@ -211,7 +212,7 @@ status_t PicturePlayer::Play(int32 tableEntries,void *userData, LayerData *d)
int32 numPoints = GetInt32(); int32 numPoints = GetInt32();
BPoint *points = new BPoint[numPoints]; BPoint *points = new BPoint[numPoints];
GetData(points, numPoints * sizeof(BPoint)); GetData(points, numPoints * sizeof(BPoint));
fdriver->FillPolygon(points,numPoints,&fldata); fdriver->FillPolygon(points,numPoints,CalculatePolygonBounds(points,numPoints),&fldata);
delete points; delete points;
break; break;
} }

View File

@ -1854,9 +1854,7 @@ void ServerWindow::DispatchMessage(int32 code)
for(int i=0;i<3;i++) for(int i=0;i<3;i++)
pts[i]=cl->ConvertToTop(pts[i]); pts[i]=cl->ConvertToTop(pts[i]);
// TODO: modify DisplayDriver::StrokeTriangle to utilize a boundary BRect desktop->GetDisplayDriver()->StrokeTriangle(pts,cl->ConvertToTop(rect),cl->fLayerData);
desktop->GetDisplayDriver()->StrokeTriangle(pts,cl->fLayerData);
// desktop->GetDisplayDriver()->StrokeTriangle(pts,cl->ConvertToTop(rect),cl->fLayerData);
} }
break; break;
} }
@ -1876,12 +1874,174 @@ void ServerWindow::DispatchMessage(int32 code)
for(int i=0;i<3;i++) for(int i=0;i<3;i++)
pts[i]=cl->ConvertToTop(pts[i]); pts[i]=cl->ConvertToTop(pts[i]);
// TODO: modify DisplayDriver::FillTriangle to utilize a boundary BRect desktop->GetDisplayDriver()->FillTriangle(pts,cl->ConvertToTop(rect),cl->fLayerData);
desktop->GetDisplayDriver()->FillTriangle(pts,cl->fLayerData);
// desktop->GetDisplayDriver()->FillTriangle(pts,cl->ConvertToTop(rect),cl->fLayerData);
} }
break; break;
} }
case AS_STROKE_POLYGON:
{
BRect polyframe;
bool isclosed;
int32 pointcount;
BPoint *pointlist;
fSession->Read<BRect>(&polyframe);
fSession->Read<bool>(&isclosed);
fSession->Read<int32>(&pointcount);
pointlist=new BPoint[pointcount];
for(int32 i=0; i<pointcount; i++)
pointlist[i]=cl->ConvertToTop(pointlist[i]);
// TODO: modify DisplayDriver::StrokePolygon to utilize a boundary BRect
desktop->GetDisplayDriver()->StrokePolygon(pointlist,pointcount,polyframe,
cl->fLayerData,isclosed);
delete [] pointlist;
break;
}
case AS_FILL_POLYGON:
{
BRect polyframe;
bool isclosed;
int32 pointcount;
BPoint *pointlist;
fSession->Read<BRect>(&polyframe);
fSession->Read<bool>(&isclosed);
fSession->Read<int32>(&pointcount);
pointlist=new BPoint[pointcount];
fSession->Read(pointlist, sizeof(BPoint)*pointcount);
for(int32 i=0; i<pointcount; i++)
pointlist[i]=cl->ConvertToTop(pointlist[i]);
// TODO: modify DisplayDriver::FillPolygon to utilize a boundary BRect
desktop->GetDisplayDriver()->StrokePolygon(pointlist,pointcount,polyframe,cl->fLayerData);
delete [] pointlist;
break;
}
case AS_STROKE_SHAPE:
{
BRect shaperect;
int32 opcount;
int32 ptcount;
int32 *oplist;
BPoint *ptlist;
fSession->Read<BRect>(&shaperect);
fSession->Read<int32>(&opcount);
fSession->Read<int32>(&ptcount);
oplist=new int32[opcount];
ptlist=new BPoint[ptcount];
fSession->Read(oplist,sizeof(int32)*opcount);
fSession->Read(ptlist,sizeof(BPoint)*ptcount);
for(int32 i=0; i<ptcount; i++)
ptlist[i]=cl->ConvertToTop(ptlist[i]);
desktop->GetDisplayDriver()->StrokeShape(shaperect, opcount, oplist, ptcount, ptlist, cl->fLayerData);
delete oplist;
delete ptlist;
break;
}
case AS_FILL_SHAPE:
{
BRect shaperect;
int32 opcount;
int32 ptcount;
int32 *oplist;
BPoint *ptlist;
fSession->Read<BRect>(&shaperect);
fSession->Read<int32>(&opcount);
fSession->Read<int32>(&ptcount);
oplist=new int32[opcount];
ptlist=new BPoint[ptcount];
fSession->Read(oplist,sizeof(int32)*opcount);
fSession->Read(ptlist,sizeof(BPoint)*ptcount);
for(int32 i=0; i<ptcount; i++)
ptlist[i]=cl->ConvertToTop(ptlist[i]);
desktop->GetDisplayDriver()->FillShape(shaperect, opcount, oplist, ptcount, ptlist, cl->fLayerData);
delete oplist;
delete ptlist;
break;
}
case AS_FILL_REGION:
{
// TODO: Implement AS_FILL_REGION
int32 rectcount;
BRect *rectlist;
fSession->Read<int32>(&rectcount);
rectlist=new BRect[rectcount];
fSession->Read(rectlist, sizeof(BRect)*rectcount);
// Between the client-side conversion to BRects from clipping_rects to the overhead
// in repeatedly calling FillRect(), this is definitely in need of optimization. At
// least it works for now. :)
for(int32 i=0; i<rectcount; i++)
desktop->GetDisplayDriver()->FillRect(cl->ConvertToTop(cl->ConvertToTop(rectlist[i])),cl->fLayerData);
delete [] rectlist;
// TODO: create support for clipping_rect usage for faster BRegion display.
// Tweaks to DisplayDriver are necessary along with conversion routines in Layer
break;
}
case AS_STROKE_LINEARRAY:
{
// TODO: Implement AS_STROKE_LINEARRAY
break;
}
case AS_MOVEPENBY:
{
// TODO: Implement AS_MOVEPENBY
break;
}
case AS_MOVEPENTO:
{
// TODO: Implement AS_MOVEPENTO
break;
}
case AS_SETPENSIZE:
{
// TODO: Implement AS_SETPENSIZE
break;
}
case AS_DRAW_STRING:
{
// TODO: Implement AS_DRAW_STRING
break;
}
case AS_SET_FONT:
{
// TODO: Implement AS_SET_FONT
break;
}
case AS_SET_FONT_SIZE:
{
// TODO: Implement AS_SET_FONT_SIZE
break;
}
default: default:
{ {
printf("ServerWindow %s received unexpected code - message offset %lx\n",fTitle.String(), code - SERVER_TRUE); printf("ServerWindow %s received unexpected code - message offset %lx\n",fTitle.String(), code - SERVER_TRUE);
@ -1890,138 +2050,6 @@ void ServerWindow::DispatchMessage(int32 code)
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/*!
\brief Iterator for graphics update messages
\param msgsize Size of the buffer containing the graphics messages
\param msgbuffer Buffer containing the graphics message
*/
void ServerWindow::DispatchGraphicsMessage(int32 msgsize, int8 *msgbuffer)
{
/* Layer *layer;
LayerData *layerdata;
int32 code;
int32 view_token;
uint32 sizeRemaining = (uint32)msgsize;
BRegion WindowClipRegion;
BRegion LayerClipRegion;
// Layer *sibling;
int32 numRects = 0;
if (!msgsize || !msgbuffer)
return;
if (IsHidden())
return;
// TODO: fix sibling-related clipping calculations in DispatchGraphicsMessage
// WindowClipRegion.Set(fWinBorder->Frame());
// sibling = fWinBorder->UpperSibling();
// while (sibling)
// {
// WindowClipRegion.Exclude(sibling->Frame());
// sibling = sibling->UpperSibling();
// }
if (!WindowClipRegion.Frame().IsValid())
return;
// We need to decide whether coordinates are specified in view or root coordinates.
// For now, we assume root level coordinates.
code = AS_BEGIN_UPDATE;
while ((sizeRemaining > 2*sizeof(int32)) && (code != AS_END_UPDATE))
{
code = read_from_buffer<int32>(&msgbuffer);
view_token = read_from_buffer<int32>(&msgbuffer);
//TODO: fix code to find a layer based on a view token in DispatchGraphicsMessage
layer = NULL;//fWorkspace->GetRoot()->FindLayer(view_token);
if (layer)
{
layerdata = layer->fLayerData;
LayerClipRegion.Set(layer->Frame());
LayerClipRegion.IntersectWith(&WindowClipRegion);
numRects = LayerClipRegion.CountRects();
}
else
{
layerdata = NULL;
STRACE(("ServerWindow %s received invalid view token %lx",fTitle.String(),view_token));
}
switch (code)
{
case AS_STROKE_LINEARRAY:
{
// TODO: Implement AS_STROKE_LINEARRAY
break;
}
case AS_STROKE_POLYGON:
{
// TODO: Implement AS_STROKE_POLYGON
break;
}
case AS_STROKE_SHAPE:
{
// TODO: Implement AS_STROKE_SHAPE
break;
}
case AS_FILL_POLYGON:
{
// TODO: Implement AS_FILL_POLYGON
break;
}
case AS_FILL_REGION:
{
// TODO: Implement AS_FILL_REGION
break;
}
case AS_FILL_SHAPE:
{
// TODO: Implement AS_FILL_SHAPE
break;
}
case AS_MOVEPENBY:
{
// TODO: Implement AS_MOVEPENBY
break;
}
case AS_MOVEPENTO:
{
// TODO: Implement AS_MOVEPENTO
break;
}
case AS_SETPENSIZE:
{
// TODO: Implement AS_SETPENSIZE
break;
}
case AS_DRAW_STRING:
{
// TODO: Implement AS_DRAW_STRING
break;
}
case AS_SET_FONT:
{
// TODO: Implement AS_SET_FONT
break;
}
case AS_SET_FONT_SIZE:
{
// TODO: Implement AS_SET_FONT_SIZE
break;
}
default:
{
sizeRemaining -= sizeof(int32);
printf("ServerWindow %s received unexpected graphics code %lx",fTitle.String(),code);
break;
}
}
}
*/
}
//------------------------------------------------------------------------------
/*! /*!
\brief Message-dispatching loop for the ServerWindow \brief Message-dispatching loop for the ServerWindow

View File

@ -126,7 +126,6 @@ private:
// message handle methods. // message handle methods.
void DispatchMessage(int32 code); void DispatchMessage(int32 code);
void DispatchGraphicsMessage(int32 msgsize, int8 *msgbuffer);
static int32 MonitorWin(void *data); static int32 MonitorWin(void *data);

View File

@ -301,3 +301,27 @@ status_t ConvertModeToDisplayMode(uint32 mode, display_mode *dmode)
} }
return B_OK; return B_OK;
} }
BRect CalculatePolygonBounds(BPoint *pts, int32 pointcount)
{
if(!pts)
return BRect(0,0,0,0);
BRect r(0,0,0,0);
// shamelessly stolen from Marc's BPolygon code and tweaked to fit. :P
r = BRect(pts[0], pts[0]);
for (int32 i = 1; i < 4; i++)
{
if (pts[i].x < r.left)
r.left = pts[i].x;
if (pts[i].y < r.top)
r.top = pts[i].y;
if (pts[i].x > r.right)
r.right = pts[i].x;
if (pts[i].y > r.bottom)
r.bottom = pts[i].y;
}
return r;
}

View File

@ -35,5 +35,5 @@ void SendMessage(port_id port, BMessage *message, int32 target=-1);
const char *MsgCodeToString(int32 code); const char *MsgCodeToString(int32 code);
BString MsgCodeToBString(int32 code); BString MsgCodeToBString(int32 code);
status_t ConvertModeToDisplayMode(uint32 mode, display_mode *dmode); status_t ConvertModeToDisplayMode(uint32 mode, display_mode *dmode);
BRect CalculatePolygonBounds(BPoint *pts, int32 pointcount);
#endif #endif