1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
* @file myx_gc_feedback.h
* @brief Implementation of the feedback layer and its related classes and structures.
*
*/
#ifndef __GC_FEEDBACK_H__
#define __GC_FEEDBACK_H__
#include "myx_gc_layer.h"
//----------------------------------------------------------------------------------------------------------------------
typedef struct tagSelectionEntry
{
CFigureInstance* instance;
bool dirty;
TBoundingBox bounds;
} TSelectionEntry;
typedef map<CFigureInstance*, TSelectionEntry*> CSelection;
typedef map<CFigureInstance*, TSelectionEntry*>::iterator CSelectionIterator;
typedef map<CFigureInstance*, TSelectionEntry*>::reverse_iterator CSelectionIteratorReverse;
/** Interal states of the feedback layer. */
#define GC_FBSTATE_RUBBERRECT 0x0001
#define GC_FBSTATE_RUBBERBAND 0x0002
/** Possible part switches for the feedback layer. */
#define GC_FBPART_SELECTION 0x0001
#define GC_FBPART_FLOATERS 0x0002
#define GC_FBPART_RUBBERRECT 0x0004
#define GC_FBPART_RUBBERBAND 0x0008
#define GC_FBPART_ALL 0xFFFF
typedef unsigned int TFeedbackParts;
class CFeedbackLayer;
//----------------- CSelectionEnumerator -------------------------------------------------------------------------------
/**
* Helper class to allow enumeration of the currently selected figure instances. An instance is created by the feedback layer's
* getSelectionEnumerator method and must be freed by the caller. Non C++ callers must use the enumerator's release method to free
* the class.
*/
class GENERIC_CANVAS_API CSelectionEnumerator
{
private:
CFeedbackLayer* FLayer;
CSelectionIterator FIterator;
public:
CSelectionEnumerator(CFeedbackLayer* layer);
virtual bool __cdecl hasNext(void);
virtual CFigureInstance* __cdecl next(void);
virtual void __cdecl release(void);
virtual void __cdecl reset(void);
};
//----------------- CFloater -------------------------------------------------------------------------------------------
/**
* CFloater is a helper class for the feedback layer to display.
*/
class GENERIC_CANVAS_API CFloater: public CGraphicElement
{
private:
GLuint FDisplayList;
GLfloat FTranslation[3];
float FWidth;
float FHeight;
GLfloat FColor1[4]; // Normal interior color. Also used as one color in the checker board.
GLfloat FColor2[4]; // Normal border color. Also used as the other color in the checkboard.
TFloaterDecoration FDecoration;
protected:
public:
CFloater(CGenericCanvas* canvas, const TBoundingBox& bounds, GLfloat* color1, GLfloat* color2,
TFloaterDecoration decoration);
virtual ~CFloater(void);
HIDESBASE virtual TFeedbackInfo __cdecl getFeedbackInfo(int modifiers, const TVertex& coords);
void move(float dX, float dY);
virtual TGCVariant __cdecl propertyGet(const char* name, unsigned int index);
virtual void __cdecl propertySet(const char* name, unsigned int index, TGCVariant value);
void render(void);
virtual void __cdecl validate(void);
};
typedef vector<CFloater*> CFloaters;
//----------------- CFeedbackLayer -------------------------------------------------------------------------------------
/**
* The feedback layer is a special layer variant that renders decorations for selected figures and can be queried
* for quick hit tests and lists of selected figures. Additionally it serves as means for various general decorations
* used to give user feedback.
*/
class GENERIC_CANVAS_API CFeedbackLayer: public CLayer
{
friend class CSelectionEnumerator;
friend class CGCView;
private:
class CFeedbackInstanceListener: public CGCBaseListener
{
friend class CFeedbackLayer;
protected:
CFeedbackLayer* layer;
public:
virtual void __cdecl onChange(CGCBase* sender, CGCBase* origin, TGCChangeReason reason);
virtual void __cdecl onDestroy(CGCBase* object);
};
CGCView* FView; // The view to which this layer belongs.
CSelection FSelection; // The list of currently selected figure instances.
float FHandleSize; // The size of the decoration handles.
unsigned int FStates; // A number of flags holding transient states of the layer.
TBoundingBox FRubberBounds; // The current bounds of the rubber rectangle/band (if active).
GLuint FRubberRectDisplayList; // The display list for the rubber rectangle (if active).
GLuint FRubberBandDisplayList; // The display list for the rubber band (if active).
GLuint FSelectionDecoration; // The display list for the selection decoration.
CFloaters FFloaters;
TFeedbackParts FVisibleParts; // Indicates, which feedback is to be displayed.
CFeedbackInstanceListener FListener;
TRubberRectStyle FLastRRStyle; // Cache for the last rubber rect style to avoid annecessary rebuild of the display list.
TRubberBandStyle FLastRBStyle; // Dito for the rubber band.
protected:
void createSelectionDecoration(void);
bool internalAddToSelection(CFigureInstance* instance);
void internalRemoveFromSelection(CFigureInstance* instance);
virtual void renderLayerContent(TBoundingBox bounds);
int selectionCount(void);
virtual void validateLayerContent(void);
public:
CFeedbackLayer(CGCView* view);
virtual ~CFeedbackLayer(void);
void addToSelection(CFigureInstance* instance);
void clearFloaters(void);
void clearSelection(void);
CFloater* createFloater(const TBoundingBox& bounds, GLfloat* color1, GLfloat* color2, TFloaterDecoration decoration);
virtual TFeedbackInfo getFeedbackInfo(int modifiers, const TVertex& coords, float zoom, CFigureInstance** instance);
CSelectionEnumerator* getSelectionEnumerator(void);
void invalidateBounds(CFigureInstance* instance);
void moveSelectedInstances(float x, float y, float z, bool accumulative);
virtual void __cdecl removeInstance(CFigureInstance* instance);
void removeFloater(CFloater* floater);
void removeFromSelection(CFigureInstance* instance);
void rubberBandResize(const TVertex& coords);
void rubberBandStart(TRubberBandStyle style, const TVertex& coords);
void rubberBandStop(void);
TBoundingBox rubberBounds(void) { return FRubberBounds; };
void rubberRectResize(const TVertex& coords, TRRSelectionAction action);
void rubberRectStart(TRubberRectStyle style, const TVertex& coords, bool removeSelection);
void rubberRectStop(void);
void visibleParts(TFeedbackParts parts);
};
//----------------------------------------------------------------------------------------------------------------------
#endif // __GC_FEEDBACK_H__
|