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:
@@ -40,7 +40,11 @@ APRWindow::APRWindow(BRect frame)
|
|||||||
|
|
||||||
BTab *tab=NULL;
|
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);
|
colors=new APRView(Bounds(),"Colors",B_FOLLOW_ALL, B_WILL_DRAW);
|
||||||
tab=new BTab(colors);
|
tab=new BTab(colors);
|
||||||
tabview->AddTab(colors,tab);
|
tabview->AddTab(colors,tab);
|
||||||
@@ -49,11 +53,6 @@ APRWindow::APRWindow(BRect frame)
|
|||||||
tab=new BTab(decorators);
|
tab=new BTab(decorators);
|
||||||
tabview->AddTab(decorators,tab);
|
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);
|
AddChild(tabview);
|
||||||
decorators->SetColors(*colors->currentset);
|
decorators->SetColors(*colors->currentset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,12 +39,14 @@
|
|||||||
#include <ServerProtocol.h>
|
#include <ServerProtocol.h>
|
||||||
#include <PortMessage.h>
|
#include <PortMessage.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include <TranslationUtils.h>
|
||||||
|
|
||||||
//#define DEBUG_CURSORSET
|
//#define DEBUG_CURSORSET
|
||||||
|
|
||||||
#define SAVE_CURSORSET 'svcu'
|
#define SAVE_CURSORSET 'svcu'
|
||||||
#define DELETE_CURSORSET 'dlcu'
|
#define DELETE_CURSORSET 'dlcu'
|
||||||
#define LOAD_CURSORSET 'ldcu'
|
#define LOAD_CURSORSET 'ldcu'
|
||||||
|
#define CURSOR_UPDATED 'csru'
|
||||||
|
|
||||||
CurView::CurView(const BRect &frame, const char *name, int32 resize, int32 flags)
|
CurView::CurView(const BRect &frame, const char *name, int32 resize, int32 flags)
|
||||||
:BView(frame,name,resize,flags), settings(B_SIMPLE_DATA)
|
: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);
|
AddChild(apply);
|
||||||
apply->SetEnabled(false);
|
apply->SetEnabled(false);
|
||||||
|
|
||||||
cvrect.Set(0,0,48,48);
|
cvrect.Set(0,0,75,75);
|
||||||
BPoint pt;
|
BPoint pt;
|
||||||
pt.x=scrollview->Frame().right+(Bounds().right-scrollview->Frame().right-cvrect.Width())/2;
|
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;
|
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);
|
AddChild(bmpview);
|
||||||
|
|
||||||
BEntry entry(COLOR_SET_DIR);
|
BEntry entry(COLOR_SET_DIR);
|
||||||
@@ -163,7 +165,7 @@ void CurView::AllAttached(void)
|
|||||||
revert->SetTarget(this);
|
revert->SetTarget(this);
|
||||||
settings_menu->SetTargetForItems(this);
|
settings_menu->SetTargetForItems(this);
|
||||||
cursorset_menu->SetTargetForItems(this);
|
cursorset_menu->SetTargetForItems(this);
|
||||||
|
bmpview->SetTarget(this);
|
||||||
BMessenger msgr(this);
|
BMessenger msgr(this);
|
||||||
savepanel->SetTarget(msgr);
|
savepanel->SetTarget(msgr);
|
||||||
}
|
}
|
||||||
@@ -176,99 +178,26 @@ void CurView::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
switch(msg->what)
|
switch(msg->what)
|
||||||
{
|
{
|
||||||
/* case DELETE_CURSORSET:
|
case CURSOR_UPDATED:
|
||||||
{
|
{
|
||||||
// Construct the path and delete
|
CursorWhichItem *cwi=(CursorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection());
|
||||||
BString path(COLOR_SET_DIR);
|
if(cwi)
|
||||||
path+=cursorset_name;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case ATTRIBUTE_CHOSEN:
|
case ATTRIBUTE_CHOSEN:
|
||||||
{
|
{
|
||||||
break;
|
CursorWhichItem *cwi=(CursorWhichItem*)attrlist->ItemAt(attrlist->CurrentSelection());
|
||||||
}
|
if(cwi)
|
||||||
case APPLY_SETTINGS:
|
{
|
||||||
{
|
bmpview->SetBitmap(cwi->GetBitmap());
|
||||||
SaveSettings();
|
bmpview->Invalidate();
|
||||||
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();
|
|
||||||
|
|
||||||
LoadCursorSet(prev_set_name);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEFAULT_SETTINGS:
|
default:
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/ default:
|
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -473,29 +402,86 @@ void CurView::SetDefaults(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapView::BitmapView(const BPoint &pt)
|
BitmapView::BitmapView(const BPoint &pt,BMessage *message, const BHandler *handler, const BLooper *looper=NULL)
|
||||||
: BView(BRect(0,0,48,48).OffsetToCopy(pt),"bitmapview",B_FOLLOW_NONE,B_WILL_DRAW)
|
: 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;
|
bitmap=NULL;
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
drawrect=Bounds().InsetByCopy(5,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapView::~BitmapView(void)
|
BitmapView::~BitmapView(void)
|
||||||
{
|
{
|
||||||
if(bitmap)
|
|
||||||
delete bitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapView::SetBitmap(BBitmap *bmp)
|
void BitmapView::SetBitmap(BBitmap *bmp)
|
||||||
{
|
{
|
||||||
if(bitmap)
|
|
||||||
delete bitmap;
|
|
||||||
bitmap=bmp;
|
bitmap=bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapView::Draw(BRect r)
|
void BitmapView::Draw(BRect r)
|
||||||
{
|
{
|
||||||
|
BBox::Draw(r);
|
||||||
|
|
||||||
if(bitmap)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,18 +43,24 @@
|
|||||||
#include <Invoker.h>
|
#include <Invoker.h>
|
||||||
#include <SysCursor.h>
|
#include <SysCursor.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Invoker.h>
|
||||||
|
|
||||||
class APRWindow;
|
class APRWindow;
|
||||||
|
|
||||||
class BitmapView : public BView
|
class BitmapView : public BBox, public BInvoker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BitmapView(const BPoint &pt);
|
BitmapView(const BPoint &pt,BMessage *message,
|
||||||
|
const BHandler *handler, const BLooper *looper=NULL);
|
||||||
~BitmapView(void);
|
~BitmapView(void);
|
||||||
void SetBitmap(BBitmap *bmp);
|
void SetBitmap(BBitmap *bmp);
|
||||||
|
BBitmap *GetBitmap(void) const { return bitmap; }
|
||||||
void Draw(BRect r);
|
void Draw(BRect r);
|
||||||
|
void MessageReceived(BMessage *msg);
|
||||||
protected:
|
protected:
|
||||||
BBitmap *bitmap;
|
BBitmap *bitmap;
|
||||||
|
BRect drawrect;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CurView : public BView
|
class CurView : public BView
|
||||||
|
|||||||
@@ -31,11 +31,14 @@ CursorWhichItem::CursorWhichItem(cursor_which which)
|
|||||||
: BStringItem(NULL,0,false)
|
: BStringItem(NULL,0,false)
|
||||||
{
|
{
|
||||||
SetAttribute(which);
|
SetAttribute(which);
|
||||||
|
image=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorWhichItem::~CursorWhichItem(void)
|
CursorWhichItem::~CursorWhichItem(void)
|
||||||
{
|
{
|
||||||
// Empty, but exists for just-in-case
|
// Empty, but exists for just-in-case
|
||||||
|
if(image)
|
||||||
|
delete image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CursorWhichItem::SetAttribute(cursor_which which)
|
void CursorWhichItem::SetAttribute(cursor_which which)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
#include <SysCursor.h>
|
#include <SysCursor.h>
|
||||||
|
|
||||||
class CursorWhichItem : public BStringItem
|
class CursorWhichItem : public BStringItem
|
||||||
@@ -39,8 +39,11 @@ public:
|
|||||||
~CursorWhichItem(void);
|
~CursorWhichItem(void);
|
||||||
void SetAttribute(cursor_which which);
|
void SetAttribute(cursor_which which);
|
||||||
cursor_which GetAttribute(void);
|
cursor_which GetAttribute(void);
|
||||||
|
void SetBitmap(BBitmap *bmp) { if(image) delete image; image=bmp; }
|
||||||
|
BBitmap *GetBitmap(void) const { return image; }
|
||||||
private:
|
private:
|
||||||
cursor_which attribute;
|
cursor_which attribute;
|
||||||
|
BBitmap *image;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -17,4 +17,4 @@ Preference Appearance :
|
|||||||
CursorWhichItem.cpp
|
CursorWhichItem.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs Appearance : be tracker libappserver.so libopenbeos.so ;
|
LinkSharedOSLibs Appearance : be tracker translation libappserver.so libopenbeos.so ;
|
||||||
|
|||||||
Reference in New Issue
Block a user