cargowidget.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           cargowdiget.h  -  description
00003                              -------------------
00004     begin                : Tue Feb 17 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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<bool> redrawAll;
00039       SigC::Signal3<void,int, SPoint, bool> clickOnMarkedUnit;
00040 };
00041 
00042 class CargoWidget;
00043 
00044 class StoringPosition : public PG_Widget
00045 {
00046       HighLightingManager& highlight;
00047       const ContainerBase::Cargo& storage;
00048       int num;
00049       bool regular;
00050       CargoWidget* cargoWidget;
00051 
00052       PG_Point unitPosition;
00053       PG_Point dragPointStart;
00054       PG_Point mouseCursorOffset;
00055             
00056       static int spWidth;
00057       static int spHeight;
00058 
00059       static PG_Rect CalcSize( const PG_Point& pos  );
00060       
00061       enum DragState { Off, Pressed, Dragging } dragState;
00062       
00063       Surface clippingSurface;
00064       
00065    protected:
00066       void markChanged(int old, int mark);
00067 
00068       void eventDraw (SDL_Surface *surface, const PG_Rect &src);
00069       void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst);
00070       
00071       void setBargraphValue( const ASCString& widgetName, float fraction);
00072       void setLabelText ( const ASCString& widgetName, const ASCString& text, PG_Widget* parent = NULL );
00073       bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
00074       bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
00075       bool eventMouseMotion (const SDL_MouseMotionEvent *motion);
00076    public:
00077       enum DragTarget { NoDragging, TargetAvail, TargetNotAvail } ;
00078    protected:
00079       DragTarget dragTarget;
00080       
00081    public:
00082       void setDragTarget( DragTarget dragTarget ) { this->dragTarget = dragTarget; };
00083       
00084       static vector<StoringPosition*> setup( PG_Widget* parent, ContainerBase* container, HighLightingManager& highLightingManager, int& unitColumnCount );
00085       Vehicle* getUnit();
00086       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  );
00087 };
00088 
00089 
00090 class CargoWidget : public PG_ScrollWidget {
00091       ContainerBase* container;
00092       bool dragNdrop;
00093       int unitColumnCount;
00094       Vehicle* draggedUnit;
00095       void moveSelection( int delta );
00096       
00097       typedef vector<StoringPosition*> StoringPositionVector;
00098       StoringPositionVector storingPositionVector;
00099       
00100       void checkStoringPosition( int oldpos, int newpos );
00101       HighLightingManager unitHighLight;
00102 
00103       void click( int num, SPoint mousePos, bool first );
00104    protected:
00105       bool      handleScrollTrack (PG_ScrollBar *widget, long data);
00106       
00107    public:
00108       CargoWidget( PG_Widget* parent, const PG_Rect& pos, ContainerBase* container, bool setup );
00109       bool eventKeyDown(const SDL_KeyboardEvent* key);
00110       Vehicle* getMarkedUnit();
00111       SigC::Signal1<void,Vehicle*> unitMarked;
00112 
00114       SigC::Signal3<void,Vehicle*,SPoint,bool> unitClicked;
00115       void redrawAll();
00116       
00117       void startDrag( Vehicle* v );
00118       void releaseDrag( Vehicle* v = NULL );
00119       void releaseDrag( int x, int y );
00120       
00122       SigC::Signal2<void, Vehicle*, Vehicle*> sigDragDone;
00123       
00125       SigC::Signal2<bool, Vehicle*, Vehicle*> sigDragAvail;
00126       
00127       SigC::Signal0<void> sigDragInProcess;
00128       SigC::Signal0<void> sigDragAborted;
00129 
00130       SigC::Signal0<void> sigScrollTrack;
00131 
00132       void enableDragNDrop( bool enable ) { dragNdrop = enable; };
00133       bool dragNdropEnabled() const { return dragNdrop; }; 
00134       void registerStoringPositions( vector<StoringPosition*> sp, const int& colcount );
00135       HighLightingManager& getHighLightingManager() { return unitHighLight; };
00136 };
00137 
00138 
00139 #endif
00140 

Generated on Mon May 21 01:26:29 2012 for Advanced Strategic Command by  doxygen 1.5.1