From a8224b92575fec74f2b1df620220aa2f9d2e9ff9 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Thu, 20 Feb 2003 20:14:57 +0000 Subject: [PATCH] Added CursorManager and BitmapManager to startup procedures Work on cursor support. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2784 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/server/AppServer.cpp | 23 ++++++++ src/servers/app/server/AppServer.h | 6 ++ src/servers/app/server/BitmapManager.cpp | 3 + src/servers/app/server/BitmapManager.h | 2 + src/servers/app/server/CursorData.cpp | 73 ++++++++++++++++++++++++ src/servers/app/server/Jamfile | 1 + src/servers/app/server/ServerApp.cpp | 4 +- src/servers/app/server/ServerCursor.h | 4 +- 8 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 src/servers/app/server/CursorData.cpp diff --git a/src/servers/app/server/AppServer.cpp b/src/servers/app/server/AppServer.cpp index 465f66bc74..efd7c18572 100644 --- a/src/servers/app/server/AppServer.cpp +++ b/src/servers/app/server/AppServer.cpp @@ -30,10 +30,13 @@ #include "DisplayDriver.h" #include "PortLink.h" #include "ServerApp.h" +#include "ServerCursor.h" #include "ServerProtocol.h" #include "ServerWindow.h" #include "DefaultDecorator.h" #include "RGBColor.h" +#include "BitmapManager.h" +#include "CursorManager.h" // Globals @@ -85,6 +88,23 @@ AppServer::AppServer(void) // Set up the Desktop InitDesktop(); + // Create the cursor manager. Object declared in CursorManager.cpp + cursormanager=new CursorManager(); + + // Default cursor data stored in CursorData.cpp + + // TODO: fix the cursor display +// extern int8 default_cursor_data[]; +// ServerCursor *sc=new ServerCursor(default_cursor_data); + extern int8 cross_cursor[]; + ServerCursor *sc=new ServerCursor(cross_cursor); + cursormanager->AddCursor(sc); + cursormanager->ChangeCursor(B_CURSOR_DEFAULT, sc->ID()); + cursormanager->SetCursor(B_CURSOR_DEFAULT); + + // Create the bitmap allocator. Object declared in BitmapManager.cpp + bitmapmanager=new BitmapManager(); + // This is necessary to mediate access between the Poller and app_server threads _active_lock=create_sem(1,"app_server_active_sem"); @@ -134,6 +154,9 @@ AppServer::~AppServer(void) delete _applist; release_sem(_applist_lock); + delete bitmapmanager; + delete cursormanager; + ShutdownDesktop(); // If these threads are still running, kill them - after this, if exit_poller diff --git a/src/servers/app/server/AppServer.h b/src/servers/app/server/AppServer.h index 681a3bac8f..08c9f9cbcc 100644 --- a/src/servers/app/server/AppServer.h +++ b/src/servers/app/server/AppServer.h @@ -13,6 +13,8 @@ class Layer; class BMessage; class ServerApp; class DisplayDriver; +class CursorManager; +class BitmapManager; /*! \class AppServer AppServer.h @@ -61,4 +63,8 @@ private: Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, DisplayDriver *ddriver); + +extern CursorManager *cursormanager; +extern BitmapManager *bitmapmanager; + #endif diff --git a/src/servers/app/server/BitmapManager.cpp b/src/servers/app/server/BitmapManager.cpp index a22c157e0a..a44c837155 100644 --- a/src/servers/app/server/BitmapManager.cpp +++ b/src/servers/app/server/BitmapManager.cpp @@ -28,6 +28,9 @@ #include "ServerBitmap.h" #include +//! The bitmap allocator for the server. Memory is allocated/freed by the AppServer class +BitmapManager *bitmapmanager=NULL; + //! BGET function calls - defined here because of C++ name mangling causing link problems typedef long bufsize; extern "C" void bpool(void *buffer, bufsize len); diff --git a/src/servers/app/server/BitmapManager.h b/src/servers/app/server/BitmapManager.h index 365ac5d6a8..79d02bd382 100644 --- a/src/servers/app/server/BitmapManager.h +++ b/src/servers/app/server/BitmapManager.h @@ -59,4 +59,6 @@ protected: sem_id lock; }; +extern BitmapManager *bitmapmanager; + #endif \ No newline at end of file diff --git a/src/servers/app/server/CursorData.cpp b/src/servers/app/server/CursorData.cpp new file mode 100644 index 0000000000..1410869f28 --- /dev/null +++ b/src/servers/app/server/CursorData.cpp @@ -0,0 +1,73 @@ +#include + +/* +The first four bytes of cursor data give information about the cursor: + +Byte 1: Size in pixels-per-side. Cursors are always square; currently, only 16-by-16 +cursors are allowed. +Byte 2: Color depth in bits-per-pixel. Currently, only one-bit monochrome is allowed. +Bytes 3&4: Hot spot coordinates. Given in "cursor coordinates" where (0,0) is the upper +left corner of the cursor grid, byte 3 is the hot spot's y coordinate, and byte 4 is its x +coordinate. The hot spot is a single pixel that's "activated" when the user clicks the mouse. +To push a button, for example, the hot spot must be within the button's bounds. + +Next comes an array of pixel color data. Pixels are specified from left to right in rows starting at +the top of the image and working downward. The size of an array element is the depth of the +image. In one-bit depth... + +the 16x16 array fits in 32 bytes. +1 is black and 0 is white. + +Then comes the pixel transparency bitmask, given left-to-right and top-to-bottom. 1 is opaque, 0 is +transparent. Transparency only applies to white pixels—black pixels are always opaque. +*/ + +// Impressive ASCII art, eh? + +int8 default_cursor_data[] = { +16,1,0,0, +255,224, // ***********----- +128,16, // *----------*---- +128,16, // *----------*---- +128,96, // *--------**----- +128,16, // *----------*---- +128,8, // *-----------*--- +128,8, // *-----------*--- +128,16, // *----------*---- +128,32, // *---------*----- +144,64, // *--*-----*------ +144,128, // *--*----*------- +105,0, // -**-*--*-------- + +0,6, // -----**--------- +0,0, // ---------------- +0,0, // ---------------- +0,0, // ---------------- + +// default_cursor mask - black pixels are always opaque +0,0, +255,224, +255,224, +255,128, +255,224, +255,240, +255,240, +255,224, +255,128, +255,0, +255,0, +255,0, + +0,0, +0,0, +0,0, +0,0 +}; + +// known good cursor data for testing rest of system +int8 cross_cursor[] = {16,1,5,5, +14,0,4,0,4,0,4,0,128,32,241,224,128,32,4,0, +4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0, +14,0,4,0,4,0,4,0,128,32,245,224,128,32,4,0, +4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0 +}; diff --git a/src/servers/app/server/Jamfile b/src/servers/app/server/Jamfile index cd0fb0785f..b562e9fbba 100644 --- a/src/servers/app/server/Jamfile +++ b/src/servers/app/server/Jamfile @@ -10,6 +10,7 @@ Server app_server : areafunc.c Angle.cpp bget.c + CursorData.cpp TokenHandler.cpp PatternHandler.cpp diff --git a/src/servers/app/server/ServerApp.cpp b/src/servers/app/server/ServerApp.cpp index fbcf5def8f..9bb328eb3c 100644 --- a/src/servers/app/server/ServerApp.cpp +++ b/src/servers/app/server/ServerApp.cpp @@ -413,11 +413,11 @@ void ServerApp::DispatchMessage(int32 code, int8 *buffer) // otherwise be easy to crash the server by calling SetCursor a // sufficient number of times if(_appcursor) - cursormanager->DeleteCursor(_appcursor->_token); + cursormanager->DeleteCursor(_appcursor->ID()); _appcursor=new ServerCursor(cdata); cursormanager->AddCursor(_appcursor); - cursormanager->SetCursor(_appcursor->_token); + cursormanager->SetCursor(_appcursor->ID()); break; } case SET_CURSOR_BCURSOR: diff --git a/src/servers/app/server/ServerCursor.h b/src/servers/app/server/ServerCursor.h index 93e9f89d71..98964bf1f7 100644 --- a/src/servers/app/server/ServerCursor.h +++ b/src/servers/app/server/ServerCursor.h @@ -54,8 +54,10 @@ public: BPoint GetHotSpot(void); void SetHotSpot(BPoint pt); const char *GetAppSignature(void) { return _app_signature; } + + //! Returns the cursor's ID + int32 ID(void) { return _token; } private: - friend ServerApp; friend CursorManager; BPoint _hotspot;