2003-01-29 02:58:06 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2001-2002, OpenBeOS
|
|
|
|
//
|
|
|
|
// 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.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
2003-04-05 05:51:35 +04:00
|
|
|
// Description: BView/BWindow combination graphics module
|
2003-01-29 02:58:06 +03:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
2003-04-05 05:51:35 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-07-05 01:13:48 +04:00
|
|
|
#include <iostream>
|
2003-04-05 05:51:35 +04:00
|
|
|
#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 <TranslatorRoster.h>
|
|
|
|
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "Angle.h"
|
2003-04-05 05:51:35 +04:00
|
|
|
#include "PortLink.h"
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "ServerProtocol.h"
|
|
|
|
#include "ServerBitmap.h"
|
2003-04-05 05:51:35 +04:00
|
|
|
#include "ScreenDriver.h"
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "ServerConfig.h"
|
2003-04-05 05:51:35 +04:00
|
|
|
#include "ServerCursor.h"
|
|
|
|
#include "ServerFont.h"
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "FontFamily.h"
|
|
|
|
#include "LayerData.h"
|
2003-03-30 04:17:50 +04:00
|
|
|
#include "PNGDump.h"
|
2003-10-05 02:12:18 +04:00
|
|
|
#include "PatternHandler.h"
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-09-09 01:18:39 +04:00
|
|
|
#ifdef DEBUG_DRIVER_MODULE
|
|
|
|
# include <stdio.h>
|
|
|
|
# define STRACE(x) printf x
|
|
|
|
#else
|
|
|
|
# define STRACE(x) ;
|
|
|
|
#endif
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SDWIN_CLEAR=100,
|
2003-02-23 04:35:29 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
SDWIN_SHOWCURSOR,
|
|
|
|
SDWIN_HIDECURSOR,
|
|
|
|
SDWIN_OBSCURECURSOR,
|
|
|
|
SDWIN_MOVECURSOR,
|
|
|
|
SDWIN_SETCURSOR,
|
|
|
|
};
|
2003-02-17 19:24:27 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
extern RGBColor workspace_default_color;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
FrameBuffer::FrameBuffer(const char *title, uint32 space, status_t *st,bool debug)
|
|
|
|
: BWindowScreen(title,space,st,debug)
|
|
|
|
{
|
|
|
|
is_connected=false;
|
|
|
|
port_id serverport=find_port(SERVER_INPUT_PORT);
|
|
|
|
serverlink=new PortLink(serverport);
|
|
|
|
mousepos.Set(0,0);
|
|
|
|
buttons=0;
|
2003-04-05 05:51:35 +04:00
|
|
|
viewbmp=new BBitmap(BRect(0,0,639,479),B_CMAP8,true);
|
2003-02-22 23:23:22 +03:00
|
|
|
|
|
|
|
// View exists to poll for the mouse
|
|
|
|
view=new BView(Bounds(),"view",0,0);
|
|
|
|
AddChild(view);
|
2003-02-23 04:42:11 +03:00
|
|
|
view->GetMouse(&mousepos,&buttons);
|
2003-04-05 05:51:35 +04:00
|
|
|
|
|
|
|
invalid=new BRegion(Bounds());
|
|
|
|
invalidflag=0;
|
|
|
|
|
2003-02-23 04:42:11 +03:00
|
|
|
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
2003-02-22 23:23:22 +03:00
|
|
|
monitor_thread=spawn_thread(MouseMonitor,"mousemonitor",B_NORMAL_PRIORITY,this);
|
|
|
|
resume_thread(monitor_thread);
|
|
|
|
#endif
|
2003-04-05 05:51:35 +04:00
|
|
|
|
|
|
|
copy_thread=spawn_thread(CopyThread,"copymonitor",B_NORMAL_PRIORITY,this);
|
|
|
|
resume_thread(copy_thread);
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameBuffer::~FrameBuffer(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
kill_thread(copy_thread);
|
2003-02-22 23:23:22 +03:00
|
|
|
kill_thread(monitor_thread);
|
2003-04-05 05:51:35 +04:00
|
|
|
delete viewbmp;
|
|
|
|
delete invalid;
|
|
|
|
delete serverlink;
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameBuffer::ScreenConnected(bool connected)
|
|
|
|
{
|
|
|
|
is_connected=connected;
|
|
|
|
if(connected)
|
|
|
|
{
|
|
|
|
// Cache the state just in case
|
|
|
|
graphics_card_info *info=CardInfo();
|
|
|
|
gcinfo=*info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameBuffer::MessageReceived(BMessage *msg)
|
|
|
|
{
|
|
|
|
switch(msg->what)
|
|
|
|
{
|
|
|
|
case B_KEY_DOWN:
|
|
|
|
{
|
|
|
|
int32 key,modifiers;
|
|
|
|
msg->FindInt32("key",&key);
|
|
|
|
msg->FindInt32("modifiers",&modifiers);
|
|
|
|
|
|
|
|
int32 servermods=0;
|
|
|
|
servermods|=modifiers & B_RIGHT_COMMAND_KEY;
|
|
|
|
servermods|=modifiers & B_RIGHT_OPTION_KEY;
|
|
|
|
servermods|=modifiers & B_RIGHT_CONTROL_KEY;
|
|
|
|
servermods|=modifiers & B_SHIFT_KEY;
|
|
|
|
|
|
|
|
switch(key)
|
|
|
|
{
|
|
|
|
case 0x47: // Enter key
|
|
|
|
{
|
|
|
|
port_id serverport=find_port(SERVER_PORT_NAME);
|
|
|
|
write_port(serverport,B_QUIT_REQUESTED,NULL,0);
|
|
|
|
break;
|
|
|
|
}
|
2003-02-24 00:40:44 +03:00
|
|
|
default:
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-22 23:23:22 +03:00
|
|
|
|
|
|
|
#ifdef ENABLE_INPUT_SERVER_EMULATION
|
|
|
|
case B_MOUSE_WHEEL_CHANGED:
|
|
|
|
{
|
|
|
|
float x,y;
|
|
|
|
msg->FindFloat("be:wheel_delta_x",&x);
|
|
|
|
msg->FindFloat("be:wheel_delta_y",&y);
|
|
|
|
int64 time=real_time_clock();
|
|
|
|
serverlink->SetOpCode(B_MOUSE_WHEEL_CHANGED);
|
|
|
|
serverlink->Attach(&time,sizeof(int64));
|
|
|
|
serverlink->Attach(x);
|
|
|
|
serverlink->Attach(y);
|
|
|
|
serverlink->Flush();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-24 00:40:44 +03:00
|
|
|
default:
|
2003-01-29 02:58:06 +03:00
|
|
|
BWindowScreen::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameBuffer::QuitRequested(void)
|
|
|
|
{
|
|
|
|
port_id serverport=find_port(SERVER_PORT_NAME);
|
|
|
|
|
|
|
|
if(serverport!=B_NAME_NOT_FOUND)
|
|
|
|
write_port(serverport,B_QUIT_REQUESTED,NULL,0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
int32 FrameBuffer::CopyThread(void *data)
|
|
|
|
{
|
|
|
|
FrameBuffer *fb=(FrameBuffer*)data;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if(fb->IsConnected())
|
|
|
|
{
|
|
|
|
if(fb->invalidflag)
|
|
|
|
{
|
|
|
|
fb->Lock();
|
|
|
|
fb->viewbmp->Lock();
|
|
|
|
|
|
|
|
if(fb->invalid)
|
|
|
|
{
|
|
|
|
int8 *start_ptr;
|
|
|
|
clipping_rect r;
|
|
|
|
for(int32 i=0; i<fb->invalid->CountRects(); i++)
|
|
|
|
{
|
|
|
|
// Copy from viewbmp to framebuffer
|
|
|
|
start_ptr=(int8*)fb->viewbmp->Bits();
|
|
|
|
r=fb->invalid->RectAtInt(i);
|
|
|
|
memcpy(fb->gcinfo.frame_buffer,start_ptr,fb->viewbmp->BitsLength());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fb->viewbmp->Unlock();
|
|
|
|
fb->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-22 23:23:22 +03:00
|
|
|
int32 FrameBuffer::MouseMonitor(void *data)
|
|
|
|
{
|
|
|
|
FrameBuffer *fb=(FrameBuffer*)data;
|
|
|
|
BPoint mousepos(0,0),oldpos(0,0);
|
|
|
|
uint32 buttons=0, oldbuttons=0;
|
|
|
|
uint32 clicks=1; // TODO: add multiclick support
|
|
|
|
uint32 mods;
|
|
|
|
int64 time;
|
|
|
|
|
|
|
|
fb->Lock();
|
|
|
|
PortLink *link=new PortLink(fb->serverlink->GetPort());
|
2003-02-23 04:42:11 +03:00
|
|
|
fb->view->GetMouse(&mousepos,&buttons);
|
|
|
|
oldpos=mousepos;
|
|
|
|
oldbuttons=buttons;
|
2003-02-22 23:23:22 +03:00
|
|
|
fb->Unlock();
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if(fb->IsConnected())
|
|
|
|
{
|
|
|
|
// Get the mouse position
|
|
|
|
fb->Lock();
|
|
|
|
fb->view->GetMouse(&mousepos,&buttons);
|
|
|
|
fb->Unlock();
|
|
|
|
|
|
|
|
// Check for changes and post messages as necessary
|
|
|
|
|
|
|
|
// Mouse button change?
|
|
|
|
if(buttons!=oldbuttons)
|
|
|
|
{
|
|
|
|
time=(int64)real_time_clock();
|
|
|
|
mods=modifiers();
|
|
|
|
if(oldbuttons==0)
|
|
|
|
{
|
|
|
|
// MouseDown
|
|
|
|
link->SetOpCode(B_MOUSE_DOWN);
|
|
|
|
link->Attach(&time, sizeof(int64));
|
|
|
|
link->Attach(&mousepos.x,sizeof(float));
|
|
|
|
link->Attach(&mousepos.y,sizeof(float));
|
|
|
|
link->Attach(&mods, sizeof(uint32));
|
|
|
|
link->Attach(&buttons, sizeof(uint32));
|
|
|
|
link->Attach(&clicks, sizeof(uint32));
|
|
|
|
link->Flush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// MouseUp
|
|
|
|
link->SetOpCode(B_MOUSE_UP);
|
|
|
|
link->Attach(&time, sizeof(int64));
|
|
|
|
link->Attach(&mousepos.x,sizeof(float));
|
|
|
|
link->Attach(&mousepos.y,sizeof(float));
|
|
|
|
link->Attach(&mods, sizeof(uint32));
|
|
|
|
link->Flush();
|
|
|
|
}
|
|
|
|
oldbuttons=buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse Position change?
|
|
|
|
if( (mousepos.x!=oldpos.x) || (mousepos.y!=oldpos.y))
|
|
|
|
{
|
|
|
|
time=(int64)real_time_clock();
|
|
|
|
mods=modifiers();
|
|
|
|
|
|
|
|
// B_MOUSE_MOVED
|
|
|
|
link->SetOpCode(B_MOUSE_MOVED);
|
|
|
|
link->Attach(&time, sizeof(int64));
|
|
|
|
link->Attach(&mousepos.x,sizeof(float));
|
|
|
|
link->Attach(&mousepos.y,sizeof(float));
|
|
|
|
link->Attach(&mods, sizeof(int32));
|
|
|
|
link->Attach(&buttons, sizeof(uint32));
|
|
|
|
link->Attach(&clicks, sizeof(uint32));
|
|
|
|
link->Flush();
|
|
|
|
oldpos=mousepos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse wheel support messages are actually sent to BWindowScreens,
|
|
|
|
// so we handle that in MessageReceived
|
|
|
|
}
|
|
|
|
snooze(150);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete link;
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void FrameBuffer::Invalidate(const BRect &r)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
if(invalid)
|
|
|
|
invalid->Include(r);
|
|
|
|
else
|
|
|
|
invalid=new BRegion(r);
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
ScreenDriver::ScreenDriver(void)
|
|
|
|
{
|
|
|
|
status_t st;
|
|
|
|
screenwin=new FrameBuffer("OBAppServer",B_8_BIT_640x480,&st,false);
|
|
|
|
|
|
|
|
framebuffer=screenwin->viewbmp;
|
|
|
|
serverlink=screenwin->serverlink;
|
|
|
|
hide_cursor=0;
|
2003-02-17 19:24:27 +03:00
|
|
|
_SetWidth(640);
|
|
|
|
_SetHeight(480);
|
|
|
|
_SetDepth(8);
|
2003-04-05 05:51:35 +04:00
|
|
|
_SetMode(B_8_BIT_640x480);
|
|
|
|
_SetBytesPerRow(framebuffer->BytesPerRow());
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenDriver::~ScreenDriver(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
if(is_initialized)
|
2003-02-17 19:24:27 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
screenwin->Quit();
|
|
|
|
screenwin=NULL;
|
2003-02-17 19:24:27 +03:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
bool ScreenDriver::Initialize(void)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 21:09:49 +04:00
|
|
|
Lock();
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
|
|
|
framebuffer->AddChild(drawview);
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
hide_cursor=0;
|
|
|
|
obscure_cursor=false;
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
is_initialized=true;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// We can afford to call the above functions without locking
|
|
|
|
// because the window is locked until Show() is first called
|
|
|
|
screenwin->Show();
|
2003-07-28 21:09:49 +04:00
|
|
|
Unlock();
|
2003-04-05 05:51:35 +04:00
|
|
|
return true;
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::Shutdown(void)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 21:09:49 +04:00
|
|
|
Lock();
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Disconnect();
|
|
|
|
is_initialized=false;
|
2003-07-28 21:09:49 +04:00
|
|
|
Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2004-01-14 03:54:45 +03:00
|
|
|
void ScreenDriver::SetMode(const display_mode &mode)
|
|
|
|
{
|
|
|
|
screenwin->Lock();
|
|
|
|
int16 w=mode.virtual_width,h=mode.virtual_height;
|
|
|
|
color_space s=(color_space)mode.space;
|
|
|
|
|
|
|
|
screenwin->ResizeTo(w-1,h-1);
|
|
|
|
|
|
|
|
// Clear the invalid flag so that there is no danger of a crash
|
|
|
|
while(screenwin->invalidflag>0)
|
|
|
|
atomic_add(&screenwin->invalidflag,-1);
|
|
|
|
|
|
|
|
delete framebuffer;
|
|
|
|
|
|
|
|
// don't forget to update the internal vars!
|
|
|
|
_SetWidth(w);
|
|
|
|
_SetHeight(h);
|
|
|
|
_SetMode(s);
|
|
|
|
|
|
|
|
screenwin->SetSpace((uint32)s);
|
|
|
|
|
|
|
|
screenwin->viewbmp=new BBitmap(screenwin->Bounds(),s,true);
|
|
|
|
framebuffer=screenwin->viewbmp;
|
|
|
|
drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
|
|
|
framebuffer->AddChild(drawview);
|
|
|
|
|
|
|
|
framebuffer->Lock();
|
|
|
|
drawview->SetHighColor(workspace_default_color.GetColor32());
|
|
|
|
drawview->FillRect(drawview->Bounds());
|
|
|
|
drawview->Sync();
|
|
|
|
framebuffer->Unlock();
|
|
|
|
|
|
|
|
screenwin->Invalidate(framebuffer->Bounds());
|
|
|
|
|
|
|
|
_SetBytesPerRow(framebuffer->BytesPerRow());
|
|
|
|
atomic_add(&screenwin->invalidflag,1);
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::SetMode(int32 space)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
int16 w=640,h=480;
|
|
|
|
color_space s=B_CMAP8;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
switch(space)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
case B_32_BIT_800x600:
|
|
|
|
case B_16_BIT_800x600:
|
|
|
|
case B_8_BIT_800x600:
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
w=800; h=600;
|
|
|
|
break;
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
case B_32_BIT_1024x768:
|
|
|
|
case B_16_BIT_1024x768:
|
|
|
|
case B_8_BIT_1024x768:
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
w=1024; h=768;
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
2003-04-05 05:51:35 +04:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->ResizeTo(w-1,h-1);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
switch(space)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
case B_32_BIT_640x480:
|
|
|
|
case B_32_BIT_800x600:
|
|
|
|
case B_32_BIT_1024x768:
|
|
|
|
s=B_RGBA32;
|
|
|
|
_SetDepth(32);
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
2003-04-05 05:51:35 +04:00
|
|
|
case B_16_BIT_640x480:
|
|
|
|
case B_16_BIT_800x600:
|
|
|
|
case B_16_BIT_1024x768:
|
|
|
|
s=B_RGBA15;
|
|
|
|
_SetDepth(15);
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
2003-04-05 05:51:35 +04:00
|
|
|
case B_8_BIT_640x480:
|
|
|
|
case B_8_BIT_800x600:
|
|
|
|
case B_8_BIT_1024x768:
|
|
|
|
s=B_CMAP8;
|
|
|
|
_SetDepth(8);
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
|
|
|
default:
|
2003-04-05 05:51:35 +04:00
|
|
|
_SetDepth(8);
|
2003-01-29 02:58:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// Clear the invalid flag so that there is no danger of a crash
|
|
|
|
while(screenwin->invalidflag>0)
|
|
|
|
atomic_add(&screenwin->invalidflag,-1);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
delete framebuffer;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// don't forget to update the internal vars!
|
|
|
|
_SetWidth(w);
|
|
|
|
_SetHeight(h);
|
|
|
|
_SetMode(space);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->SetSpace((uint32)space);
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->viewbmp=new BBitmap(screenwin->Bounds(),s,true);
|
|
|
|
framebuffer=screenwin->viewbmp;
|
|
|
|
drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
|
|
|
framebuffer->AddChild(drawview);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
framebuffer->Lock();
|
|
|
|
drawview->SetHighColor(workspace_default_color.GetColor32());
|
|
|
|
drawview->FillRect(drawview->Bounds());
|
|
|
|
drawview->Sync();
|
|
|
|
framebuffer->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Invalidate(framebuffer->Bounds());
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
_SetBytesPerRow(framebuffer->BytesPerRow());
|
|
|
|
atomic_add(&screenwin->invalidflag,1);
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::CopyBits(BRect src, BRect dest)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
drawview->CopyBits(src,dest);
|
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(src);
|
|
|
|
screenwin->view->Invalidate(dest);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::DrawBitmap(ServerBitmap *bitmap, BRect src, BRect dest)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-09-09 01:18:39 +04:00
|
|
|
STRACE(("ScreenDriver:: DrawBitmap unimplemented()\n"));
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::DrawChar(char c, BPoint pt, LayerData *d)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
char str[2];
|
|
|
|
str[0]=c;
|
|
|
|
str[1]='\0';
|
|
|
|
DrawString(str, 1, pt, d);
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
/*
|
|
|
|
void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-09-09 01:18:39 +04:00
|
|
|
STRACE(("ScreenDriver:: DrawString(\"%s\",%ld,BPoint(%f,%f))\n",string,length,pt.x,pt.y));
|
2003-04-05 05:51:35 +04:00
|
|
|
if(!d)
|
|
|
|
return;
|
|
|
|
BRect r;
|
|
|
|
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
SetLayerData(d,true); // set all layer data and additionally set the font-related data
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->DrawString(string,length,pt,delta);
|
|
|
|
drawview->Sync();
|
|
|
|
|
|
|
|
// calculate the invalid rectangle
|
|
|
|
font_height fh;
|
|
|
|
BFont font;
|
|
|
|
drawview->GetFont(&font);
|
|
|
|
drawview->GetFontHeight(&fh);
|
|
|
|
r.left=pt.x;
|
|
|
|
r.right=pt.x+font.StringWidth(string);
|
|
|
|
r.top=pt.y-fh.ascent;
|
|
|
|
r.bottom=pt.y+fh.descent;
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
|
|
|
|
}
|
2003-02-22 23:23:22 +03:00
|
|
|
*/
|
2003-04-05 05:51:35 +04:00
|
|
|
|
|
|
|
bool ScreenDriver::DumpToFile(const char *path)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
// Dump to PNG
|
2003-07-28 21:09:49 +04:00
|
|
|
Lock();
|
2003-04-05 05:51:35 +04:00
|
|
|
SaveToPNG(path,framebuffer->Bounds(),framebuffer->ColorSpace(),
|
|
|
|
framebuffer->Bits(),framebuffer->BitsLength(),framebuffer->BytesPerRow());
|
|
|
|
|
2003-07-28 21:09:49 +04:00
|
|
|
Unlock();
|
2003-04-05 05:51:35 +04:00
|
|
|
return true;
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillArc(r,angle,span,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillBezier(BPoint *pts, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!pts)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillBezier(pts,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
|
|
|
|
// Invalidate the whole view until I get around to adding in the invalid rect calc code
|
|
|
|
screenwin->view->Invalidate();
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-02-22 23:23:22 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillEllipse(BRect r, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillEllipse(r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillPolygon(ptlist,numpts,rect,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(rect);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillRect(BRect r, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillRect(r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillRoundRect(r,xrad,yrad,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!pts)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
BPoint first=pts[0],second=pts[1],third=pts[2];
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->FillTriangle(first,second,third,r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenDriver::HideCursor(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
2003-07-28 21:09:49 +04:00
|
|
|
Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
hide_cursor++;
|
|
|
|
screenwin->PostMessage(SDWIN_HIDECURSOR);
|
|
|
|
|
2003-07-28 21:09:49 +04:00
|
|
|
Unlock();
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::InvertRect(BRect r)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
drawview->InvertRect(r);
|
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
bool ScreenDriver::IsCursorHidden(void)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
bool value=(hide_cursor>0)?true:false;
|
|
|
|
screenwin->Unlock();
|
|
|
|
return value;
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenDriver::ObscureCursor(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
screenwin->PostMessage(SDWIN_OBSCURECURSOR);
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::MoveCursorTo(float x, float y)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
BMessage *msg=new BMessage(SDWIN_MOVECURSOR);
|
|
|
|
msg->AddFloat("x",x);
|
|
|
|
msg->AddFloat("y",y);
|
|
|
|
screenwin->PostMessage(msg);
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::SetCursor(ServerCursor *cursor)
|
|
|
|
{
|
|
|
|
printf("SetCursor unimplemented\n");
|
|
|
|
/*
|
|
|
|
if(cursor!=NULL)
|
|
|
|
{
|
|
|
|
screenwin->Lock();
|
|
|
|
BBitmap *bmp=new BBitmap(cursor->Bounds(),B_RGBA32);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// Copy the server bitmap in the cursor to a BBitmap
|
|
|
|
uint8 *sbmppos=(uint8*)cursor->Bits(),
|
|
|
|
*bbmppos=(uint8*)bmp->Bits();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
int32 bytes=cursor->BytesPerRow(),
|
|
|
|
bbytes=bmp->BytesPerRow();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
for(int i=0;i<=cursor->Bounds().IntegerHeight();i++)
|
|
|
|
memcpy(bbmppos+(i*bbytes), sbmppos+(i*bytes), bytes);
|
2003-03-30 04:17:50 +04:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// Replace the bitmap
|
|
|
|
delete screenwin->cursor;
|
|
|
|
screenwin->cursor=bmp;
|
|
|
|
screenwin->Invalidate(screenwin->view->cursorframe);
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-03-30 04:17:50 +04:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::ShowCursor(void)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
if(hide_cursor>0)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
hide_cursor--;
|
|
|
|
screenwin->PostMessage(SDWIN_SHOWCURSOR);
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeArc(r,angle,span,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!pts)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeBezier(pts,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
// Invalidate the whole view until I get around to adding in the invalid rect calc code
|
|
|
|
screenwin->view->Invalidate();
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeEllipse(BRect r, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeEllipse(r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-02-23 04:35:29 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeLine(start,end,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(BRect(start,end));
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-02-23 04:35:29 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
void ScreenDriver::StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d)
|
|
|
|
{
|
2003-09-09 01:18:39 +04:00
|
|
|
STRACE(("ScreenDriver:: StrokeLineArray unimplemented\n"));
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!ptlist)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
BRegion invalid;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
SetLayerData(d);
|
|
|
|
drawview->BeginLineArray(numpts+2);
|
|
|
|
for(int i=1;i<numpts;i++)
|
|
|
|
{
|
|
|
|
drawview->AddLine(ptlist[i-1],ptlist[i],d->highcolor.GetColor32());
|
|
|
|
invalid.Include(BRect(ptlist[i-1],ptlist[i]));
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(is_closed)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->AddLine(ptlist[numpts-1],ptlist[0],d->highcolor.GetColor32());
|
|
|
|
invalid.Include(BRect(ptlist[numpts-1],ptlist[0]));
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->EndLineArray();
|
|
|
|
|
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(invalid.Frame());
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeRect(BRect r, LayerData *d, const Pattern &pat)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeRect(r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeRoundRect(r,xrad,yrad,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-07-28 23:13:24 +04:00
|
|
|
void ScreenDriver::StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
2003-07-28 23:13:24 +04:00
|
|
|
if(!pts || !d)
|
2003-04-05 05:51:35 +04:00
|
|
|
return;
|
|
|
|
screenwin->Lock();
|
|
|
|
framebuffer->Lock();
|
|
|
|
BPoint first=pts[0],second=pts[1],third=pts[2];
|
|
|
|
SetLayerData(d);
|
2003-07-28 23:13:24 +04:00
|
|
|
drawview->StrokeTriangle(first,second,third,r,*((pattern*)pat.GetInt8()));
|
2003-04-05 05:51:35 +04:00
|
|
|
drawview->Sync();
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
framebuffer->Unlock();
|
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
}
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-06-23 06:54:52 +04:00
|
|
|
void ScreenDriver::SetLayerData(LayerData *d, bool set_font_data)
|
2003-04-05 05:51:35 +04:00
|
|
|
{
|
|
|
|
if(!d)
|
|
|
|
return;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
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;
|
2003-09-15 23:07:45 +04:00
|
|
|
ServerFont *sf=&(d->font);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(!sf)
|
|
|
|
return;
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-09-15 23:07:45 +04:00
|
|
|
FontStyle *style=d->font.Style();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(!style)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
FontFamily *family=(FontFamily *)style->Family();
|
|
|
|
if(!family)
|
|
|
|
return;
|
|
|
|
|
2003-07-05 01:13:48 +04:00
|
|
|
font_family fontfamily;
|
|
|
|
strcpy(fontfamily,family->Name());
|
|
|
|
font.SetFamilyAndStyle(fontfamily,style->Name());
|
2003-04-05 05:51:35 +04:00
|
|
|
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);
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float ScreenDriver::StringWidth(const char *string, int32 length, LayerData *d)
|
|
|
|
{
|
2003-09-15 23:07:45 +04:00
|
|
|
if(!string || !d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return 0.0;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-09-15 23:07:45 +04:00
|
|
|
ServerFont *font=&(d->font);
|
2003-01-29 02:58:06 +03:00
|
|
|
FontStyle *style=font->Style();
|
|
|
|
|
|
|
|
if(!style)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
FT_Face face;
|
|
|
|
FT_GlyphSlot slot;
|
2003-09-17 16:41:33 +04:00
|
|
|
FT_UInt glyph_index=0, previous=0;
|
2003-01-29 02:58:06 +03:00
|
|
|
FT_Vector pen,delta;
|
|
|
|
int16 error=0;
|
|
|
|
int32 strlength,i;
|
|
|
|
float returnval;
|
|
|
|
|
|
|
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
|
|
|
if(error)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
|
|
|
|
|
|
|
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
|
|
|
if(error)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
// set the pen position in 26.6 cartesian space coordinates
|
|
|
|
pen.x=0;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
strlength=strlen(string);
|
|
|
|
if(length<strlength)
|
|
|
|
strlength=length;
|
|
|
|
|
|
|
|
for(i=0;i<strlength;i++)
|
|
|
|
{
|
|
|
|
// get kerning and move pen
|
|
|
|
if(use_kerning && previous && glyph_index)
|
|
|
|
{
|
|
|
|
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
|
|
|
|
pen.x+=delta.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
error=FT_Load_Char(face,string[i],FT_LOAD_MONOCHROME);
|
|
|
|
|
|
|
|
// increment pen position
|
|
|
|
pen.x+=slot->advance.x;
|
|
|
|
previous=glyph_index;
|
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
FT_Done_Face(face);
|
|
|
|
|
|
|
|
returnval=pen.x>>6;
|
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
|
|
|
float ScreenDriver::StringHeight(const char *string, int32 length, LayerData *d)
|
|
|
|
{
|
2003-09-15 23:07:45 +04:00
|
|
|
if(!string || !d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return 0.0;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
2003-09-15 23:07:45 +04:00
|
|
|
ServerFont *font=&(d->font);
|
2003-01-29 02:58:06 +03:00
|
|
|
FontStyle *style=font->Style();
|
|
|
|
|
|
|
|
if(!style)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
FT_Face face;
|
|
|
|
FT_GlyphSlot slot;
|
|
|
|
int16 error=0;
|
|
|
|
int32 strlength,i;
|
|
|
|
float returnval=0.0,ascent=0.0,descent=0.0;
|
|
|
|
|
|
|
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
|
|
|
if(error)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
|
|
|
if(error)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
strlength=strlen(string);
|
|
|
|
if(length<strlength)
|
|
|
|
strlength=length;
|
|
|
|
|
|
|
|
for(i=0;i<strlength;i++)
|
|
|
|
{
|
|
|
|
FT_Load_Char(face,string[i],FT_LOAD_RENDER);
|
|
|
|
if(slot->metrics.horiBearingY<slot->metrics.height)
|
|
|
|
descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent);
|
|
|
|
else
|
|
|
|
ascent=MAX(slot->bitmap.rows,ascent);
|
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Unlock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
FT_Done_Face(face);
|
|
|
|
|
|
|
|
returnval=ascent+descent;
|
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
2003-06-23 06:54:52 +04:00
|
|
|
void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
2003-09-15 23:07:45 +04:00
|
|
|
if(!string || !d)
|
2003-01-29 02:58:06 +03:00
|
|
|
return;
|
2003-04-05 05:51:35 +04:00
|
|
|
screenwin->Lock();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
pt.y--; // because of Be's backward compatibility hack
|
|
|
|
|
2003-09-15 23:07:45 +04:00
|
|
|
ServerFont *font=&(d->font);
|
2003-01-29 02:58:06 +03:00
|
|
|
FontStyle *style=font->Style();
|
|
|
|
|
|
|
|
if(!style)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FT_Face face;
|
|
|
|
FT_GlyphSlot slot;
|
|
|
|
FT_Matrix rmatrix,smatrix;
|
2003-09-17 16:41:33 +04:00
|
|
|
FT_UInt glyph_index=0, previous=0;
|
2003-01-29 02:58:06 +03:00
|
|
|
FT_Vector pen,delta,space,nonspace;
|
|
|
|
int16 error=0;
|
|
|
|
int32 strlength,i;
|
|
|
|
Angle rotation(font->Rotation()), shear(font->Shear());
|
|
|
|
|
|
|
|
bool antialias=( (font->Size()<18 && font->Flags()& B_DISABLE_ANTIALIASING==0)
|
|
|
|
|| font->Flags()& B_FORCE_ANTIALIASING)?true:false;
|
|
|
|
|
|
|
|
// Originally, I thought to do this shear checking here, but it really should be
|
|
|
|
// done in BFont::SetShear()
|
|
|
|
float shearangle=shear.Value();
|
|
|
|
if(shearangle>135)
|
|
|
|
shearangle=135;
|
|
|
|
if(shearangle<45)
|
|
|
|
shearangle=45;
|
|
|
|
|
|
|
|
if(shearangle>90)
|
|
|
|
shear=90+((180-shearangle)*2);
|
|
|
|
else
|
|
|
|
shear=90-(90-shearangle)*2;
|
|
|
|
|
|
|
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
|
|
|
if(error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
|
|
|
|
|
|
|
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
|
|
|
if(error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if we do any transformation, we do a call to FT_Set_Transform() here
|
|
|
|
|
|
|
|
// First, rotate
|
|
|
|
rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000);
|
2003-04-05 05:51:35 +04:00
|
|
|
rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000);
|
|
|
|
rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000);
|
2003-01-29 02:58:06 +03:00
|
|
|
rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000);
|
|
|
|
|
|
|
|
// Next, shear
|
|
|
|
smatrix.xx = (FT_Fixed)(0x10000);
|
|
|
|
smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000);
|
|
|
|
smatrix.yx = (FT_Fixed)(0);
|
|
|
|
smatrix.yy = (FT_Fixed)(0x10000);
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
FT_Matrix_Multiply(&rmatrix,&smatrix);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
// Set up the increment value for escapement padding
|
|
|
|
space.x=int32(d->edelta.space * rotation.Cosine()*64);
|
|
|
|
space.y=int32(d->edelta.space * rotation.Sine()*64);
|
|
|
|
nonspace.x=int32(d->edelta.nonspace * rotation.Cosine()*64);
|
|
|
|
nonspace.y=int32(d->edelta.nonspace * rotation.Sine()*64);
|
|
|
|
|
|
|
|
// set the pen position in 26.6 cartesian space coordinates
|
|
|
|
pen.x=(int32)pt.x * 64;
|
|
|
|
pen.y=(int32)pt.y * 64;
|
|
|
|
|
|
|
|
slot=face->glyph;
|
|
|
|
|
|
|
|
|
|
|
|
strlength=strlen(string);
|
|
|
|
if(length<strlength)
|
|
|
|
strlength=length;
|
|
|
|
|
|
|
|
for(i=0;i<strlength;i++)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
FT_Set_Transform(face,&smatrix,&pen);
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
// Handle escapement padding option
|
|
|
|
if((uint8)string[i]<=0x20)
|
|
|
|
{
|
|
|
|
pen.x+=space.x;
|
|
|
|
pen.y+=space.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pen.x+=nonspace.x;
|
|
|
|
pen.y+=nonspace.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get kerning and move pen
|
|
|
|
if(use_kerning && previous && glyph_index)
|
|
|
|
{
|
|
|
|
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
|
|
|
|
pen.x+=delta.x;
|
|
|
|
pen.y+=delta.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
error=FT_Load_Char(face,string[i],
|
|
|
|
((antialias)?FT_LOAD_RENDER:FT_LOAD_RENDER | FT_LOAD_MONOCHROME) );
|
|
|
|
|
|
|
|
if(!error)
|
|
|
|
{
|
|
|
|
if(antialias)
|
|
|
|
BlitGray2RGB32(&slot->bitmap,
|
|
|
|
BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d);
|
|
|
|
else
|
|
|
|
BlitMono2RGB32(&slot->bitmap,
|
|
|
|
BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// increment pen position
|
|
|
|
pen.x+=slot->advance.x;
|
|
|
|
pen.y+=slot->advance.y;
|
|
|
|
previous=glyph_index;
|
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
|
|
|
|
// TODO: implement properly
|
|
|
|
// calculate the invalid rectangle
|
|
|
|
BRect r;
|
|
|
|
r.left=MIN(pt.x,pen.x>>6);
|
|
|
|
r.right=MAX(pt.x,pen.x>>6);
|
|
|
|
r.top=pt.y-face->height;
|
|
|
|
r.bottom=pt.y+face->height;
|
|
|
|
|
|
|
|
screenwin->view->Invalidate(r);
|
|
|
|
screenwin->Unlock();
|
|
|
|
|
2003-01-29 02:58:06 +03:00
|
|
|
FT_Done_Face(face);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenDriver::BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d)
|
|
|
|
{
|
|
|
|
rgb_color color=d->highcolor.GetColor32();
|
|
|
|
|
|
|
|
// pointers to the top left corner of the area to be copied in each bitmap
|
|
|
|
uint8 *srcbuffer, *destbuffer;
|
|
|
|
|
|
|
|
// index pointers which are incremented during the course of the blit
|
|
|
|
uint8 *srcindex, *destindex, *rowptr, value;
|
|
|
|
|
|
|
|
// increment values for the index pointers
|
2003-04-05 05:51:35 +04:00
|
|
|
int32 srcinc=src->pitch, destinc=framebuffer->BytesPerRow();
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows;
|
|
|
|
int32 x=(int32)pt.x,y=(int32)pt.y;
|
|
|
|
|
|
|
|
// starting point in source bitmap
|
|
|
|
srcbuffer=(uint8*)src->buffer;
|
|
|
|
|
|
|
|
if(y<0)
|
|
|
|
{
|
|
|
|
if(y<pt.y)
|
|
|
|
y++;
|
|
|
|
srcbuffer+=srcinc * (0-y);
|
|
|
|
srcheight-=srcinc;
|
|
|
|
destbuffer+=destinc * (0-y);
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
|
|
|
if(y>pt.y)
|
|
|
|
y--;
|
2003-04-05 05:51:35 +04:00
|
|
|
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
|
|
|
if(x>pt.x)
|
|
|
|
x--;
|
2003-04-05 05:51:35 +04:00
|
|
|
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(x<0)
|
|
|
|
{
|
|
|
|
if(x<pt.x)
|
|
|
|
x++;
|
|
|
|
srcbuffer+=(0-x)>>3;
|
|
|
|
srcwidth-=0-x;
|
|
|
|
destbuffer+=(0-x)*4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// starting point in destination bitmap
|
2003-04-05 05:51:35 +04:00
|
|
|
destbuffer=(uint8*)framebuffer->Bits()+int32( (pt.y*framebuffer->BytesPerRow())+(pt.x*4) );
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
srcindex=srcbuffer;
|
|
|
|
destindex=destbuffer;
|
|
|
|
|
|
|
|
for(i=0; i<srcheight; i++)
|
|
|
|
{
|
|
|
|
rowptr=destindex;
|
|
|
|
|
|
|
|
for(j=0;j<srcwidth;j++)
|
|
|
|
{
|
|
|
|
for(k=0; k<8; k++)
|
|
|
|
{
|
|
|
|
value=*(srcindex+j) & (1 << (7-k));
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
rowptr[0]=color.blue;
|
|
|
|
rowptr[1]=color.green;
|
|
|
|
rowptr[2]=color.red;
|
|
|
|
rowptr[3]=color.alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
rowptr+=4;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
srcindex+=srcinc;
|
|
|
|
destindex+=destinc;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenDriver::BlitGray2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d)
|
|
|
|
{
|
|
|
|
// pointers to the top left corner of the area to be copied in each bitmap
|
|
|
|
uint8 *srcbuffer=NULL, *destbuffer=NULL;
|
|
|
|
|
|
|
|
// index pointers which are incremented during the course of the blit
|
|
|
|
uint8 *srcindex=NULL, *destindex=NULL, *rowptr=NULL;
|
|
|
|
|
|
|
|
rgb_color highcolor=d->highcolor.GetColor32(), lowcolor=d->lowcolor.GetColor32(); float rstep,gstep,bstep,astep;
|
|
|
|
|
|
|
|
rstep=float(highcolor.red-lowcolor.red)/255.0;
|
|
|
|
gstep=float(highcolor.green-lowcolor.green)/255.0;
|
|
|
|
bstep=float(highcolor.blue-lowcolor.blue)/255.0;
|
|
|
|
astep=float(highcolor.alpha-lowcolor.alpha)/255.0;
|
|
|
|
|
|
|
|
// increment values for the index pointers
|
|
|
|
int32 x=(int32)pt.x,
|
|
|
|
y=(int32)pt.y,
|
|
|
|
srcinc=src->pitch,
|
|
|
|
// destinc=dest->BytesPerRow(),
|
2003-04-05 05:51:35 +04:00
|
|
|
destinc=framebuffer->BytesPerRow(),
|
2003-01-29 02:58:06 +03:00
|
|
|
srcwidth=src->width,
|
|
|
|
srcheight=src->rows,
|
|
|
|
incval=0;
|
|
|
|
|
|
|
|
int16 i,j;
|
|
|
|
|
|
|
|
// starting point in source bitmap
|
|
|
|
srcbuffer=(uint8*)src->buffer;
|
|
|
|
|
|
|
|
// starting point in destination bitmap
|
|
|
|
// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4));
|
2003-04-05 05:51:35 +04:00
|
|
|
destbuffer=(uint8*)framebuffer->Bits()+(y*framebuffer->BytesPerRow()+(x*4));
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
if(y<0)
|
|
|
|
{
|
|
|
|
if(y<pt.y)
|
|
|
|
y++;
|
|
|
|
|
|
|
|
incval=0-y;
|
|
|
|
|
|
|
|
srcbuffer+=incval * srcinc;
|
|
|
|
srcheight-=incval;
|
|
|
|
destbuffer+=incval * destinc;
|
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
|
|
|
if(y>pt.y)
|
|
|
|
y--;
|
2003-04-05 05:51:35 +04:00
|
|
|
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
|
|
|
if(x>pt.x)
|
|
|
|
x--;
|
2003-04-05 05:51:35 +04:00
|
|
|
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
|
2003-01-29 02:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(x<0)
|
|
|
|
{
|
|
|
|
if(x<pt.x)
|
|
|
|
x++;
|
|
|
|
incval=0-x;
|
|
|
|
srcbuffer+=incval;
|
|
|
|
srcwidth-=incval;
|
|
|
|
destbuffer+=incval*4;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 value;
|
|
|
|
|
|
|
|
srcindex=srcbuffer;
|
|
|
|
destindex=destbuffer;
|
|
|
|
|
|
|
|
for(i=0; i<srcheight; i++)
|
|
|
|
{
|
|
|
|
rowptr=destindex;
|
|
|
|
|
|
|
|
for(j=0;j<srcwidth;j++)
|
|
|
|
{
|
|
|
|
value=*(srcindex+j) ^ 255;
|
|
|
|
|
|
|
|
if(value!=255)
|
|
|
|
{
|
|
|
|
if(d->draw_mode==B_OP_COPY)
|
|
|
|
{
|
|
|
|
rowptr[0]=uint8(highcolor.blue-(value*bstep));
|
|
|
|
rowptr[1]=uint8(highcolor.green-(value*gstep));
|
|
|
|
rowptr[2]=uint8(highcolor.red-(value*rstep));
|
|
|
|
rowptr[3]=255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(d->draw_mode==B_OP_OVER)
|
|
|
|
{
|
|
|
|
if(highcolor.alpha>127)
|
|
|
|
{
|
|
|
|
rowptr[0]=uint8(highcolor.blue-(value*(float(highcolor.blue-rowptr[0])/255.0)));
|
|
|
|
rowptr[1]=uint8(highcolor.green-(value*(float(highcolor.green-rowptr[1])/255.0)));
|
|
|
|
rowptr[2]=uint8(highcolor.red-(value*(float(highcolor.red-rowptr[2])/255.0)));
|
|
|
|
rowptr[3]=255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rowptr+=4;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
srcindex+=srcinc;
|
|
|
|
destindex+=destinc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-23 06:54:52 +04:00
|
|
|
rgb_color ScreenDriver::GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high)
|
2003-01-29 02:58:06 +03:00
|
|
|
{
|
|
|
|
rgb_color returncolor={0,0,0,0};
|
|
|
|
int16 value;
|
|
|
|
if(!d)
|
|
|
|
return returncolor;
|
|
|
|
|
|
|
|
switch(d->draw_mode)
|
|
|
|
{
|
|
|
|
case B_OP_COPY:
|
|
|
|
{
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
case B_OP_ADD:
|
|
|
|
{
|
|
|
|
value=src.red+dest.red;
|
|
|
|
returncolor.red=(value>255)?255:value;
|
|
|
|
|
|
|
|
value=src.green+dest.green;
|
|
|
|
returncolor.green=(value>255)?255:value;
|
|
|
|
|
|
|
|
value=src.blue+dest.blue;
|
|
|
|
returncolor.blue=(value>255)?255:value;
|
|
|
|
return returncolor;
|
|
|
|
}
|
|
|
|
case B_OP_SUBTRACT:
|
|
|
|
{
|
|
|
|
value=src.red-dest.red;
|
|
|
|
returncolor.red=(value<0)?0:value;
|
|
|
|
|
|
|
|
value=src.green-dest.green;
|
|
|
|
returncolor.green=(value<0)?0:value;
|
|
|
|
|
|
|
|
value=src.blue-dest.blue;
|
|
|
|
returncolor.blue=(value<0)?0:value;
|
|
|
|
return returncolor;
|
|
|
|
}
|
|
|
|
case B_OP_BLEND:
|
|
|
|
{
|
|
|
|
value=int16(src.red+dest.red)>>1;
|
|
|
|
returncolor.red=value;
|
|
|
|
|
|
|
|
value=int16(src.green+dest.green)>>1;
|
|
|
|
returncolor.green=value;
|
|
|
|
|
|
|
|
value=int16(src.blue+dest.blue)>>1;
|
|
|
|
returncolor.blue=value;
|
|
|
|
return returncolor;
|
|
|
|
}
|
|
|
|
case B_OP_MIN:
|
|
|
|
{
|
|
|
|
|
|
|
|
return ( uint16(src.red+src.blue+src.green) >
|
|
|
|
uint16(dest.red+dest.blue+dest.green) )?dest:src;
|
|
|
|
}
|
|
|
|
case B_OP_MAX:
|
|
|
|
{
|
|
|
|
return ( uint16(src.red+src.blue+src.green) <
|
|
|
|
uint16(dest.red+dest.blue+dest.green) )?dest:src;
|
|
|
|
}
|
|
|
|
case B_OP_OVER:
|
|
|
|
{
|
|
|
|
return (use_high && src.alpha>127)?src:dest;
|
|
|
|
}
|
|
|
|
case B_OP_INVERT:
|
|
|
|
{
|
|
|
|
returncolor.red=dest.red ^ 255;
|
|
|
|
returncolor.green=dest.green ^ 255;
|
|
|
|
returncolor.blue=dest.blue ^ 255;
|
|
|
|
return (use_high && src.alpha>127)?returncolor:dest;
|
|
|
|
}
|
|
|
|
// This is a pain in the arse to implement, so I'm saving it for the real
|
|
|
|
// server
|
|
|
|
case B_OP_ALPHA:
|
|
|
|
{
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
case B_OP_ERASE:
|
|
|
|
{
|
|
|
|
// This one's tricky.
|
|
|
|
return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest;
|
|
|
|
}
|
|
|
|
case B_OP_SELECT:
|
|
|
|
{
|
|
|
|
// This one's tricky, too. We are passed a color in src. If it's the layer's
|
|
|
|
// high color or low color, we check for a swap.
|
|
|
|
if(d->highcolor==src)
|
|
|
|
return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest;
|
|
|
|
|
|
|
|
if(d->lowcolor==src)
|
|
|
|
return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest;
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returncolor;
|
|
|
|
}
|