From 8a14aea116d879f6a1f46f8255c2d343e24f0092 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Wed, 28 Jan 2004 02:23:20 +0000 Subject: [PATCH] Updated PreviewDriver to the new DisplayDriver API and made appropriate changes to DecView as a result git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6387 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/appearance/DecView.cpp | 8 +- src/prefs/appearance/PreviewDriver.cpp | 305 +++++-------------------- src/prefs/appearance/PreviewDriver.h | 50 ++-- 3 files changed, 79 insertions(+), 284 deletions(-) diff --git a/src/prefs/appearance/DecView.cpp b/src/prefs/appearance/DecView.cpp index fd05d37780..5adb7f6bd5 100644 --- a/src/prefs/appearance/DecView.cpp +++ b/src/prefs/appearance/DecView.cpp @@ -100,7 +100,7 @@ DecView::DecView(BRect frame, const char *name, int32 resize, int32 flags) // Finish setup ldata.highcolor.SetColor(51,102,160); pat_solid_high=0xFFFFFFFFFFFFFFFFLL; - driver->FillRect(preview_bounds,&ldata,(int8*)&pat_solid_high); + driver->FillRect(preview_bounds,&ldata); decorator=NULL; decorator_id=-1; @@ -110,7 +110,7 @@ DecView::DecView(BRect frame, const char *name, int32 resize, int32 flags) BString path(ConvertIndexToPath(0L)); if(LoadDecorator(path.String())) { - driver->FillRect(preview_bounds,&ldata,(int8*)&pat_solid_high); + driver->FillRect(preview_bounds,&ldata); if(decorator) { BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); @@ -166,7 +166,7 @@ void DecView::MessageReceived(BMessage *msg) break; } - driver->FillRect(preview_bounds,&ldata,(int8*)&pat_solid_high); + driver->FillRect(preview_bounds,&ldata); if(decorator) { BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection()); @@ -415,7 +415,7 @@ void DecView::SetColors(const ColorSet &set) colorset=set; if(decorator) { - driver->FillRect(preview_bounds,&ldata,(int8*)&pat_solid_high); + driver->FillRect(preview_bounds,&ldata); decorator->SetColors(colorset); decorator->Draw(); } diff --git a/src/prefs/appearance/PreviewDriver.cpp b/src/prefs/appearance/PreviewDriver.cpp index f42432ffef..538839a6ab 100644 --- a/src/prefs/appearance/PreviewDriver.cpp +++ b/src/prefs/appearance/PreviewDriver.cpp @@ -54,13 +54,14 @@ #include #include #include "PortLink.h" +#include "PatternHandler.h" #include "PreviewDriver.h" #include "LayerData.h" #include "ColorSet.h" BRect preview_bounds(0,0,150,150);; -PVView::PVView(BRect bounds) +PVView::PVView(const BRect &bounds) : BView(bounds,"previewdriver_view",B_FOLLOW_NONE, B_WILL_DRAW) { viewbmp=new BBitmap(bounds,B_RGB32,true); @@ -117,64 +118,11 @@ void PreviewDriver::Shutdown(void) view->viewbmp->Unlock(); } -void PreviewDriver::CopyBits(BRect src, BRect dest) -{ - view->viewbmp->Lock(); - drawview->CopyBits(src,dest); - drawview->Sync(); - view->Invalidate(dest); - view->viewbmp->Unlock(); -} - -void PreviewDriver::DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest, LayerData *d) +void PreviewDriver::DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d) { } -void PreviewDriver::DrawChar(char c, BPoint pt) -{ - view->viewbmp->Lock(); - drawview->DrawChar(c,pt); - drawview->Sync(); - view->Invalidate(); - view->viewbmp->Unlock(); -} - -/* -void DrawPicture(SPicture *pic, BPoint pt) -{ -} -*/ -void PreviewDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL) -{ - if(!d) - return; - BRect r; - - view->viewbmp->Lock(); - - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - pt.y--; - drawview->DrawString(string,length,pt,delta); - drawview->Sync(); - - // calculate the invalid rectangle - font_height fh; - BFont font; - drawview->GetFont(&font); - drawview->GetFontHeight(&fh); - r.left=pt.x; - r.right=pt.x+font.StringWidth(string); - r.top=pt.y-fh.ascent; - r.bottom=pt.y+fh.descent; - view->Invalidate(r); - - view->viewbmp->Unlock(); -} - - -void PreviewDriver::InvertRect(BRect r) +void PreviewDriver::InvertRect(const BRect &r) { view->viewbmp->Lock(); drawview->InvertRect(r); @@ -183,191 +131,7 @@ void PreviewDriver::InvertRect(BRect r) view->viewbmp->Unlock(); } -void PreviewDriver::StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat) -{ - BPoint points[4]; - for(uint8 i=0;i<4;i++) - points[i]=pts[i]; - - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeBezier(points,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillBezier(BPoint *pts, LayerData *d, const Pattern &pat) -{ - BPoint points[4]; - for(uint8 i=0;i<4;i++) - points[i]=pts[i]; - - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeBezier(points,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeEllipse(BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeEllipse(r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillEllipse(BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->FillEllipse(r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeArc(r,angle,span,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->FillArc(r,angle,span,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeLine(start,end,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed=true) -{ -} - -void PreviewDriver::FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat) -{ -} - -void PreviewDriver::StrokeRect(BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeRect(r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillRect(BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->FillRect(r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeRoundRect(r,xrad,yrad,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->FillRoundRect(r,xrad,yrad,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -/* -void StrokeShape(SShape *sh, LayerData *d, const Pattern &pat) -{ -} - -void FillShape(SShape *sh, LayerData *d, const Pattern &pat) -{ -} -*/ - -void PreviewDriver::StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->StrokeTriangle(pts[0],pts[1], - pts[2],r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat) -{ - view->viewbmp->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetPenSize(d->pensize); - drawview->FillTriangle(pts[0],pts[1], - pts[2],r,*((pattern *)pat.GetInt8())); - drawview->Sync(); - view->Invalidate(r); - view->viewbmp->Unlock(); -} - -void PreviewDriver::StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d) +void PreviewDriver::StrokeLineArray(BPoint *pts, const int32 &numlines, const DrawData *d, RGBColor *colors) { view->viewbmp->Lock(); drawview->SetHighColor(d->highcolor.GetColor32()); @@ -382,26 +146,69 @@ void PreviewDriver::StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *color view->viewbmp->Unlock(); } -void PreviewDriver::SetMode(int32 mode) +void PreviewDriver::SetMode(const int32 &mode) { } -bool PreviewDriver::DumpToFile(const char *path) +void PreviewDriver::SetMode(const display_mode &mode) { - return false; } -float PreviewDriver::StringWidth(const char *string, int32 length, LayerData *d) +void PreviewDriver::FillSolidRect(const BRect &rect, RGBColor &color) { view->viewbmp->Lock(); - float returnval=drawview->StringWidth(string,length); + drawview->SetHighColor(color.GetColor32()); + drawview->FillRect(rect); + drawview->Sync(); + view->Invalidate(rect); view->viewbmp->Unlock(); - return returnval; } -void PreviewDriver::GetTruncatedStrings( const char **instrings, int32 stringcount, uint32 mode, float maxwidth, char **outstrings) +void PreviewDriver::FillPatternRect(const BRect &rect, const DrawData *d) { + if(!d) + return; + view->viewbmp->Lock(); - be_plain_font->GetTruncatedStrings(instrings,stringcount,mode,maxwidth,outstrings); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->FillRect(rect,*((pattern*)d->patt.GetInt8())); + drawview->Sync(); + view->Invalidate(rect); view->viewbmp->Unlock(); } + +void PreviewDriver::StrokeSolidLine(const BPoint &start, const BPoint &end, RGBColor &color) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(color.GetColor32()); + drawview->StrokeLine(start,end); + drawview->Sync(); + view->Invalidate(BRect(start,end)); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokePatternLine(const BPoint &start, const BPoint &end, const DrawData *d) +{ + if(!d) + return; + + view->viewbmp->Lock(); + drawview->SetHighColor(d->highcolor.GetColor32()); + drawview->SetLowColor(d->lowcolor.GetColor32()); + drawview->StrokeLine(start,end,*((pattern*)d->patt.GetInt8())); + drawview->Sync(); + view->Invalidate(BRect(start,end)); + view->viewbmp->Unlock(); +} + +void PreviewDriver::StrokeSolidRect(const BRect &rect, RGBColor &color) +{ + view->viewbmp->Lock(); + drawview->SetHighColor(color.GetColor32()); + drawview->StrokeRect(rect); + drawview->Sync(); + view->Invalidate(rect); + view->viewbmp->Unlock(); +} + diff --git a/src/prefs/appearance/PreviewDriver.h b/src/prefs/appearance/PreviewDriver.h index 317b2810a6..16da482a6d 100644 --- a/src/prefs/appearance/PreviewDriver.h +++ b/src/prefs/appearance/PreviewDriver.h @@ -45,7 +45,7 @@ class ColorSet; class PVView : public BView { public: - PVView(BRect bounds); + PVView(const BRect &bounds); ~PVView(void); void AttachedToWindow(void); void DetachedFromWindow(void); @@ -61,39 +61,27 @@ public: PreviewDriver(void); ~PreviewDriver(void); - bool Initialize(void); - void Shutdown(void); - void CopyBits(BRect src, BRect dest); - void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest, LayerData *d); - void DrawChar(char c, BPoint pt); -// void DrawPicture(SPicture *pic, BPoint pt); - void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL); - void InvertRect(BRect r); - void StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat); - void FillBezier(BPoint *pts, LayerData *d, const Pattern &pat); - void StrokeEllipse(BRect r, LayerData *d, const Pattern &pat); - void FillEllipse(BRect r, LayerData *d, const Pattern &pat); - void StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat); - void FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat); - void StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat); - void StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed=true); - void FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat); - void StrokeRect(BRect r, LayerData *d, const Pattern &pat); - void FillRect(BRect r, LayerData *d, const Pattern &pat); - void StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat); - void FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat); -// void StrokeShape(SShape *sh, LayerData *d, const Pattern &pat); -// void FillShape(SShape *sh, LayerData *d, const Pattern &pat); - void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat); - void FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat); - void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d); - void SetMode(int32 mode); - float StringWidth(const char *string, int32 length, LayerData *d); - void GetTruncatedStrings( const char **instrings, int32 stringcount, uint32 mode, float maxwidth, char **outstrings); - bool DumpToFile(const char *path); + bool Initialize(void); // Sets the driver + void Shutdown(void); // You never know when you'll need this + + // Drawing functions + void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d); + void InvertRect(const BRect &r); + + virtual void StrokeLineArray(BPoint *pts, const int32 &numlines, const DrawData *d, RGBColor *colors); + + void SetMode(const int32 &mode); + void SetMode(const display_mode &mode); + BView *View(void) { return (BView*)view; }; protected: + virtual void FillSolidRect(const BRect &rect, RGBColor &color); + virtual void FillPatternRect(const BRect &rect, const DrawData *d); + virtual void StrokeSolidLine(const BPoint &start, const BPoint &end, RGBColor &color); + virtual void StrokePatternLine(const BPoint &start, const BPoint &end, const DrawData *d); + virtual void StrokeSolidRect(const BRect &rect, RGBColor &color); + BBitmap *framebuffer; BView *drawview;