Wrote code to make it possible to drag and drop an image to set a cursor for any system cursor attribute in the list

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4983 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-10-10 00:34:38 +00:00
parent 28d6d190dc
commit 9b2a55526a
6 changed files with 101 additions and 104 deletions

View File

@ -40,7 +40,11 @@ APRWindow::APRWindow(BRect frame)
BTab *tab=NULL;
// TODO: Finish CurView
cursors=new CurView(Bounds(),"Cursors",B_FOLLOW_ALL, B_WILL_DRAW);
tab=new BTab(cursors);
tabview->AddTab(cursors,tab);
colors=new APRView(Bounds(),"Colors",B_FOLLOW_ALL, B_WILL_DRAW);
tab=new BTab(colors);
tabview->AddTab(colors,tab);
@ -49,11 +53,6 @@ APRWindow::APRWindow(BRect frame)
tab=new BTab(decorators);
tabview->AddTab(decorators,tab);
// TODO: Finish CurView
cursors=new CurView(Bounds(),"Cursors",B_FOLLOW_ALL, B_WILL_DRAW);
tab=new BTab(cursors);
tabview->AddTab(cursors,tab);
AddChild(tabview);
decorators->SetColors(*colors->currentset);
}

View File

@ -39,12 +39,14 @@
#include <ServerProtocol.h>
#include <PortMessage.h>
#include <InterfaceDefs.h>
#include <TranslationUtils.h>
//#define DEBUG_CURSORSET
#define SAVE_CURSORSET 'svcu'
#define DELETE_CURSORSET 'dlcu'
#define LOAD_CURSORSET 'ldcu'
#define CURSOR_UPDATED 'csru'
CurView::CurView(const BRect &frame, const char *name, int32 resize, int32 flags)
:BView(frame,name,resize,flags), settings(B_SIMPLE_DATA)
@ -128,12 +130,12 @@ CurView::CurView(const BRect &frame, const char *name, int32 resize, int32 flags
AddChild(apply);
apply->SetEnabled(false);
cvrect.Set(0,0,48,48);
cvrect.Set(0,0,75,75);
BPoint pt;
pt.x=scrollview->Frame().right+(Bounds().right-scrollview->Frame().right-cvrect.Width())/2;
pt.y=mb->Frame().bottom+(apply->Frame().top-mb->Frame().bottom-cvrect.Height())/2;
bmpview=new BitmapView(pt);
bmpview=new BitmapView(pt,new BMessage(CURSOR_UPDATED),this);
AddChild(bmpview);
BEntry entry(COLOR_SET_DIR);
@ -163,7 +165,7 @@ void CurView::AllAttached(void)
revert->SetTarget(this);
settings_menu->SetTargetForItems(this);
cursorset_menu->SetTargetForItems(this);
bmpview->SetTarget(this);
BMessenger msgr(this);
savepanel->SetTarget(msgr);
}
@ -176,99 +178,26 @@ void CurView::MessageReceived(BMessage *msg)
switch(msg->what)
{
/* case DELETE_CURSORSET:
case CURSOR_UPDATED:
{
// Construct the path and delete
BString path(COLOR_SET_DIR);
path+=cursorset_name;
CursorWhichItem *cwi=(CursorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection());
if(cwi)
cwi->SetBitmap(bmpview->GetBitmap());
BString printstring("Remove ");
printstring+=cursorset_name;
printstring+=" from disk permenantly?";
BAlert *a=new BAlert("OpenBeOS",printstring.String(),"Yes", "No");
if(a->Go()==0)
{
int stat=remove(path.String());
if(stat!=0)
{
#ifdef DEBUG_CURSORSET
printf("MSG: Delete Request - couldn't delete file %s\n",path.String());
#endif
}
else
{
BMenuItem *item=cursorset_menu->FindItem(cursorset_name.String());
if(item!=NULL)
{
if(cursorset_menu->RemoveItem(item))
delete item;
}
}
}
break;
}
case LOAD_CURSORSET:
{
BString name;
if(msg->FindString("name",&name)!=B_OK)
{
#ifdef DEBUG_CURSORSET
printf("MSG: Load Request - couldn't find file name\n");
#endif
break;
}
LoadCursorSet(name);
break;
}
case SAVE_CURSORSET:
{
savepanel->Show();
break;
}
case B_SAVE_REQUESTED:
{
BString name;
if(msg->FindString("name",&name)!=B_OK)
{
#ifdef DEBUG_CURSORSET
printf("MSG: Save Request - couldn't find file name\n");
#endif
break;
}
SaveCursorSet(name);
break;
}
case ATTRIBUTE_CHOSEN:
{
break;
}
case APPLY_SETTINGS:
{
SaveSettings();
NotifyServer();
break;
}
case TRY_SETTINGS:
{
// Tell server to apply settings here without saving them.
// Theoretically, the user can set this temporarily and keep it
// until the next boot.
NotifyServer();
break;
}
case REVERT_SETTINGS:
{
if(prev_set_name=="Default")
SetDefaults();
CursorWhichItem *cwi=(CursorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection());
if(cwi)
{
bmpview->SetBitmap(cwi->GetBitmap());
bmpview->Invalidate();
}
LoadCursorSet(prev_set_name);
break;
}
case DEFAULT_SETTINGS:
{
break;
}
*/ default:
default:
BView::MessageReceived(msg);
break;
}
@ -473,29 +402,86 @@ void CurView::SetDefaults(void)
}
BitmapView::BitmapView(const BPoint &pt)
: BView(BRect(0,0,48,48).OffsetToCopy(pt),"bitmapview",B_FOLLOW_NONE,B_WILL_DRAW)
BitmapView::BitmapView(const BPoint &pt,BMessage *message, const BHandler *handler, const BLooper *looper=NULL)
: BBox(BRect(0,0,75,75).OffsetToCopy(pt),"bitmapview",B_FOLLOW_NONE,B_WILL_DRAW, B_PLAIN_BORDER),
BInvoker(message,handler,looper)
{
SetFont(be_plain_font);
bitmap=NULL;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetDrawingMode(B_OP_ALPHA);
drawrect=Bounds().InsetByCopy(5,5);
}
BitmapView::~BitmapView(void)
{
if(bitmap)
delete bitmap;
}
void BitmapView::SetBitmap(BBitmap *bmp)
{
if(bitmap)
delete bitmap;
bitmap=bmp;
}
void BitmapView::Draw(BRect r)
{
BBox::Draw(r);
if(bitmap)
DrawBitmap(bitmap);
DrawBitmap(bitmap, drawrect);
}
void BitmapView::MessageReceived(BMessage *msg)
{
if(msg->WasDropped())
{
entry_ref ref;
if(msg->FindRef("refs",&ref)!=B_OK)
return;
BBitmap *tmp=BTranslationUtils::GetBitmap(&ref);
if(tmp)
{
delete bitmap;
bitmap=tmp;
int32 offset;
BRect r(Bounds());
r.right-=10;
r.bottom-=10;
drawrect=bitmap->Bounds();
if(r.Contains(bitmap->Bounds()))
{
// calculate a centered rect for direct display
offset=((r.IntegerWidth()-bitmap->Bounds().IntegerWidth()) >> 1)+5;
drawrect.OffsetBy(offset,offset);
}
else
{
// calculate a scaled-down rectangle for display
drawrect.left=drawrect.top=0;
if(bitmap->Bounds().Height() > bitmap->Bounds().Width())
{
drawrect.right=(r.Height()*bitmap->Bounds().Width())/bitmap->Bounds().Height();
drawrect.bottom=r.Height();
offset=((r.IntegerWidth()-drawrect.IntegerWidth()) >> 1)+5;
drawrect.OffsetBy(offset,5);
}
else
{
drawrect.bottom=(r.Width()*bitmap->Bounds().Height())/bitmap->Bounds().Width();
drawrect.right=r.Width();
offset=((r.IntegerHeight()-drawrect.IntegerHeight()) >> 1)+5;
drawrect.OffsetBy(5,offset);
}
}
Invoke();
Invalidate();
return;
}
}
else
BBox::MessageReceived(msg);
}

