Advanced Strategic Command
cargowidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  cargowdiget.h - description
3  -------------------
4  begin : Tue Feb 17 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #ifndef cargowidgetH
20  #define cargowidgetH
21 
22 #include "selectionwindow.h"
23 #include "../graphics/surface.h"
24 #include "../containerbase.h"
25 
26 class Vehicle;
27 class ContainerBase;
28 
30 {
31  int marked;
32  public:
34  int getMark();
35  sigc::signal<void,int,int> markChanged;
36  void setNew(int pos );
37  sigc::signal<bool> redrawAll;
39  sigc::signal<void,int, SPoint, bool> clickOnMarkedUnit;
40 };
41 
42 class CargoWidget;
43 
44 class StoringPosition : public PG_Widget
45 {
46  HighLightingManager& highlight;
47  const ContainerBase::Cargo& storage;
48  int num;
49  bool regular;
50  CargoWidget* cargoWidget;
51 
52  PG_Point unitPosition;
53  PG_Point dragPointStart;
54  PG_Point mouseCursorOffset;
55 
56  static int spWidth;
57  static int spHeight;
58 
59  static PG_Rect CalcSize( const PG_Point& pos );
60 
61  enum DragState { Off, Pressed, Dragging } dragState;
62 
63  Surface clippingSurface;
64 
65  protected:
66  void markChanged(int old, int mark);
67 
68  void eventDraw (SDL_Surface *surface, const PG_Rect &src);
69  void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst);
70 
71  void setBargraphValue( const ASCString& widgetName, float fraction);
72  void setLabelText ( const ASCString& widgetName, const ASCString& text, PG_Widget* parent = NULL );
73  bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
74  bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
75  bool eventMouseMotion (const SDL_MouseMotionEvent *motion);
76  public:
78  protected:
80 
81  public:
82  void setDragTarget( DragTarget dragTarget ) { this->dragTarget = dragTarget; };
83 
84  static vector<StoringPosition*> setup( PG_Widget* parent, ContainerBase* container, HighLightingManager& highLightingManager, int& unitColumnCount );
85  Vehicle* getUnit();
86  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 );
87 };
88 
89 
90 class CargoWidget : public PG_ScrollWidget {
91  ContainerBase* container;
92  bool dragNdrop;
93  int unitColumnCount;
94  Vehicle* draggedUnit;
95  void moveSelection( int delta );
96 
97  typedef vector<StoringPosition*> StoringPositionVector;
98  StoringPositionVector storingPositionVector;
99 
100  void checkStoringPosition( int oldpos, int newpos );
101  HighLightingManager unitHighLight;
102 
103  void click( int num, SPoint mousePos, bool first );
104  protected:
105  bool handleScrollTrack (long data);
106 
107  public:
108  CargoWidget( PG_Widget* parent, const PG_Rect& pos, ContainerBase* container, bool setup );
109  bool eventKeyDown(const SDL_KeyboardEvent* key);
111  sigc::signal<void,Vehicle*> unitMarked;
112 
114  sigc::signal<void,Vehicle*,SPoint,bool> unitClicked;
115  void redrawAll();
116 
117  void startDrag( Vehicle* v );
118  void releaseDrag( Vehicle* v = NULL );
119  void releaseDrag( int x, int y );
120 
122  sigc::signal<void, Vehicle*, Vehicle*> sigDragDone;
123 
125  sigc::signal<bool, Vehicle*, Vehicle*> sigDragAvail;
126 
127  sigc::signal<void> sigDragInProcess;
128  sigc::signal<void> sigDragAborted;
129 
130  sigc::signal<void> sigScrollTrack;
131 
132  void enableDragNDrop( bool enable ) { dragNdrop = enable; };
133  bool dragNdropEnabled() const { return dragNdrop; };
134  void registerStoringPositions( vector<StoringPosition*> sp, const int& colcount );
135  HighLightingManager& getHighLightingManager() { return unitHighLight; };
136 };
137 
138 
139 #endif
140 
Vehicle * getUnit()
void releaseDrag(Vehicle *v=NULL)
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)
Definition: cargowidget.cpp:76
void enableDragNDrop(bool enable)
Definition: cargowidget.h:132
sigc::signal< void > sigDragInProcess
Definition: cargowidget.h:127
sigc::signal< bool, Vehicle *, Vehicle * > sigDragAvail
First param: dragged unit, Second Param: target unit.
Definition: cargowidget.h:125
bool dragNdropEnabled() const
Definition: cargowidget.h:133
bool handleScrollTrack(long data)
sigc::signal< void, Vehicle * > unitMarked
Definition: cargowidget.h:111
void setNew(int pos)
Definition: cargowidget.cpp:43
DragTarget dragTarget
Definition: cargowidget.h:79
bool eventMouseButtonUp(const SDL_MouseButtonEvent *button)
sigc::signal< void, Vehicle *, Vehicle * > sigDragDone
First param: dragged unit, Second Param: target unit.
Definition: cargowidget.h:122
sigc::signal< void > sigScrollTrack
Definition: cargowidget.h:130
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void redrawAll()
bool eventMouseMotion(const SDL_MouseMotionEvent *motion)
CargoWidget(PG_Widget *parent, const PG_Rect &pos, ContainerBase *container, bool setup)
static vector< StoringPosition * > setup(PG_Widget *parent, ContainerBase *container, HighLightingManager &highLightingManager, int &unitColumnCount)
sigc::signal< void, int, SPoint, bool > clickOnMarkedUnit
the bool param is set to true if this is the first click on a unit
Definition: cargowidget.h:39
Vehicle * getMarkedUnit()
bool eventMouseButtonDown(const SDL_MouseButtonEvent *button)
void registerStoringPositions(vector< StoringPosition * > sp, const int &colcount)
sigc::signal< void, int, int > markChanged
Definition: cargowidget.h:35
SDLmm::SPoint SPoint
Definition: surface.h:27
sigc::signal< bool > redrawAll
Definition: cargowidget.h:37
void eventBlit(SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
void startDrag(Vehicle *v)
sigc::signal< void, Vehicle *, SPoint, bool > unitClicked
the bool param is set to true if this is the first click on a unit
Definition: cargowidget.h:114
void markChanged(int old, int mark)
Definition: cargowidget.cpp:52
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
void setLabelText(const ASCString &widgetName, const ASCString &text, PG_Widget *parent=NULL)
vector< Vehicle * > Cargo
void setBargraphValue(const ASCString &widgetName, float fraction)
Definition: cargowidget.cpp:93
bool eventKeyDown(const SDL_KeyboardEvent *key)
HighLightingManager & getHighLightingManager()
Definition: cargowidget.h:135
void eventDraw(SDL_Surface *surface, const PG_Rect &src)
sigc::signal< void > sigDragAborted
Definition: cargowidget.h:128
void setDragTarget(DragTarget dragTarget)
Definition: cargowidget.h:82