If you still think this is informative, just have a look in the SVN history :-)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16849 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ebaeaa1224
commit
8c86105b9a
File diff suppressed because it is too large
Load Diff
@ -1,124 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2003, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: AccelerantDriver.h
|
||||
// Author: Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Michael Lotz <mmlr@mlotz.ch>
|
||||
// Description: A display driver which works directly with the
|
||||
// accelerant of the graphics card.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _ACCELERANTDRIVER_H_
|
||||
#define _ACCELERANTDRIVER_H_
|
||||
|
||||
#include <Accelerant.h>
|
||||
|
||||
#include "PatternHandler.h"
|
||||
#include "FontServer.h"
|
||||
#include "LayerData.h"
|
||||
#include "DisplayDriverImpl.h"
|
||||
|
||||
class ServerBitmap;
|
||||
class ServerCursor;
|
||||
|
||||
class AccelerantDriver : public DisplayDriverImpl {
|
||||
public:
|
||||
AccelerantDriver();
|
||||
~AccelerantDriver();
|
||||
|
||||
virtual bool Initialize();
|
||||
virtual void Shutdown();
|
||||
|
||||
/*
|
||||
virtual bool Lock(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||
virtual void Unlock(void);
|
||||
*/
|
||||
|
||||
virtual void SetMode(const int32 &mode);
|
||||
virtual void SetMode(const display_mode &mode);
|
||||
|
||||
virtual bool DumpToFile(const char *path);
|
||||
virtual void InvertRect(const BRect &r);
|
||||
virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *linedata,const DrawData *d);
|
||||
|
||||
/*
|
||||
virtual status_t SetDPMSMode(const uint32 &state);
|
||||
virtual uint32 DPMSMode() const;
|
||||
virtual uint32 DPMSCapabilities() const;
|
||||
*/
|
||||
|
||||
virtual status_t GetDeviceInfo(accelerant_device_info *info);
|
||||
virtual status_t GetModeList(display_mode **mode_list, uint32 *count);
|
||||
virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high);
|
||||
virtual status_t GetTimingConstraints(display_timing_constraints *dtc);
|
||||
virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high);
|
||||
virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
|
||||
protected:
|
||||
virtual bool AcquireBuffer(FBBitmap *bmp);
|
||||
virtual void ReleaseBuffer(void);
|
||||
|
||||
void BlitBitmap(ServerBitmap *sourcebmp, BRect sourcerect, BRect destrect, drawing_mode mode=B_OP_COPY);
|
||||
void ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect);
|
||||
rgb_color GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true);
|
||||
int OpenGraphicsDevice(int deviceNumber);
|
||||
int GetModeFromResolution(int width, int height, int space);
|
||||
int GetWidthFromMode(int mode);
|
||||
int GetHeightFromMode(int mode);
|
||||
int GetDepthFromMode(int mode);
|
||||
int GetDepthFromColorspace(int space);
|
||||
|
||||
// Support functions for the rest of the driver
|
||||
virtual void Blit(const BRect &src, const BRect &dest, const DrawData *d);
|
||||
virtual void FillSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void FillPatternRect(const BRect &rect, const DrawData *d);
|
||||
virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color);
|
||||
virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d);
|
||||
virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d);
|
||||
virtual void CopyToBitmap(ServerBitmap *target, const BRect &source);
|
||||
|
||||
ServerCursor *cursor;
|
||||
ServerCursor *under_cursor;
|
||||
BRect cursorframe;
|
||||
|
||||
int card_fd;
|
||||
image_id accelerant_image;
|
||||
GetAccelerantHook accelerant_hook;
|
||||
engine_token *mEngineToken;
|
||||
acquire_engine AcquireEngine;
|
||||
release_engine ReleaseEngine;
|
||||
|
||||
// accelerant hooks
|
||||
fill_rectangle accFillRect;
|
||||
invert_rectangle accInvertRect;
|
||||
set_cursor_shape accSetCursorShape;
|
||||
move_cursor accMoveCursor;
|
||||
show_cursor accShowCursor;
|
||||
screen_to_screen_blit accScreenBlit;
|
||||
|
||||
frame_buffer_config mFrameBufferConfig;
|
||||
int mode_count;
|
||||
display_mode *mode_list;
|
||||
display_mode R5DisplayMode; // This should go away once we stop running under r5
|
||||
};
|
||||
|
||||
#endif
|
@ -1,998 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: BitmapDriver.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Description: Driver to draw on ServerBitmaps
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#include "Angle.h"
|
||||
#include "PatternHandler.h"
|
||||
#include "BitmapDriver.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "ServerBitmap.h"
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerConfig.h"
|
||||
#include "SystemPalette.h"
|
||||
#include "ColorUtils.h"
|
||||
#include "PortLink.h"
|
||||
#include "FontFamily.h"
|
||||
#include "RGBColor.h"
|
||||
#include "LayerData.h"
|
||||
#include <View.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <String.h>
|
||||
#include <math.h>
|
||||
|
||||
extern RGBColor workspace_default_color; // defined in AppServer.cpp
|
||||
|
||||
/*!
|
||||
\brief Sets up internal variables needed by all DisplayDriver subclasses
|
||||
|
||||
Subclasses should follow DisplayDriver's lead and use this function mostly
|
||||
for initializing data members.
|
||||
*/
|
||||
BitmapDriver::BitmapDriver()
|
||||
: DisplayDriverImpl(),
|
||||
// NOTE: fLineThickness appeared to be never
|
||||
// initialized in DisplayDriver
|
||||
fLineThickness(1)
|
||||
{
|
||||
fTarget=NULL;
|
||||
fGraphicsBuffer=NULL;
|
||||
fPixelRenderer=NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Deletes the locking semaphore
|
||||
|
||||
Subclasses should use the destructor mostly for freeing allocated heap space.
|
||||
*/
|
||||
BitmapDriver::~BitmapDriver()
|
||||
{
|
||||
}
|
||||
|
||||
void BitmapDriver::SetTarget(ServerBitmap *target)
|
||||
{
|
||||
Lock();
|
||||
|
||||
if(fGraphicsBuffer)
|
||||
{
|
||||
delete fGraphicsBuffer;
|
||||
fGraphicsBuffer=NULL;
|
||||
}
|
||||
|
||||
if(fPixelRenderer)
|
||||
{
|
||||
delete fPixelRenderer;
|
||||
fPixelRenderer=NULL;
|
||||
}
|
||||
|
||||
fTarget=target;
|
||||
|
||||
if(target)
|
||||
{
|
||||
fDisplayMode.virtual_width=target->Width();
|
||||
fDisplayMode.virtual_height=target->Height();
|
||||
fDisplayMode.space=target->ColorSpace();
|
||||
|
||||
fGraphicsBuffer=new GraphicsBuffer((uint8*)fTarget->Bits(),fTarget->Bounds().Width(),
|
||||
fTarget->Bounds().Height(),fTarget->BytesPerRow());
|
||||
|
||||
switch(fTarget->ColorSpace())
|
||||
{
|
||||
case B_RGB32:
|
||||
case B_RGBA32:
|
||||
{
|
||||
fPixelRenderer=new PixelRendererRGBA32(*fGraphicsBuffer);
|
||||
break;
|
||||
}
|
||||
case B_RGB16:
|
||||
{
|
||||
fPixelRenderer=new PixelRendererRGB16(*fGraphicsBuffer);
|
||||
break;
|
||||
}
|
||||
case B_RGB15:
|
||||
case B_RGBA15:
|
||||
{
|
||||
fPixelRenderer=new PixelRendererRGBA15(*fGraphicsBuffer);
|
||||
break;
|
||||
}
|
||||
case B_CMAP8:
|
||||
case B_GRAY8:
|
||||
{
|
||||
fPixelRenderer=new PixelRendererCMAP8(*fGraphicsBuffer);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Setting mode not necessary. Can get color space stuff via ServerBitmap->ColorSpace
|
||||
}
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
//! Empty
|
||||
void BitmapDriver::SetMode(const int32 &space)
|
||||
{
|
||||
// No need to reset a bitmap's color space
|
||||
}
|
||||
|
||||
//! Empty
|
||||
void BitmapDriver::SetMode(const display_mode &mode)
|
||||
{
|
||||
// No need to reset a bitmap's color space
|
||||
}
|
||||
|
||||
void BitmapDriver::InvertRect(const BRect &r)
|
||||
{
|
||||
Lock();
|
||||
if(fTarget)
|
||||
{
|
||||
if(r.top<0 || r.left<0 ||
|
||||
r.right>fTarget->Width()-1 || r.bottom>fTarget->Height()-1)
|
||||
{
|
||||
Unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 32:
|
||||
case 24:
|
||||
{
|
||||
uint16 width=r.IntegerWidth(), height=r.IntegerHeight();
|
||||
uint32 *start=(uint32*)fTarget->Bits(), *index;
|
||||
start+=int32(r.top)*fTarget->Width();
|
||||
start+=int32(r.left);
|
||||
|
||||
for(int32 i=0;i<height;i++)
|
||||
{
|
||||
index=start + (i*fTarget->Width());
|
||||
for(int32 j=0; j<width; j++)
|
||||
index[j]^=0xFFFFFF00L;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 16:
|
||||
// TODO: Implement
|
||||
printf("BitmapDriver::16-bit mode unimplemented\n");
|
||||
break;
|
||||
case 15:
|
||||
// TODO: Implement
|
||||
printf("BitmapDriver::15-bit mode unimplemented\n");
|
||||
break;
|
||||
case 8:
|
||||
// TODO: Implement
|
||||
printf("BitmapDriver::8-bit mode unimplemented\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
rgb_color BitmapDriver::GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
return returncolor;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Draws a point using the display driver's specified thickness and pattern
|
||||
\param x The x coordinate (not guaranteed to be in bounds)
|
||||
\param y The y coordinate (not guaranteed to be in bounds)
|
||||
*/
|
||||
void BitmapDriver::SetThickPatternPixel(int x, int y)
|
||||
{
|
||||
int left, right, top, bottom;
|
||||
int bytes_per_row = fTarget->BytesPerRow();
|
||||
left = x - fLineThickness/2;
|
||||
right = x + fLineThickness/2;
|
||||
top = y - fLineThickness/2;
|
||||
bottom = y + fLineThickness/2;
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
int x,y;
|
||||
uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor8();
|
||||
fb += bytes_per_row;
|
||||
}
|
||||
} break;
|
||||
case 15:
|
||||
{
|
||||
int x,y;
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor15();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 16:
|
||||
{
|
||||
int x,y;
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor16();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
int x,y;
|
||||
uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
rgb_color color;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
{
|
||||
color = fDrawPattern.ColorAt(x,y).GetColor32();
|
||||
fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue);
|
||||
}
|
||||
fb = (uint32 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
printf("Error: Unknown color space\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Draws a horizontal line using the display driver's line thickness and pattern
|
||||
\param x1 The first x coordinate (not guaranteed to be in bounds)
|
||||
\param x2 The second x coordinate (not guaranteed to be in bounds)
|
||||
\param y The y coordinate (not guaranteed to be in bounds)
|
||||
*/
|
||||
void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y)
|
||||
{
|
||||
int x, y1, y2;
|
||||
int bytes_per_row = fTarget->BytesPerRow();
|
||||
|
||||
if ( x1 > x2 )
|
||||
{
|
||||
x = x2;
|
||||
x2 = x1;
|
||||
x1 = x;
|
||||
}
|
||||
y1 = y - fLineThickness/2;
|
||||
y2 = y + fLineThickness/2;
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
uint8 *fb = (uint8 *)fTarget->Bits() + y1*bytes_per_row;
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor8();
|
||||
fb += bytes_per_row;
|
||||
}
|
||||
} break;
|
||||
case 15:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor15();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 16:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor16();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
rgb_color color;
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
color = fDrawPattern.ColorAt(x,y).GetColor32();
|
||||
fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue);
|
||||
}
|
||||
fb = (uint32 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
printf("Error: Unknown color space\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Draws a vertical line using the display driver's line thickness and pattern
|
||||
\param x The x coordinate
|
||||
\param y1 The first y coordinate
|
||||
\param y2 The second y coordinate
|
||||
*/
|
||||
void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2)
|
||||
{
|
||||
int y, x1, x2;
|
||||
int bytes_per_row = fTarget->BytesPerRow();
|
||||
|
||||
if ( y1 > y2 )
|
||||
{
|
||||
y = y2;
|
||||
y2 = y1;
|
||||
y1 = y;
|
||||
}
|
||||
x1 = x - fLineThickness/2;
|
||||
x2 = x + fLineThickness/2;
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
uint8 *fb = (uint8 *)fTarget->Bits() + y1*bytes_per_row;
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor8();
|
||||
fb += bytes_per_row;
|
||||
}
|
||||
} break;
|
||||
case 15:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor15();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 16:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor16();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row);
|
||||
rgb_color color;
|
||||
for (y=y1; y<=y2; y++)
|
||||
{
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
color = fDrawPattern.ColorAt(x,y).GetColor32();
|
||||
fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue);
|
||||
}
|
||||
fb = (uint32 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
printf("Error: Unknown color space\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void BitmapDriver::DrawBitmap(ServerBitmap *sourcebmp, const BRect &source,
|
||||
const BRect &dest, const DrawData *d)
|
||||
{
|
||||
// Another internal function called from other functions.
|
||||
|
||||
if(!sourcebmp | !d)
|
||||
return;
|
||||
|
||||
if(sourcebmp->BitsPerPixel() != fTarget->BitsPerPixel())
|
||||
return;
|
||||
|
||||
uint8 colorspace_size=sourcebmp->BitsPerPixel()/8;
|
||||
|
||||
BRect sourcerect(source),destrect(dest);
|
||||
|
||||
// First, clip source rect to destination
|
||||
if(sourcerect.Width() > destrect.Width())
|
||||
sourcerect.right=sourcerect.left+destrect.Width();
|
||||
|
||||
|
||||
if(sourcerect.Height() > destrect.Height())
|
||||
sourcerect.bottom=sourcerect.top+destrect.Height();
|
||||
|
||||
|
||||
// Second, check rectangle bounds against their own bitmaps
|
||||
BRect work_rect;
|
||||
|
||||
work_rect=sourcebmp->Bounds();
|
||||
|
||||
if( !(work_rect.Contains(sourcerect)) )
|
||||
{ // something in selection must be clipped
|
||||
if(sourcerect.left < 0)
|
||||
sourcerect.left = 0;
|
||||
if(sourcerect.right > work_rect.right)
|
||||
sourcerect.right = work_rect.right;
|
||||
if(sourcerect.top < 0)
|
||||
sourcerect.top = 0;
|
||||
if(sourcerect.bottom > work_rect.bottom)
|
||||
sourcerect.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
work_rect.Set(0,0,fTarget->Width()-1,fTarget->Height()-1);
|
||||
|
||||
// Check to see if we actually need to copy anything
|
||||
if( (destrect.right<work_rect.left) || (destrect.left>work_rect.right) ||
|
||||
(destrect.bottom<work_rect.top) || (destrect.top>work_rect.bottom) )
|
||||
return;
|
||||
|
||||
// something in selection must be clipped
|
||||
if(destrect.left < 0)
|
||||
destrect.left = 0;
|
||||
if(destrect.right > work_rect.right)
|
||||
destrect.right = work_rect.right;
|
||||
if(destrect.top < 0)
|
||||
destrect.top = 0;
|
||||
if(destrect.bottom > work_rect.bottom)
|
||||
destrect.bottom = work_rect.bottom;
|
||||
|
||||
// Set pointers to the actual data
|
||||
uint8 *src_bits = (uint8*) sourcebmp->Bits();
|
||||
uint8 *dest_bits = (uint8*) fTarget->Bits();
|
||||
|
||||
// Get row widths for offset looping
|
||||
uint32 src_width = uint32 (sourcebmp->BytesPerRow());
|
||||
uint32 dest_width = uint32 (fTarget->BytesPerRow());
|
||||
|
||||
// Offset bitmap pointers to proper spot in each bitmap
|
||||
src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) );
|
||||
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
|
||||
|
||||
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
|
||||
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
|
||||
|
||||
switch(d->draw_mode)
|
||||
{
|
||||
case B_OP_OVER:
|
||||
{
|
||||
// uint32 srow_pixels=src_width>>2;
|
||||
uint32 srow_pixels=((destrect.IntegerWidth()>=sourcerect.IntegerWidth())?src_width:destrect.IntegerWidth()+1)>>2;
|
||||
uint8 *srow_index, *drow_index;
|
||||
|
||||
|
||||
// This could later be optimized to use uint32's for faster copying
|
||||
for (uint32 pos_y=0; pos_y!=lines; pos_y++)
|
||||
{
|
||||
|
||||
srow_index=src_bits;
|
||||
drow_index=dest_bits;
|
||||
|
||||
for(uint32 pos_x=0; pos_x!=srow_pixels;pos_x++)
|
||||
{
|
||||
// 32-bit RGBA32 mode byte order is BGRA
|
||||
if(srow_index[3]>127)
|
||||
{
|
||||
*drow_index=*srow_index; drow_index++; srow_index++;
|
||||
*drow_index=*srow_index; drow_index++; srow_index++;
|
||||
*drow_index=*srow_index; drow_index++; srow_index++;
|
||||
// we don't copy the alpha channel
|
||||
drow_index++; srow_index++;
|
||||
}
|
||||
else
|
||||
{
|
||||
srow_index+=4;
|
||||
drow_index+=4;
|
||||
}
|
||||
}
|
||||
|
||||
// Increment offsets
|
||||
src_bits += src_width;
|
||||
dest_bits += dest_width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: // B_OP_COPY
|
||||
{
|
||||
for (uint32 pos_y = 0; pos_y != lines; pos_y++)
|
||||
{
|
||||
memcpy(dest_bits,src_bits,line_length);
|
||||
|
||||
// Increment offsets
|
||||
src_bits += src_width;
|
||||
dest_bits += dest_width;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
bool BitmapDriver::AcquireBuffer(FBBitmap *fbmp)
|
||||
{
|
||||
if(!fbmp)
|
||||
return false;
|
||||
|
||||
fbmp->ServerBitmap::ShallowCopy(fTarget);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BitmapDriver::ReleaseBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void BitmapDriver::Blit(const BRect &src, const BRect &dest, const DrawData *d)
|
||||
{
|
||||
}
|
||||
|
||||
void BitmapDriver::FillSolidRect(const BRect &rect, const RGBColor &color)
|
||||
{
|
||||
int bytes_per_row = fTarget->BytesPerRow();
|
||||
int top = (int)rect.top;
|
||||
int left = (int)rect.left;
|
||||
int right = (int)rect.right;
|
||||
int bottom = (int)rect.bottom;
|
||||
RGBColor col(color); // to avoid GetColor8/15/16() const issues
|
||||
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row;
|
||||
uint8 color8 = col.GetColor8();
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = color8;
|
||||
fb += bytes_per_row;
|
||||
}
|
||||
} break;
|
||||
case 15:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
uint16 color15 = col.GetColor15();
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = color15;
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 16:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
uint16 color16 = col.GetColor16();
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = color16;
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
rgb_color fill_color = color.GetColor32();
|
||||
uint32 color32 = (fill_color.alpha << 24) | (fill_color.red << 16) | (fill_color.green << 8) | (fill_color.blue);
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = color32;
|
||||
fb = (uint32 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
printf("Error: Unknown color space\n");
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d)
|
||||
{
|
||||
int bytes_per_row = fTarget->BytesPerRow();
|
||||
int top = (int)rect.top;
|
||||
int left = (int)rect.left;
|
||||
int right = (int)rect.right;
|
||||
int bottom = (int)rect.bottom;
|
||||
|
||||
switch(fTarget->BitsPerPixel())
|
||||
{
|
||||
case 8:
|
||||
{
|
||||
uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row;
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor8();
|
||||
fb += bytes_per_row;
|
||||
}
|
||||
} break;
|
||||
case 15:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor15();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 16:
|
||||
{
|
||||
uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
int x,y;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
fb[x] = fDrawPattern.ColorAt(x,y).GetColor16();
|
||||
fb = (uint16 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row);
|
||||
int x,y;
|
||||
rgb_color color;
|
||||
for (y=top; y<=bottom; y++)
|
||||
{
|
||||
for (x=left; x<=right; x++)
|
||||
{
|
||||
color = fDrawPattern.ColorAt(x,y).GetColor32();
|
||||
fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue);
|
||||
}
|
||||
fb = (uint32 *)((uint8 *)fb + bytes_per_row);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
printf("Error: Unknown color space\n");
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color)
|
||||
{
|
||||
}
|
||||
|
||||
void BitmapDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d)
|
||||
{
|
||||
}
|
||||
|
||||
void BitmapDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Copy a ServerBitmap to the BitmapDriver's internal ServerBitmap
|
||||
\param bitmap The ServerBitmap source of the copy
|
||||
\param sourcerect The source rectangle of the copy
|
||||
\param dest The destination position of the copy (no scaling occurs)
|
||||
\param d The DrawData (currently unused)
|
||||
*/
|
||||
|
||||
// TODO: dest should really become a BPoint to avoid confusion
|
||||
// TODO: can we unify CopyBitmap and CopyToBitmap somehow, to avoid the
|
||||
// near-total code duplication?
|
||||
|
||||
void BitmapDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &sourcerect, const BRect &dest, const DrawData *d)
|
||||
{
|
||||
if(!bitmap)
|
||||
{
|
||||
printf("CopyBitmap returned - not init or NULL bitmap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(((uint32)bitmap->ColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F))
|
||||
{
|
||||
printf("CopyBitmap returned - unequal buffer pixel depth\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// dest shows position only, not size (i.e. no scaling), so we
|
||||
// emphasize that point by using the source rect and offsetting it
|
||||
BRect destrect(sourcerect), source(sourcerect);
|
||||
destrect.OffsetTo(dest.left, dest.top);
|
||||
|
||||
uint8 colorspace_size=bitmap->BitsPerPixel()/8;
|
||||
|
||||
// First, clip source rect to destination
|
||||
if(source.Width() > destrect.Width())
|
||||
source.right=source.left+destrect.Width();
|
||||
|
||||
if(source.Height() > destrect.Height())
|
||||
source.bottom=source.top+destrect.Height();
|
||||
|
||||
|
||||
// Second, check rectangle bounds against their own bitmaps
|
||||
BRect work_rect(bitmap->Bounds());
|
||||
|
||||
// Is there anything at all to copy?
|
||||
if(!work_rect.Contains(sourcerect))
|
||||
return;
|
||||
|
||||
if( !(work_rect.Contains(source)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(source.left < 0)
|
||||
source.left = 0;
|
||||
if(source.right > work_rect.right)
|
||||
source.right = work_rect.right;
|
||||
if(source.top < 0)
|
||||
source.top = 0;
|
||||
if(source.bottom > work_rect.bottom)
|
||||
source.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1);
|
||||
|
||||
if( !(work_rect.Contains(destrect)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(destrect.left < 0)
|
||||
destrect.left = 0;
|
||||
if(destrect.right > work_rect.right)
|
||||
destrect.right = work_rect.right;
|
||||
if(destrect.top < 0)
|
||||
destrect.top = 0;
|
||||
if(destrect.bottom > work_rect.bottom)
|
||||
destrect.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
// Set pointers to the actual data
|
||||
uint8 *dest_bits = (uint8*) fTarget->Bits();
|
||||
uint8 *src_bits = (uint8*) bitmap->Bits();
|
||||
|
||||
// Get row widths for offset looping
|
||||
uint32 dest_width = uint32 (fTarget->BytesPerRow());
|
||||
uint32 src_width = uint32 (bitmap->BytesPerRow());
|
||||
|
||||
// Offset bitmap pointers to proper spot in each bitmap
|
||||
src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) );
|
||||
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
|
||||
|
||||
|
||||
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
|
||||
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
|
||||
|
||||
for (uint32 pos_y=0; pos_y<lines; pos_y++)
|
||||
{
|
||||
memcpy(dest_bits,src_bits,line_length);
|
||||
|
||||
// Increment offsets
|
||||
src_bits += src_width;
|
||||
dest_bits += dest_width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Copy from the BitmapDriver's internal ServerBitmap to a ServerBitmap
|
||||
\param destbmp The ServerBitmap destination of the copy
|
||||
\param sourcerect The source rectangle of the copy
|
||||
*/
|
||||
void BitmapDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
|
||||
{
|
||||
if(!destbmp)
|
||||
{
|
||||
printf("CopyToBitmap returned - not init or NULL bitmap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(((uint32)destbmp->ColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F))
|
||||
{
|
||||
printf("CopyToBitmap returned - unequal buffer pixel depth\n");
|
||||
return;
|
||||
}
|
||||
|
||||
BRect destrect(destbmp->Bounds()), source(sourcerect);
|
||||
|
||||
uint8 colorspace_size=destbmp->BitsPerPixel()/8;
|
||||
|
||||
// First, clip source rect to destination
|
||||
if(source.Width() > destrect.Width())
|
||||
source.right=source.left+destrect.Width();
|
||||
|
||||
if(source.Height() > destrect.Height())
|
||||
source.bottom=source.top+destrect.Height();
|
||||
|
||||
|
||||
// Second, check rectangle bounds against their own bitmaps
|
||||
BRect work_rect(destbmp->Bounds());
|
||||
|
||||
if( !(work_rect.Contains(destrect)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(destrect.left < 0)
|
||||
destrect.left = 0;
|
||||
if(destrect.right > work_rect.right)
|
||||
destrect.right = work_rect.right;
|
||||
if(destrect.top < 0)
|
||||
destrect.top = 0;
|
||||
if(destrect.bottom > work_rect.bottom)
|
||||
destrect.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1);
|
||||
|
||||
// Is there anything at all to copy?
|
||||
if(!work_rect.Contains(sourcerect))
|
||||
return;
|
||||
|
||||
if( !(work_rect.Contains(source)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(source.left < 0)
|
||||
source.left = 0;
|
||||
if(source.right > work_rect.right)
|
||||
source.right = work_rect.right;
|
||||
if(source.top < 0)
|
||||
source.top = 0;
|
||||
if(source.bottom > work_rect.bottom)
|
||||
source.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
// Set pointers to the actual data
|
||||
uint8 *dest_bits = (uint8*) destbmp->Bits();
|
||||
uint8 *src_bits = (uint8*) fTarget->Bits();
|
||||
|
||||
// Get row widths for offset looping
|
||||
uint32 dest_width = uint32 (destbmp->BytesPerRow());
|
||||
uint32 src_width = uint32 (fTarget->BytesPerRow());
|
||||
|
||||
// Offset bitmap pointers to proper spot in each bitmap
|
||||
src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) );
|
||||
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
|
||||
|
||||
|
||||
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
|
||||
uint32 lines = uint32 (source.bottom-source.top+1);
|
||||
|
||||
for (uint32 pos_y=0; pos_y<lines; pos_y++)
|
||||
{
|
||||
memcpy(dest_bits,src_bits,line_length);
|
||||
|
||||
// Increment offsets
|
||||
src_bits += src_width;
|
||||
dest_bits += dest_width;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,110 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: BitmapDriver.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: Driver to draw on ServerBitmaps
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _BITMAPDRIVER_H_
|
||||
#define _BITMAPNDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <View.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <Message.h>
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
#include <Region.h> // for clipping_rect definition
|
||||
#include <Bitmap.h>
|
||||
#include <OS.h>
|
||||
|
||||
#include "FontServer.h"
|
||||
#include "GraphicsBuffer.h"
|
||||
#include "PixelRenderer.h"
|
||||
|
||||
#include "DisplayDriverImpl.h"
|
||||
|
||||
class ServerCursor;
|
||||
class ServerBitmap;
|
||||
class RGBColor;
|
||||
class PatternHandler;
|
||||
|
||||
/*!
|
||||
\class BitmapDriver BitmapDriver.h
|
||||
\brief Driver to draw on ServerBitmaps
|
||||
|
||||
This driver is not technically a regular DisplayDriver subclass. BitmapDriver
|
||||
objects are intended for use when a BBitmap is created with the ability to
|
||||
accept child views. It also adds one significant function over regular DisplayDriver
|
||||
child classes - SetTarget. There is also no option for input server emulation, for
|
||||
obvious reasons. Cursor functions are redefined to do absolutely nothing
|
||||
|
||||
Usage: Allocate and call SetTarget on the desired ServerBitmap and start calling
|
||||
graphics methods. All ServerBitmap memory belongs to the BitmapManager.
|
||||
*/
|
||||
class BitmapDriver : public DisplayDriverImpl
|
||||
{
|
||||
public:
|
||||
BitmapDriver();
|
||||
~BitmapDriver();
|
||||
|
||||
void SetTarget(ServerBitmap *target);
|
||||
ServerBitmap *GetTarget() const { return fTarget; }
|
||||
|
||||
// Settings functions
|
||||
// virtual void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d);
|
||||
|
||||
virtual void SetMode(const int32 &mode);
|
||||
virtual void SetMode(const display_mode &mode);
|
||||
virtual void InvertRect(const BRect &rect);
|
||||
protected:
|
||||
virtual bool AcquireBuffer(FBBitmap *bmp);
|
||||
virtual void ReleaseBuffer();
|
||||
|
||||
virtual void Blit(const BRect &src, const BRect &dest, const DrawData *d);
|
||||
virtual void FillSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void FillPatternRect(const BRect &rect, const DrawData *d);
|
||||
virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color);
|
||||
virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d);
|
||||
virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d);
|
||||
virtual void CopyToBitmap(ServerBitmap *target, const BRect &source);
|
||||
|
||||
void ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect);
|
||||
rgb_color GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high=true);
|
||||
void HLinePatternThick(int32 x1, int32 x2, int32 y);
|
||||
void VLinePatternThick(int32 x, int32 y1, int32 y2);
|
||||
// void FillSolidRect(int32 left, int32 top, int32 right, int32 bottom);
|
||||
// void FillPatternRect(int32 left, int32 top, int32 right, int32 bottom);
|
||||
void SetThickPatternPixel(int x, int y);
|
||||
|
||||
ServerBitmap *fTarget;
|
||||
GraphicsBuffer *fGraphicsBuffer;
|
||||
PixelRenderer *fPixelRenderer;
|
||||
|
||||
// NOTE: completely outdated?
|
||||
int fLineThickness;
|
||||
PatternHandler fDrawPattern;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,376 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2003, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: Clipper.cpp
|
||||
// Author: Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Description: A wrapper which translates drawing commands
|
||||
// into appropriately clipped drawing commands.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#include "Clipper.h"
|
||||
#include "LayerData.h"
|
||||
|
||||
Clipper::Clipper(DisplayDriver* driver)
|
||||
{
|
||||
fDriver = driver;
|
||||
}
|
||||
|
||||
Clipper::~Clipper()
|
||||
{
|
||||
}
|
||||
|
||||
void Clipper::DrawBitmap(BRegion* clip_reg, ServerBitmap *bmp, BRect src, BRect dest, LayerData *d)
|
||||
{
|
||||
fDriver->DrawBitmap(bmp,src,dest,d);
|
||||
}
|
||||
|
||||
void Clipper::DrawString(BRegion* clip_reg, const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta)
|
||||
{
|
||||
fDriver->DrawString(string,length,pt,d,edelta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Clipper::FillArc(const BRect r, float angle, float span, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillArc(r,angle,span,color);
|
||||
}
|
||||
|
||||
void Clipper::FillArc(const BRect r, float angle, float span, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillArc(r,angle,span,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillBezier(BPoint *pts, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillBezier(pts,color);
|
||||
}
|
||||
|
||||
void Clipper::FillBezier(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillBezier(pts,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillEllipse(BRect r, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillEllipse(r,color);
|
||||
}
|
||||
|
||||
void Clipper::FillEllipse(BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillEllipse(r,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillPolygon(BPoint *ptlist, int32 numpts, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillPolygon(ptlist,numpts,color);
|
||||
}
|
||||
|
||||
void Clipper::FillPolygon(BPoint *ptlist, int32 numpts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillPolygon(ptlist,numpts,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillRect(const BRect r, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
BRegion reg;
|
||||
reg.Set(r);
|
||||
reg.IntersectWith(clip_reg);
|
||||
fDriver->FillRegion(reg,color);
|
||||
}
|
||||
else
|
||||
fDriver->FillRect(r,color);
|
||||
}
|
||||
|
||||
void Clipper::FillRect(const BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
BRegion reg;
|
||||
reg.Set(r);
|
||||
reg.IntersectWith(clip_reg);
|
||||
fDriver->FillRegion(reg,pattern,high_color,low_color);
|
||||
}
|
||||
else
|
||||
fDriver->FillRect(r,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillRegion(BRegion& r, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
BRegion reg;
|
||||
reg = r;
|
||||
reg.IntersectWith(clip_reg);
|
||||
fDriver->FillRegion(reg,color);
|
||||
}
|
||||
else
|
||||
fDriver->FillRegion(r,color);
|
||||
}
|
||||
|
||||
void Clipper::FillRegion(BRegion& r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
BRegion reg;
|
||||
reg = r;
|
||||
reg.IntersectWith(clip_reg);
|
||||
fDriver->FillRegion(reg,pattern,high_color,low_color);
|
||||
}
|
||||
else
|
||||
fDriver->FillRegion(r,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::FillRoundRect(BRect r, float xrad, float yrad, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
if ( !clip_reg )
|
||||
fDriver->FillRoundRect(r,xrad,yrad,color);
|
||||
else
|
||||
{
|
||||
BRegion reg(r);
|
||||
BRect corner_rect(0,0,xrad,yrad);
|
||||
BRect arc_rect(0,0,2*xrad,2*yrad);
|
||||
corner_rect.OffsetTo(r.left,r.top);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.right-xrad,r.top);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.left,r.bottom-yrad);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.right-xrad,r.bottom-yrad);
|
||||
reg.Exclude(corner_rect);
|
||||
FillRegion(reg,color,clip_reg);
|
||||
arc_rect.OffsetTo(r.left,r.top);
|
||||
FillArc(arc_rect,90,90,color,clip_reg);
|
||||
arc_rect.OffsetTo(r.left,r.bottom-2*yrad);
|
||||
FillArc(arc_rect,180,90,color,clip_reg);
|
||||
arc_rect.OffsetTo(r.right-2*xrad,r.bottom-2*yrad);
|
||||
FillArc(arc_rect,270,90,color,clip_reg);
|
||||
arc_rect.OffsetTo(r.right-2*xrad,r.top);
|
||||
FillArc(arc_rect,0,90,color,clip_reg);
|
||||
}
|
||||
}
|
||||
|
||||
void Clipper::FillRoundRect(BRect r, float xrad, float yrad, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
if ( !clip_reg )
|
||||
fDriver->FillRoundRect(r,xrad,yrad,pattern,high_color,low_color);
|
||||
else
|
||||
{
|
||||
BRegion reg(r);
|
||||
BRect corner_rect(0,0,xrad,yrad);
|
||||
BRect arc_rect(0,0,2*xrad,2*yrad);
|
||||
corner_rect.OffsetTo(r.left,r.top);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.right-xrad,r.top);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.left,r.bottom-yrad);
|
||||
reg.Exclude(corner_rect);
|
||||
corner_rect.OffsetTo(r.right-xrad,r.bottom-yrad);
|
||||
reg.Exclude(corner_rect);
|
||||
FillRegion(reg,pattern,high_color,low_color,clip_reg);
|
||||
arc_rect.OffsetTo(r.left,r.top);
|
||||
FillArc(arc_rect,90,90,pattern,high_color,low_color,clip_reg);
|
||||
arc_rect.OffsetTo(r.left,r.bottom-2*yrad);
|
||||
FillArc(arc_rect,180,90,pattern,high_color,low_color,clip_reg);
|
||||
arc_rect.OffsetTo(r.right-2*xrad,r.bottom-2*yrad);
|
||||
FillArc(arc_rect,270,90,pattern,high_color,low_color,clip_reg);
|
||||
arc_rect.OffsetTo(r.right-2*xrad,r.top);
|
||||
FillArc(arc_rect,0,90,pattern,high_color,low_color,clip_reg);
|
||||
}
|
||||
}
|
||||
|
||||
void Clipper::FillTriangle(BPoint *pts, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillTriangle(pts,color);
|
||||
}
|
||||
|
||||
void Clipper::FillTriangle(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->FillTriangle(pts,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeArc(BRect r, float angle, float span, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeArc(r,angle,span,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeArc(BRect r, float angle, float span, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeArc(r,angle,span,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeBezier(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeBezier(pts,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeBezier(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeBezier(pts,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeEllipse(BRect r, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeEllipse(r,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeEllipse(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeEllipse(r,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeLine(BPoint start, BPoint end, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
int i;
|
||||
BRect currentRect;
|
||||
LineCalc line(start,end);
|
||||
BRect lineBounds(line.MinX(),line.MinY(),line.MaxX(),line.MaxY());
|
||||
for (i=0; i<clip_reg->CountRects(); i++)
|
||||
{
|
||||
currentRect = clip_reg->RectAt(i);
|
||||
if ( currentRect.Intersects(lineBounds) )
|
||||
{
|
||||
if ( currentRect.Contains(start) && currentRect.Contains(end) )
|
||||
{
|
||||
fDriver->StrokeLine(start,end,pensize,color);
|
||||
return;
|
||||
}
|
||||
if ( line.ClipToRect(currentRect) )
|
||||
{
|
||||
fDriver->StrokeLine(line.GetStart(),line.GetEnd(),pensize,color);
|
||||
line.SetPoints(start,end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
fDriver->StrokeLine(start,end,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeLine(BPoint start, BPoint end, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
int i;
|
||||
BRect currentRect;
|
||||
LineCalc line(start,end);
|
||||
BRect lineBounds(line.MinX(),line.MinY(),line.MaxX(),line.MaxY());
|
||||
for (i=0; i<clip_reg->CountRects(); i++)
|
||||
{
|
||||
currentRect = clip_reg->RectAt(i);
|
||||
if ( currentRect.Intersects(lineBounds) )
|
||||
{
|
||||
if ( currentRect.Contains(start) && currentRect.Contains(end) )
|
||||
{
|
||||
fDriver->StrokeLine(start,end,pensize,pattern,high_color,low_color);
|
||||
return;
|
||||
}
|
||||
if ( line.ClipToRect(currentRect) )
|
||||
{
|
||||
fDriver->StrokeLine(line.GetStart(),line.GetEnd(),pensize,pattern,high_color,low_color);
|
||||
line.SetPoints(start,end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
fDriver->StrokeLine(start,end,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, RGBColor& color, bool is_closed, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokePolygon(ptlist,numpts,pensize,color,is_closed);
|
||||
}
|
||||
|
||||
void Clipper::StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, bool is_closed, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokePolygon(ptlist,numpts,pensize,pattern,high_color,low_color,is_closed);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRect(BRect r, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
StrokeLine(r.LeftTop(), r.RightTop(), pensize, color, clip_reg);
|
||||
StrokeLine(r.LeftTop(), r.LeftBottom(), pensize, color, clip_reg);
|
||||
StrokeLine(r.RightTop(), r.RightBottom(), pensize, color, clip_reg);
|
||||
StrokeLine(r.LeftBottom(), r.RightBottom(), pensize, color, clip_reg);
|
||||
}
|
||||
else
|
||||
fDriver->StrokeRect(r,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRect(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
if ( clip_reg )
|
||||
{
|
||||
StrokeLine(r.LeftTop(), r.RightTop(), pensize, pattern, high_color, low_color, clip_reg);
|
||||
StrokeLine(r.LeftTop(), r.LeftBottom(), pensize, pattern, high_color, low_color, clip_reg);
|
||||
StrokeLine(r.RightTop(), r.RightBottom(), pensize, pattern, high_color, low_color, clip_reg);
|
||||
StrokeLine(r.LeftBottom(), r.RightBottom(), pensize, pattern, high_color, low_color, clip_reg);
|
||||
}
|
||||
else
|
||||
fDriver->StrokeRect(r,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRegion(BRegion& r, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeRegion(r,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRegion(BRegion& r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeRegion(r,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeRoundRect(r,xrad,yrad,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeRoundRect(r,xrad,yrad,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeTriangle(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeTriangle(pts,pensize,color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeTriangle(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeTriangle(pts,pensize,pattern,high_color,low_color);
|
||||
}
|
||||
|
||||
void Clipper::StrokeLineArray(BPoint *pts, int32 numlines, float pensize, RGBColor *colors, BRegion* clip_reg)
|
||||
{
|
||||
fDriver->StrokeLineArray(pts,numlines,pensize,colors);
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2003, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: Clipper.h
|
||||
// Author: Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Description: A wrapper which translates drawing commands
|
||||
// into appropriately clipped drawing commands.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _CLIPPER_H_
|
||||
#define _CLIPPER_H_
|
||||
|
||||
#include "DisplayDriver.h"
|
||||
#include "Region.h"
|
||||
#include "Picture.h"
|
||||
|
||||
class Clipper
|
||||
{
|
||||
public:
|
||||
Clipper(DisplayDriver* driver);
|
||||
~Clipper();
|
||||
|
||||
void DrawBitmap(BRegion* clip_reg, ServerBitmap *bmp, BRect src, BRect dest, LayerData *d);
|
||||
void DrawString(BRegion* clip_reg, const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL);
|
||||
|
||||
|
||||
void FillArc(const BRect r, float angle, float span, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillArc(const BRect r, float angle, float span, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillBezier(BPoint *pts, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillBezier(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillEllipse(BRect r, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillEllipse(BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillPolygon(BPoint *ptlist, int32 numpts, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillPolygon(BPoint *ptlist, int32 numpts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillRect(const BRect r, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillRect(const BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillRegion(BRegion& r, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillRegion(BRegion& r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillRoundRect(BRect r, float xrad, float yrad, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillRoundRect(BRect r, float xrad, float yrad, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void FillTriangle(BPoint *pts, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void FillTriangle(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
|
||||
void StrokeArc(BRect r, float angle, float span, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeArc(BRect r, float angle, float span, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeBezier(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeBezier(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeEllipse(BRect r, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeEllipse(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeLine(BPoint start, BPoint end, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeLine(BPoint start, BPoint end, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, RGBColor& color, bool is_closed=true, BRegion* clip_reg=NULL);
|
||||
void StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, bool is_closed=true, BRegion* clip_reg=NULL);
|
||||
void StrokeRect(BRect r, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeRect(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeRegion(BRegion& r, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeRegion(BRegion& r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
void StrokeTriangle(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg=NULL);
|
||||
void StrokeTriangle(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL);
|
||||
|
||||
void StrokeLineArray(BPoint *pts, int32 numlines, float pensize, RGBColor *colors, BRegion* clip_reg=NULL);
|
||||
private:
|
||||
DisplayDriver* fDriver;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,249 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: CursorHandler.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: class for handling cursor display for DisplayDriver
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#include "CursorHandler.h"
|
||||
#include "DisplayDriver.h"
|
||||
#include "RectUtils.h"
|
||||
|
||||
CursorHandler::CursorHandler(DisplayDriver *driver)
|
||||
: fDriver(driver),
|
||||
fOldPosition(0,0,0,0),
|
||||
fPosition(0,0,0,0),
|
||||
fCursorPos(0,0),
|
||||
fSavedData(NULL),
|
||||
fCursor(NULL),
|
||||
fHideLevel(0),
|
||||
fDrawData(),
|
||||
fDriverHidden(false),
|
||||
fIsObscured(false),
|
||||
fValidSaveData(false)
|
||||
{
|
||||
}
|
||||
|
||||
//! Frees any memory used for saving screen data
|
||||
CursorHandler::~CursorHandler(void)
|
||||
{
|
||||
delete fSavedData;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Tests to see if the passed rectangle intersects the cursor's current position
|
||||
\param r The rectangle to test against
|
||||
\return true if r intersects the cursor's current screen footprint
|
||||
*/
|
||||
bool CursorHandler::IntersectsCursor(const BRect &r)
|
||||
{
|
||||
return TestRectIntersection(r, fPosition);
|
||||
}
|
||||
|
||||
void CursorHandler::SetCursor(ServerCursor *cursor)
|
||||
{
|
||||
// we may start empty, but we will never need to stay that way
|
||||
if(!cursor)
|
||||
return;
|
||||
|
||||
Hide();
|
||||
|
||||
if(fSavedData && cursor->Bounds()!=fSavedData->Bounds())
|
||||
{
|
||||
delete fSavedData;
|
||||
fSavedData=NULL;
|
||||
}
|
||||
|
||||
if(!fSavedData)
|
||||
fSavedData=new UtilityBitmap(cursor);
|
||||
|
||||
fCursor=cursor;
|
||||
|
||||
// We change the position rectangles to reflect the new cursor, compensating for the
|
||||
// new cursor's hotspot.
|
||||
fPosition=cursor->Bounds().OffsetToCopy(fCursorPos.x-fCursor->GetHotSpot().x,
|
||||
fCursorPos.y-fCursor->GetHotSpot().y);
|
||||
fOldPosition=fPosition;
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Moves the cursor to the specified place on screen
|
||||
\param pt The new cursor location
|
||||
|
||||
This function fails if asked to move the cursor outside the screen boundaries
|
||||
*/
|
||||
void CursorHandler::MoveTo(BPoint pt)
|
||||
{
|
||||
pt.x = max_c(pt.x, 0.0);
|
||||
pt.y = max_c(pt.y, 0.0);
|
||||
pt.x = min_c(pt.x, fDriver->DisplayMode()->virtual_width - 1);
|
||||
pt.y = min_c(pt.y, fDriver->DisplayMode()->virtual_height - 1);
|
||||
|
||||
if (fCursorPos != pt) {
|
||||
|
||||
fCursorPos=pt;
|
||||
|
||||
if (!fSavedData)
|
||||
debugger("NULL savedata\n");
|
||||
|
||||
fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData);
|
||||
fPosition.OffsetTo(fCursorPos.x-fCursor->GetHotSpot().x,
|
||||
fCursorPos.y-fCursor->GetHotSpot().y);
|
||||
fDriver->CopyToBitmap(fSavedData,fPosition);
|
||||
|
||||
fDrawData.draw_mode=B_OP_ALPHA;
|
||||
fDriver->CopyBitmap(fCursor,fCursor->Bounds(),fPosition,&fDrawData);
|
||||
fDrawData.draw_mode=B_OP_COPY;
|
||||
|
||||
fDriver->Invalidate(fOldPosition);
|
||||
fOldPosition=fPosition;
|
||||
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
||||
}
|
||||
|
||||
//! Shows the cursor. Unlike BView, calls are not cumulative
|
||||
void CursorHandler::Show(void)
|
||||
{
|
||||
// This call is pretty simple -- save the area underneath the cursor and draw the thing
|
||||
|
||||
if (fHideLevel == 0)
|
||||
return;
|
||||
|
||||
fIsObscured = false;
|
||||
fHideLevel--;
|
||||
|
||||
if (fHideLevel > 0)
|
||||
return;
|
||||
|
||||
fOldPosition = fPosition;
|
||||
|
||||
if (!fCursor)
|
||||
return;
|
||||
|
||||
fValidSaveData = true;
|
||||
|
||||
if (!fSavedData)
|
||||
fSavedData = new UtilityBitmap(fCursor->Bounds(),
|
||||
(color_space)fDriver->DisplayMode()->space, 0);
|
||||
|
||||
fDriver->CopyToBitmap(fSavedData, fPosition);
|
||||
|
||||
// Draw the data to the buffer
|
||||
fDrawData.draw_mode = B_OP_ALPHA;
|
||||
fDriver->CopyBitmap(fCursor, fCursor->Bounds(), fPosition, &fDrawData);
|
||||
fDrawData.draw_mode = B_OP_COPY;
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
||||
|
||||
//! Hides the cursor. Unlike BView, calls are not cumulative
|
||||
void CursorHandler::Hide(void)
|
||||
{
|
||||
fHideLevel++;
|
||||
|
||||
// TODO: find out what the behavior is if a Hide is called on an obscured cursor
|
||||
|
||||
// For now, we will change the state from obscured to hidden and leave it at that
|
||||
if(fIsObscured)
|
||||
{
|
||||
fIsObscured=false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(fHideLevel>1)
|
||||
return;
|
||||
|
||||
if(!fCursor)
|
||||
return;
|
||||
|
||||
if(!fSavedData)
|
||||
fSavedData=new UtilityBitmap(fCursor);
|
||||
|
||||
fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData);
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
||||
|
||||
//! Hides the cursor until the next MoveTo call. Unlike BView, calls are not cumulative
|
||||
void CursorHandler::Obscure(void)
|
||||
{
|
||||
if(IsObscured())
|
||||
return;
|
||||
|
||||
fIsObscured=true;
|
||||
|
||||
// TODO: find out what the behavior is if an Obscure is called on a hidden cursor
|
||||
|
||||
// For now, we will change the state from obscured to hidden and leave it at that
|
||||
if(fHideLevel>0)
|
||||
{
|
||||
fHideLevel=0;
|
||||
return;
|
||||
}
|
||||
|
||||
fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData);
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
||||
|
||||
void CursorHandler::DriverHide(void)
|
||||
{
|
||||
if(fDriverHidden)
|
||||
return;
|
||||
|
||||
fDriverHidden=true;
|
||||
|
||||
if(!fCursor)
|
||||
return;
|
||||
|
||||
if(!fSavedData)
|
||||
fSavedData=new UtilityBitmap(fCursor);
|
||||
|
||||
fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData);
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
||||
|
||||
void CursorHandler::DriverShow(void)
|
||||
{
|
||||
if(!fDriverHidden)
|
||||
return;
|
||||
|
||||
fDriverHidden=false;
|
||||
|
||||
fOldPosition=fPosition;
|
||||
|
||||
if(!fCursor)
|
||||
return;
|
||||
|
||||
fValidSaveData=true;
|
||||
|
||||
if(!fSavedData)
|
||||
fSavedData=new UtilityBitmap(fCursor->Bounds(),(color_space)fDriver->DisplayMode()->space,0);
|
||||
|
||||
fDriver->CopyToBitmap(fSavedData,fPosition);
|
||||
|
||||
// Draw the data to the buffer
|
||||
fDrawData.draw_mode=B_OP_ALPHA;
|
||||
fDriver->CopyBitmap(fCursor,fCursor->Bounds(),fPosition,&fDrawData);
|
||||
fDrawData.draw_mode=B_OP_COPY;
|
||||
fDriver->Invalidate(fPosition);
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: CursorHandler.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: class for handling cursor display for DisplayDriver
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef CURSORHANDLER_H
|
||||
#define CURSORHANDLER_H
|
||||
|
||||
#include "GraphicsBuffer.h"
|
||||
#include "LayerData.h"
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerBitmap.h"
|
||||
|
||||
class DisplayDriver;
|
||||
|
||||
/*!
|
||||
\class CursorHandler CursorHandler.h
|
||||
\brief Object used by DisplayDriver to handle all the messiness of displaying the cursor
|
||||
*/
|
||||
class CursorHandler
|
||||
{
|
||||
public:
|
||||
CursorHandler(DisplayDriver *driver);
|
||||
~CursorHandler(void);
|
||||
|
||||
bool IntersectsCursor(const BRect &r);
|
||||
|
||||
void SetCursor(ServerCursor *cursor);
|
||||
ServerCursor *GetCursor(void) const { return fCursor; }
|
||||
|
||||
void MoveTo(BPoint pt);
|
||||
BPoint GetPosition(void) const { return fPosition.LeftTop(); }
|
||||
|
||||
void Hide(void);
|
||||
void Show(void);
|
||||
void Obscure(void);
|
||||
bool IsHidden(void) const { return (fHideLevel>0); }
|
||||
bool IsObscured(void) const { return fIsObscured; }
|
||||
|
||||
void DriverHide(void);
|
||||
void DriverShow(void);
|
||||
private:
|
||||
|
||||
DisplayDriver *fDriver;
|
||||
|
||||
BRect fOldPosition;
|
||||
BRect fPosition;
|
||||
BPoint fCursorPos;
|
||||
|
||||
UtilityBitmap *fSavedData;
|
||||
ServerCursor *fCursor;
|
||||
int8 fHideLevel;
|
||||
DrawData fDrawData;
|
||||
|
||||
bool fDriverHidden;
|
||||
bool fIsObscured;
|
||||
bool fValidSaveData;
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,174 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: DirectDriver.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: BDirectWindow graphics module
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef DIRECTDRIVER_H_
|
||||
#define DIRECTDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <Region.h> // for clipping_rect definition
|
||||
#include <GraphicsCard.h>
|
||||
#include <Message.h>
|
||||
#include "PortLink.h"
|
||||
#include <DirectWindow.h>
|
||||
#include "PatternHandler.h"
|
||||
|
||||
#include "DisplayDriverImpl.h"
|
||||
|
||||
class UtilityBitmap;
|
||||
class SDWindow;
|
||||
class LayerData;
|
||||
class DirectDriver;
|
||||
|
||||
// This is very much not the fastest thing in the world - just quickly hacked out to get it going
|
||||
// and make it relatively easy to optimize later. Ideally, rectangles stored in this should be
|
||||
// stored in a singly-linked list and allocated items should be saved (and freed upon the object's
|
||||
// destruction) to minimize calls to the OS' memory manager.
|
||||
class RectPipe
|
||||
{
|
||||
public:
|
||||
RectPipe();
|
||||
~RectPipe();
|
||||
|
||||
void PutRect(const BRect &rect);
|
||||
void PutRect(const clipping_rect &rect);
|
||||
bool GetRect(clipping_rect *rect);
|
||||
bool HasRects();
|
||||
int32 CountRects() const { return list.CountItems(); }
|
||||
protected:
|
||||
BList list;
|
||||
BLocker lock;
|
||||
bool has_rects;
|
||||
};
|
||||
|
||||
class DDView : public BView
|
||||
{
|
||||
public:
|
||||
DDView(BRect bounds);
|
||||
void MouseDown(BPoint pt);
|
||||
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
|
||||
void MouseUp(BPoint pt);
|
||||
void MessageReceived(BMessage *msg);
|
||||
|
||||
BPortLink serverlink;
|
||||
};
|
||||
|
||||
class DDWindow : public BDirectWindow
|
||||
{
|
||||
public:
|
||||
DDWindow(uint16 width, uint16 height, color_space space, DirectDriver *owner);
|
||||
~DDWindow();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void DirectConnected(direct_buffer_info *info);
|
||||
virtual void WindowActivated(bool active);
|
||||
static int32 DrawingThread(void *data);
|
||||
|
||||
uint8 *fBits;
|
||||
int32 fRowBytes;
|
||||
color_space fFormat;
|
||||
clipping_rect fBounds;
|
||||
uint32 fNumClipRects;
|
||||
clipping_rect *fClipList;
|
||||
|
||||
bool fDirty, fConnected, fConnectionDisabled;
|
||||
BLocker locker;
|
||||
thread_id fDrawThreadID;
|
||||
DisplayDriver *fOwner;
|
||||
BBitmap *framebuffer;
|
||||
clipping_rect screensize;
|
||||
RectPipe rectpipe;
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief BDirectWindow graphics module
|
||||
|
||||
Last (and best) driver class in the app_server which is designed
|
||||
to provide fast graphics access for testing.
|
||||
|
||||
The concept is to have a bitmap get written to which is used for double-buffering
|
||||
the video display. An updater thread simply locks access to this bitmap, copies data to
|
||||
the framebuffer, and releases access. Derived DisplayDriver functions operate on this bitmap.
|
||||
*/
|
||||
class DirectDriver : public DisplayDriverImpl
|
||||
{
|
||||
public:
|
||||
DirectDriver();
|
||||
~DirectDriver();
|
||||
|
||||
virtual bool Initialize();
|
||||
virtual void Shutdown();
|
||||
|
||||
// void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d);
|
||||
|
||||
virtual void InvertRect(const BRect &r);
|
||||
|
||||
virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *linedata, const DrawData *d);
|
||||
|
||||
virtual void SetMode(const display_mode &mode);
|
||||
|
||||
virtual bool DumpToFile(const char *path);
|
||||
|
||||
virtual status_t SetDPMSMode(const uint32 &state);
|
||||
virtual uint32 DPMSMode();
|
||||
virtual uint32 DPMSCapabilities();
|
||||
virtual status_t GetDeviceInfo(accelerant_device_info *info);
|
||||
virtual status_t GetModeList(display_mode **mode_list, uint32 *count);
|
||||
virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high);
|
||||
virtual status_t GetTimingConstraints(display_timing_constraints *dtc);
|
||||
virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high);
|
||||
virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
|
||||
BBitmap *framebuffer;
|
||||
display_mode fCurrentScreenMode, fSavedScreenMode;
|
||||
|
||||
protected:
|
||||
virtual void FillSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void FillPatternRect(const BRect &rect, const DrawData *d);
|
||||
virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color);
|
||||
virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d);
|
||||
virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source,
|
||||
const BRect &dest, const DrawData *d);
|
||||
virtual void CopyToBitmap(ServerBitmap *target, const BRect &source);
|
||||
|
||||
// Temporary function which will exist while we use BViews in the regular code
|
||||
void SetDrawData(const DrawData *d, bool set_font_data=false);
|
||||
|
||||
// temporarily virtual - until clipping code is added in DisplayDriver
|
||||
virtual void ConstrainClippingRegion(BRegion *reg);
|
||||
|
||||
rgb_color GetBlitColor(rgb_color src, rgb_color dest,DrawData *d, bool use_high=true);
|
||||
|
||||
BPortLink *serverlink;
|
||||
DDWindow *screenwin;
|
||||
BView *drawview;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,433 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: DisplayDriver.h
|
||||
// Authors: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Stephan Aßmus <superstippi@gmx.de>
|
||||
//
|
||||
// Description: Abstract class which handles all graphics output
|
||||
// for the server
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _DISPLAY_DRIVER_IMPL_H_
|
||||
#define _DISPLAY_DRIVER_IMPL_H_
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <View.h>
|
||||
#include <Rect.h>
|
||||
#include <Screen.h>
|
||||
#include <Region.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
//#include "CursorHandler.h"
|
||||
#include "DisplaySupport.h"
|
||||
#include "LayerData.h"
|
||||
#include "PatternHandler.h"
|
||||
#include "RGBColor.h"
|
||||
#include "ServerBitmap.h"
|
||||
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
#ifndef ROUND
|
||||
#define ROUND(a) ( (long)(a+.5) )
|
||||
#endif
|
||||
|
||||
|
||||
class ServerCursor;
|
||||
|
||||
/*!
|
||||
\brief Data structure for passing cursor information to hardware drivers.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uchar *xormask, *andmask;
|
||||
int32 width, height;
|
||||
int32 hotx, hoty;
|
||||
|
||||
} cursor_data;
|
||||
|
||||
#ifndef HOOK_DEFINE_CURSOR
|
||||
|
||||
#define HOOK_DEFINE_CURSOR 0
|
||||
#define HOOK_MOVE_CURSOR 1
|
||||
#define HOOK_SHOW_CURSOR 2
|
||||
#define HOOK_DRAW_LINE_8BIT 3
|
||||
#define HOOK_DRAW_LINE_16BIT 12
|
||||
#define HOOK_DRAW_LINE_32BIT 4
|
||||
#define HOOK_DRAW_RECT_8BIT 5
|
||||
#define HOOK_DRAW_RECT_16BIT 13
|
||||
#define HOOK_DRAW_RECT_32BIT 6
|
||||
#define HOOK_BLIT 7
|
||||
#define HOOK_DRAW_ARRAY_8BIT 8
|
||||
#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers
|
||||
#define HOOK_DRAW_ARRAY_32BIT 9
|
||||
#define HOOK_SYNC 10
|
||||
#define HOOK_INVERT_RECT 11
|
||||
|
||||
#endif
|
||||
|
||||
class DisplayDriverImpl;
|
||||
|
||||
typedef void (DisplayDriverImpl::* SetPixelFuncType)(int x, int y);
|
||||
typedef void (DisplayDriverImpl::* SetHorizontalLineFuncType)(int xstart, int xend, int y);
|
||||
typedef void (DisplayDriverImpl::* SetVerticalLineFuncType)(int x, int ystart, int yend);
|
||||
typedef void (DisplayDriverImpl::* SetRectangleFuncType)(int left, int top, int right, int bottom);
|
||||
|
||||
/*!
|
||||
\class DisplayDriverImpl DisplayDriverImpl.h
|
||||
\brief original DisplayDriver implementation.
|
||||
|
||||
While all virtual functions are technically optional, the default versions
|
||||
do very little, so implementing them all more or less required.
|
||||
*/
|
||||
|
||||
class DisplayDriverImpl : public DisplayDriver {
|
||||
public:
|
||||
DisplayDriverImpl();
|
||||
virtual ~DisplayDriverImpl();
|
||||
|
||||
// Graphics calls implemented in DisplayDriver
|
||||
virtual void CopyBits( const BRect &src,
|
||||
const BRect &dest,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void CopyRegion( BRegion *src,
|
||||
const BPoint &lefttop);
|
||||
|
||||
virtual void InvertRect( const BRect &r);
|
||||
|
||||
virtual void DrawBitmap( BRegion *region,
|
||||
ServerBitmap *bitmap,
|
||||
const BRect &source,
|
||||
const BRect &dest,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void CopyRegionList( BList* list,
|
||||
BList* pList,
|
||||
int32 rCount,
|
||||
BRegion* clipReg);
|
||||
|
||||
virtual void FillArc( const BRect &r,
|
||||
const float &angle,
|
||||
const float &span,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillBezier( BPoint *pts,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillEllipse( const BRect &r,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillPolygon( BPoint *ptlist,
|
||||
int32 numpts,
|
||||
const BRect &bounds,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillRect( const BRect &r,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void FillRect( const BRect &r,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillRegion( BRegion &r,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillRoundRect( const BRect &r,
|
||||
const float &xrad,
|
||||
const float &yrad,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillShape( const BRect &bounds,
|
||||
const int32 &opcount,
|
||||
const int32 *oplist,
|
||||
const int32 &ptcount,
|
||||
const BPoint *ptlist,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillTriangle( BPoint *pts,
|
||||
const BRect &bounds,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeArc( const BRect &r,
|
||||
const float &angle,
|
||||
const float &span,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeBezier( BPoint *pts,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeEllipse( const BRect &r,
|
||||
const DrawData *d);
|
||||
|
||||
// this version used by Decorator
|
||||
virtual void StrokeLine( const BPoint &start,
|
||||
const BPoint &end,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void StrokeLine( const BPoint &start,
|
||||
const BPoint &end,
|
||||
DrawData *d);
|
||||
|
||||
// this version used by Decorator
|
||||
virtual void StrokePoint( const BPoint &pt,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void StrokePoint( const BPoint &pt,
|
||||
DrawData *d);
|
||||
|
||||
virtual void StrokePolygon( BPoint *ptlist,
|
||||
int32 numpts,
|
||||
const BRect &bounds,
|
||||
const DrawData *d,
|
||||
bool is_closed=true);
|
||||
|
||||
// this version used by Decorator
|
||||
virtual void StrokeRect( const BRect &r,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void StrokeRect( const BRect &r,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeRegion( BRegion &r,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeRoundRect(const BRect &r,
|
||||
const float &xrad,
|
||||
const float &yrad,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeShape( const BRect &bounds,
|
||||
const int32 &opcount,
|
||||
const int32 *oplist,
|
||||
const int32 &ptcount,
|
||||
const BPoint *ptlist,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeTriangle( BPoint *pts,
|
||||
const BRect &bounds,
|
||||
const DrawData *d);
|
||||
|
||||
// Font-related calls
|
||||
|
||||
// DrawData is NOT const because this call updates the pen position in the passed DrawData
|
||||
virtual void DrawString(const char *string,
|
||||
const int32 &length,
|
||||
const BPoint &pt,
|
||||
DrawData *d);
|
||||
|
||||
virtual void DrawString(const char *string,
|
||||
const int32 &length,
|
||||
const BPoint &pt,
|
||||
const RGBColor &color,
|
||||
escapement_delta *delta=NULL);
|
||||
|
||||
virtual float StringWidth(const char *string,
|
||||
int32 length,
|
||||
const DrawData *d);
|
||||
|
||||
virtual float StringHeight(const char *string,
|
||||
int32 length,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void GetBoundingBoxes(const char *string,
|
||||
int32 count,
|
||||
font_metric_mode mode,
|
||||
escapement_delta *delta,
|
||||
BRect *rectarray,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void GetEscapements(const char *string,
|
||||
int32 charcount,
|
||||
escapement_delta *delta,
|
||||
escapement_delta *escapements,
|
||||
escapement_delta *offsets,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void GetEdges(const char *string,
|
||||
int32 charcount,
|
||||
edge_info *edgearray,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void GetHasGlyphs(const char *string,
|
||||
int32 charcount,
|
||||
bool *hasarray);
|
||||
|
||||
virtual void GetTruncatedStrings(const char **instrings,
|
||||
const int32 &stringcount,
|
||||
const uint32 &mode,
|
||||
const float &maxwidth,
|
||||
char **outstrings);
|
||||
|
||||
// cursor handling
|
||||
virtual void HideCursor();
|
||||
virtual bool IsCursorHidden();
|
||||
virtual void MoveCursorTo( const float &x,
|
||||
const float &y);
|
||||
virtual void ShowCursor();
|
||||
virtual void ObscureCursor();
|
||||
virtual void SetCursor(ServerCursor *cursor);
|
||||
BPoint GetCursorPosition();
|
||||
virtual bool IsCursorObscured(bool state);
|
||||
|
||||
|
||||
// These two will rarely be implemented by subclasses,
|
||||
// but it still needs to be possible
|
||||
virtual bool Lock(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||
virtual void Unlock();
|
||||
|
||||
virtual bool DumpToFile(const char *path);
|
||||
virtual ServerBitmap* DumpToBitmap();
|
||||
|
||||
virtual void StrokeLineArray(const int32 &numlines,
|
||||
const LineArrayData *data,
|
||||
const DrawData *d);
|
||||
|
||||
virtual status_t SetDPMSMode(const uint32 &state);
|
||||
virtual uint32 DPMSMode();
|
||||
virtual uint32 DPMSCapabilities();
|
||||
|
||||
virtual status_t GetDeviceInfo(accelerant_device_info *info);
|
||||
|
||||
virtual status_t GetModeList(display_mode **mode_list,
|
||||
uint32 *count);
|
||||
|
||||
virtual status_t GetPixelClockLimits(display_mode *mode,
|
||||
uint32 *low,
|
||||
uint32 *high);
|
||||
|
||||
virtual status_t GetTimingConstraints(display_timing_constraints *dtc);
|
||||
virtual status_t ProposeMode(display_mode *candidate,
|
||||
const display_mode *low,
|
||||
const display_mode *high);
|
||||
|
||||
virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||
|
||||
|
||||
// needed by CursorHandler
|
||||
virtual void CopyBitmap(ServerBitmap *bitmap,
|
||||
const BRect &source,
|
||||
const BRect &dest,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void CopyToBitmap(ServerBitmap *target,
|
||||
const BRect &source);
|
||||
|
||||
// This is for drivers which are internally double buffered
|
||||
// and calling this will cause the real framebuffer to be updated
|
||||
virtual void Invalidate(const BRect &r);
|
||||
|
||||
// temporarily virtual - until clipping code is added in DisplayDriver
|
||||
// needed by Layer
|
||||
virtual void ConstrainClippingRegion(BRegion *reg);
|
||||
|
||||
protected:
|
||||
//friend class Layer;
|
||||
friend class WinBorder;
|
||||
//friend CursorHandler;
|
||||
|
||||
ServerCursor* _GetCursor();
|
||||
|
||||
virtual void HLinePatternThick(int32 x1, int32 x2, int32 y);
|
||||
|
||||
virtual void VLinePatternThick(int32 x, int32 y1, int32 y2);
|
||||
|
||||
virtual void SetThickPatternPixel(int x, int y);
|
||||
|
||||
// Blit functions specific to FreeType2 glyph copying.
|
||||
// These probably could be replaced with more generic functions,
|
||||
// but these are written and can be replaced later.
|
||||
void BlitMono2RGB32(FT_Bitmap *src,
|
||||
const BPoint &pt,
|
||||
const DrawData *d);
|
||||
|
||||
void BlitGray2RGB32(FT_Bitmap *src,
|
||||
const BPoint &pt,
|
||||
const DrawData *d);
|
||||
|
||||
// Two functions for gaining direct access to the framebuffer
|
||||
// of a child class. This removes the need for a set of
|
||||
// glyph-blitting virtual functions for each driver.
|
||||
virtual bool AcquireBuffer(FBBitmap *bmp);
|
||||
virtual void ReleaseBuffer();
|
||||
|
||||
|
||||
/* void FillBezier(BPoint *pts,
|
||||
DisplayDriver* driver,
|
||||
SetHorizontalLineFuncType setLine);
|
||||
|
||||
void FillRegion(BRegion &r,
|
||||
DisplayDriver* driver,
|
||||
SetRectangleFuncType setRect);
|
||||
|
||||
void StrokeArc(const BRect &r,
|
||||
const float &angle,
|
||||
const float &span,
|
||||
DisplayDriver* driver,
|
||||
SetPixelFuncType setPixel);
|
||||
|
||||
void StrokeBezier(BPoint *pts,
|
||||
DisplayDriver* driver,
|
||||
SetPixelFuncType setPixel);
|
||||
|
||||
void StrokeEllipse(const BRect &r,
|
||||
DisplayDriver* driver,
|
||||
SetPixelFuncType setPixel);
|
||||
|
||||
void StrokeLine(const BPoint &start,
|
||||
const BPoint &end,
|
||||
DisplayDriver* driver,
|
||||
SetPixelFuncType setPixel);*/
|
||||
|
||||
// Support functions for the rest of the driver
|
||||
virtual void Blit(const BRect &src,
|
||||
const BRect &dest,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void FillSolidRect(const BRect &rect,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void FillPatternRect(const BRect &rect,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeSolidLine(int32 x1, int32 y1,
|
||||
int32 x2, int32 y2,
|
||||
const RGBColor &color);
|
||||
|
||||
virtual void StrokePatternLine(int32 x1, int32 y1,
|
||||
int32 x2, int32 y2,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void StrokeSolidRect(const BRect &rect,
|
||||
const RGBColor &color);
|
||||
|
||||
protected:
|
||||
BLocker fLocker;
|
||||
CursorHandler fCursorHandler;
|
||||
|
||||
uint32 fDPMSState;
|
||||
uint32 fDPMSCaps;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,473 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: DisplaySupport.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Description: Support classes for the DisplayDriver class
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#include "DisplaySupport.h"
|
||||
|
||||
BezierCurve::BezierCurve(BPoint* pts)
|
||||
{
|
||||
int i;
|
||||
|
||||
pointArray = NULL;
|
||||
for (i=0; i<4; i++)
|
||||
points.AddItem(new BPoint(pts[i]));
|
||||
GenerateFrame(pts);
|
||||
GeneratePoints(0);
|
||||
}
|
||||
|
||||
BezierCurve::~BezierCurve()
|
||||
{
|
||||
int i, numPoints;
|
||||
|
||||
numPoints = points.CountItems();
|
||||
for (i=0; i<numPoints; i++)
|
||||
delete (BPoint*)points.ItemAt(i);
|
||||
if ( pointArray )
|
||||
delete[] pointArray;
|
||||
}
|
||||
|
||||
BPoint* BezierCurve::GetPointArray()
|
||||
{
|
||||
int i, numPoints;
|
||||
|
||||
if ( !pointArray )
|
||||
{
|
||||
numPoints = points.CountItems();
|
||||
pointArray = new BPoint[numPoints];
|
||||
for (i=0; i<numPoints; i++)
|
||||
pointArray[i] = *((BPoint*)points.ItemAt(i));
|
||||
}
|
||||
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)
|
||||
{
|
||||
double slopeAB, slopeBC, slopeCD;
|
||||
BPoint** pointList = (BPoint **)points.Items();
|
||||
|
||||
// TODO Check for more conditions where we can fudge the curve to a line
|
||||
|
||||
if ( (fabs(pointList[startPos]->x-pointList[startPos+3]->x) <= 1) &&
|
||||
(fabs(pointList[startPos]->y-pointList[startPos+3]->y) <= 1) )
|
||||
return 0;
|
||||
|
||||
if ( (pointList[startPos]->x == pointList[startPos+1]->x) &&
|
||||
(pointList[startPos+1]->x == pointList[startPos+2]->x) &&
|
||||
(pointList[startPos+2]->x == pointList[startPos+3]->x) )
|
||||
return 0;
|
||||
|
||||
slopeAB = (pointList[startPos]->y-pointList[startPos+1]->y)/(pointList[startPos]->x-pointList[startPos+1]->x);
|
||||
slopeBC = (pointList[startPos+1]->y-pointList[startPos+2]->y)/(pointList[startPos+1]->x-pointList[startPos+2]->x);
|
||||
slopeCD = (pointList[startPos+2]->y-pointList[startPos+3]->y)/(pointList[startPos+2]->x-pointList[startPos+3]->x);
|
||||
|
||||
if ( (slopeAB == slopeBC) && (slopeBC == slopeCD) )
|
||||
return 0;
|
||||
|
||||
BPoint *pointAB = new BPoint();
|
||||
BPoint pointBC;
|
||||
BPoint *pointCD = new BPoint();
|
||||
BPoint *pointABC = new BPoint();
|
||||
BPoint *pointBCD = new BPoint();
|
||||
BPoint *curvePoint = new BPoint();
|
||||
int lengthIncrement = 3;
|
||||
|
||||
pointAB->x = (pointList[startPos]->x + pointList[startPos+1]->x)/2;
|
||||
pointAB->y = (pointList[startPos]->y + pointList[startPos+1]->y)/2;
|
||||
pointBC.x = (pointList[startPos+1]->x + pointList[startPos+2]->x)/2;
|
||||
pointBC.y = (pointList[startPos+1]->y + pointList[startPos+2]->y)/2;
|
||||
pointCD->x = (pointList[startPos+2]->x + pointList[startPos+3]->x)/2;
|
||||
pointCD->y = (pointList[startPos+2]->y + pointList[startPos+3]->y)/2;
|
||||
pointABC->x = (pointAB->x + pointBC.x)/2;
|
||||
pointABC->y = (pointAB->y + pointBC.y)/2;
|
||||
pointBCD->x = (pointCD->x + pointBC.x)/2;
|
||||
pointBCD->y = (pointCD->y + pointBC.y)/2;
|
||||
curvePoint->x = (pointABC->x + pointBCD->x)/2;
|
||||
curvePoint->y = (pointABC->y + pointBCD->y)/2;
|
||||
delete pointList[startPos+1];
|
||||
delete pointList[startPos+2];
|
||||
pointList[startPos+1] = pointAB;
|
||||
pointList[startPos+2] = pointCD;
|
||||
points.AddItem(pointABC,startPos+2);
|
||||
points.AddItem(curvePoint,startPos+3);
|
||||
points.AddItem(pointBCD,startPos+4);
|
||||
lengthIncrement += GeneratePoints(startPos);
|
||||
lengthIncrement += GeneratePoints(startPos + lengthIncrement);
|
||||
return lengthIncrement;
|
||||
}
|
||||
|
||||
Blitter::Blitter()
|
||||
{
|
||||
DrawFunc = &Blitter::draw_none;
|
||||
}
|
||||
|
||||
void Blitter::draw_8_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint8 *s = (uint8 *)src;
|
||||
uint8 *d = (uint8 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_8_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint8 *s = (uint8 *)src;
|
||||
uint16 *d = (uint16 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_8_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint8 *s = (uint8 *)src;
|
||||
uint32 *d = (uint32 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_16_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint16 *s = (uint16 *)src;
|
||||
uint8 *d = (uint8 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_16_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint16 *s = (uint16 *)src;
|
||||
uint16 *d = (uint16 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_16_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint16 *s = (uint16 *)src;
|
||||
uint32 *d = (uint32 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_32_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint32 *s = (uint32 *)src;
|
||||
uint8 *d = (uint8 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_32_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint32 *s = (uint32 *)src;
|
||||
uint16 *d = (uint16 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::draw_32_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
uint32 *s = (uint32 *)src;
|
||||
uint32 *d = (uint32 *)dst;
|
||||
|
||||
while(width--)
|
||||
{
|
||||
*d++ = s[xscale_position >> 16];
|
||||
xscale_position += xscale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Blitter::Draw(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor)
|
||||
{
|
||||
(this->*DrawFunc)(src, dst, width, xscale_position, xscale_factor);
|
||||
}
|
||||
|
||||
void Blitter::Select(int32 source_bits_per_pixel, int32 dest_bits_per_pixel)
|
||||
{
|
||||
if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 8)
|
||||
DrawFunc = &Blitter::draw_8_to_8;
|
||||
else if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 16)
|
||||
DrawFunc = &Blitter::draw_8_to_16;
|
||||
else if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 32)
|
||||
DrawFunc = &Blitter::draw_8_to_32;
|
||||
else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 16)
|
||||
DrawFunc = &Blitter::draw_16_to_16;
|
||||
else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 8)
|
||||
DrawFunc = &Blitter::draw_16_to_8;
|
||||
else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 32)
|
||||
DrawFunc = &Blitter::draw_16_to_32;
|
||||
else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 32)
|
||||
DrawFunc = &Blitter::draw_32_to_32;
|
||||
else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 16)
|
||||
DrawFunc = &Blitter::draw_32_to_16;
|
||||
else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 8)
|
||||
DrawFunc = &Blitter::draw_32_to_8;
|
||||
else
|
||||
DrawFunc = &Blitter::draw_none;
|
||||
}
|
||||
|
||||
LineCalc::LineCalc()
|
||||
{
|
||||
}
|
||||
|
||||
LineCalc::LineCalc(const BPoint &pta, const BPoint &ptb)
|
||||
{
|
||||
start=pta;
|
||||
end=ptb;
|
||||
slope=(start.y-end.y)/(start.x-end.x);
|
||||
offset=start.y-(slope * start.x);
|
||||
minx = MIN(start.x,end.x);
|
||||
maxx = MAX(start.x,end.x);
|
||||
miny = MIN(start.y,end.y);
|
||||
maxy = MAX(start.y,end.y);
|
||||
}
|
||||
|
||||
void LineCalc::SetPoints(const BPoint &pta, const BPoint &ptb)
|
||||
{
|
||||
start=pta;
|
||||
end=ptb;
|
||||
slope=(start.y-end.y)/(start.x-end.x);
|
||||
offset=start.y-(slope * start.x);
|
||||
minx = MIN(start.x,end.x);
|
||||
maxx = MAX(start.x,end.x);
|
||||
miny = MIN(start.y,end.y);
|
||||
maxy = MAX(start.y,end.y);
|
||||
}
|
||||
|
||||
bool LineCalc::ClipToRect(const BRect& rect)
|
||||
{
|
||||
if ( (maxx < rect.left) || (minx > rect.right) || (miny < rect.top) || (maxy > rect.bottom) )
|
||||
return false;
|
||||
BPoint newStart(-1,-1);
|
||||
BPoint newEnd(-1,-1);
|
||||
if ( maxx == minx )
|
||||
{
|
||||
newStart.x = newEnd.x = minx;
|
||||
if ( miny < rect.top )
|
||||
newStart.y = rect.top;
|
||||
else
|
||||
newStart.y = miny;
|
||||
if ( maxy > rect.bottom )
|
||||
newEnd.y = rect.bottom;
|
||||
else
|
||||
newEnd.y = maxy;
|
||||
}
|
||||
else if ( maxy == miny )
|
||||
{
|
||||
newStart.y = newEnd.y = miny;
|
||||
if ( minx < rect.left )
|
||||
newStart.x = rect.left;
|
||||
else
|
||||
newStart.x = minx;
|
||||
if ( maxx > rect.right )
|
||||
newEnd.x = rect.right;
|
||||
else
|
||||
newEnd.x = maxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
float leftInt, rightInt, topInt, bottomInt;
|
||||
BPoint tempPoint;
|
||||
leftInt = GetY(rect.left);
|
||||
rightInt = GetY(rect.right);
|
||||
topInt = GetX(rect.top);
|
||||
bottomInt = GetX(rect.bottom);
|
||||
if ( end.x < start.x )
|
||||
{
|
||||
tempPoint = start;
|
||||
start = end;
|
||||
end = tempPoint;
|
||||
}
|
||||
if ( start.x < rect.left )
|
||||
{
|
||||
if ( (leftInt >= rect.top) && (leftInt <= rect.bottom) )
|
||||
{
|
||||
newStart.x = rect.left;
|
||||
newStart.y = leftInt;
|
||||
}
|
||||
if ( start.y < end.y )
|
||||
{
|
||||
if ( (topInt >= rect.left) && (topInt <= rect.right) )
|
||||
{
|
||||
newStart.x = topInt;
|
||||
newStart.y = rect.top;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) )
|
||||
{
|
||||
newStart.x = bottomInt;
|
||||
newStart.y = rect.bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( start.y < rect.top )
|
||||
{
|
||||
if ( (topInt >= rect.left) && (topInt <= rect.right) )
|
||||
{
|
||||
newStart.x = topInt;
|
||||
newStart.y = rect.top;
|
||||
}
|
||||
}
|
||||
else if ( start.y > rect.bottom )
|
||||
{
|
||||
if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) )
|
||||
{
|
||||
newStart.x = bottomInt;
|
||||
newStart.y = rect.bottom;
|
||||
}
|
||||
}
|
||||
else
|
||||
newStart = start;
|
||||
}
|
||||
if ( end.x > rect.right )
|
||||
{
|
||||
if ( (rightInt >= rect.top) && (rightInt <= rect.bottom) )
|
||||
{
|
||||
newEnd.x = rect.right;
|
||||
newEnd.y = rightInt;
|
||||
}
|
||||
if ( start.y < end.y )
|
||||
{
|
||||
if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) )
|
||||
{
|
||||
newEnd.x = bottomInt;
|
||||
newEnd.y = rect.bottom;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (topInt >= rect.left) && (topInt <= rect.right) )
|
||||
{
|
||||
newEnd.x = topInt;
|
||||
newEnd.y = rect.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( end.y < rect.top )
|
||||
{
|
||||
if ( (topInt >= rect.left) && (topInt <= rect.right) )
|
||||
{
|
||||
newEnd.x = topInt;
|
||||
newEnd.y = rect.top;
|
||||
}
|
||||
}
|
||||
else if ( end.y > rect.bottom )
|
||||
{
|
||||
if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) )
|
||||
{
|
||||
newEnd.x = bottomInt;
|
||||
newEnd.y = rect.bottom;
|
||||
}
|
||||
}
|
||||
else
|
||||
newEnd = end;
|
||||
}
|
||||
}
|
||||
if ( (newStart.x == -1) || (newStart.y == -1) || (newEnd.x == -1) || (newEnd.y == -1) )
|
||||
return false;
|
||||
SetPoints(newStart,newEnd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LineCalc::Swap(LineCalc &from)
|
||||
{
|
||||
BPoint pta, ptb;
|
||||
pta = start;
|
||||
ptb = end;
|
||||
SetPoints(from.start,from.end);
|
||||
from.SetPoints(pta,ptb);
|
||||
}
|
||||
|
||||
float LineCalc::GetX(float y)
|
||||
{
|
||||
if (start.x == end.x)
|
||||
return start.x;
|
||||
return ( (y-offset)/slope );
|
||||
}
|
||||
|
||||
float LineCalc::GetY(float x)
|
||||
{
|
||||
if ( start.x == end.x )
|
||||
return start.y;
|
||||
return ( (slope * x) + offset );
|
||||
}
|
@ -1,334 +0,0 @@
|
||||
// FontManager.cpp
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_SFNT_NAMES_H
|
||||
#include <freetype/ttnameid.h>
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <Directory.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
#include "FontManager.h"
|
||||
|
||||
// static default instance
|
||||
FontManager*
|
||||
FontManager::fDefaultManager = NULL;
|
||||
|
||||
static const char* threadName = "font scanner";
|
||||
|
||||
// constructor
|
||||
FontManager::FontManager(bool scanFontsInline)
|
||||
: BLooper(threadName, B_LOW_PRIORITY),
|
||||
fLibrary(NULL),
|
||||
fFontFiles(1024)
|
||||
{
|
||||
// initialize engine
|
||||
FT_Error error = FT_Init_FreeType(&fLibrary);
|
||||
if (error)
|
||||
fprintf(stderr, "Could not initialise FreeType library\n");
|
||||
|
||||
/*
|
||||
if (scanFontsInline) {
|
||||
_update((void*)this);
|
||||
} else {
|
||||
// start thread to read keyfile
|
||||
thread_id fontScanner = spawn_thread(_update, threadName,
|
||||
B_LOW_PRIORITY, this);
|
||||
if (fontScanner >= B_OK)
|
||||
resume_thread(fontScanner);
|
||||
}*/
|
||||
|
||||
Run();
|
||||
}
|
||||
|
||||
// destructor
|
||||
FontManager::~FontManager()
|
||||
{
|
||||
_MakeEmpty();
|
||||
}
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
FontManager::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_UPDATE: {
|
||||
// notify potential observes
|
||||
BMessage message(MSG_FONTS_CHANGED);
|
||||
SendNotices(FONTS_CHANGED, &message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// CreateDefault
|
||||
void
|
||||
FontManager::CreateDefault(bool scanFontsInline)
|
||||
{
|
||||
if (!fDefaultManager)
|
||||
fDefaultManager = new FontManager(scanFontsInline);
|
||||
}
|
||||
|
||||
// DeleteDefault
|
||||
void
|
||||
FontManager::DeleteDefault()
|
||||
{
|
||||
fDefaultManager->Lock();
|
||||
fDefaultManager->Quit();
|
||||
}
|
||||
|
||||
// Default
|
||||
FontManager*
|
||||
FontManager::Default()
|
||||
{
|
||||
if (!fDefaultManager)
|
||||
CreateDefault();
|
||||
return fDefaultManager;
|
||||
}
|
||||
|
||||
// FontFileAt
|
||||
const entry_ref*
|
||||
FontManager::FontFileAt(int32 index) const
|
||||
{
|
||||
if (font_file* ff = (font_file*)fFontFiles.ItemAt(index)) {
|
||||
return &ff->ref;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// FontFileFor
|
||||
const entry_ref*
|
||||
FontManager::FontFileFor(const char* family, const char* style) const
|
||||
{
|
||||
if (family && style) {
|
||||
for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) {
|
||||
if (ff->family_name && strcmp(ff->family_name, family) == 0
|
||||
&& ff->style_name && strcmp(ff->style_name, style) == 0)
|
||||
return &ff->ref;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// FamilyFor
|
||||
const char*
|
||||
FontManager::FamilyFor(const entry_ref* fontFile) const
|
||||
{
|
||||
if (font_file* ff = _FontFileFor(fontFile))
|
||||
return ff->family_name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// StyleFor
|
||||
const char*
|
||||
FontManager::StyleFor(const entry_ref* fontFile) const
|
||||
{
|
||||
if (font_file* ff = _FontFileFor(fontFile))
|
||||
return ff->style_name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// FullFamilyFor
|
||||
const char*
|
||||
FontManager::FullFamilyFor(const entry_ref* fontFile) const
|
||||
{
|
||||
if (font_file* ff = _FontFileFor(fontFile))
|
||||
return ff->full_family_name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// PostScriptNameFor
|
||||
const char*
|
||||
FontManager::PostScriptNameFor(const entry_ref* fontFile) const
|
||||
{
|
||||
if (font_file* ff = _FontFileFor(fontFile))
|
||||
return ff->ps_name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// CountFontFiles
|
||||
int32
|
||||
FontManager::CountFontFiles() const
|
||||
{
|
||||
return fFontFiles.CountItems();
|
||||
}
|
||||
|
||||
// _MakeEmpty
|
||||
void
|
||||
FontManager::_MakeEmpty()
|
||||
{
|
||||
int32 i = fFontFiles.CountItems() - 1;
|
||||
while (i >= 0) {
|
||||
if (font_file* ff = (font_file*)fFontFiles.ItemAt(i)) {
|
||||
if (ff->family_name)
|
||||
free(ff->family_name);
|
||||
if (ff->style_name)
|
||||
free(ff->style_name);
|
||||
if (ff->full_family_name)
|
||||
free(ff->full_family_name);
|
||||
if (ff->ps_name)
|
||||
free(ff->ps_name);
|
||||
delete ff;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
fFontFiles.MakeEmpty();
|
||||
}
|
||||
|
||||
int32
|
||||
FontManager::_update(void* cookie)
|
||||
{
|
||||
FontManager* fm = (FontManager*)cookie;
|
||||
if (fm && fm->Lock()) {
|
||||
//bigtime_t now = system_time();
|
||||
// update from system, common and user fonts folders
|
||||
BPath path;
|
||||
if (find_directory(B_BEOS_FONTS_DIRECTORY, &path) >= B_OK) {
|
||||
BDirectory fontFolder(path.Path());
|
||||
fm->_Update(&fontFolder);
|
||||
}
|
||||
if (find_directory(B_COMMON_FONTS_DIRECTORY, &path) >= B_OK) {
|
||||
BDirectory fontFolder(path.Path());
|
||||
fm->_Update(&fontFolder);
|
||||
}
|
||||
/* if (find_directory(B_USER_FONTS_DIRECTORY, &path) >= B_OK) {
|
||||
BDirectory fontFolder(path.Path());
|
||||
_Update(&fontFolder);
|
||||
}*/
|
||||
/*printf("scanning fonts: %lld µsecs\n", system_time() - now);
|
||||
for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) {
|
||||
printf("fond %ld: \"%s, %s\"\n", i, ff->family_name, ff->style_name);
|
||||
}*/
|
||||
fm->Unlock();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//_Update
|
||||
void
|
||||
FontManager::_Update(BDirectory* fontFolder)
|
||||
{
|
||||
fontFolder->Rewind();
|
||||
// scan the entire folder for font files
|
||||
BEntry entry;
|
||||
while (fontFolder->GetNextEntry(&entry) >= B_OK) {
|
||||
if (entry.IsDirectory()) {
|
||||
// recursive scan of sub folders
|
||||
BDirectory subFolder(&entry);
|
||||
_Update(&subFolder);
|
||||
} else {
|
||||
// see if this is a usable font file
|
||||
BPath path;
|
||||
if (entry.GetPath(&path) >= B_OK) {
|
||||
FT_Face face;
|
||||
FT_Error error = FT_New_Face(fLibrary, path.Path(), 0, &face);
|
||||
if (!error && face->family_name && face->style_name) {
|
||||
// create font_file object and init it
|
||||
font_file* fontFile = new font_file;
|
||||
entry.GetRef(&fontFile->ref);
|
||||
fontFile->family_name = strdup(face->family_name);
|
||||
fontFile->style_name = strdup(face->style_name);
|
||||
fontFile->full_family_name = NULL;
|
||||
fontFile->ps_name = NULL;
|
||||
// iterate over the names we find for this font face
|
||||
int32 nameCount = FT_Get_Sfnt_Name_Count(face);
|
||||
FT_SfntName fontName;
|
||||
//printf("\n\nfont: '%s'/'%s':\n", fontFile->family_name, fontFile->style_name);
|
||||
for (int32 i = 0; (fontFile->full_family_name == NULL || fontFile->ps_name == NULL)
|
||||
&& i < nameCount; i++) {
|
||||
if (FT_Get_Sfnt_Name(face, i, &fontName ) == 0) {
|
||||
switch (fontName.platform_id) {
|
||||
case TT_PLATFORM_APPLE_UNICODE:
|
||||
//printf(" platform: TT_PLATFORM_APPLE_UNICODE\n");
|
||||
// TODO: implement
|
||||
break;
|
||||
case TT_PLATFORM_MACINTOSH:
|
||||
//printf(" platform: TT_PLATFORM_MACINTOSH\n");
|
||||
if (fontName.encoding_id == TT_MAC_ID_ROMAN) {
|
||||
if (fontName.name_id == TT_NAME_ID_FULL_NAME) {
|
||||
fontFile->full_family_name = (char*)malloc(fontName.string_len + 1);
|
||||
memcpy(fontFile->full_family_name, fontName.string, fontName.string_len);
|
||||
fontFile->full_family_name[fontName.string_len] = 0;
|
||||
} else if (fontName.name_id == TT_NAME_ID_PS_NAME) {
|
||||
fontFile->ps_name = (char*)malloc(fontName.string_len + 1);
|
||||
memcpy(fontFile->ps_name, fontName.string, fontName.string_len);
|
||||
fontFile->ps_name[fontName.string_len] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TT_PLATFORM_MICROSOFT:
|
||||
//printf(" platform: TT_PLATFORM_MICROSOFT\n");
|
||||
// TODO: implement
|
||||
if (fontName.encoding_id == TT_MS_ID_UNICODE_CS) {
|
||||
if (fontName.name_id == TT_NAME_ID_FULL_NAME
|
||||
|| fontName.name_id == TT_NAME_ID_PS_NAME) {
|
||||
int32 length = fontName.string_len + 1;
|
||||
char* buffer = (char*)malloc(length);
|
||||
memcpy(buffer, fontName.string, length - 1);
|
||||
buffer[length - 1] = 0;
|
||||
int32 state = 0;
|
||||
convert_to_utf8(B_UNICODE_CONVERSION,
|
||||
buffer,
|
||||
&length,
|
||||
buffer,
|
||||
&length,
|
||||
&state,
|
||||
B_SUBSTITUTE);
|
||||
if (fontName.name_id == TT_NAME_ID_FULL_NAME)
|
||||
fontFile->full_family_name = buffer;
|
||||
else if (fontName.name_id == TT_NAME_ID_PS_NAME)
|
||||
fontFile->ps_name = buffer;
|
||||
//printf("uni-code name: '%s' (orig-length: %d, length: %ld)\n", buffer, fontName.string_len, length);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
char* name = (char*)malloc(fontName.string_len + 1);
|
||||
memcpy(name, fontName.string, fontName.string_len);
|
||||
name[fontName.string_len] = 0;
|
||||
printf(" %d, %d, ", fontName.encoding_id, fontName.name_id);
|
||||
printf("name: '%s'\n", name);
|
||||
free(name);
|
||||
*/
|
||||
}
|
||||
// find slot in sorted list and add it
|
||||
int32 i = 0;
|
||||
for (; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) {
|
||||
if (strcmp(fontFile->family_name, ff->family_name) < 0
|
||||
&& strcmp(fontFile->style_name, ff->style_name) <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fFontFiles.AddItem((void*)fontFile, i);
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _FontFileFor
|
||||
FontManager::font_file*
|
||||
FontManager::_FontFileFor(const entry_ref* ref) const
|
||||
{
|
||||
if (ref) {
|
||||
for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) {
|
||||
if (ff->ref == *ref) {
|
||||
return ff;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
// FontManager.h
|
||||
|
||||
#ifndef FT_FONT_MANAGER_H
|
||||
#define FT_FONT_MANAGER_H
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Looper.h>
|
||||
|
||||
class BMenu;
|
||||
|
||||
enum {
|
||||
MSG_FONTS_CHANGED = 'fnch',
|
||||
MSG_SET_FONT = 'stfn',
|
||||
MSG_UPDATE = 'updt',
|
||||
};
|
||||
|
||||
enum {
|
||||
FONTS_CHANGED = 0x01,
|
||||
};
|
||||
|
||||
class FontManager : public BLooper {
|
||||
public:
|
||||
FontManager(bool scanFontsInline);
|
||||
virtual ~FontManager();
|
||||
|
||||
// BLooper
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
// FontManager
|
||||
static void CreateDefault(bool scanFontsInline = false);
|
||||
static void DeleteDefault();
|
||||
static FontManager* Default();
|
||||
|
||||
// lock the object!
|
||||
virtual const entry_ref* FontFileAt(int32 index) const;
|
||||
virtual const entry_ref* FontFileFor(const char* family,
|
||||
const char* style) const;
|
||||
|
||||
virtual const char* FamilyFor(const entry_ref* fontFile) const;
|
||||
virtual const char* StyleFor(const entry_ref* fontFile) const;
|
||||
|
||||
virtual const char* FullFamilyFor(const entry_ref* fontFile) const;
|
||||
virtual const char* PostScriptNameFor(const entry_ref* fontFile) const;
|
||||
|
||||
virtual int32 CountFontFiles() const;
|
||||
|
||||
private:
|
||||
void _MakeEmpty();
|
||||
static int32 _update(void* cookie);
|
||||
void _Update(BDirectory* fontFolder);
|
||||
|
||||
struct font_file {
|
||||
char* family_name;
|
||||
char* style_name;
|
||||
char* full_family_name;
|
||||
char* ps_name;
|
||||
entry_ref ref;
|
||||
};
|
||||
|
||||
font_file* _FontFileFor(const entry_ref* ref) const;
|
||||
|
||||
FT_Library fLibrary; // the FreeType fLibrary
|
||||
|
||||
BList fFontFiles;
|
||||
|
||||
static FontManager* fDefaultManager;
|
||||
};
|
||||
|
||||
#endif // FT_FONT_MANAGER_H
|
@ -1,97 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: GraphicsBuffer.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: Convenience class for working with graphics buffers
|
||||
// Based on concepts from the Anti-Grain Geometry vector gfx library
|
||||
//------------------------------------------------------------------------------
|
||||
#include "GraphicsBuffer.h"
|
||||
|
||||
GraphicsBuffer::GraphicsBuffer(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes)
|
||||
{
|
||||
fBuffer=NULL;
|
||||
fRowList=NULL;
|
||||
fWidth=0;
|
||||
fHeight=0;
|
||||
fBytesPerRow=0;
|
||||
fMaxHeight=0;
|
||||
|
||||
SetTo(buffer, width, height, rowbytes);
|
||||
}
|
||||
|
||||
GraphicsBuffer::GraphicsBuffer(const GraphicsBuffer &buffer)
|
||||
{
|
||||
SetTo(buffer.fBuffer, buffer.fWidth, buffer.fHeight, buffer.fBytesPerRow);
|
||||
}
|
||||
|
||||
GraphicsBuffer::~GraphicsBuffer()
|
||||
{
|
||||
delete [] fRowList;
|
||||
}
|
||||
|
||||
void GraphicsBuffer::SetTo(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes)
|
||||
{
|
||||
fBuffer = buffer;
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
fBytesPerRow = rowbytes;
|
||||
|
||||
if(height > fMaxHeight)
|
||||
{
|
||||
delete [] fRowList;
|
||||
fRowList = new uint8* [fMaxHeight = height];
|
||||
}
|
||||
|
||||
uint8 *row_ptr = fBuffer;
|
||||
|
||||
if(rowbytes < 0)
|
||||
{
|
||||
row_ptr = fBuffer - int(height - 1) * rowbytes;
|
||||
}
|
||||
|
||||
uint8 **rows = fRowList;
|
||||
|
||||
while(height--)
|
||||
{
|
||||
*rows++ = row_ptr;
|
||||
row_ptr += rowbytes;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsBuffer::Unset(void)
|
||||
{
|
||||
delete [] fRowList;
|
||||
fBuffer=NULL;
|
||||
fRowList=NULL;
|
||||
fWidth=0;
|
||||
fHeight=0;
|
||||
fBytesPerRow=0;
|
||||
fMaxHeight=0;
|
||||
}
|
||||
|
||||
|
||||
GraphicsBuffer &GraphicsBuffer::operator=(const GraphicsBuffer &buffer)
|
||||
{
|
||||
SetTo(buffer.fBuffer, buffer.fWidth, buffer.fHeight, buffer.fBytesPerRow);
|
||||
return *this;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: GraphicsBuffer.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: Convenience class for working with graphics buffers
|
||||
// Based on concepts from the Anti-Grain Geometry vector gfx library
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef GFX_BUFFER_H
|
||||
#define GFX_BUFFER_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class GraphicsBuffer
|
||||
{
|
||||
public:
|
||||
GraphicsBuffer(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes);
|
||||
GraphicsBuffer(const GraphicsBuffer &buffer);
|
||||
~GraphicsBuffer();
|
||||
|
||||
void SetTo(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes);
|
||||
void Unset(void);
|
||||
|
||||
uint8 *Bits(void) const { return fBuffer; }
|
||||
uint8 *RowAt(uint32 row) { return fRowList[row]; }
|
||||
|
||||
uint32 Width(void) const { return fWidth; }
|
||||
uint32 Height(void) const { return fHeight; }
|
||||
|
||||
uint32 BytesPerRow(void) const { return fBytesPerRow; }
|
||||
GraphicsBuffer &operator=(const GraphicsBuffer &buf);
|
||||
|
||||
private:
|
||||
|
||||
uint32 fWidth;
|
||||
uint32 fHeight;
|
||||
uint8 *fBuffer;
|
||||
uint8 **fRowList;
|
||||
uint32 fBytesPerRow;
|
||||
uint32 fMaxHeight;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,278 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: PixelRenderer.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: Base class for pixel plotting renderers
|
||||
// Based on concepts from the Anti-Grain Geometry vector gfx library
|
||||
//------------------------------------------------------------------------------
|
||||
#include "PixelRenderer.h"
|
||||
#include <string.h>
|
||||
#include "IPoint.h"
|
||||
|
||||
PixelRenderer::PixelRenderer(GraphicsBuffer &buffer)
|
||||
{
|
||||
fBuffer=&buffer;
|
||||
}
|
||||
|
||||
PixelRenderer::~PixelRenderer(void)
|
||||
{
|
||||
}
|
||||
|
||||
RGBColor PixelRenderer::GetPixel(const IPoint &pt)
|
||||
{
|
||||
RGBColor c(0,0,0,0);
|
||||
return c;
|
||||
}
|
||||
|
||||
void PixelRenderer::PixelRenderer::PutPixel(const IPoint &pt, RGBColor &c)
|
||||
{
|
||||
}
|
||||
|
||||
void PixelRenderer::PutHLine(const IPoint &pt, const uint32 length, RGBColor &c)
|
||||
{
|
||||
}
|
||||
|
||||
void PixelRenderer::PutVLine(const IPoint &pt, const uint32 length, RGBColor &c)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// PixelRendererRGBA32: 32-Bit color handler
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
PixelRendererRGBA32::PixelRendererRGBA32(GraphicsBuffer &buffer)
|
||||
: PixelRenderer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
PixelRendererRGBA32::~PixelRendererRGBA32(void)
|
||||
{
|
||||
}
|
||||
|
||||
RGBColor PixelRendererRGBA32::GetPixel(const IPoint &pt)
|
||||
{
|
||||
uint8 *pixel=GetBuffer()->RowAt(pt.y) + (pt.x << 2);
|
||||
return RGBColor(pixel[2],pixel[1],pixel[0],pixel[3]);
|
||||
}
|
||||
|
||||
void PixelRendererRGBA32::PutPixel(const IPoint &pt, RGBColor &color)
|
||||
{
|
||||
rgb_color c=color.GetColor32();
|
||||
|
||||
uint8 *pixel=GetBuffer()->RowAt(pt.y) + (pt.x << 2);
|
||||
|
||||
pixel[0]=c.blue;
|
||||
pixel[1]=c.green;
|
||||
pixel[2]=c.red;
|
||||
pixel[3]=c.alpha;
|
||||
}
|
||||
|
||||
void PixelRendererRGBA32::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
rgb_color c=color.GetColor32();
|
||||
|
||||
uint32 *pixel32=(uint32*)GetBuffer()->RowAt(pt.y);
|
||||
uint8 *pixel=(uint8*)&(pixel32[pt.x]);
|
||||
|
||||
pixel[0]=c.blue;
|
||||
pixel[1]=c.green;
|
||||
pixel[2]=c.red;
|
||||
pixel[3]=c.alpha;
|
||||
int32 color32=*pixel32;
|
||||
|
||||
uint32 end=pt.x+length;
|
||||
|
||||
for(uint32 i=pt.x+1; i<end; i++)
|
||||
pixel32[i]=color32;
|
||||
}
|
||||
|
||||
void PixelRendererRGBA32::PutVLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
rgb_color c=color.GetColor32();
|
||||
|
||||
uint32 *pixel32=(uint32*)GetBuffer()->RowAt(pt.y);
|
||||
uint8 *pixel=(uint8*)&(pixel32[pt.x]);
|
||||
|
||||
pixel[0]=c.blue;
|
||||
pixel[1]=c.green;
|
||||
pixel[2]=c.red;
|
||||
pixel[3]=c.alpha;
|
||||
int32 color32=*pixel32;
|
||||
|
||||
uint32 end=pt.y+length;
|
||||
|
||||
for(uint32 i=pt.y+1; i<end; i++)
|
||||
{
|
||||
pixel32=(uint32*)GetBuffer()->RowAt(i);
|
||||
pixel32[pt.x]=color32;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// PixelRendererRGB16: 16-Bit color handler -- 565 space
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
PixelRendererRGB16::PixelRendererRGB16(GraphicsBuffer &buffer)
|
||||
: PixelRenderer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
PixelRendererRGB16::~PixelRendererRGB16(void)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Double check the values in RGB16 renderer to make sure they are correct for little endian
|
||||
|
||||
RGBColor PixelRendererRGB16::GetPixel(const IPoint &pt)
|
||||
{
|
||||
uint16 pixel=((uint16*)GetBuffer()->RowAt(pt.y))[pt.x];
|
||||
return RGBColor( (pixel<<3) & 248, (pixel>>3) & 252, (pixel>>8) & 248);
|
||||
}
|
||||
|
||||
void PixelRendererRGB16::PutPixel(const IPoint &pt, RGBColor &c)
|
||||
{
|
||||
((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]=c.GetColor16();
|
||||
}
|
||||
|
||||
void PixelRendererRGB16::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint16 *pixel16=(uint16*)GetBuffer()->RowAt(pt.y);
|
||||
uint32 end=pt.x+length;
|
||||
|
||||
for(uint32 i=pt.x; i<end; i++)
|
||||
pixel16[i]=color.GetColor16();
|
||||
}
|
||||
|
||||
void PixelRendererRGB16::PutVLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint32 end=pt.y+length;
|
||||
uint16 *index;
|
||||
|
||||
for(uint32 i=pt.y; i<end; i++)
|
||||
{
|
||||
index=(uint16*)GetBuffer()->RowAt(i);
|
||||
index[pt.x]=color.GetColor16();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// PixelRendererRGBA15: 15-Bit color handler -- 5551 space
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
PixelRendererRGBA15::PixelRendererRGBA15(GraphicsBuffer &buffer)
|
||||
: PixelRenderer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
PixelRendererRGBA15::~PixelRendererRGBA15(void)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Double check the values in RGBA15 renderer to make sure they are correct for little endian
|
||||
|
||||
RGBColor PixelRendererRGBA15::GetPixel(const IPoint &pt)
|
||||
{
|
||||
uint16 pixel=((uint16*)GetBuffer()->RowAt(pt.y))[pt.x];
|
||||
return RGBColor( (pixel<<3) & 248,
|
||||
(pixel>>3) & 252,
|
||||
(pixel>>7) & 248,
|
||||
((pixel>>8) & 128)?255:0 );
|
||||
}
|
||||
|
||||
void PixelRendererRGBA15::PutPixel(const IPoint &pt, RGBColor &color)
|
||||
{
|
||||
((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]=color.GetColor15();
|
||||
}
|
||||
|
||||
void PixelRendererRGBA15::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint16 *pixel16=(uint16*)GetBuffer()->RowAt(pt.y);
|
||||
uint32 end=pt.x+length;
|
||||
|
||||
for(uint32 i=pt.x; i<end; i++)
|
||||
pixel16[i]=color.GetColor15();
|
||||
}
|
||||
|
||||
void PixelRendererRGBA15::PutVLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint32 end=pt.y+length;
|
||||
uint16 *index;
|
||||
|
||||
for(uint32 i=pt.y; i<end; i++)
|
||||
{
|
||||
index=(uint16*)GetBuffer()->RowAt(i);
|
||||
index[pt.x]=color.GetColor15();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// PixelRendererCMAP8: 8-Bit color handler
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
PixelRendererCMAP8::PixelRendererCMAP8(GraphicsBuffer &buffer)
|
||||
: PixelRenderer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
PixelRendererCMAP8::~PixelRendererCMAP8(void)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Double check the values in CMAP8 renderer to make sure they are correct for little endian
|
||||
|
||||
RGBColor PixelRendererCMAP8::GetPixel(const IPoint &pt)
|
||||
{
|
||||
uint8 pixel=((uint8*)GetBuffer()->RowAt(pt.y))[pt.x];
|
||||
return RGBColor(pixel);
|
||||
}
|
||||
|
||||
void PixelRendererCMAP8::PutPixel(const IPoint &pt, RGBColor &color)
|
||||
{
|
||||
(GetBuffer()->RowAt(pt.y))[pt.x]=color.GetColor8();
|
||||
}
|
||||
|
||||
void PixelRendererCMAP8::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint8 *index=GetBuffer()->RowAt(pt.y)+pt.x;
|
||||
memset(index,color.GetColor8(),length);
|
||||
}
|
||||
|
||||
void PixelRendererCMAP8::PutVLine(const IPoint &pt, const uint32 length, RGBColor &color)
|
||||
{
|
||||
uint8 *index=GetBuffer()->RowAt(pt.y)+pt.x;
|
||||
uint32 end=pt.y+length;
|
||||
|
||||
for(uint32 i=pt.y; i<end; i++)
|
||||
{
|
||||
*index=color.GetColor8();
|
||||
index+=GetBuffer()->BytesPerRow();
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: PixelRenderer.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
//
|
||||
// Description: Base class for pixel plotting renderers
|
||||
// Based on concepts from the Anti-Grain Geometry vector gfx library
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef PIXEL_RENDERER
|
||||
#define PIXEL_RENDERER
|
||||
|
||||
#include "GraphicsBuffer.h"
|
||||
#include "GraphicsDefs.h"
|
||||
#include "RGBColor.h"
|
||||
|
||||
class IPoint;
|
||||
|
||||
class PixelRenderer
|
||||
{
|
||||
public:
|
||||
PixelRenderer(GraphicsBuffer &buffer);
|
||||
virtual ~PixelRenderer(void);
|
||||
|
||||
virtual color_space ColorSpace(void) { return B_NO_COLOR_SPACE; }
|
||||
|
||||
virtual RGBColor GetPixel(const IPoint &pt);
|
||||
virtual void PutPixel(const IPoint &pt, RGBColor &c);
|
||||
virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
|
||||
virtual void SetBuffer(GraphicsBuffer &buffer) { fBuffer=&buffer; }
|
||||
GraphicsBuffer *GetBuffer(void) const { return fBuffer; }
|
||||
|
||||
private:
|
||||
GraphicsBuffer *fBuffer;
|
||||
};
|
||||
|
||||
class PixelRendererRGBA32 : public PixelRenderer
|
||||
{
|
||||
public:
|
||||
PixelRendererRGBA32(GraphicsBuffer &buffer);
|
||||
virtual ~PixelRendererRGBA32(void);
|
||||
|
||||
virtual color_space ColorSpace(void) { return B_RGBA32; }
|
||||
|
||||
virtual RGBColor GetPixel(const IPoint &pt);
|
||||
virtual void PutPixel(const IPoint &pt, RGBColor &c);
|
||||
virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
};
|
||||
|
||||
class PixelRendererRGB16 : public PixelRenderer
|
||||
{
|
||||
public:
|
||||
PixelRendererRGB16(GraphicsBuffer &buffer);
|
||||
virtual ~PixelRendererRGB16(void);
|
||||
|
||||
virtual color_space ColorSpace(void) { return B_RGB16; }
|
||||
|
||||
virtual RGBColor GetPixel(const IPoint &pt);
|
||||
virtual void PutPixel(const IPoint &pt, RGBColor &c);
|
||||
virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
};
|
||||
|
||||
class PixelRendererRGBA15 : public PixelRenderer
|
||||
{
|
||||
public:
|
||||
PixelRendererRGBA15(GraphicsBuffer &buffer);
|
||||
virtual ~PixelRendererRGBA15(void);
|
||||
|
||||
virtual color_space ColorSpace(void) { return B_RGBA15; }
|
||||
|
||||
virtual RGBColor GetPixel(const IPoint &pt);
|
||||
virtual void PutPixel(const IPoint &pt, RGBColor &c);
|
||||
virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
};
|
||||
|
||||
class PixelRendererCMAP8 : public PixelRenderer
|
||||
{
|
||||
public:
|
||||
PixelRendererCMAP8(GraphicsBuffer &buffer);
|
||||
virtual ~PixelRendererCMAP8(void);
|
||||
|
||||
virtual color_space ColorSpace(void) { return B_CMAP8; }
|
||||
|
||||
virtual RGBColor GetPixel(const IPoint &pt);
|
||||
virtual void PutPixel(const IPoint &pt, RGBColor &c);
|
||||
virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c);
|
||||
};
|
||||
|
||||
// TODO: These inlines probably should go in ColorUtils
|
||||
inline uint16 MakeRGB16Color(uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
return (uint16)(((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3));
|
||||
}
|
||||
|
||||
// TODO: Doublecheck to make sure the shifting is correct in MakeRGBA15Color
|
||||
inline uint16 MakeRGBA15Color(uint8 r, uint8 g, uint8 b, bool visible=true)
|
||||
{
|
||||
return (uint16)(((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3));
|
||||
}
|
||||
|
||||
#endif
|
@ -1,131 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: RectUtils.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: Utilities for work around R5 Interface Kit bugs
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#include "RectUtils.h"
|
||||
|
||||
/*!
|
||||
\brief Checks for the intersection of two rectangles. Works properly,
|
||||
unlike BRect::Intersects
|
||||
|
||||
\param r First rectangle
|
||||
\param r2 Second rectangle
|
||||
\return True if they intersect, false if they don't.
|
||||
|
||||
The two rectangles intersect if they are equal, one contains the other,
|
||||
or if any edge intersects any edge of the other rectangle.
|
||||
*/
|
||||
bool TestRectIntersection(const BRect &r,const BRect &r2)
|
||||
{
|
||||
return TestLineIntersection(r, r2.left, r2.top, r2.left, r2.bottom) ||
|
||||
TestLineIntersection(r, r2.left, r2.top, r2.right, r2.top, false) ||
|
||||
TestLineIntersection(r, r2.right, r2.top, r2.right, r2.bottom) ||
|
||||
TestLineIntersection(r, r2.left, r2.bottom, r2.right, r2.bottom, false) ||
|
||||
r.Contains(r2) ||
|
||||
r2.Contains(r);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Checks to see if a region intersects with a particular rectangle
|
||||
|
||||
\param r Region
|
||||
\param r2 Rectangle to check intersection with
|
||||
\return True if they intersect, false if they don't.
|
||||
|
||||
The two intersect if they the rectangle intersects any one rectangle in the
|
||||
region.
|
||||
*/
|
||||
bool TestRegionIntersection(BRegion *r,const BRect &r2)
|
||||
{
|
||||
for(int32 i=0; i<r->CountRects(); i++)
|
||||
if(TestRectIntersection(r->RectAt(i),r2));
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Modifies the region to intersect with the rectangle given
|
||||
|
||||
\param r Region
|
||||
\param r2 Rectangle to intersect with
|
||||
*/
|
||||
void IntersectRegionWith(BRegion *r,const BRect &r2)
|
||||
{
|
||||
// We have three conditions:
|
||||
// 1) Region frame contains rect. Action: call Include()
|
||||
// 2) Rect intersects region frame. Action: call IntersectWith
|
||||
// 3) Region frame does not intersect rectangle. Make the region empty
|
||||
if(r->Frame().Contains(r2))
|
||||
r->Include(r2);
|
||||
if(r->Frame().Intersects(r2))
|
||||
{
|
||||
BRegion reg(r2);
|
||||
r->IntersectWith(®);
|
||||
}
|
||||
else
|
||||
r->MakeEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Checks for the intersection of a line with a rectangle
|
||||
|
||||
\param r Rectangle
|
||||
\param x1 starting x of line
|
||||
\param y1 starting y of line
|
||||
\param x2 ending x of line
|
||||
\param y2 ending y of line
|
||||
\param vertical Test for vertical intersection
|
||||
\return true if they intersect, false if not
|
||||
*/
|
||||
bool TestLineIntersection(const BRect& r, float x1, float y1, float x2, float y2,
|
||||
bool vertical)
|
||||
{
|
||||
if (vertical)
|
||||
{
|
||||
return (x1 >= r.left && x1 <= r.right) &&
|
||||
((y1 >= r.top && y1 <= r.bottom) ||
|
||||
(y2 >= r.top && y2 <= r.bottom));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (y1 >= r.top && y1 <= r.bottom) &&
|
||||
((x1 >= r.left && x1 <= r.right) ||
|
||||
(x2 >= r.left && x2 <= r.right));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Ensures that a BRect's IsValid() member returns true
|
||||
\param rect BRect to validate
|
||||
*/
|
||||
void ValidateRect(BRect *rect)
|
||||
{
|
||||
float l,r,t,b;
|
||||
l=(rect->left<rect->right)?rect->left:rect->right;
|
||||
r=(rect->left>rect->right)?rect->left:rect->right;
|
||||
t=(rect->top<rect->bottom)?rect->top:rect->bottom;
|
||||
b=(rect->top>rect->bottom)?rect->top:rect->bottom;
|
||||
rect->Set(l,t,r,b);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: RectUtils.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: Utilities for work around R5 Interface Kit bugs
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef RECTUTILS_H_
|
||||
#define RECTUTILS_H_
|
||||
|
||||
#include <Rect.h>
|
||||
#include <Region.h>
|
||||
|
||||
bool TestLineIntersection(const BRect&r, float x1, float y1, float x2, float y2,bool vertical=true);
|
||||
bool TestRectIntersection(const BRect &r,const BRect &r2);
|
||||
bool TestRegionIntersection(BRegion *r,const BRect &r2);
|
||||
void IntersectRegionWith(BRegion *r,const BRect &r2);
|
||||
void ValidateRect(BRect *r);
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,201 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: ScreenDriver.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Gabe Yoder <gyoder@stny.rr.com>
|
||||
// Description: BWindowScreen graphics module
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _SCREENDRIVER_H_
|
||||
#define _SCREENDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <GraphicsDefs.h> // for pattern struct
|
||||
#include <Cursor.h>
|
||||
#include <Message.h>
|
||||
#include <Region.h>
|
||||
#include <Font.h>
|
||||
#include "DisplayDriver.h"
|
||||
#include <WindowScreen.h>
|
||||
#include "FontServer.h"
|
||||
#include "PatternHandler.h"
|
||||
|
||||
class BBitmap;
|
||||
class BPortLink;
|
||||
class SDWindow;
|
||||
class LayerData;
|
||||
class ScreenDriver;
|
||||
|
||||
class FrameBuffer : public BWindowScreen
|
||||
{
|
||||
public:
|
||||
FrameBuffer(const char *title, uint32 space, status_t *st,bool debug);
|
||||
~FrameBuffer(void);
|
||||
void ScreenConnected(bool connected);
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool IsConnected(void) const { return is_connected; }
|
||||
bool QuitRequested(void);
|
||||
static int32 MouseMonitor(void *data);
|
||||
static int32 CopyThread(void *data);
|
||||
void Invalidate(const BRect &r);
|
||||
graphics_card_info gcinfo;
|
||||
protected:
|
||||
friend class ScreenDriver;
|
||||
|
||||
bool is_connected;
|
||||
BPortLink *serverlink;
|
||||
BPoint mousepos;
|
||||
uint32 buttons;
|
||||
thread_id monitor_thread,copy_thread;
|
||||
BView *view;
|
||||
BBitmap *viewbmp;
|
||||
ServerBitmap *cursor;
|
||||
BRegion *invalid;
|
||||
int32 invalidflag;
|
||||
};
|
||||
/*
|
||||
class SDView : public BView
|
||||
{
|
||||
public:
|
||||
SDView(BRect bounds);
|
||||
~SDView(void);
|
||||
void AttachedToWindow(void);
|
||||
void Draw(BRect rect);
|
||||
void MouseDown(BPoint pt);
|
||||
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
|
||||
void MouseUp(BPoint pt);
|
||||
void MessageReceived(BMessage *msg);
|
||||
|
||||
BBitmap *viewbmp;
|
||||
BPortLink *serverlink;
|
||||
|
||||
int hide_cursor;
|
||||
BBitmap *cursor;
|
||||
|
||||
BRect cursorframe, oldcursorframe;
|
||||
bool obscure_cursor;
|
||||
};
|
||||
*/
|
||||
class SDWindow : public BWindowScreen
|
||||
{
|
||||
public:
|
||||
SDWindow(void);
|
||||
~SDWindow(void);
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool QuitRequested(void);
|
||||
void WindowActivated(bool active);
|
||||
|
||||
// SDView *view;
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief BView/BWindow combination graphics module
|
||||
|
||||
First, slowest, and easiest driver class in the app_server which is designed
|
||||
to utilize the BeOS graphics functions to cut out a lot of junk in getting the
|
||||
drawing infrastructure in this server.
|
||||
|
||||
The concept is to have SDView::Draw() draw a bitmap, which is a "frame buffer"
|
||||
of sorts, utilize a second view to write to it. This cuts out
|
||||
the most problems with having a crapload of code to get just right without
|
||||
having to write a bunch of unit tests
|
||||
|
||||
Components: 3 classes, SDView, SDWindow, and ScreenDriver
|
||||
|
||||
ScreenDriver - a wrapper class which mostly posts messages to the SDWindow
|
||||
SDWindow - does most of the work.
|
||||
SDView - doesn't do all that much except display the rendered bitmap
|
||||
*/
|
||||
class ScreenDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
ScreenDriver(void);
|
||||
~ScreenDriver(void);
|
||||
|
||||
bool Initialize(void); // Sets the driver
|
||||
void Shutdown(void); // You never know when you'll need this
|
||||
|
||||
// Drawing functions
|
||||
void CopyBits(BRect src, BRect dest);
|
||||
void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest);
|
||||
void DrawChar(char c, BPoint pt, LayerData *d);
|
||||
// virtual void DrawPicture(SPicture *pic, BPoint pt);
|
||||
void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL);
|
||||
|
||||
void FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat);
|
||||
void FillBezier(BPoint *pts, LayerData *d, const Pattern &pat);
|
||||
void FillEllipse(BRect r, LayerData *d, const Pattern &pat);
|
||||
void FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat);
|
||||
void FillRect(BRect r, LayerData *d, const Pattern &pat);
|
||||
void FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat);
|
||||
// void FillShape(SShape *sh, LayerData *d, const Pattern &pat);
|
||||
void FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat);
|
||||
|
||||
void HideCursor(void);
|
||||
void InvertRect(BRect r);
|
||||
bool IsCursorHidden(void);
|
||||
void MoveCursorTo(float x, float y);
|
||||
// void MovePenTo(BPoint pt);
|
||||
void ObscureCursor(void);
|
||||
// BPoint PenPosition(void);
|
||||
// float PenSize(void);
|
||||
void SetCursor(ServerCursor *cursor);
|
||||
// drawing_mode GetDrawingMode(void);
|
||||
// void SetDrawingMode(drawing_mode mode);
|
||||
void ShowCursor(void);
|
||||
|
||||
void StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat);
|
||||
void StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat);
|
||||
void StrokeEllipse(BRect r, LayerData *d, const Pattern &pat);
|
||||
void StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat);
|
||||
void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d);
|
||||
void StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed=true);
|
||||
void StrokeRect(BRect r, LayerData *d, const Pattern &pat);
|
||||
void StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat);
|
||||
// void StrokeShape(SShape *sh, LayerData *d, const Pattern &pat);
|
||||
void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat);
|
||||
void SetMode(int32 mode);
|
||||
void SetMode(const display_mode &mode);
|
||||
float StringWidth(const char *string, int32 length, LayerData *d);
|
||||
float StringHeight(const char *string, int32 length, LayerData *d);
|
||||
bool DumpToFile(const char *path);
|
||||
FrameBuffer *screenwin;
|
||||
protected:
|
||||
void SetLayerData(LayerData *d, bool set_font_data=false);
|
||||
void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d);
|
||||
void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d);
|
||||
rgb_color GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true);
|
||||
int hide_cursor;
|
||||
bool obscure_cursor;
|
||||
BBitmap *framebuffer;
|
||||
BView *drawview;
|
||||
BRegion laregion;
|
||||
BPortLink *serverlink;
|
||||
|
||||
rgb_color highcolor,lowcolor;
|
||||
bool is_initialized;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,986 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: ViewDriver.cpp
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: BView/BWindow combination graphics module
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <Message.h>
|
||||
#include <Region.h>
|
||||
#include <Bitmap.h>
|
||||
#include <OS.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Font.h>
|
||||
#include <BitmapStream.h>
|
||||
#include <File.h>
|
||||
#include <Entry.h>
|
||||
#include <Screen.h>
|
||||
#include <TranslatorRoster.h>
|
||||
|
||||
#include "fake_input_server.h"
|
||||
|
||||
#include "PortLink.h"
|
||||
#include "RectUtils.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "ServerBitmap.h"
|
||||
#include "ViewDriver.h"
|
||||
#include "ServerConfig.h"
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerFont.h"
|
||||
#include "FontFamily.h"
|
||||
#include "LayerData.h"
|
||||
#include "PNGDump.h"
|
||||
|
||||
#ifdef DEBUG_DRIVER_MODULE
|
||||
# include <stdio.h>
|
||||
# define STRACE(x) printf x
|
||||
#else
|
||||
# define STRACE(x) ;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
VDWIN_CLEAR=100,
|
||||
|
||||
VDWIN_SHOWCURSOR,
|
||||
VDWIN_HIDECURSOR,
|
||||
VDWIN_OBSCURECURSOR,
|
||||
VDWIN_MOVECURSOR,
|
||||
VDWIN_SETCURSOR,
|
||||
};
|
||||
|
||||
extern RGBColor workspace_default_color;
|
||||
|
||||
bool is_initialized = false;
|
||||
BPoint offset(50,50);
|
||||
|
||||
VDView::VDView(BRect bounds)
|
||||
: BView(bounds,"viewdriver_view",B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
viewbmp=new BBitmap(bounds,B_RGBA32,true);
|
||||
|
||||
// This link for sending mouse messages to the Haiku app_server.
|
||||
// This is only to take the place of the Input Server.
|
||||
port_id input_port = find_port(SERVER_INPUT_PORT);
|
||||
serverlink = new BPortLink(input_port);
|
||||
|
||||
// Create a cursor which isn't just a box
|
||||
cursor=new BBitmap(BRect(0,0,20,20),B_RGBA32,true);
|
||||
BView *v=new BView(cursor->Bounds(),"v", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
hide_cursor=0;
|
||||
|
||||
cursor->Lock();
|
||||
cursor->AddChild(v);
|
||||
|
||||
v->SetHighColor(255,255,255,0);
|
||||
v->FillRect(cursor->Bounds());
|
||||
v->SetHighColor(255,0,0,255);
|
||||
v->FillTriangle(cursor->Bounds().LeftTop(),cursor->Bounds().RightTop(),cursor->Bounds().LeftBottom());
|
||||
|
||||
cursor->RemoveChild(v);
|
||||
cursor->Unlock();
|
||||
|
||||
cursorframe=cursor->Bounds();
|
||||
oldcursorframe=cursor->Bounds();
|
||||
}
|
||||
|
||||
VDView::~VDView()
|
||||
{
|
||||
delete serverlink;
|
||||
delete cursor;
|
||||
|
||||
viewbmp->Lock();
|
||||
delete viewbmp;
|
||||
}
|
||||
|
||||
void VDView::AttachedToWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void VDView::Draw(BRect rect)
|
||||
{
|
||||
if(viewbmp)
|
||||
{
|
||||
DrawBitmapAsync(viewbmp,oldcursorframe,oldcursorframe);
|
||||
DrawBitmapAsync(viewbmp,rect,rect);
|
||||
|
||||
if(hide_cursor==0 && obscure_cursor==false)
|
||||
{
|
||||
SetDrawingMode(B_OP_ALPHA);
|
||||
DrawBitmapAsync(cursor,cursor->Bounds(),cursorframe);
|
||||
SetDrawingMode(B_OP_COPY);
|
||||
}
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
|
||||
// These functions emulate the Input Server by sending the *exact* same kind of messages
|
||||
// to the server's port. Being we're using a regular window, it would make little sense
|
||||
// to do anything else.
|
||||
|
||||
void VDView::MouseDown(BPoint pt)
|
||||
{
|
||||
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
||||
send_mouse_down(serverlink, pt, Window()->CurrentMessage());
|
||||
#endif
|
||||
}
|
||||
|
||||
void VDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
|
||||
{
|
||||
if (!(transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW))
|
||||
return;
|
||||
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
||||
send_mouse_moved(serverlink, pt, Window()->CurrentMessage());
|
||||
#endif
|
||||
}
|
||||
|
||||
void VDView::MouseUp(BPoint pt)
|
||||
{
|
||||
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
||||
send_mouse_up(serverlink, pt, Window()->CurrentMessage());
|
||||
#endif
|
||||
}
|
||||
|
||||
void VDView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what)
|
||||
{
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VDWindow::VDWindow(BRect frame)
|
||||
: BWindow(frame, "Haiku App Server", B_TITLED_WINDOW,
|
||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
||||
{
|
||||
view=new VDView(Bounds());
|
||||
AddChild(view);
|
||||
}
|
||||
|
||||
VDWindow::~VDWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void VDWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
||||
if (!handle_message(view->serverlink, msg))
|
||||
#endif
|
||||
BWindow::MessageReceived(msg);
|
||||
}
|
||||
|
||||
bool VDWindow::QuitRequested()
|
||||
{
|
||||
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||
|
||||
if(serverport>=0)
|
||||
{
|
||||
BPortLink link(serverport);
|
||||
link.StartMessage(B_QUIT_REQUESTED);
|
||||
link.Flush();
|
||||
}
|
||||
else
|
||||
printf("ERROR: couldn't find the app_server's main port!");
|
||||
|
||||
// We actually have to perform the internal equivalent of calling Shutdown
|
||||
// to eliminate a race condition. If a ServerWindow attempts to call a driver
|
||||
// function after the window has closed but before the AppServer instance
|
||||
// has called Shutdown, we end up with a crash inside one of the graphics
|
||||
// methods
|
||||
is_initialized=false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void VDWindow::WindowActivated(bool active)
|
||||
{
|
||||
// This is just to hide the regular system cursor so we can see our own
|
||||
|
||||
if(active)
|
||||
be_app->HideCursor();
|
||||
else
|
||||
be_app->ShowCursor();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ViewDriver::ViewDriver()
|
||||
: DisplayDriverImpl()
|
||||
{
|
||||
fDisplayMode.virtual_width=640;
|
||||
fDisplayMode.virtual_height=480;
|
||||
fDisplayMode.space=B_RGBA32;
|
||||
|
||||
screenwin=new VDWindow(BRect(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1).OffsetToCopy(offset));
|
||||
framebuffer=screenwin->view->viewbmp;
|
||||
serverlink=screenwin->view->serverlink;
|
||||
hide_cursor=0;
|
||||
|
||||
framebuffer->Lock();
|
||||
drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
framebuffer->AddChild(drawview);
|
||||
framebuffer->Unlock();
|
||||
}
|
||||
|
||||
ViewDriver::~ViewDriver()
|
||||
{
|
||||
if(is_initialized)
|
||||
{
|
||||
screenwin->Lock();
|
||||
screenwin->Quit();
|
||||
screenwin=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ViewDriver::Initialize()
|
||||
{
|
||||
Lock();
|
||||
|
||||
// the screen should start black
|
||||
framebuffer->Lock();
|
||||
rgb_color c; c.red = 0; c.blue = 0; c.green = 0; c.alpha = 255;
|
||||
drawview->SetHighColor(c);
|
||||
drawview->FillRect(drawview->Bounds());
|
||||
drawview->Sync();
|
||||
framebuffer->Unlock();
|
||||
|
||||
hide_cursor=0;
|
||||
obscure_cursor=false;
|
||||
|
||||
is_initialized=true;
|
||||
|
||||
// We can afford to call the above functions without locking
|
||||
// because the window is locked until Show() is first called
|
||||
screenwin->Show();
|
||||
Unlock();
|
||||
|
||||
return DisplayDriver::Initialize();
|
||||
}
|
||||
|
||||
void ViewDriver::Shutdown()
|
||||
{
|
||||
DisplayDriver::Shutdown();
|
||||
|
||||
Lock();
|
||||
is_initialized=false;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::SetMode(const display_mode &mode)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
if (fDisplayMode.virtual_width==mode.virtual_width &&
|
||||
fDisplayMode.virtual_height==mode.virtual_height &&
|
||||
fDisplayMode.space==mode.space)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fDisplayMode.virtual_width = mode.virtual_width;
|
||||
fDisplayMode.virtual_height = mode.virtual_height;
|
||||
fDisplayMode.space = mode.space;
|
||||
|
||||
screenwin->Lock();
|
||||
|
||||
BBitmap *tempbmp=new BBitmap(BRect(0,0,mode.virtual_width-1, mode.virtual_height-1),
|
||||
(color_space)mode.space,true);
|
||||
|
||||
if(!tempbmp)
|
||||
{
|
||||
screenwin->Unlock();
|
||||
delete tempbmp;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!tempbmp->IsValid())
|
||||
{
|
||||
screenwin->Unlock();
|
||||
delete tempbmp;
|
||||
return;
|
||||
}
|
||||
|
||||
delete framebuffer;
|
||||
|
||||
screenwin->ResizeTo(mode.virtual_width-1, mode.virtual_height-1);
|
||||
|
||||
screenwin->view->viewbmp=tempbmp;
|
||||
framebuffer=screenwin->view->viewbmp;
|
||||
|
||||
drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
framebuffer->AddChild(drawview);
|
||||
|
||||
// the screen should start black
|
||||
framebuffer->Lock();
|
||||
rgb_color c; c.red = 0; c.blue = 0; c.green = 0; c.alpha = 255;
|
||||
drawview->SetHighColor(c);//workspace_default_color.GetColor32());
|
||||
drawview->FillRect(drawview->Bounds());
|
||||
drawview->Sync();
|
||||
framebuffer->Unlock();
|
||||
|
||||
screenwin->view->Invalidate();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
/*
|
||||
void ViewDriver::DrawBitmap(ServerBitmap *bitmap, const BRect &src, const BRect &dest, const DrawData *d)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
STRACE(("ViewDriver:: DrawBitmap unimplemented()\n"));
|
||||
}*/
|
||||
|
||||
bool ViewDriver::DumpToFile(const char *path)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return false;
|
||||
|
||||
// Dump to PNG
|
||||
Lock();
|
||||
SaveToPNG(path,framebuffer->Bounds(),framebuffer->ColorSpace(),
|
||||
framebuffer->Bits(),framebuffer->BitsLength(),framebuffer->BytesPerRow());
|
||||
|
||||
Unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Draws a series of lines - optimized for speed
|
||||
\param pts Array of BPoints pairs
|
||||
\param numlines Number of lines to be drawn
|
||||
\param pensize The thickness of the lines
|
||||
\param colors Array of colors for each respective line
|
||||
*/
|
||||
void ViewDriver::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata,
|
||||
const DrawData *d)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
if( !numlines || !linedata || !d)
|
||||
return;
|
||||
|
||||
const LineArrayData *data;
|
||||
|
||||
Lock();
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
|
||||
drawview->SetPenSize(d->pensize);
|
||||
drawview->SetDrawingMode(d->draw_mode);
|
||||
|
||||
drawview->BeginLineArray(numlines);
|
||||
for(int32 i=0; i<numlines; i++)
|
||||
{
|
||||
data=(const LineArrayData *)&linedata[i];
|
||||
drawview->AddLine(data->pt1,data->pt2,data->color);
|
||||
}
|
||||
drawview->EndLineArray();
|
||||
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate();
|
||||
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
void ViewDriver::InvertRect(const BRect &r)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->InvertRect(r);
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(r);
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::FillSolidRect(const BRect &rect, const RGBColor &color)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->SetHighColor(color.GetColor32());
|
||||
drawview->FillRect(rect);
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(rect);
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::FillPatternRect(const BRect &rect, const DrawData *d)
|
||||
{
|
||||
if(!d)
|
||||
return;
|
||||
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->SetHighColor(d->highcolor.GetColor32());
|
||||
drawview->SetLowColor(d->lowcolor.GetColor32());
|
||||
drawview->FillRect(rect,*((pattern*)d->patt.GetInt8()));
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(rect);
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d)
|
||||
{
|
||||
if(!d)
|
||||
return;
|
||||
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->SetHighColor(d->highcolor.GetColor32());
|
||||
drawview->SetLowColor(d->lowcolor.GetColor32());
|
||||
drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2),*((pattern*)d->patt.GetInt8()));
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(BRect(x1, y1, x2, y2));
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->SetHighColor(color.GetColor32());
|
||||
drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2));
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(BRect(x1,y1,x2,y2));
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
drawview->SetHighColor(color.GetColor32());
|
||||
drawview->StrokeRect(rect);
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(rect);
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::SetDrawData(const DrawData *d, bool set_font_data)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
if(!d)
|
||||
return;
|
||||
|
||||
bool unlock=false;
|
||||
if(!framebuffer->IsLocked())
|
||||
{
|
||||
framebuffer->Lock();
|
||||
unlock=true;
|
||||
}
|
||||
|
||||
drawview->ConstrainClippingRegion(d->clipReg);
|
||||
drawview->SetPenSize(d->pensize);
|
||||
drawview->SetDrawingMode(d->draw_mode);
|
||||
drawview->SetHighColor(d->highcolor.GetColor32());
|
||||
drawview->SetLowColor(d->lowcolor.GetColor32());
|
||||
drawview->SetScale(d->scale);
|
||||
drawview->MovePenTo(d->penlocation);
|
||||
if(set_font_data)
|
||||
{
|
||||
BFont font;
|
||||
const ServerFont *sf=&(d->font);
|
||||
|
||||
if(!sf)
|
||||
return;
|
||||
|
||||
font.SetFamilyAndStyle(sf->GetFamily(),sf->GetStyle());
|
||||
font.SetFlags(sf->Flags());
|
||||
font.SetEncoding(sf->Encoding());
|
||||
font.SetSize(sf->Size());
|
||||
font.SetRotation(sf->Rotation());
|
||||
font.SetShear(sf->Shear());
|
||||
font.SetSpacing(sf->Spacing());
|
||||
drawview->SetFont(&font);
|
||||
}
|
||||
if(unlock)
|
||||
framebuffer->Unlock();
|
||||
}
|
||||
|
||||
rgb_color ViewDriver::GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high)
|
||||
{
|
||||
rgb_color returncolor={0,0,0,0};
|
||||
|
||||
int16 value;
|
||||
if(!d || !is_initialized)
|
||||
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;
|
||||
}
|
||||
|
||||
status_t ViewDriver::SetDPMSMode(const uint32 &state)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
// NOTE: Originally, this was a to-do item to implement software DPMS,
|
||||
// but this driver will not be the official testing driver, so implementing
|
||||
// this stuff the way it was intended -- blanking the server's screen but not
|
||||
// the physical monitor -- is moot, but we will support blanking the
|
||||
// actual monitor if it is supported.
|
||||
return BScreen().SetDPMS(state);
|
||||
}
|
||||
|
||||
uint32 ViewDriver::DPMSMode()
|
||||
{
|
||||
// See note for SetDPMSMode if there are questions
|
||||
return BScreen().DPMSState();
|
||||
}
|
||||
|
||||
uint32 ViewDriver::DPMSCapabilities()
|
||||
{
|
||||
// See note for SetDPMSMode if there are questions
|
||||
return BScreen().DPMSCapabilites();
|
||||
}
|
||||
|
||||
status_t ViewDriver::GetDeviceInfo(accelerant_device_info *info)
|
||||
{
|
||||
if(!info || !is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
// We really don't have to provide anything here because this is strictly
|
||||
// a software-only driver, but we'll have some fun, anyway.
|
||||
|
||||
info->version=100;
|
||||
sprintf(info->name,"Haiku, Inc. ViewDriver");
|
||||
sprintf(info->chipset,"Haiku, Inc. Chipset");
|
||||
sprintf(info->serial_no,"3.14159265358979323846");
|
||||
info->memory=134217728; // 128 MB, not that we really have that much. :)
|
||||
info->dac_speed=0xFFFFFFFF; // *heh*
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t ViewDriver::GetModeList(display_mode **modes, uint32 *count)
|
||||
{
|
||||
if(!count || !is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
screenwin->Lock();
|
||||
|
||||
// DEPRECATED:
|
||||
// NOTE: Originally, I was going to figure out good timing values to be
|
||||
// returned in each of the modes supported, but I won't bother, being this
|
||||
// won't be used much longer anyway.
|
||||
|
||||
*modes=new display_mode[13];
|
||||
*count=13;
|
||||
|
||||
modes[0]->virtual_width=640;
|
||||
modes[0]->virtual_width=480;
|
||||
modes[0]->space=B_CMAP8;
|
||||
modes[1]->virtual_width=640;
|
||||
modes[1]->virtual_width=480;
|
||||
modes[1]->space=B_RGB16;
|
||||
modes[2]->virtual_width=640;
|
||||
modes[2]->virtual_width=480;
|
||||
modes[2]->space=B_RGB32;
|
||||
modes[3]->virtual_width=640;
|
||||
modes[3]->virtual_width=480;
|
||||
modes[3]->space=B_RGBA32;
|
||||
|
||||
modes[4]->virtual_width=800;
|
||||
modes[4]->virtual_width=600;
|
||||
modes[4]->space=B_CMAP8;
|
||||
modes[5]->virtual_width=800;
|
||||
modes[5]->virtual_width=600;
|
||||
modes[5]->space=B_RGB16;
|
||||
modes[6]->virtual_width=800;
|
||||
modes[6]->virtual_width=600;
|
||||
modes[6]->space=B_RGB32;
|
||||
|
||||
modes[7]->virtual_width=1024;
|
||||
modes[7]->virtual_width=768;
|
||||
modes[7]->space=B_CMAP8;;
|
||||
modes[8]->virtual_width=1024;
|
||||
modes[8]->virtual_width=768;
|
||||
modes[8]->space=B_RGB16;
|
||||
modes[9]->virtual_width=1024;
|
||||
modes[9]->virtual_width=768;
|
||||
modes[9]->space=B_RGB32;
|
||||
|
||||
modes[10]->virtual_width=1152;
|
||||
modes[10]->virtual_width=864;
|
||||
modes[10]->space=B_CMAP8;
|
||||
modes[11]->virtual_width=1152;
|
||||
modes[11]->virtual_width=864;
|
||||
modes[11]->space=B_RGB16;
|
||||
modes[12]->virtual_width=1152;
|
||||
modes[12]->virtual_width=864;
|
||||
modes[12]->space=B_RGB32;
|
||||
|
||||
for(int32 i=0; i<13; i++)
|
||||
{
|
||||
modes[i]->h_display_start=0;
|
||||
modes[i]->v_display_start=0;
|
||||
modes[i]->flags=B_PARALLEL_ACCESS;
|
||||
}
|
||||
screenwin->Unlock();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t ViewDriver::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t ViewDriver::GetTimingConstraints(display_timing_constraints *dtc)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t ViewDriver::ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
// We should be able to get away with this because we're not dealing with any
|
||||
// specific hardware. This is a Good Thing(TM) because we can support any hardware
|
||||
// we wish within reasonable expectaions and programmer laziness. :P
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t ViewDriver::WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return B_ERROR;
|
||||
|
||||
// Locking shouldn't be necessary here - R5 should handle this for us. :)
|
||||
BScreen screen;
|
||||
return screen.WaitForRetrace(timeout);
|
||||
}
|
||||
|
||||
void ViewDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d)
|
||||
{
|
||||
if(!is_initialized || !bitmap || !d)
|
||||
{
|
||||
printf("CopyBitmap returned - not init or NULL bitmap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// DON't set draw data here! your existing clipping region will be deleted
|
||||
// SetDrawData(d);
|
||||
|
||||
// Oh, wow, is this going to be slow. Then again, ViewDriver was never meant to be very fast. It could
|
||||
// be made significantly faster by directly copying from the source to the destination, but that would
|
||||
// require implementing a lot of code. Eventually, this should be replaced, but for now, using
|
||||
// DrawBitmap will at least work with a minimum of effort.
|
||||
|
||||
BBitmap *mediator=new BBitmap(bitmap->Bounds(),bitmap->ColorSpace());
|
||||
memcpy(mediator->Bits(),bitmap->Bits(),bitmap->BitsLength());
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
|
||||
drawview->DrawBitmap(mediator,source,dest);
|
||||
drawview->Sync();
|
||||
screenwin->view->Invalidate(dest);
|
||||
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
delete mediator;
|
||||
}
|
||||
|
||||
void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
|
||||
{
|
||||
if(!is_initialized || !destbmp)
|
||||
{
|
||||
printf("CopyToBitmap returned - not init or NULL bitmap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(((uint32)destbmp->ColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F))
|
||||
{
|
||||
printf("CopyToBitmap returned - unequal buffer pixel depth\n");
|
||||
return;
|
||||
}
|
||||
|
||||
BRect destrect(destbmp->Bounds()), source(sourcerect);
|
||||
|
||||
uint8 colorspace_size=destbmp->BitsPerPixel()/8;
|
||||
|
||||
// First, clip source rect to destination
|
||||
if(source.Width() > destrect.Width())
|
||||
source.right=source.left+destrect.Width();
|
||||
|
||||
if(source.Height() > destrect.Height())
|
||||
source.bottom=source.top+destrect.Height();
|
||||
|
||||
|
||||
// Second, check rectangle bounds against their own bitmaps
|
||||
BRect work_rect(destbmp->Bounds());
|
||||
|
||||
if( !(work_rect.Contains(destrect)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(destrect.left < 0)
|
||||
destrect.left = 0;
|
||||
if(destrect.right > work_rect.right)
|
||||
destrect.right = work_rect.right;
|
||||
if(destrect.top < 0)
|
||||
destrect.top = 0;
|
||||
if(destrect.bottom > work_rect.bottom)
|
||||
destrect.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1);
|
||||
|
||||
if(!work_rect.Contains(sourcerect))
|
||||
return;
|
||||
|
||||
if( !(work_rect.Contains(source)) )
|
||||
{
|
||||
// something in selection must be clipped
|
||||
if(source.left < 0)
|
||||
source.left = 0;
|
||||
if(source.right > work_rect.right)
|
||||
source.right = work_rect.right;
|
||||
if(source.top < 0)
|
||||
source.top = 0;
|
||||
if(source.bottom > work_rect.bottom)
|
||||
source.bottom = work_rect.bottom;
|
||||
}
|
||||
|
||||
// Set pointers to the actual data
|
||||
uint8 *dest_bits = (uint8*) destbmp->Bits();
|
||||
uint8 *src_bits = (uint8*) framebuffer->Bits();
|
||||
|
||||
// Get row widths for offset looping
|
||||
uint32 dest_width = uint32 (destbmp->BytesPerRow());
|
||||
uint32 src_width = uint32 (framebuffer->BytesPerRow());
|
||||
|
||||
// Offset bitmap pointers to proper spot in each bitmap
|
||||
src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) );
|
||||
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
|
||||
|
||||
|
||||
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
|
||||
uint32 lines = uint32 (source.bottom-source.top+1);
|
||||
|
||||
for (uint32 pos_y=0; pos_y<lines; pos_y++)
|
||||
{
|
||||
memcpy(dest_bits,src_bits,line_length);
|
||||
|
||||
// Increment offsets
|
||||
src_bits += src_width;
|
||||
dest_bits += dest_width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ViewDriver::ConstrainClippingRegion(BRegion *reg)
|
||||
{
|
||||
if(!is_initialized)
|
||||
{
|
||||
printf("ConstrainClippingRegion returned - not init\n");
|
||||
return;
|
||||
}
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
|
||||
// screenwin->view->ConstrainClippingRegion(reg);
|
||||
drawview->ConstrainClippingRegion(reg);
|
||||
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
bool ViewDriver::AcquireBuffer(FBBitmap *bmp)
|
||||
{
|
||||
if(!bmp || !is_initialized)
|
||||
return false;
|
||||
|
||||
screenwin->Lock();
|
||||
framebuffer->Lock();
|
||||
|
||||
bmp->SetBytesPerRow(framebuffer->BytesPerRow());
|
||||
bmp->SetSpace(framebuffer->ColorSpace());
|
||||
bmp->SetSize(framebuffer->Bounds().IntegerWidth(), framebuffer->Bounds().IntegerHeight());
|
||||
bmp->SetBuffer(framebuffer->Bits());
|
||||
bmp->SetBitsPerPixel(framebuffer->ColorSpace(),framebuffer->BytesPerRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewDriver::ReleaseBuffer()
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
framebuffer->Unlock();
|
||||
screenwin->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::Invalidate(const BRect &r)
|
||||
{
|
||||
if(!is_initialized)
|
||||
return;
|
||||
|
||||
screenwin->Lock();
|
||||
screenwin->view->Draw(r);
|
||||
screenwin->Unlock();
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: ViewDriver.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Description: BView/BWindow combination graphics module
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef _VIEWDRIVER_H_
|
||||
#define _VIEWDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <GraphicsDefs.h> // for pattern struct
|
||||
#include <Cursor.h>
|
||||
#include <Message.h>
|
||||
#include <Region.h>
|
||||
#include <Font.h>
|
||||
#include "FontServer.h"
|
||||
|
||||
#include "DisplayDriverImpl.h"
|
||||
|
||||
class BBitmap;
|
||||
class BPortLink;
|
||||
class VDWindow;
|
||||
class DrawData;
|
||||
|
||||
class VDView : public BView
|
||||
{
|
||||
public:
|
||||
VDView(BRect bounds);
|
||||
~VDView();
|
||||
void AttachedToWindow();
|
||||
void Draw(BRect rect);
|
||||
void MouseDown(BPoint pt);
|
||||
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
|
||||
void MouseUp(BPoint pt);
|
||||
void MessageReceived(BMessage *msg);
|
||||
|
||||
BBitmap *viewbmp;
|
||||
BPortLink *serverlink;
|
||||
|
||||
int hide_cursor;
|
||||
BBitmap *cursor;
|
||||
|
||||
BRect cursorframe, oldcursorframe;
|
||||
bool obscure_cursor;
|
||||
};
|
||||
|
||||
class VDWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
VDWindow(BRect frame);
|
||||
~VDWindow();
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool QuitRequested();
|
||||
void WindowActivated(bool active);
|
||||
|
||||
VDView *view;
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief BView/BWindow combination graphics module
|
||||
|
||||
First, slowest, and easiest driver class in the app_server which is designed
|
||||
to utilize the BeOS graphics functions to cut out a lot of junk in getting the
|
||||
drawing infrastructure in this server.
|
||||
|
||||
The concept is to have VDView::Draw() draw a bitmap, which is a "frame buffer"
|
||||
of sorts, utilize a second view to write to it. This cuts out
|
||||
the most problems with having a crapload of code to get just right without
|
||||
having to write a bunch of unit tests
|
||||
|
||||
Components: 3 classes, VDView, VDWindow, and ViewDriver
|
||||
|
||||
ViewDriver - a wrapper class which mostly posts messages to the VDWindow
|
||||
VDWindow - does most of the work.
|
||||
VDView - doesn't do all that much except display the rendered bitmap
|
||||
*/
|
||||
class ViewDriver : public DisplayDriverImpl
|
||||
{
|
||||
public:
|
||||
ViewDriver();
|
||||
~ViewDriver();
|
||||
|
||||
virtual bool Initialize(); // Sets the driver
|
||||
virtual void Shutdown(); // You never know when you'll need this
|
||||
|
||||
// Drawing functions
|
||||
// void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d);
|
||||
|
||||
virtual void InvertRect(const BRect &r);
|
||||
|
||||
virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *data,
|
||||
const DrawData *d);
|
||||
|
||||
virtual void SetMode(const display_mode &mode);
|
||||
|
||||
virtual bool DumpToFile(const char *path);
|
||||
|
||||
VDWindow *screenwin;
|
||||
|
||||
virtual status_t SetDPMSMode(const uint32 &state);
|
||||
virtual uint32 DPMSMode();
|
||||
virtual uint32 DPMSCapabilities();
|
||||
virtual status_t GetDeviceInfo(accelerant_device_info *info);
|
||||
virtual status_t GetModeList(display_mode **mode_list, uint32 *count);
|
||||
virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high);
|
||||
virtual status_t GetTimingConstraints(display_timing_constraints *dtc);
|
||||
virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high);
|
||||
virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
|
||||
protected:
|
||||
virtual void FillSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void FillPatternRect(const BRect &rect, const DrawData *d);
|
||||
virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color);
|
||||
virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2,
|
||||
const RGBColor &color);
|
||||
virtual void SetDrawData(const DrawData *d, bool set_font_data=false);
|
||||
virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2,
|
||||
const DrawData *d);
|
||||
virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source,
|
||||
const BRect &dest, const DrawData *d);
|
||||
virtual void CopyToBitmap(ServerBitmap *target, const BRect &source);
|
||||
// temporarily virtual - until clipping code is added in DisplayDriver
|
||||
virtual void ConstrainClippingRegion(BRegion *reg);
|
||||
|
||||
|
||||
virtual bool AcquireBuffer(FBBitmap *bmp);
|
||||
virtual void ReleaseBuffer();
|
||||
virtual void Invalidate(const BRect &r);
|
||||
|
||||
// void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
|
||||
// void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
|
||||
rgb_color GetBlitColor(rgb_color src, rgb_color dest,
|
||||
DrawData *d, bool use_high=true);
|
||||
|
||||
int hide_cursor;
|
||||
bool obscure_cursor;
|
||||
BBitmap *framebuffer;
|
||||
BView *drawview;
|
||||
BRegion laregion;
|
||||
|
||||
BPortLink *serverlink;
|
||||
// drawing_mode drawmode;
|
||||
|
||||
rgb_color highcolor,lowcolor;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user