View File

@ -43,18 +43,24 @@
#include <Invoker.h>
#include <SysCursor.h>
#include <Bitmap.h>
#include <Box.h>
#include <Invoker.h>
class APRWindow;
class BitmapView : public BView
class BitmapView : public BBox, public BInvoker
{
public:
BitmapView(const BPoint &pt);
BitmapView(const BPoint &pt,BMessage *message,
const BHandler *handler, const BLooper *looper=NULL);
~BitmapView(void);
void SetBitmap(BBitmap *bmp);
BBitmap *GetBitmap(void) const { return bitmap; }
void Draw(BRect r);
void MessageReceived(BMessage *msg);
protected:
BBitmap *bitmap;
BRect drawrect;
};
class CurView : public BView

View File

@ -31,11 +31,14 @@ CursorWhichItem::CursorWhichItem(cursor_which which)
: BStringItem(NULL,0,false)
{
SetAttribute(which);
image=NULL;
}
CursorWhichItem::~CursorWhichItem(void)
{
// Empty, but exists for just-in-case
if(image)
delete image;
}
void CursorWhichItem::SetAttribute(cursor_which which)

View File

@ -29,7 +29,7 @@
#include <InterfaceDefs.h>
#include <ListItem.h>
#include <Bitmap.h>
#include <SysCursor.h>
class CursorWhichItem : public BStringItem
@ -39,8 +39,11 @@ public:
~CursorWhichItem(void);
void SetAttribute(cursor_which which);
cursor_which GetAttribute(void);
void SetBitmap(BBitmap *bmp) { if(image) delete image; image=bmp; }
BBitmap *GetBitmap(void) const { return image; }
private:
cursor_which attribute;
BBitmap *image;
};
#endif

View File

@ -17,4 +17,4 @@ Preference Appearance :
CursorWhichItem.cpp
;
LinkSharedOSLibs Appearance : be tracker libappserver.so libopenbeos.so ;
LinkSharedOSLibs Appearance : be tracker translation libappserver.so libopenbeos.so ;