diff --git a/src/servers/app/proto7/BeDecorator.cpp b/src/servers/app/proto7/BeDecorator.cpp index 3ad08f22b0..db27f9f22a 100644 --- a/src/servers/app/proto7/BeDecorator.cpp +++ b/src/servers/app/proto7/BeDecorator.cpp @@ -2,6 +2,7 @@ #include #include "LayerData.h" #include "ColorUtils.h" +#include "ColorSet.h" #include "BeDecorator.h" #include "RGBColor.h" #include "Desktop.h" diff --git a/src/servers/app/proto7/Desktop.cpp b/src/servers/app/proto7/Desktop.cpp index c94f848a66..4389d963a8 100644 --- a/src/servers/app/proto7/Desktop.cpp +++ b/src/servers/app/proto7/Desktop.cpp @@ -48,7 +48,7 @@ int8 default_cursor[]={ //--------------------GLOBALS------------------------- uint32 workspace_count, active_workspace; BList *desktop; -ServerCursor *startup_cursor; +ServerBitmap *startup_cursor; Workspace *pactive_workspace; DisplayDriver *gfxdriver; int32 token_count=-1; @@ -145,9 +145,9 @@ printf("init_desktop(%d)\n",workspaces); workspace_count++; // Instantiate and initialize display driver -// gfxdriver=new ViewDriver(); + gfxdriver=new ViewDriver(); // gfxdriver=new SecondDriver(); - gfxdriver=new ScreenDriver(); +// gfxdriver=new ScreenDriver(); gfxdriver->Initialize(); workspacelock=new BLocker(); @@ -194,8 +194,17 @@ printf("Driver %s\n", (gfxdriver->IsInitialized()==true)?"initialized":"NOT init // Clear the screen pactive_workspace->toplayer->SetColor(RGBColor(80,85,152)); // gfxdriver->Clear(pactive_workspace->toplayer->GetColor()); - startup_cursor=new ServerCursor(default_cursor); - gfxdriver->SetCursor(startup_cursor); + + // CURSOR_ARROW + startup_cursor=new ServerBitmap('CURS',"CURSOR_DEFAULT"); + if(!startup_cursor->InitCheck()) + { + // Apparently, something is screwed up beyond recognition in loading the cursor, + // so we'll put in one just so we have something usable. + delete startup_cursor; + startup_cursor=new ServerBitmap(default_cursor); + } + gfxdriver->SetCursor(startup_cursor, BPoint(0,0)); gfxdriver->ShowCursor(); pactive_workspace->toplayer->SetVisible(true); diff --git a/src/servers/app/proto7/DisplayDriver.cpp b/src/servers/app/proto7/DisplayDriver.cpp index 519e3dc1e9..97ff36cff8 100644 --- a/src/servers/app/proto7/DisplayDriver.cpp +++ b/src/servers/app/proto7/DisplayDriver.cpp @@ -5,7 +5,6 @@ */ #include "DisplayDriver.h" #include "LayerData.h" -#include "ServerCursor.h" DisplayDriver::DisplayDriver(void) { @@ -71,8 +70,19 @@ void DisplayDriver::ObscureCursor(void) SetCursorObscured(true); } -void DisplayDriver::SetCursor(ServerCursor *cursor) +void DisplayDriver::SetCursor(ServerBitmap *cursor, const BPoint &hotspot) { + SetHotSpot(hotspot); +} + +void DisplayDriver::SetHotSpot(const BPoint &pt) +{ + cursor_hotspot=pt; +} + +BPoint DisplayDriver::GetHotSpot(void) +{ + return cursor_hotspot; } //--------------------------------------------------------- @@ -147,7 +157,7 @@ void DisplayDriver::SetCursorObscured(bool state) void DisplayDriver::Shutdown(void) {} void DisplayDriver::CopyBits(BRect src, BRect dest) {} void DisplayDriver::DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest) {} -void DisplayDriver::DrawChar(char c, BPoint pt) {} +void DisplayDriver::DrawChar(char c, BPoint pt, LayerData *d) {} //void DisplayDriver::DrawPicture(SPicture *pic, BPoint pt) {} void DisplayDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL) {} diff --git a/src/servers/app/proto7/DisplayDriver.h b/src/servers/app/proto7/DisplayDriver.h index 652df6dce3..b51d5f5a30 100644 --- a/src/servers/app/proto7/DisplayDriver.h +++ b/src/servers/app/proto7/DisplayDriver.h @@ -66,7 +66,7 @@ public: virtual void Shutdown(void); virtual void CopyBits(BRect src, BRect dest); virtual void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest); - virtual void DrawChar(char c, BPoint pt); + virtual void DrawChar(char c, BPoint pt, LayerData *d); // virtual void DrawPicture(SPicture *pic, BPoint pt); virtual void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL); @@ -85,7 +85,7 @@ public: virtual void InvertRect(BRect r); virtual void ShowCursor(void); virtual void ObscureCursor(void); - virtual void SetCursor(ServerCursor *cursor); + virtual void SetCursor(ServerBitmap *cursor, const BPoint &hotspot); virtual void StrokeArc(BRect r, float angle, float span, LayerData *d, int8 *pat); virtual void StrokeBezier(BPoint *pts, LayerData *d, int8 *pat); @@ -104,6 +104,8 @@ public: uint16 GetHeight(void); uint16 GetWidth(void); int32 GetMode(void); + void SetHotSpot(const BPoint &pt); + BPoint GetHotSpot(void); protected: void Lock(void); @@ -126,6 +128,7 @@ private: drawing_mode drawmode; int32 is_cursor_hidden; bool is_cursor_obscured, cursor_state_changed; + BPoint cursor_hotspot; }; #endif \ No newline at end of file diff --git a/src/servers/app/proto7/FontFamily.cpp b/src/servers/app/proto7/FontFamily.cpp index dc64f24e44..bfde92dbff 100644 --- a/src/servers/app/proto7/FontFamily.cpp +++ b/src/servers/app/proto7/FontFamily.cpp @@ -17,11 +17,14 @@ FontStyle::FontStyle(const char *filepath, FT_Face face) has_kerning=(face->face_flags & FT_FACE_FLAG_KERNING)?true:false; glyphcount=face->num_glyphs; charmapcount=face->num_charmaps; + path=new BString(filepath); + fbounds.Set(0,0,0,0); } FontStyle::~FontStyle(void) { delete name; + delete path; delete cachedface; // Mark all instances as Free here @@ -42,7 +45,7 @@ FontStyle::~FontStyle(void) const char *FontStyle::Style(void) { - return name->String(); + return path->String(); } FT_Face FontStyle::GetFace(void) @@ -51,6 +54,11 @@ FT_Face FontStyle::GetFace(void) return (FTC_Manager_Lookup_Face(ftmanager,cachedface,&f)!=0)?f:NULL; } +const char *FontStyle::GetPath(void) +{ + return path->String(); +} + int16 FontStyle::ConvertToUnicode(uint16 c) { FT_Face f; diff --git a/src/servers/app/proto7/FontFamily.h b/src/servers/app/proto7/FontFamily.h index 3a566b2a3e..7e46f593d6 100644 --- a/src/servers/app/proto7/FontFamily.h +++ b/src/servers/app/proto7/FontFamily.h @@ -2,6 +2,7 @@ #define FONT_FAMILY_H_ #include +#include #include #include #include @@ -49,6 +50,7 @@ public: const char *Style(void); FontFamily *Family(void) { return family; } FT_Face GetFace(void); + const char *GetPath(void); int16 ConvertToUnicode(uint16 c); protected: friend FontFamily; @@ -59,6 +61,7 @@ protected: bool is_fixedwidth, is_scalable, has_kerning, has_bitmaps; CachedFace cachedface; uint8 format; + BRect fbounds; }; class FontFamily : public SharedObject diff --git a/src/servers/app/proto7/FontInstance.h b/src/servers/app/proto7/FontInstance.h deleted file mode 100644 index 5d0007641b..0000000000 --- a/src/servers/app/proto7/FontInstance.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef FONTINSTANCE_H_ -#define FONTINSTANCE_H_ - -class FontStyle; - -#include - -class FontInstance -{ -public: - FontInstance(void); - FontInstance(float size, float rotation, float shear); - ~FontInstance(void); - - void SetProperties(float size=12.0, float rotation=0.0, float shear=90.0); - void SetSpacing(uint8 spacing); - void SetFlags(int32 flags); - void SetFace(int32 face); - void SetSize(float size); - void SetRotation(float rotation); - void SetShear(float shear); - void SetEncoding(uint8 encoding); - - unicode_block Blocks(void); - BRect BoundingBox(void); - float Rotation(void) { return fRotation; } - float Shear(void) { return fShear; } - float Size(void) { return fSize; } - uint8 Spacing(void) { return fSpacing; } - uint8 Encoding(void) { return fEncoding; } - font_direction Direction(void) { return fDirection; } - FontStyle *Style(void) { return fStyle; } - - void Height(font_height *height) { *height=fHeight; } - - float fSize, - fRotation, - fShear; - - int32 fToken, - fFlags, - fFace; - - uint8 fEncoding, - fSpacing; - - font_height fHeight; - font_direction fDirection; - - FontStyle *fStyle; -}; - -#endif \ No newline at end of file diff --git a/src/servers/app/proto7/FontServer.cpp b/src/servers/app/proto7/FontServer.cpp index a3225a5018..0676d4e25d 100644 --- a/src/servers/app/proto7/FontServer.cpp +++ b/src/servers/app/proto7/FontServer.cpp @@ -366,6 +366,9 @@ void FontServer::SaveList(void) // Check to see if it has prerendered strikes (has "tuned" fonts) sty=fam->GetStyle(styname.String()); + if(!sty) + continue; + if(sty->HasTuned() && sty->IsScalable()) tuned=true; diff --git a/src/servers/app/proto7/FontServer.h b/src/servers/app/proto7/FontServer.h index f856b132b4..e1f99496cf 100644 --- a/src/servers/app/proto7/FontServer.h +++ b/src/servers/app/proto7/FontServer.h @@ -5,8 +5,9 @@ #include #include #include -#include -#include +#include +#include FT_FREETYPE_H +#include FT_CACHE_H class FontFamily; class FontStyle; diff --git a/src/servers/app/proto7/Jamfile b/src/servers/app/proto7/Jamfile index a10960f8b3..ee2c81a8e6 100644 --- a/src/servers/app/proto7/Jamfile +++ b/src/servers/app/proto7/Jamfile @@ -4,8 +4,10 @@ UseFreeTypeHeaders ; Server OBAppServer : # Misc. Sources + Angle.cpp BeDecorator.cpp ColorUtils.cc + ColorSet.cpp DebugTools.cpp Decorator.cpp PortLink.cpp @@ -18,7 +20,6 @@ Server OBAppServer : Layer.cpp ServerApp.cpp ServerBitmap.cpp - ServerCursor.cpp ServerWindow.cpp WindowBorder.cpp diff --git a/src/servers/app/proto7/LayerData.h b/src/servers/app/proto7/LayerData.h index daf2503ae9..6d5ed51a85 100644 --- a/src/servers/app/proto7/LayerData.h +++ b/src/servers/app/proto7/LayerData.h @@ -2,6 +2,7 @@ #define LAYERDATA_H_ #include +#include #include "RGBColor.h" #include "ServerFont.h" #include "FontServer.h" @@ -16,12 +17,16 @@ LayerData(void) pensize=1.0; penlocation.Set(0,0); draw_mode=B_OP_COPY; + blending_mode=B_ALPHA_OVERLAY; + alpha_mode=B_CONSTANT_ALPHA; bitmap_background=NULL; bitmap_overlay=NULL; highcolor.SetColor(0,0,0,255); lowcolor.SetColor(255,255,255,255); font=fontserver->GetSystemPlain(); scale=1.0; + edelta.space=0; + edelta.nonspace=0; } ~LayerData(void) { @@ -34,11 +39,14 @@ LayerData(void) float pensize; BPoint penlocation; drawing_mode draw_mode; +source_alpha alpha_mode; +alpha_function blending_mode; ServerBitmap *bitmap_background; ServerBitmap *bitmap_overlay; RGBColor highcolor, lowcolor; ServerFont *font; float scale; +escapement_delta edelta; }; extern int8 *solidhigh; diff --git a/src/servers/app/proto7/RGBColor.cpp b/src/servers/app/proto7/RGBColor.cpp index a760362007..6b8751fbe7 100644 --- a/src/servers/app/proto7/RGBColor.cpp +++ b/src/servers/app/proto7/RGBColor.cpp @@ -174,3 +174,15 @@ void RGBColor::PrintToStream(void) { printf("RGBColor (%u,%u,%u,%u)\n", color32.red,color32.green,color32.blue,color32.alpha); } + +bool RGBColor::operator==(const rgb_color &col) +{ + return (color32.red==col.red && color32.green==col.green + && color32.blue==col.blue)?true:false; +} + +bool RGBColor::operator==(const RGBColor &col) +{ + return (color32.red==col.color32.red && color32.green==col.color32.green + && color32.blue==col.color32.blue)?true:false; +} diff --git a/src/servers/app/proto7/RGBColor.h b/src/servers/app/proto7/RGBColor.h index fde6854a2a..7be035d09d 100644 --- a/src/servers/app/proto7/RGBColor.h +++ b/src/servers/app/proto7/RGBColor.h @@ -26,6 +26,8 @@ public: RGBColor MakeBlendColor(RGBColor color, float position); RGBColor & operator=(const RGBColor &col); RGBColor & operator=(rgb_color col); + bool operator==(const rgb_color &col); + bool operator==(const RGBColor &col); protected: rgb_color color32; uint16 color16; diff --git a/src/servers/app/proto7/ScreenDriver.cpp b/src/servers/app/proto7/ScreenDriver.cpp index aebd5a5843..d1c556725a 100644 --- a/src/servers/app/proto7/ScreenDriver.cpp +++ b/src/servers/app/proto7/ScreenDriver.cpp @@ -16,12 +16,15 @@ to the video card Internal functions for doing graphics on the buffer */ +#include "Angle.h" #include "ScreenDriver.h" #include "ServerProtocol.h" #include "ServerBitmap.h" +#include "ServerCursor.h" #include "SystemPalette.h" #include "ColorUtils.h" #include "PortLink.h" +#include "FontFamily.h" #include "RGBColor.h" #include "DebugTools.h" #include "LayerData.h" @@ -30,6 +33,7 @@ #include #include #include +#include //#define DEBUG_DRIVER #define DEBUG_SERVER_EMU @@ -1051,8 +1055,8 @@ printf("ScreenDriver::ObscureCursor\n"); BlitBitmap(under_cursor,under_cursor->Bounds(),oldcursorframe); Unlock(); } -/* -void ScreenDriver::SetCursor(ServerBitmap *csr) + +void ScreenDriver::SetCursor(ServerBitmap *csr, const BPoint &spot) { #ifdef DEBUG_DRIVER printf("ScreenDriver::SetCursor\n"); @@ -1074,6 +1078,11 @@ printf("ScreenDriver::SetCursor\n"); cursor=new ServerBitmap(csr); under_cursor=new ServerBitmap(csr); + if(cursor->Bounds().Contains(spot)) + SetHotSpot(spot); + else + SetHotSpot(BPoint(0,0)); + cursorframe.right=cursorframe.left+csr->Bounds().Width(); cursorframe.bottom=cursorframe.top+csr->Bounds().Height(); oldcursorframe=cursorframe; @@ -1085,7 +1094,7 @@ printf("ScreenDriver::SetCursor\n"); Unlock(); } -*/ + void ScreenDriver::HLine(int32 x1, int32 x2, int32 y, RGBColor color) { // Internal function called from others in the driver @@ -1293,3 +1302,449 @@ void ScreenDriver::InvertRect(BRect r) } Unlock(); } + +void ScreenDriver::DrawChar(char c, BPoint pt, LayerData *d) +{ + char st[2]; + st[0]=c; + st[1]='\0'; + DrawString(st,1,pt,d); +} + +void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL) +{ + if(!string || !d || !d->font) + return; + + pt.y--; // because of Be's backward compatibility hack + + ServerFont *font=d->font; + FontStyle *style=font->Style(); + + if(!style) + return; + + FT_Face face; + FT_GlyphSlot slot; + FT_Matrix rmatrix,smatrix; + FT_UInt glyph_index, previous=0; + FT_Vector pen,delta,space,nonspace; + int16 error=0; + int32 strlength,i; + Angle rotation(font->Rotation()), shear(font->Shear()); + + bool antialias=( (font->Size()<18 && font->Flags()& B_DISABLE_ANTIALIASING==0) + || font->Flags()& B_FORCE_ANTIALIASING)?true:false; + + // Originally, I thought to do this shear checking here, but it really should be + // done in BFont::SetShear() + float shearangle=shear.Value(); + if(shearangle>135) + shearangle=135; + if(shearangle<45) + shearangle=45; + + if(shearangle>90) + shear=90+((180-shearangle)*2); + else + shear=90-(90-shearangle)*2; + + error=FT_New_Face(ftlib, style->GetPath(), 0, &face); + if(error) + { + printf("Couldn't create face object\n"); + return; + } + + slot=face->glyph; + + bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING; + + error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72); + if(error) + { + printf("Couldn't set character size - error 0x%x\n",error); + return; + } + + // if we do any transformation, we do a call to FT_Set_Transform() here + + // First, rotate + rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000); + rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000); + rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000); + rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000); + + // Next, shear + smatrix.xx = (FT_Fixed)(0x10000); + smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000); + smatrix.yx = (FT_Fixed)(0); + smatrix.yy = (FT_Fixed)(0x10000); + + FT_Matrix_Multiply(&rmatrix,&smatrix); + + // Set up the increment value for escapement padding + space.x=int32(d->edelta.space * rotation.Cosine()*64); + space.y=int32(d->edelta.space * rotation.Sine()*64); + nonspace.x=int32(d->edelta.nonspace * rotation.Cosine()*64); + nonspace.y=int32(d->edelta.nonspace * rotation.Sine()*64); + + // set the pen position in 26.6 cartesian space coordinates + pen.x=(int32)pt.x * 64; + pen.y=(int32)pt.y * 64; + + slot=face->glyph; + + + strlength=strlen(string); + if(lengthbitmap, + BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d); + else + BlitMono2RGB32(&slot->bitmap, + BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d); + } + else + printf("Couldn't load character %c\n", string[i]); + + // increment pen position + pen.x+=slot->advance.x; + pen.y+=slot->advance.y; + previous=glyph_index; + } + FT_Done_Face(face); +} + +void ScreenDriver::BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d) +{ + rgb_color color=d->highcolor.GetColor32(); + + // pointers to the top left corner of the area to be copied in each bitmap + uint8 *srcbuffer, *destbuffer; + + // index pointers which are incremented during the course of the blit + uint8 *srcindex, *destindex, *rowptr, value; + + // increment values for the index pointers + int32 srcinc=src->pitch, destinc=fbuffer->gcinfo.bytes_per_row; + + int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows; + int32 x=(int32)pt.x,y=(int32)pt.y; + + // starting point in source bitmap + srcbuffer=(uint8*)src->buffer; + + if(y<0) + { + if(yfbuffer->gcinfo.height) + { + if(y>pt.y) + y--; + srcheight-=(y+srcheight-1)-fbuffer->gcinfo.height; + } + + if(x+srcwidth>fbuffer->gcinfo.width) + { + if(x>pt.x) + x--; + srcwidth-=(x+srcwidth-1)-fbuffer->gcinfo.width; + } + + if(x<0) + { + if(x>3; + srcwidth-=0-x; + destbuffer+=(0-x)*4; + } + + // starting point in destination bitmap + destbuffer=(uint8*)fbuffer->gcinfo.frame_buffer+int32( (pt.y*fbuffer->gcinfo.bytes_per_row)+(pt.x*4) ); + + srcindex=srcbuffer; + destindex=destbuffer; + + for(i=0; ihighcolor.GetColor32(), lowcolor=d->lowcolor.GetColor32(); float rstep,gstep,bstep,astep; + + rstep=float(highcolor.red-lowcolor.red)/255.0; + gstep=float(highcolor.green-lowcolor.green)/255.0; + bstep=float(highcolor.blue-lowcolor.blue)/255.0; + astep=float(highcolor.alpha-lowcolor.alpha)/255.0; + + // increment values for the index pointers + int32 x=(int32)pt.x, + y=(int32)pt.y, + srcinc=src->pitch, +// destinc=dest->BytesPerRow(), + destinc=fbuffer->gcinfo.bytes_per_row, + srcwidth=src->width, + srcheight=src->rows, + incval=0; + + int16 i,j; + + // starting point in source bitmap + srcbuffer=(uint8*)src->buffer; + + // starting point in destination bitmap +// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4)); + destbuffer=(uint8*)fbuffer->gcinfo.frame_buffer+(y*fbuffer->gcinfo.bytes_per_row+(x*4)); + + + if(y<0) + { + if(yfbuffer->gcinfo.height) + { + if(y>pt.y) + y--; + srcheight-=(y+srcheight-1)-fbuffer->gcinfo.height; + } + + if(x+srcwidth>fbuffer->gcinfo.width) + { + if(x>pt.x) + x--; + srcwidth-=(x+srcwidth-1)-fbuffer->gcinfo.width; + } + + if(x<0) + { + if(xdraw_mode==B_OP_COPY) + { + rowptr[0]=uint8(highcolor.blue-(value*bstep)); + rowptr[1]=uint8(highcolor.green-(value*gstep)); + rowptr[2]=uint8(highcolor.red-(value*rstep)); + rowptr[3]=255; + } + else + if(d->draw_mode==B_OP_OVER) + { + if(highcolor.alpha>127) + { + rowptr[0]=uint8(highcolor.blue-(value*(float(highcolor.blue-rowptr[0])/255.0))); + rowptr[1]=uint8(highcolor.green-(value*(float(highcolor.green-rowptr[1])/255.0))); + rowptr[2]=uint8(highcolor.red-(value*(float(highcolor.red-rowptr[2])/255.0))); + rowptr[3]=255; + } + } + } + rowptr+=4; + + } + + srcindex+=srcinc; + destindex+=destinc; + } +} + +rgb_color ScreenDriver::GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true) +{ + rgb_color returncolor={0,0,0,0}; + int16 value; + if(!d) + return returncolor; + + switch(d->draw_mode) + { + case B_OP_COPY: + { + return src; + } + case B_OP_ADD: + { + value=src.red+dest.red; + returncolor.red=(value>255)?255:value; + + value=src.green+dest.green; + returncolor.green=(value>255)?255:value; + + value=src.blue+dest.blue; + returncolor.blue=(value>255)?255:value; + return returncolor; + } + case B_OP_SUBTRACT: + { + value=src.red-dest.red; + returncolor.red=(value<0)?0:value; + + value=src.green-dest.green; + returncolor.green=(value<0)?0:value; + + value=src.blue-dest.blue; + returncolor.blue=(value<0)?0:value; + return returncolor; + } + case B_OP_BLEND: + { + value=int16(src.red+dest.red)>>1; + returncolor.red=value; + + value=int16(src.green+dest.green)>>1; + returncolor.green=value; + + value=int16(src.blue+dest.blue)>>1; + returncolor.blue=value; + return returncolor; + } + case B_OP_MIN: + { + + return ( uint16(src.red+src.blue+src.green) > + uint16(dest.red+dest.blue+dest.green) )?dest:src; + } + case B_OP_MAX: + { + return ( uint16(src.red+src.blue+src.green) < + uint16(dest.red+dest.blue+dest.green) )?dest:src; + } + case B_OP_OVER: + { + return (use_high && src.alpha>127)?src:dest; + } + case B_OP_INVERT: + { + returncolor.red=dest.red ^ 255; + returncolor.green=dest.green ^ 255; + returncolor.blue=dest.blue ^ 255; + return (use_high && src.alpha>127)?returncolor:dest; + } + // This is a pain in the arse to implement, so I'm saving it for the real + // server + case B_OP_ALPHA: + { + return src; + } + case B_OP_ERASE: + { + // This one's tricky. + return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest; + } + case B_OP_SELECT: + { + // This one's tricky, too. We are passed a color in src. If it's the layer's + // high color or low color, we check for a swap. + if(d->highcolor==src) + return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest; + + if(d->lowcolor==src) + return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest; + + return dest; + } + default: + { + break; + } + } + return returncolor; +} diff --git a/src/servers/app/proto7/ScreenDriver.h b/src/servers/app/proto7/ScreenDriver.h index e9bb701232..6f00913cc6 100644 --- a/src/servers/app/proto7/ScreenDriver.h +++ b/src/servers/app/proto7/ScreenDriver.h @@ -11,6 +11,9 @@ #include // for clipping_rect definition #include #include "DisplayDriver.h" +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H class VDWindow; class ServerCursor; @@ -49,9 +52,9 @@ public: // Settings functions // virtual void CopyBits(BRect src, BRect dest); virtual void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest); -// virtual void DrawChar(char c, BPoint pt); // virtual void DrawPicture(SPicture *pic, BPoint pt); -// virtual void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL); + virtual void DrawChar(char c, BPoint pt, LayerData *d); + virtual void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL); // virtual void FillArc(BRect r, float angle, float span, LayerData *d, int8 *pat); // virtual void FillBezier(BPoint *pts, LayerData *d, int8 *pat); @@ -67,7 +70,7 @@ public: virtual void InvertRect(BRect r); virtual void ShowCursor(void); virtual void ObscureCursor(void); -// virtual void SetCursor(ServerBitmap *cursor); + virtual void SetCursor(ServerBitmap *cursor, const BPoint &spot); // virtual void StrokeArc(BRect r, float angle, float span, LayerData *d, int8 *pat); // virtual void StrokeBezier(BPoint *pts, LayerData *d, int8 *pat); @@ -82,10 +85,13 @@ public: virtual void SetMode(int32 mode); // virtual bool DumpToFile(const char *path); protected: + void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d); + void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d); void BlitBitmap(ServerBitmap *sourcebmp, BRect sourcerect, BRect destrect); void SetPixelPattern(int x, int y, uint8 *pattern, uint8 patternindex); void Line(BPoint start, BPoint end, LayerData *d, int8 *pat); void HLine(int32 x1, int32 x2, int32 y, RGBColor color); + rgb_color GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true); void SetPixel(int x, int y, RGBColor col); void SetPixel32(int x, int y, rgb_color col); void SetPixel16(int x, int y, uint16 col); diff --git a/src/servers/app/proto7/ServerApp.cpp b/src/servers/app/proto7/ServerApp.cpp index cbb2e91036..cff340bb1e 100644 --- a/src/servers/app/proto7/ServerApp.cpp +++ b/src/servers/app/proto7/ServerApp.cpp @@ -411,8 +411,8 @@ printf("ServerApp: ActivateWorkspace(%ld)\n",*((int32*)index)); memcpy(cdata, buffer, 68); if(cursor) delete cursor; - cursor=new ServerCursor(cdata); - driver->SetCursor(cursor); + cursor=new ServerBitmap(cdata); + driver->SetCursor(cursor,BPoint(cdata[2],cdata[3])); #ifdef DEBUG_SERVERAPP_CURSOR printf("ServerApp: SetCursor(%d,%d,%d,%d)\n",r,g,b,a); #endif diff --git a/src/servers/app/proto7/ServerApp.h b/src/servers/app/proto7/ServerApp.h index 6a53822cbf..90b2a88327 100644 --- a/src/servers/app/proto7/ServerApp.h +++ b/src/servers/app/proto7/ServerApp.h @@ -28,7 +28,7 @@ public: thread_id monitor_thread; PortLink *applink; BList *winlist, *bmplist; - ServerCursor *cursor; + ServerBitmap *cursor; DisplayDriver *driver; rgb_color high, low; // just for testing until layers are implemented diff --git a/src/servers/app/proto7/ServerBitmap.cpp b/src/servers/app/proto7/ServerBitmap.cpp index 9aca4698ed..c29d2d974b 100644 --- a/src/servers/app/proto7/ServerBitmap.cpp +++ b/src/servers/app/proto7/ServerBitmap.cpp @@ -12,7 +12,6 @@ #include #include -#include #include "ServerBitmap.h" #include "Desktop.h" #include "DisplayDriver.h" @@ -23,8 +22,16 @@ #include #endif +long pow2(int power) +{ + if(power==0) + return 1; + return long(2 << (power-1)); +} + ServerBitmap::ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0) { + is_initialized=true; width=rect.IntegerWidth()+1; height=rect.IntegerHeight()+1; cspace=space; @@ -36,6 +43,7 @@ ServerBitmap::ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0) ServerBitmap::ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0) { + is_initialized=true; width=w; height=h; cspace=space; @@ -45,22 +53,22 @@ ServerBitmap::ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine= buffer=new uint8[bytesperline*height]; } -// This particular version is not intended for use except for testing purposes. -// It loads a BBitmap and copies it to the ServerBitmap. Probably will disappear -// when the *real* server is written +// This loads a bitmap from disk, given a path ServerBitmap::ServerBitmap(const char *path) { + is_initialized=true; if(!path) { width=0; height=0; cspace=B_NO_COLOR_SPACE; bytesperline=0; + is_initialized=false; + buffer=NULL; return; } BBitmap *bmp=BTranslationUtils::GetBitmap(path); - assert(bmp!=NULL); if(bmp==NULL) { @@ -68,6 +76,59 @@ ServerBitmap::ServerBitmap(const char *path) height=0; cspace=B_NO_COLOR_SPACE; bytesperline=0; + is_initialized=false; + buffer=NULL; + } + else + { + width=bmp->Bounds().IntegerWidth(); + height=bmp->Bounds().IntegerHeight(); + cspace=bmp->ColorSpace(); + bytesperline=bmp->BytesPerRow(); + buffer=new uint8[bmp->BitsLength()]; + memcpy(buffer,(void *)bmp->Bits(),bmp->BitsLength()); + } +} + +// Load a bitmap from a resource file +ServerBitmap::ServerBitmap(uint32 type,int32 id) +{ + is_initialized=true; + BBitmap *bmp=BTranslationUtils::GetBitmap(type,id); + + if(bmp==NULL) + { + width=0; + height=0; + cspace=B_NO_COLOR_SPACE; + bytesperline=0; + is_initialized=false; + buffer=NULL; + } + else + { + width=bmp->Bounds().IntegerWidth(); + height=bmp->Bounds().IntegerHeight(); + cspace=bmp->ColorSpace(); + bytesperline=bmp->BytesPerRow(); + buffer=new uint8[bmp->BitsLength()]; + memcpy(buffer,(void *)bmp->Bits(),bmp->BitsLength()); + } +} + +ServerBitmap::ServerBitmap(uint32 type, const char *name) +{ + is_initialized=true; + BBitmap *bmp=BTranslationUtils::GetBitmap(type,name); + + if(bmp==NULL) + { + width=0; + height=0; + cspace=B_NO_COLOR_SPACE; + bytesperline=0; + is_initialized=false; + buffer=NULL; } else { @@ -82,6 +143,7 @@ ServerBitmap::ServerBitmap(const char *path) ServerBitmap::ServerBitmap(ServerBitmap *bitmap) { + is_initialized=true; width=bitmap->width; height=bitmap->height; cspace=bitmap->cspace; @@ -92,6 +154,65 @@ ServerBitmap::ServerBitmap(ServerBitmap *bitmap) memcpy(buffer, bitmap->buffer, bytesperline * height); } +ServerBitmap::ServerBitmap(int8 *data) +{ + // 68-byte array used in R5 for holding cursors. + // This API has serious problems and should be deprecated(but supported) in R2 + + // Now that we have all the setup, we're going to map (for now) the cursor + // to RGBA32. Eventually, there will be support for 16 and 8-bit depths + is_initialized=true; + if(data) + { + uint32 black=0xFF000000, + white=0xFFFFFFFF, + *bmppos; + uint16 *cursorpos, *maskpos,cursorflip, maskflip, + cursorval, maskval; + uint8 i,j; + + cursorpos=(uint16*)(data+4); + maskpos=(uint16*)(data+36); + + buffer=new uint8[1024]; // 16x16x4 - RGBA32 space + width=16; + height=16; + bytesperline=64; + + // for each row in the cursor data + for(j=0;j<16;j++) + { + bmppos=(uint32*)(buffer+ (j*64) ); + + // On intel, our bytes end up swapped, so we must swap them back + cursorflip=(cursorpos[j] & 0xFF) << 8; + cursorflip |= (cursorpos[j] & 0xFF00) >> 8; + maskflip=(maskpos[j] & 0xFF) << 8; + maskflip |= (maskpos[j] & 0xFF00) >> 8; + + // for each column in each row of cursor data + for(i=0;i<16;i++) + { + // Get the values and dump them to the bitmap + cursorval=cursorflip & pow2(15-i); + maskval=maskflip & pow2(15-i); + bmppos[i]=((cursorval!=0)?black:white) & ((maskval>0)?0xFFFFFFFF:0x00FFFFFF); + } + } + } + else + { + buffer=NULL; + width=0; + height=0; + bytesperline=0; + } + +#ifdef DEBUG_SERVER_CURSOR + PrintToStream(); +#endif +} + ServerBitmap::~ServerBitmap(void) { if(buffer) diff --git a/src/servers/app/proto7/ServerBitmap.h b/src/servers/app/proto7/ServerBitmap.h index 2a030dff30..b9d97e4776 100644 --- a/src/servers/app/proto7/ServerBitmap.h +++ b/src/servers/app/proto7/ServerBitmap.h @@ -14,6 +14,9 @@ public: ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0); ServerBitmap(const char *path); ServerBitmap(ServerBitmap *bitmap); + ServerBitmap(uint32 type, int32 id); + ServerBitmap(int8 *data); + ServerBitmap(uint32 type, const char *name); ~ServerBitmap(void); void UpdateSettings(void); void SetBuffer(void *ptr) { buffer=(uint8*)ptr; } @@ -26,6 +29,7 @@ public: int32 BytesPerRow(void) { return bytesperline; }; uint8 BitsPerPixel(void) { return bpp; } color_space ColorSpace(void) { return cspace; } + const bool &InitCheck(void) { return is_initialized; } int32 width,height; int32 bytesperline; @@ -33,6 +37,7 @@ public: int bpp; protected: + bool is_initialized; void HandleSpace(color_space space, int32 BytesPerLine); DisplayDriver *driver; area_id areaid; diff --git a/src/servers/app/proto7/ServerCursor.cpp b/src/servers/app/proto7/ServerCursor.cpp deleted file mode 100644 index 38f268648c..0000000000 --- a/src/servers/app/proto7/ServerCursor.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - ServerCursor.cpp - This is the server-side class used to handle cursors. Note that it - will handle the R5 cursor API, but it will also handle taking a bitmap. - - ServerCursors are 32-bit. Eventually, we will be mapping colors to fit - when the set is called. - - This is new code, and there may be changes to the API before it settles - in. -*/ - -#include "ServerCursor.h" -#include -#include - -long pow2(int power) -{ - if(power==0) - return 1; - return long(2 << (power-1)); -} - -//#define DEBUG_SERVER_CURSOR - -/* -ServerCursor::ServerCursor(ServerBitmap *bmp, ServerBitmap *cmask=NULL) -{ - // The OpenBeOS R1 API can use Bitmaps to create cursors - more flexibility that way. -} -*/ -ServerCursor::ServerCursor(int8 *data) -{ - // 68-byte array used in R5 for holding cursors. - // This API has serious problems and should be deprecated(but supported) in R2 - - // Now that we have all the setup, we're going to map (for now) the cursor - // to RGBA32. Eventually, there will be support for 16 and 8-bit depths - if(data) - { - uint32 black=0xFF000000, - white=0xFFFFFFFF, - *bmppos; - uint16 *cursorpos, *maskpos,cursorflip, maskflip, - cursorval, maskval; - uint8 i,j; - - cursorpos=(uint16*)(data+4); - maskpos=(uint16*)(data+36); - - buffer=new uint8[1024]; // 16x16x4 - RGBA32 space - width=16; - height=16; - bytesperline=64; - - // for each row in the cursor data - for(j=0;j<16;j++) - { - bmppos=(uint32*)(buffer+ (j*64) ); - - // On intel, our bytes end up swapped, so we must swap them back - cursorflip=(cursorpos[j] & 0xFF) << 8; - cursorflip |= (cursorpos[j] & 0xFF00) >> 8; - maskflip=(maskpos[j] & 0xFF) << 8; - maskflip |= (maskpos[j] & 0xFF00) >> 8; - - // for each column in each row of cursor data - for(i=0;i<16;i++) - { - // Get the values and dump them to the bitmap - cursorval=cursorflip & pow2(15-i); - maskval=maskflip & pow2(15-i); - bmppos[i]=((cursorval!=0)?black:white) & ((maskval>0)?0xFFFFFFFF:0x00FFFFFF); - } - } - } - else - { - buffer=NULL; - width=0; - height=0; - bytesperline=0; - } - -#ifdef DEBUG_SERVER_CURSOR - PrintToStream(); -#endif -} - -ServerCursor::~ServerCursor(void) -{ - if(buffer) - delete buffer; -} - -void ServerCursor::PrintToStream(void) -{ - if(!buffer) - { - printf("ServerCursor with NULL buffer\n"); - return; - } - - rgb_color *color=(rgb_color*)buffer; - printf("Server Cursor\n"); - for(int32 i=0; i0)?'*':'.'); - - printf("\n"); - } -} diff --git a/src/servers/app/proto7/ServerCursor.h b/src/servers/app/proto7/ServerCursor.h deleted file mode 100644 index ee7d821813..0000000000 --- a/src/servers/app/proto7/ServerCursor.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _SERVER_CURSOR_H -#define _SERVER_CURSOR_H - -#include -#include -#include "ServerBitmap.h" - -class ServerCursor -{ -public: -// ServerCursor(ServerBitmap *bmp,ServerBitmap *cmask=NULL); - ServerCursor(int8 *data); - ~ServerCursor(void); - BRect Bounds() { return BRect(0,0,width-1,height-1); }; - uint8 *Buffer(void) const { return buffer;} - int32 Width(void) const { return width; } - int32 Height(void) const { return height; } - int32 BytesPerLine(void) const { return bytesperline; }; - void PrintToStream(void); -protected: - uint8 *buffer; - int32 width,height; - int32 bytesperline; -}; - -#endif \ No newline at end of file diff --git a/src/servers/app/proto7/ServerFont.cpp b/src/servers/app/proto7/ServerFont.cpp index 98fbce91ca..25b11eb040 100644 --- a/src/servers/app/proto7/ServerFont.cpp +++ b/src/servers/app/proto7/ServerFont.cpp @@ -21,6 +21,7 @@ ServerFont::ServerFont(FontStyle *style, float size=12.0, float rotation=0.0, fl fface=B_REGULAR_FACE; ftruncate=B_TRUNCATE_END; fencoding=B_UNICODE_UTF8; + fbounds.Set(0,0,0,0); if(fstyle) fstyle->AddDependent(); } @@ -37,6 +38,7 @@ ServerFont::ServerFont(const ServerFont &font) fface=font.fface; ftruncate=font.ftruncate; fencoding=font.fencoding; + fbounds.Set(0,0,0,0); if(fstyle) fstyle->AddDependent(); } @@ -56,6 +58,17 @@ escapement_delta Escapements(char c) { } */ + +const BRect &ServerFont::BoundingBox(void) +{ + return fbounds; +} + +BRect ServerFont::StringBounds(const char *string) +{ + return BRect(0,0,0,0); +} + void ServerFont::Height(font_height *fh) { fh->ascent=fheight.ascent; diff --git a/src/servers/app/proto7/ServerFont.h b/src/servers/app/proto7/ServerFont.h index ce219b84eb..8735174f07 100644 --- a/src/servers/app/proto7/ServerFont.h +++ b/src/servers/app/proto7/ServerFont.h @@ -35,16 +35,17 @@ public: void SetRotation(const float &value) { frotation=value; } void SetFace(const uint16 &value) { fface=value; } -// BRect BoundingBox(void); + const BRect &BoundingBox(void); + BRect StringBounds(const char *string); // escapement_delta Escapements(char c); void Height(font_height *fh); protected: friend FontStyle; FontStyle *fstyle; font_height fheight; - escapement_delta fescapements; edge_info fedges; float fsize, frotation, fshear; + BRect fbounds; uint32 fflags; uint8 fspacing; uint16 fface; diff --git a/src/servers/app/proto7/ViewDriver.cpp b/src/servers/app/proto7/ViewDriver.cpp index 60b8ba1ce6..3b0805e178 100644 --- a/src/servers/app/proto7/ViewDriver.cpp +++ b/src/servers/app/proto7/ViewDriver.cpp @@ -732,7 +732,7 @@ void ViewDriver::MoveCursorTo(float x, float y) screenwin->Unlock(); } -void ViewDriver::SetCursor(ServerCursor *cursor) +void ViewDriver::SetCursor(ServerBitmap *cursor, const BPoint &spot) { #ifdef DEBUG_DRIVER_MODULE printf("ViewDriver:: SetCursor(%p)\n",cursor); @@ -743,14 +743,19 @@ printf("ViewDriver:: SetCursor(%p)\n",cursor); BBitmap *bmp=new BBitmap(cursor->Bounds(),B_RGBA32); // Copy the server bitmap in the cursor to a BBitmap - uint8 *sbmppos=(uint8*)cursor->Buffer(), + uint8 *sbmppos=(uint8*)cursor->Bits(), *bbmppos=(uint8*)bmp->Bits(); - int32 bytes=cursor->BytesPerLine(), + int32 bytes=cursor->BytesPerRow(), bbytes=bmp->BytesPerRow(); - for(int i=0;iHeight();i++) + for(int i=0;i<=cursor->Bounds().IntegerHeight();i++) memcpy(bbmppos+(i*bbytes), sbmppos+(i*bytes), bytes); + + if(cursor->Bounds().Contains(spot)) + SetHotSpot(spot); + else + SetHotSpot(BPoint(0,0)); // Replace the bitmap delete screenwin->view->cursor; diff --git a/src/servers/app/proto7/ViewDriver.h b/src/servers/app/proto7/ViewDriver.h index b91ea70b1e..a147fcb27e 100644 --- a/src/servers/app/proto7/ViewDriver.h +++ b/src/servers/app/proto7/ViewDriver.h @@ -84,7 +84,7 @@ public: void ObscureCursor(void); // BPoint PenPosition(void); // float PenSize(void); - void SetCursor(ServerCursor *cursor); + void SetCursor(ServerBitmap *cursor, const BPoint &spot); // drawing_mode GetDrawingMode(void); // void SetDrawingMode(drawing_mode mode); void ShowCursor(void); diff --git a/src/servers/app/proto7/testobapp/ClientFontList.cpp b/src/servers/app/proto7/testobapp/ClientFontList.cpp index 614929896d..9c30ad63e6 100644 --- a/src/servers/app/proto7/testobapp/ClientFontList.cpp +++ b/src/servers/app/proto7/testobapp/ClientFontList.cpp @@ -4,14 +4,15 @@ kept on the client side. */ +#include "ClientFontList.h" #include #include #include #include #include +#include #include "PortLink.h" #include "ServerProtocol.h" -#include "ClientFontList.h" #define DEBUG_CLIENT_FONT_LIST diff --git a/src/servers/app/proto7/testobapp/Jamfile b/src/servers/app/proto7/testobapp/Jamfile index a92925a2f6..4df0b13d80 100644 --- a/src/servers/app/proto7/testobapp/Jamfile +++ b/src/servers/app/proto7/testobapp/Jamfile @@ -10,4 +10,4 @@ App proto7_test_app : <$(SOURCE_GRIST)>OBWindow.cpp <$(SOURCE_GRIST)>PortLink.cpp ; -LinkSharedOSLibs OBApplication : be stdc++.r4 ; +LinkSharedOSLibs proto7_test_app : be stdc++.r4 ;