00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef cargowidgetH
00020 #define cargowidgetH
00021
00022 #include "selectionwindow.h"
00023 #include "../graphics/surface.h"
00024 #include "../containerbase.h"
00025
00026 class Vehicle;
00027 class ContainerBase;
00028
00029 class HighLightingManager
00030 {
00031 int marked;
00032 public:
00033 HighLightingManager();
00034 int getMark();
00035 SigC::Signal2<void,int,int> markChanged;
00036 void setNew(int pos );
00037 SigC::Signal0<void> redrawAll;
00039 SigC::Signal3<void,int, SPoint, bool> clickOnMarkedUnit;
00040 };
00041
00042 class CargoWidget;
00043
00044 class StoringPosition : public PG_Widget
00045 {
00046 static Surface clippingSurface;
00047 HighLightingManager& highlight;
00048 const ContainerBase::Cargo& storage;
00049 int num;
00050 bool regular;
00051 CargoWidget* cargoWidget;
00052
00053 PG_Point unitPosition;
00054 PG_Point dragPointStart;
00055 PG_Point mouseCursorOffset;
00056
00057 static int spWidth;
00058 static int spHeight;
00059
00060 static PG_Rect CalcSize( const PG_Point& pos );
00061
00062 enum DragState { Off, Pressed, Dragging } dragState;
00063
00064
00065 protected:
00066 void markChanged(int old, int mark);
00067
00068 void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst);
00069
00070 void setBargraphValue( const ASCString& widgetName, float fraction);
00071 bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
00072 bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
00073 bool eventMouseMotion (const SDL_MouseMotionEvent *motion);
00074 public:
00075 enum DragTarget { NoDragging, TargetAvail, TargetNotAvail } ;
00076 protected:
00077 DragTarget dragTarget;
00078
00079 public:
00080 void setDragTarget( DragTarget dragTarget ) { this->dragTarget = dragTarget; };
00081
00082 static vector<StoringPosition*> setup( PG_Widget* parent, ContainerBase* container, HighLightingManager& highLightingManager, int& unitColumnCount );
00083 Vehicle* getUnit();
00084 StoringPosition( PG_Widget *parent, const PG_Point &pos, const PG_Point& unitPos, HighLightingManager& highLightingManager, const ContainerBase::Cargo& storageVector, int number, bool regularPosition, CargoWidget* cargoWidget = NULL );
00085 };
00086
00087
00088 class CargoWidget : public PG_ScrollWidget {
00089 ContainerBase* container;
00090 bool dragNdrop;
00091 int unitColumnCount;
00092 Vehicle* draggedUnit;
00093 void moveSelection( int delta );
00094
00095 typedef vector<StoringPosition*> StoringPositionVector;
00096 StoringPositionVector storingPositionVector;
00097
00098 void checkStoringPosition( int oldpos, int newpos );
00099 HighLightingManager unitHighLight;
00100
00101 void click( int num, SPoint mousePos, bool first );
00102 protected:
00103 bool handleScrollTrack (PG_ScrollBar *widget, long data);
00104
00105 public:
00106 CargoWidget( PG_Widget* parent, const PG_Rect& pos, ContainerBase* container, bool setup );
00107 bool eventKeyDown(const SDL_KeyboardEvent* key);
00108 Vehicle* getMarkedUnit();
00109 SigC::Signal1<void,Vehicle*> unitMarked;
00110
00112 SigC::Signal3<void,Vehicle*,SPoint,bool> unitClicked;
00113 void redrawAll();
00114
00115 void startDrag( Vehicle* v );
00116 void releaseDrag( Vehicle* v = NULL );
00117 void releaseDrag( int x, int y );
00118
00120 SigC::Signal2<void, Vehicle*, Vehicle*> sigDragDone;
00121
00123 SigC::Signal2<bool, Vehicle*, Vehicle*> sigDragAvail;
00124
00125 SigC::Signal0<void> sigDragInProcess;
00126 SigC::Signal0<void> sigDragAborted;
00127
00128 SigC::Signal0<void> sigScrollTrack;
00129
00130 void enableDragNDrop( bool enable ) { dragNdrop = enable; };
00131 bool dragNdropEnabled() const { return dragNdrop; };
00132 void registerStoringPositions( vector<StoringPosition*> sp, const int& colcount );
00133 HighLightingManager& getHighLightingManager() { return unitHighLight; };
00134 };
00135
00136
00137 #endif
00138