DragAndDropSprite.cpp
Go to the documentation of this file.00001 //*** DragAndDropSprite.cpp ** 00002 00003 #include "DragAndDropSprite.h" 00004 #include "BitmapStrip.h" 00005 #include "Bitmap.h" 00006 #include "SpriteControllerManager.h" 00007 #include "SpriteController.h" 00008 #include "SpriteAction_ButtonStateCrossFade.h" 00009 00010 00011 //** Constructor *** 00012 00013 DragAndDropSprite::DragAndDropSprite(): 00014 dragging_(false), 00015 dragOffsetX_(0), 00016 dragOffsetY_(0) 00017 { 00018 00019 } 00020 00021 00022 //** Constructor *** 00023 00024 DragAndDropSprite::DragAndDropSprite(SpriteManager* spriteManager): 00025 Button(spriteManager), 00026 dragging_(false), 00027 dragOffsetX_(0), 00028 dragOffsetY_(0) 00029 { 00030 00031 } 00032 00033 00034 //*** OnMouseOver *** 00035 00036 bool DragAndDropSprite::OnMouseOver(int x, int y, bool button, StringId& eventId, void*& userData) 00037 { 00038 if (!IsEnabled()) 00039 { 00040 dragging_=false; 00041 return false; 00042 } 00043 00044 if (dragging_) 00045 { 00046 SetPosition((float)x-dragOffsetX_,(float)y-dragOffsetY_); 00047 } 00048 00049 00050 const BitmapStrip& bitmapStrip=GetBitmap(); 00051 if (bitmapStrip.GetCelCount()!=0) 00052 { 00053 int currentCel=(int)GetCel(); 00054 const Bitmap& bitmap=bitmapStrip.GetCel(currentCel); 00055 if (bitmap.GetPixelAlpha(x-(int)(GetX()+GetOriginX()),y-(int)(GetY()+GetOriginY()))>128) 00056 { 00057 if (IsEnabled()) 00058 { 00059 // highlighted_=true; 00060 if (button) 00061 { 00062 SetState(State_Pressed); 00063 if (!dragging_) 00064 { 00065 dragOffsetX_=x-GetX()+GetOriginX(); 00066 dragOffsetY_=y-GetY()+GetOriginY(); 00067 } 00068 dragging_=true; 00069 } 00070 else 00071 { 00072 SetState(State_Highlighted); 00073 dragging_=false; 00074 } 00075 } 00076 00077 eventId=GetEventId(); 00078 userData=GetEventUserData(); 00079 00080 return true; 00081 } 00082 } 00083 00084 return false; 00085 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
