Skip to content
This repository
Browse code

replaced stg_color_t with Color class and added static named construc…

…tors
  • Loading branch information...
commit 4ccc5cd77713aa3b87e3268fde7b1f53c9f400ad 1 parent ff51521
authored

Showing 35 changed files with 718 additions and 975 deletions. Show diff stats Hide diff stats

  1. 6  CMakeLists.txt
  2. 2  examples/ctrl/source.cc
  3. 11  libstage/CMakeLists.txt
  4. 13  libstage/ancestor.cc
  5. 17  libstage/block.cc
  6. 23  libstage/blockgroup.cc
  7. 8  libstage/canvas.cc
  8. 4  libstage/canvas.hh
  9. 10  libstage/glcolorstack.cc
  10. 20  libstage/model.cc
  11. 2  libstage/model_blinkenlight.cc
  12. 21  libstage/model_blobfinder.cc
  13. 2  libstage/model_camera.cc
  14. 33  libstage/model_draw.cc
  15. 4  libstage/model_getset.cc
  16. 2  libstage/model_gripper.cc
  17. 2  libstage/model_laser.cc
  18. 25  libstage/model_lightindicator.cc
  19. 20  libstage/model_load.cc
  20. 8  libstage/model_position.cc
  21. 3  libstage/model_props.cc
  22. 2  libstage/model_ranger.cc
  23. 4  libstage/powerpack.cc
  24. 7  libstage/region.cc
  25. 2  libstage/resource.cc
  26. 419  libstage/stage.cc
  27. 805  libstage/stage.hh
  28. 4  libstage/test.cc
  29. 82  libstage/typetable.cc
  30. 2  libstage/vis_strip.cc
  31. 12  libstage/waypoint.cc
  32. 46  libstage/world.cc
  33. 22  libstage/worldfile.cc
  34. 2  libstage/worldgui.cc
  35. 48  worlds/fasr.world
6  CMakeLists.txt
@@ -53,8 +53,10 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
53 53
 					${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
54 54
 
55 55
 # Enable -Wall by default
56  
-SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
57  
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
  56
+#SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
  57
+#SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
  58
+SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall")
  59
+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
58 60
 
59 61
 message( STATUS "Checking for libtool" )
60 62
 find_path( LTDL_INCLUDE_DIR ltdl.h DOC "Libtool include dir" )
2  examples/ctrl/source.cc
@@ -18,7 +18,7 @@ extern "C" int Init( Model* mod )
18 18
 int Update( Model* mod, void* dummy )
19 19
 {
20 20
   if( mod->GetWorld()->GetUpdateCount() % INTERVAL  == 0 )
21  
-	 mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0), FLAGSZ ) );
  21
+	mod->PushFlag( new Flag( Color( 1,1,0,0), FLAGSZ ) );
22 22
 
23 23
   return 0; // run again
24 24
 }
11  libstage/CMakeLists.txt
@@ -8,6 +8,7 @@ set( stageSrcs
8 8
 	block.cc
9 9
 	blockgroup.cc
10 10
 	camera.cc
  11
+	color.cc
11 12
 	file_manager.cc
12 13
 	file_manager.hh
13 14
 	gl.cc
@@ -37,11 +38,11 @@ set( stageSrcs
37 38
 	stage.cc
38 39
 	stage.hh
39 40
 	texture_manager.cc
40  
-	typetable.cc
41  
-   vis_strip.cc
42  
-	waypoint.cc
43  
-	world.cc
44  
-	worldfile.cc
  41
+	typetable.cc		
  42
+   vis_strip.cc			
  43
+	waypoint.cc			
  44
+	world.cc			
  45
+	worldfile.cc		
45 46
    worldgui.cc 
46 47
    canvas.cc 
47 48
    options_dlg.cc
13  libstage/ancestor.cc
@@ -19,18 +19,21 @@ Ancestor::~Ancestor()
19 19
 
20 20
 void Ancestor::AddChild( Model* mod )
21 21
 {
22  
-  
23 22
   // poke a name into the child  
24 23
   char* buf = new char[TOKEN_MAX];	
  24
+  
  25
+  //  printf( "adding child of type %d token %s\n", mod->type, mod->Token() );
  26
+  
  27
+  std::string typestr =  Model::type_map[ mod->type ];
25 28
 
26 29
   if( token ) // if this object has a name, use it
27 30
     snprintf( buf, TOKEN_MAX, "%s.%s:%d", 
28  
-	      token, 
29  
-	      typetable[mod->type].token, 
30  
-	      child_type_counts[mod->type] );
  31
+			  token, 
  32
+			  typestr.c_str(),
  33
+			  child_type_counts[mod->type] );
31 34
   else
32 35
     snprintf( buf, TOKEN_MAX, "%s:%d", 
33  
-	      typetable[mod->type].token, 
  36
+			  typestr.c_str(),
34 37
 	      child_type_counts[mod->type] );
35 38
     
36 39
   //printf( "%s generated a name for my child %s\n", token, buf );
17  libstage/block.cc
@@ -12,7 +12,7 @@ Block::Block( Model* mod,
12 12
 				  size_t pt_count,
13 13
 				  stg_meters_t zmin,
14 14
 				  stg_meters_t zmax,
15  
-				  stg_color_t color,
  15
+				  Color color,
16 16
 				  bool inherit_color
17 17
 				  ) :
18 18
   mod( mod ),
@@ -134,7 +134,7 @@ void Block::SetZ( double min, double max )
134 134
   mod->blockgroup.BuildDisplayList( mod );
135 135
 }
136 136
 
137  
-stg_color_t Block::GetColor()
  137
+Color Block::GetColor()
138 138
 {
139 139
   return( inherit_color ? mod->color : color );
140 140
 }
@@ -390,8 +390,10 @@ void Block::DrawFootPrint()
390 390
 void Block::Draw( Model* mod )
391 391
 {
392 392
   // draw filled color polygons
393  
-  stg_color_t col = inherit_color ? mod->color : color;
  393
+  Color col = inherit_color ? mod->color : color;
394 394
   
  395
+  col.Print( "block color" );
  396
+
395 397
   mod->PushColor( col );
396 398
   glEnable(GL_POLYGON_OFFSET_FILL);
397 399
   glPolygonOffset(1.0, 1.0);
@@ -400,9 +402,10 @@ void Block::Draw( Model* mod )
400 402
   glDisable(GL_POLYGON_OFFSET_FILL);
401 403
   
402 404
   //   // draw the block outline in a darker version of the same color
403  
-  double r,g,b,a;
404  
-  stg_color_unpack( col, &r, &g, &b, &a );
405  
-  mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
  405
+  //double r,g,b,a;
  406
+  //stg_color_unpack( col, &r, &g, &b, &a );
  407
+  //mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
  408
+  mod->PushColor( Color( col.r/2.0, col.g/2.0, col.b/2.0, col.a ));
406 409
   
407 410
   glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
408 411
   glDepthMask(GL_FALSE);
@@ -445,7 +448,7 @@ void Block::Load( Worldfile* wf, int entity )
445 448
   const char* colorstr = wf->ReadString( entity, "color", NULL );
446 449
   if( colorstr )
447 450
     {
448  
-      color = stg_lookup_color( colorstr );
  451
+      color = Color( colorstr );
449 452
       inherit_color = false;
450 453
     }
451 454
   else
23  libstage/blockgroup.cc
@@ -200,18 +200,27 @@ void BlockGroup::BuildDisplayList( Model* mod )
200 200
   glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
201 201
   glDepthMask(GL_FALSE);
202 202
   
203  
-  double r,g,b,a;
204  
-  stg_color_unpack( mod->color, &r, &g, &b, &a );
205  
-  mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
206  
-  
  203
+  Color c = mod->color;
  204
+  c.r /= 2.0;
  205
+  c.g /= 2.0;
  206
+  c.b /= 2.0;
  207
+  mod->PushColor( c );
  208
+
  209
+  //c.Print( "color" );
  210
+
  211
+
207 212
   FOR_EACH( it, blocks )
208 213
 	{
209 214
 	  Block* blk = *it;
210 215
 		
211 216
 	  if( (!blk->inherit_color) && (blk->color != mod->color) )
212 217
 		{
213  
-		  stg_color_unpack( blk->color, &r, &g, &b, &a );
214  
-		  mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
  218
+		  Color c = blk->color;
  219
+		  c.r /= 2.0;
  220
+		  c.g /= 2.0;
  221
+		  c.b /= 2.0;
  222
+		  mod->PushColor( c );
  223
+		  //c.Print( "bar" );
215 224
 		  blk->DrawSolid();
216 225
 		  mod->PopColor();
217 226
 		}
@@ -277,7 +286,7 @@ void BlockGroup::LoadBitmap( Model* mod, const char* bitmapfile, Worldfile* wf )
277 286
   if( rects && (rect_count > 0) )
278 287
 	{
279 288
 	  // TODO fix this
280  
-	  stg_color_t col = stg_color_pack( 1.0, 0,0,1.0 ); 
  289
+	  Color col( 1.0, 0.0, 1.0, 1.0 );
281 290
 		
282 291
 	  for( unsigned int r=0; r<rect_count; r++ )
283 292
 		{
8  libstage/canvas.cc
@@ -791,7 +791,7 @@ void Canvas::renderFrame()
791 791
 		GLfloat scale = 1.0/world->Resolution();
792 792
       glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
793 793
 
794  
-		world->PushColor( stg_color_pack( 0,0,1,0.5) );
  794
+		world->PushColor( Color( 0,0,1,0.5) );
795 795
 
796 796
 		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
797 797
 
@@ -822,7 +822,7 @@ void Canvas::renderFrame()
822 822
 		glEnd();
823 823
 
824 824
 #if 1
825  
-  		world->PushColor( stg_color_pack( 0,1,0,0.2) );
  825
+  		world->PushColor( Color( 0,1,0,0.2) );
826 826
   		glBegin( GL_LINE_STRIP );
827 827
   		for( unsigned int i=0;
828 828
   			  i < world->rt_cells.size();
@@ -844,7 +844,7 @@ void Canvas::renderFrame()
844 844
 		GLfloat scale = 1.0/world->Resolution();
845 845
       glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
846 846
 
847  
-		world->PushColor( stg_color_pack( 1,0,0,0.5) );
  847
+		world->PushColor( Color( 1,0,0,0.5) );
848 848
 
849 849
 		glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
850 850
 
@@ -865,7 +865,7 @@ void Canvas::renderFrame()
865 865
 						 world->rt_candidate_cells[i].x+1, world->rt_candidate_cells[i].y+1 );
866 866
 		  }
867 867
 		
868  
- 		world->PushColor( stg_color_pack( 0,1,0,0.2) );
  868
+ 		world->PushColor( Color( 0,1,0,0.2) );
869 869
  		glBegin( GL_LINE_STRIP );
870 870
  		for( unsigned int i=0;
871 871
  			  i < world->rt_candidate_cells.size();
4  libstage/canvas.hh
@@ -16,7 +16,7 @@ class GlColorStack
16 16
 		void Push( GLdouble col[4] );
17 17
 		void Push( double r, double g, double b, double a );
18 18
 		void Push( double r, double g, double b );
19  
-		void Push( stg_color_t col );
  19
+		void Push( Color col );
20 20
 
21 21
 		void Pop();
22 22
 
@@ -121,7 +121,7 @@ public:
121 121
 	inline void setDirtyBuffer( void ) { dirty_buffer = true; }
122 122
 	inline bool dirtyBuffer( void ) const { return dirty_buffer; }
123 123
 	
124  
-	inline void PushColor( stg_color_t col )
  124
+	inline void PushColor( Color col )
125 125
 	{ colorstack.Push( col ); } 
126 126
 
127 127
 	void PushColor( double r, double g, double b, double a )
10  libstage/glcolorstack.cc
@@ -46,14 +46,14 @@ void GlColorStack::Push( double r, double g, double b, double a )
46 46
 	Push( col );
47 47
 }
48 48
 
49  
-void GlColorStack::Push( stg_color_t col )
  49
+void GlColorStack::Push( Color col )
50 50
 {
51 51
 	GLdouble d[4];
52 52
 
53  
-	d[0] = ((col & 0x00FF0000) >> 16) / 256.0;
54  
-	d[1] = ((col & 0x0000FF00) >> 8)  / 256.0;
55  
-	d[2] = ((col & 0x000000FF) >> 0)  / 256.0;
56  
-	d[3] = (((col & 0xFF000000) >> 24) / 256.0);
  53
+	d[0] = col.r;
  54
+	d[1] = col.g;
  55
+	d[2] = col.b;
  56
+	d[3] = col.a;
57 57
 
58 58
 	Push( d );
59 59
 }
20  libstage/model.cc
@@ -112,6 +112,9 @@ uint32_t Model::count = 0;
112 112
 //GHashTable* Model::modelsbyid = g_hash_table_new( NULL, NULL );
113 113
 std::map<stg_id_t,Model*> Model::modelsbyid;
114 114
 
  115
+std::map<std::string, stg_creator_t> Model::name_map;
  116
+std::map<stg_model_type_t, std::string> Model::type_map;
  117
+
115 118
 void Size::Load( Worldfile* wf, int section, const char* keyword )
116 119
 {
117 120
   x = wf->ReadTupleLength( section, keyword, 0, x );
@@ -186,8 +189,8 @@ void GuiState::Load( Worldfile* wf, int wf_entity )
186 189
 
187 190
 // constructor
188 191
 Model::Model( World* world,
189  
-	      Model* parent,
190  
-				  const stg_model_type_t type )
  192
+			  Model* parent,
  193
+			  const stg_model_type_t type )
191 194
   : Ancestor(), 	 
192 195
     access_mutex(NULL),
193 196
     blinkenlights( g_ptr_array_new() ),
@@ -195,10 +198,10 @@ Model::Model( World* world,
195 198
     blocks_dl(0),
196 199
     boundary(false),
197 200
     callbacks( g_hash_table_new( g_direct_hash, g_direct_equal ) ),
198  
-    color( 0xFFFF0000 ), // red
  201
+    color( 1,0,0 ), // red
199 202
     data_fresh(false),
200 203
     disabled(false),
201  
-	 custom_visual_list( NULL ),
  204
+	custom_visual_list( NULL ),
202 205
     flag_list(NULL),
203 206
     geom(),
204 207
     has_default_block( true ),
@@ -206,17 +209,16 @@ Model::Model( World* world,
206 209
     initfunc(NULL),
207 210
     interval((stg_usec_t)1e4), // 10msec
208 211
     last_update(0),
209  
-	 log_state(false),
  212
+	log_state(false),
210 213
     map_resolution(0.1),
211 214
     mass(0),
212  
-	//   on_update_list( false ),
213 215
     on_velocity_list( false ),
214 216
     parent(parent),
215 217
     pose(),
216  
-	 power_pack( NULL ),
217  
-	 pps_charging(NULL),
  218
+	power_pack( NULL ),
  219
+	pps_charging(NULL),
218 220
     props(NULL),
219  
-	 rastervis(),
  221
+	rastervis(),
220 222
     rebuild_displaylist(true),
221 223
     say_string(NULL),
222 224
     stall(false),	 
2  libstage/model_blinkenlight.cc
@@ -70,7 +70,7 @@ ModelBlinkenlight::ModelBlinkenlight( World* world,
70 70
 
71 71
 	// Set up sensible defaults
72 72
 
73  
-	this->SetColor( stg_lookup_color( "green" ) );
  73
+	this->SetColor( Color( "green" ) );
74 74
 
75 75
 
76 76
 	Geom geom;
21  libstage/model_blobfinder.cc
@@ -111,20 +111,23 @@ static bool blob_match( Model* candidate,
111 111
 }	
112 112
 
113 113
 
114  
-static bool ColorMatchIgnoreAlpha( stg_color_t a, stg_color_t b )
  114
+static bool ColorMatchIgnoreAlpha( Color a, Color b )
115 115
 {
116  
-	return( (a & 0x00FFFFFF) == (b & 0x00FFFFFF ) );
  116
+  double epsilon = 1e-5; // small
  117
+  return( fabs(a.r - b.r) < epsilon &&
  118
+		  fabs(a.g - b.g) < epsilon &&
  119
+		  fabs(a.b - b.b) < epsilon );
117 120
 }
118 121
 
119  
-void ModelBlobfinder::ModelBlobfinder::AddColor( stg_color_t col )
  122
+void ModelBlobfinder::ModelBlobfinder::AddColor( Color col )
120 123
 {
121 124
 	colors.push_back( col );
122 125
 }
123 126
 
124 127
 /** Stop tracking blobs with this color */
125  
-void ModelBlobfinder::RemoveColor( stg_color_t col )
  128
+void ModelBlobfinder::RemoveColor( Color col )
126 129
 {
127  
-	for( std::vector<stg_color_t>::iterator it = colors.begin();
  130
+	for( std::vector<Color>::iterator it = colors.begin();
128 131
 			 it != colors.end();
129 132
 			 ++it )
130 133
 		{
@@ -166,7 +169,7 @@ void ModelBlobfinder::Load( void )
166 169
 			if( ! colorstr )
167 170
 				break;
168 171
 			else
169  
-				AddColor( stg_lookup_color( colorstr ));
  172
+			  AddColor( Color( colorstr ));
170 173
 		}
171 174
 	}    
172 175
 }
@@ -194,7 +197,7 @@ void ModelBlobfinder::Update( void )
194 197
 			continue; // we saw nothing
195 198
 		 
196 199
 		 unsigned int right = s;
197  
-		 stg_color_t blobcol = samples[s].color;
  200
+		 Color blobcol = samples[s].color;
198 201
 		 
199 202
 		 //printf( "blob start %d color %X\n", blobleft, blobcol );
200 203
 		 
@@ -351,14 +354,14 @@ void ModelBlobfinder::Vis::Visualize( Model* mod, Camera* cam )
351 354
   glScalef( 0.025, 0.025, 1 );
352 355
   
353 356
   // draw a white screen with a black border
354  
-  bf->PushColor( 0xFFFFFFFF );
  357
+  bf->PushColor( 1,1,1,1 );
355 358
   glRectf( 0,0, bf->scan_width, bf->scan_height );
356 359
   bf->PopColor();
357 360
   
358 361
   glTranslatef(0,0,0.01 );
359 362
   
360 363
   glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
361  
-  bf->PushColor( 0xFF000000 );
  364
+  bf->PushColor( 1,0,0,1 );
362 365
   glRectf( 0,0, bf->scan_width, bf->scan_height );
363 366
   bf->PopColor();
364 367
   glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
2  libstage/model_camera.cc
@@ -120,7 +120,7 @@ _pitch_offset( 0.0 )
120 120
 	SetGeom( geom );
121 121
 	
122 122
 	// set default color
123  
-	SetColor( stg_lookup_color(DEFAULT_GEOM_COLOR));
  123
+	SetColor( Color( DEFAULT_GEOM_COLOR) );
124 124
 	
125 125
 	RegisterOption( &showCameraData );
126 126
 
33  libstage/model_draw.cc
@@ -5,9 +5,9 @@
5 5
 using namespace Stg;
6 6
 
7 7
 // speech bubble colors
8  
-static const stg_color_t BUBBLE_FILL = 0xFFC8C8FF; // light blue/grey
9  
-static const stg_color_t BUBBLE_BORDER = 0xFF000000; // black
10  
-static const stg_color_t BUBBLE_TEXT = 0xFF000000; // black
  8
+static const Color BUBBLE_FILL( 1.0, 0.8, 0.8 );// light blue/grey
  9
+static const Color BUBBLE_BORDER( 0,0,0 );  // black
  10
+static const Color BUBBLE_TEXT( 0,0,0 ); // black
11 11
 
12 12
 void Model::DrawSelected()
13 13
 {
@@ -50,8 +50,6 @@ void Model::DrawSelected()
50 50
 
51 51
 void Model::DrawTrailFootprint()
52 52
 {
53  
-  double r,g,b,a;
54  
-
55 53
   for( int i=trail->len-1; i>=0; i-- )
56 54
     {
57 55
       stg_trail_item_t* checkpoint = & g_array_index( trail, stg_trail_item_t, i );
@@ -60,13 +58,15 @@ void Model::DrawTrailFootprint()
60 58
 		Gl::pose_shift( checkpoint->pose );
61 59
 		Gl::pose_shift( geom.pose );
62 60
 
63  
-      stg_color_unpack( checkpoint->color, &r, &g, &b, &a );
64  
-      PushColor( r, g, b, 0.1 );
  61
+		//stg_color_unpack( checkpoint->color, &r, &g, &b, &a );
  62
+		Color c = checkpoint->color;
  63
+		c.a = 0.1;
  64
+		PushColor( c );
65 65
 
66 66
       blockgroup.DrawFootPrint( geom );
67 67
 
68 68
       glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
69  
-      PushColor( r/2, g/2, b/2, 0.1 );
  69
+      PushColor( c.r/2, c.g/2, c.b/2, 0.1 );
70 70
 
71 71
       blockgroup.DrawFootPrint( geom );
72 72
 
@@ -99,8 +99,6 @@ void Model::DrawTrailBlocks()
99 99
 
100 100
 void Model::DrawTrailArrows()
101 101
 {
102  
-  double r,g,b,a;
103  
-
104 102
   double dx = 0.2;
105 103
   double dy = 0.07;
106 104
   double timescale = 0.0000001;
@@ -131,8 +129,11 @@ void Model::DrawTrailArrows()
131 129
 
132 130
       glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
133 131
 
134  
-      stg_color_unpack( checkpoint->color, &r, &g, &b, &a );
135  
-      PushColor( r/2, g/2, b/2, 1 ); // darker color
  132
+	  Color c = checkpoint->color;
  133
+	  c.r /= 2.0;
  134
+	  c.g /= 2.0;
  135
+	  c.b /= 2.0;	  
  136
+      PushColor( c ); // darker color
136 137
 
137 138
       glDepthMask(GL_FALSE);
138 139
       glBegin( GL_TRIANGLES );
@@ -470,9 +471,11 @@ void Model::DrawFlagList( void )
470 471
 		glDisable(GL_POLYGON_OFFSET_FILL);
471 472
 
472 473
       // draw the edges darker version of the same color
473  
-      double r,g,b,a;
474  
-      stg_color_unpack( flag->color, &r, &g, &b, &a );
475  
-      PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
  474
+		Color c = flag->color;
  475
+		c.r /= 2.0;
  476
+		c.g /= 2.0;
  477
+		c.b /= 2.0;
  478
+		PushColor( c );
476 479
 		
477 480
       gluQuadricDrawStyle( quadric, GLU_LINE );
478 481
       gluSphere( quadric, flag->size/2.0, 4,2 );
4  libstage/model_getset.cc
@@ -17,11 +17,11 @@ void Model::SetGeom( const Geom& g )
17 17
   CallCallbacks( &geom );
18 18
 }
19 19
 
20  
-void Model::SetColor( stg_color_t col )
  20
+void Model::SetColor( Color col )
21 21
 {
22 22
   this->color = col;
23 23
   NeedRedraw();
24  
-  CallCallbacks( &color );
  24
+  CallCallbacks( &this->color );
25 25
 }
26 26
 
27 27
 void Model::SetMass( stg_kg_t mass )
2  libstage/model_gripper.cc
@@ -88,7 +88,7 @@ ModelGripper::ModelGripper( World* world,
88 88
   
89 89
   cfg.close_limit = 1.0;
90 90
   
91  
-  SetColor( stg_color_pack( 0.3, 0.3, 0.3, 0 ));
  91
+  SetColor( Color(0.3, 0.3, 0.3, 1.0) );
92 92
 
93 93
   FixBlocks();
94 94
 
2  libstage/model_laser.cc
@@ -96,7 +96,7 @@ ModelLaser::ModelLaser( World* world,
96 96
   thread_safe = true;
97 97
 
98 98
   // set default color
99  
-  SetColor( stg_lookup_color(DEFAULT_COLOR));
  99
+  SetColor( Color(DEFAULT_COLOR));
100 100
 
101 101
   // set up our data buffers and raytracing
102 102
   SampleConfig();
25  libstage/model_lightindicator.cc
@@ -27,19 +27,18 @@ void ModelLightIndicator::DrawBlocks()
27 27
 		Model::DrawBlocks();
28 28
 	}
29 29
 	else
30  
-	{
31  
-		stg_color_t currColour = this->GetColor();
32  
-
  30
+	  {
33 31
 		const double scaleFactor = 0.8;
34  
-		double r = 0, g = 0, b = 0, a = 0;
35  
-		stg_color_unpack(currColour, &r, &g, &b, &a);
36  
-		r *= scaleFactor;
37  
-		g *= scaleFactor;
38  
-		b *= scaleFactor;
39  
-
40  
-		this->SetColor(stg_color_pack(r, g, b, a));
  32
+		
  33
+		Color keep = this->GetColor();
  34
+		Color c = this->GetColor();
  35
+		c.r *= scaleFactor;
  36
+		c.g *= scaleFactor;
  37
+		c.b *= scaleFactor;
  38
+		
  39
+		this->SetColor( c );
41 40
 		Model::DrawBlocks();
42  
-
43  
-		this->SetColor(currColour);
44  
-	}
  41
+		
  42
+		this->SetColor( keep );
  43
+	  }
45 44
 }
20  libstage/model_load.cc
@@ -117,20 +117,16 @@ void Model::Load()
117 117
   
118 118
   if( wf->PropertyExists( wf_entity, "color" ))
119 119
     {      
120  
-      stg_color_t col = 0xFFFF0000; // red;
  120
+      Color col( 1,0,0 ); // red;
121 121
       const char* colorstr = wf->ReadString( wf_entity, "color", NULL );
122 122
       if( colorstr )
123  
-		  {
124  
-			 if( strcmp( colorstr, "random" ) == 0 )
125  
-	    {
126  
-	      col = (uint32_t)random();
127  
-	      col |= 0xFF000000; // set the alpha channel to max
128  
-	    }
129  
-	  else
130  
-	    col = stg_lookup_color( colorstr );
131  
-
  123
+		{
  124
+		  if( strcmp( colorstr, "random" ) == 0 )
  125
+			col = Color( drand48(), drand48(), drand48() );
  126
+		  else
  127
+			col = Color( colorstr );
  128
+		}
132 129
 	  this->SetColor( col );
133  
-	}
134 130
     }      
135 131
 
136 132
 
@@ -147,7 +143,7 @@ void Model::Load()
147 143
       double blue  = wf->ReadTupleFloat( wf_entity, "color_rgba", 2, 0 );
148 144
       double alpha = wf->ReadTupleFloat( wf_entity, "color_rgba", 3, 1 );
149 145
 
150  
-      this->SetColor( stg_color_pack( red, green, blue, alpha ));
  146
+      this->SetColor( Color( red, green, blue, alpha ));
151 147
     }  
152 148
     }
153 149
   
8  libstage/model_position.cc
@@ -597,10 +597,10 @@ void ModelPosition::PoseVis::Visualize( Model* mod, Camera* cam )
597 597
   pos->PushColor( 0,0,1,1 ); // offset in blue
598 598
   Gl::draw_origin( 0.5 );
599 599
   pos->PopColor();
600  
-  
601  
-  double r,g,b,a;
602  
-  stg_color_unpack( pos->color, &r, &g, &b, &a );
603  
-  pos->PushColor( r, g, b, 0.5 );
  600
+
  601
+  Color c = pos->color;
  602
+  c.a = 0.5;
  603
+  pos->PushColor( c );
604 604
   
605 605
   glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
606 606
   pos->blockgroup.DrawFootPrint( pos->geom );
3  libstage/model_props.cc
@@ -61,7 +61,8 @@ int Model::SetProperty( const char* key,
61 61
 		}
62 62
 		if( MATCH( key, MP_COLOR ) )
63 63
 		{
64  
-			this->SetColor( *(int*)data );
  64
+		  float* f = (float*)data;
  65
+		  this->SetColor( Color(f[0], f[1], f[2], f[3]));
65 66
 			return 0;
66 67
 		}
67 68
 		if( MATCH( key, MP_MASS ) )
2  libstage/model_ranger.cc
@@ -110,7 +110,7 @@ ModelRanger::ModelRanger( World* world,
110 110
   // assert that Update() is reentrant for this derived model
111 111
   thread_safe = true;
112 112
   
113  
-  this->SetColor( stg_lookup_color( RANGER_CONFIG_COLOR ) );
  113
+  this->SetColor( Color( RANGER_CONFIG_COLOR ) );
114 114
   
115 115
   // remove the polygon: ranger has no body
116 116
   this->ClearBlocks();
4  libstage/powerpack.cc
@@ -17,8 +17,8 @@ stg_joules_t PowerPack::global_dissipated = 0.0;
17 17
 
18 18
 PowerPack::PowerPack( Model* mod ) :
19 19
   event_vis( 32,32,1.0 ),
20  
-  output_vis( 0,100,200,40, 1200, stg_color_pack(1,0,0,0), stg_color_pack(0,0,0,0.5), "energy output", "energy_input" ),
21  
-  stored_vis( 0,142,200,40, 1200, stg_color_pack(0,1,0,0), stg_color_pack(0,0,0,0.5), "energy stored", "energy_stored" ),
  20
+  output_vis( 0,100,200,40, 1200, Color(1,0,0), Color(0,0,0,0.5), "energy output", "energy_input" ),
  21
+  stored_vis( 0,142,200,40, 1200, Color(0,1,0), Color(0,0,0,0.5), "energy stored", "energy_stored" ),
22 22
   mod( mod), 
23 23
   stored( 0.0 ), 
24 24
   capacity( 0.0 ), 
7  libstage/region.cc
@@ -141,9 +141,8 @@ void SuperRegion::Draw( bool drawall )
141 141
 						  
142 142
 								//printf( "zb %.2f %.2f\n", ent->zbounds.min, ent->zbounds.max );
143 143
 						  
144  
-								double r,g,b,a;
145  
-								stg_color_unpack( block->GetColor(), &r, &g, &b, &a );
146  
-								glColor4f( r,g,b, 1.0 );
  144
+								Color c = block->GetColor();
  145
+								glColor4f( c.r, c.g, c.b, 1.0 );
147 146
 						  
148 147
 								glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
149 148
 								glEnable(GL_POLYGON_OFFSET_FILL);
@@ -184,7 +183,7 @@ void SuperRegion::Draw( bool drawall )
184 183
 						  
185 184
 								glDisable(GL_POLYGON_OFFSET_FILL);
186 185
 						  
187  
-								glColor4f( r/2.0,g/2.0,b/2.0, 1.0-a );
  186
+								glColor4f( c.r/2.0, c.g/2.0, c.b/2.0, c.a );
188 187
 								glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
189 188
 						  
190 189
 								// TOP
2  libstage/resource.cc
... ...
@@ -1,7 +1,7 @@
1 1
 #include "stage.hh"
2 2
 using namespace Stg;
3 3
 
4  
-Flag::Flag( stg_color_t color, double size )
  4
+Flag::Flag( Color color, double size )
5 5
 { 
6 6
 	this->color = color;
7 7
 	this->size = size;
419  libstage/stage.cc
... ...
@@ -1,6 +1,5 @@
1 1
 // Author: Richard Vaughan
2 2
 
3  
-#include <errno.h>
4 3
 #include <FL/Fl_Shared_Image.H>
5 4
 
6 5
 #include "stage.hh"
@@ -10,8 +9,6 @@ using namespace Stg;
10 9
 
11 10
 static bool init_called = false;
12 11
 
13  
-stg_typetable_entry_t Stg::typetable[MODEL_TYPE_COUNT];
14  
-
15 12
 
16 13
 const char* Stg::Version()
17 14
 { 
@@ -20,127 +17,30 @@ const char* Stg::Version()
20 17
 
21 18
 void Stg::Init( int* argc, char** argv[] )
22 19
 {
23  
-	PRINT_DEBUG( "Stg::Init()" );
  20
+  PRINT_DEBUG( "Stg::Init()" );
24 21
 
25  
-	// seed the RNG 
26  
-	srand48( time(NULL) );
  22
+  // seed the RNG 
  23
+  srand48( time(NULL) );
27 24
 
28  
-	if(!setlocale(LC_ALL,"POSIX"))
29  
-		PRINT_WARN("Failed to setlocale(); config file may not be parse correctly\n" );
  25
+  if(!setlocale(LC_ALL,"POSIX"))
  26
+	PRINT_WARN("Failed to setlocale(); config file may not be parse correctly\n" );
30 27
 						
31  
-	if (!g_thread_supported ()) g_thread_init (NULL);
32  
-
33  
-	//g_thread_init( NULL );
34  
-
35  
-	RegisterModels();
36  
-
37  
-	init_called = true;
38  
-
39  
-	// ask FLTK to load support for various image formats
40  
-	fl_register_images();
  28
+  if (!g_thread_supported ()) g_thread_init (NULL);
  29
+	
  30
+  RegisterModels();
  31
+	
  32
+  init_called = true;
  33
+	
  34
+  // ask FLTK to load support for various image formats
  35
+  fl_register_images();
41 36
 }
42 37
 
43 38
 bool Stg::InitDone()
44 39
 {
45  
-	return init_called;
  40
+  return init_called;
46 41
 }
47 42
 
48  
-void Stg::RegisterModel( stg_model_type_t type, 
49  
-								 const char* name, 
50  
-								 stg_creator_t creator )
51  
-{
52  
-  Stg::typetable[ type ].token = name;
53  
-  Stg::typetable[ type ].creator = creator;
54  
-}
55  
-  
56  
-
57  
-
58  
-void Stg::stg_print_err( const char* err )
59  
-{
60  
-	printf( "Stage error: %s\n", err );
61  
-	//_stg_quit = TRUE;
62  
-}
63  
-
64  
-
65  
-void Stg::stg_print_velocity( const Velocity& vel )
66  
-{
67  
-	printf( "velocity [x:%.3f y:%.3f a:%.3f]\n",
68  
-			vel.x, vel.y, vel.a );
69  
-}
70  
-
71  
-
72  
-// Look up the color in a database.  (i.e. transform color name to
73  
-// color value).  If the color is not found in the database, a bright
74  
-// red color will be returned instead.
75  
-stg_color_t Stg::stg_lookup_color(const char *name)
76  
-{
77  
-	if( name == NULL ) // no string?
78  
-		return 0; // black
79  
-
80  
-	if( strcmp( name, "" ) == 0 ) // empty string?
81  
-		return 0; // black
82  
-
83  
-	static FILE *file = NULL;
84  
-	static GHashTable* table = g_hash_table_new( g_str_hash, g_str_equal );
85  
-
86  
-	if( file == NULL )
87  
-	{
88  
-		std::string rgbFile = FileManager::findFile( "rgb.txt" );
89  
-		file = fopen( rgbFile.c_str(), "r" );
90  
-		
91  
-		if( file == NULL )
92  
-		{
93  
-			PRINT_ERR1("unable to open color database: %s "
94  
-					   "(try adding rgb.txt's location to your STAGEPATH)",
95  
-					   strerror(errno));
96  
-			exit(0);
97  
-		}
98  
-
99  
-		PRINT_DEBUG( "Success!" );
100  
-
101  
-		// load the file into the hash table       
102  
-		while (TRUE)
103  
-		{
104  
-			char line[1024];
105  
-			if (!fgets(line, sizeof(line), file))
106  
-				break;
107  
-
108  
-			// it's a macro or comment line - ignore the line
109  
-			if (line[0] == '!' || line[0] == '#' || line[0] == '%') 
110  
-				continue;
111  
-
112  
-			// Trim the trailing space
113  
-			while (strchr(" \t\n", line[strlen(line)-1]))
114  
-				line[strlen(line)-1] = 0;
115  
-
116  
-			// Read the color
117  
-			int r, g, b;
118  
-			int chars_matched = 0;
119  
-			sscanf( line, "%d %d %d %n", &r, &g, &b, &chars_matched );
120  
-
121  
-
122  
-			stg_color_t* col = new stg_color_t;
123  
-			*col = ( 0xFF000000 | (r << 16) | (g << 8) | b);
124  
-
125  
-			// Read the name
126  
-			char* colorname = strdup( line + chars_matched );
127  
-
128  
-			// map the name to the color in the table
129  
-			g_hash_table_insert( table, (gpointer)colorname, (gpointer)col );
130  
-		}
131  
-		fclose(file);
132  
-	}
133  
-
134  
-	// look up the colorname in the database  
135  
-	stg_color_t* found = (stg_color_t*)g_hash_table_lookup( table, name );
136  
-
137  
-	if( found )
138  
-		return *found;
139  
-	else
140  
-		return (stg_color_t)0;
141  
-}
142  
-
143  
-static guchar* pb_get_pixel( Fl_Shared_Image* img, int x, int y )
  43
+static inline guchar* pb_get_pixel( Fl_Shared_Image* img, int x, int y )
144 44
 {
145 45
   guchar* pixels = (guchar*)(img->data()[0]);
146 46
   unsigned int index = (y * img->w() * img->d()) + (x * img->d());
@@ -148,221 +48,172 @@ static guchar* pb_get_pixel( Fl_Shared_Image* img, int x, int y )
148 48
 }
149 49
 
150 50
 // set all the pixels in a rectangle 
151  
-static void pb_set_rect( Fl_Shared_Image* pb, int x, int y, int width, int height, uint8_t val )
152  
-{
153  
-	int bytes_per_sample = 1;
154  
-	int num_samples = pb->d();
155  
-
156  
-	int a, b;
157  
-	for( a = y; a < y+height; a++ )
158  
-		for( b = x; b < x+width; b++ )
159  
-		{	
160  
-			// zeroing
161  
-			guchar* pix = pb_get_pixel( pb, b, a );
162  
-			memset( pix, val, num_samples * bytes_per_sample );
163  
-		}
  51
+static inline void pb_set_rect( Fl_Shared_Image* pb, int x, int y, int width, int height, uint8_t val )
  52
+{
  53
+  int bytes_per_sample = 1;
  54
+  int num_samples = pb->d();
  55
+
  56
+  int a, b;
  57
+  for( a = y; a < y+height; a++ )
  58
+	for( b = x; b < x+width; b++ )
  59
+	  {	
  60
+		// zeroing
  61
+		guchar* pix = pb_get_pixel( pb, b, a );
  62
+		memset( pix, val, num_samples * bytes_per_sample );
  63
+	  }
164 64
 }  
165 65
 
166 66
 // returns true if the value in the first channel is above threshold
167  
-static gboolean pb_pixel_is_set( Fl_Shared_Image* img, int x, int y, int threshold )
  67
+static inline gboolean pb_pixel_is_set( Fl_Shared_Image* img, int x, int y, int threshold )
168 68
 {
169  
-	guchar* pixel = pb_get_pixel( img,x,y );
170  
-	return( pixel[0] > threshold );
  69
+  guchar* pixel = pb_get_pixel( img,x,y );
  70
+  return( pixel[0] > threshold );
171 71
 }
172 72
 
173 73
 int Stg::stg_rotrects_from_image_file( const char* filename, 
174  
-		stg_rotrect_t** rects, 
175  
-		unsigned int* rect_count,
176  
-		unsigned int* widthp, 
177  
-		unsigned int* heightp )
  74
+									   stg_rotrect_t** rects, 
  75
+									   unsigned int* rect_count,
  76
+									   unsigned int* widthp, 
  77
+									   unsigned int* heightp )
178 78
 {
179  
-	// TODO: make this a parameter
180  
-	const int threshold = 127;
  79
+  // TODO: make this a parameter
  80
+  const int threshold = 127;
181 81
 
182  
-	Fl_Shared_Image *img = Fl_Shared_Image::get(filename);
183  
-	if( img == NULL ) {
184  
-		std::cerr << "failed to open file: " << filename << std::endl;
185  
-		assert( img );
186  
-	}
  82
+  Fl_Shared_Image *img = Fl_Shared_Image::get(filename);
  83
+  if( img == NULL ) {
  84
+	std::cerr << "failed to open file: " << filename << std::endl;
  85
+	assert( img );
  86
+  }
187 87
 
188  
-	//printf( "loaded image %s w %d h %d d %d count %d ld %d\n", 
189  
-	//  filename, img->w(), img->h(), img->d(), img->count(), img->ld() );
  88
+  //printf( "loaded image %s w %d h %d d %d count %d ld %d\n", 
  89
+  //  filename, img->w(), img->h(), img->d(), img->count(), img->ld() );
190 90
 
191  
-	*rect_count = 0;
192  
-	size_t allocation_unit = 1000;
193  
-	size_t rects_allocated = allocation_unit;
194  
-	*rects = (stg_rotrect_t*)calloc( sizeof(stg_rotrect_t), rects_allocated );
  91
+  *rect_count = 0;
  92
+  size_t allocation_unit = 1000;
  93
+  size_t rects_allocated = allocation_unit;
  94
+  *rects = (stg_rotrect_t*)calloc( sizeof(stg_rotrect_t), rects_allocated );
195 95
 
196  
-	int img_width = img->w();
197  
-	int img_height = img->h();
  96
+  int img_width = img->w();
  97
+  int img_height = img->h();
198 98
 
199  
-	// if the caller wanted to know the dimensions
200  
-	if( widthp ) *widthp = img_width;
201  
-	if( heightp ) *heightp = img_height;
  99
+  // if the caller wanted to know the dimensions
  100
+  if( widthp ) *widthp = img_width;
  101
+  if( heightp ) *heightp = img_height;
202 102
 
203  
-	for(int y = 0; y < img_height; y++)
204  
-	  {
205  
-		for(int x = 0; x < img_width; x++)
206  
-		  {
207  
-			// skip blank (white) pixels
208  
-			if(  pb_pixel_is_set( img,x,y, threshold) )
209  
-				continue;
  103
+  for(int y = 0; y < img_height; y++)
  104
+	{
  105
+	  for(int x = 0; x < img_width; x++)
  106
+		{
  107
+		  // skip blank (white) pixels
  108
+		  if(  pb_pixel_is_set( img,x,y, threshold) )
  109
+			continue;
210 110
 
211  
-			// a rectangle starts from this point
212  
-			int startx = x;
213  
-			int starty = y;
214  
-			int height = img_height; // assume full height for starters
  111
+		  // a rectangle starts from this point
  112
+		  int startx = x;
  113
+		  int starty = y;
  114
+		  int height = img_height; // assume full height for starters
215 115
 
216  
-			// grow the width - scan along the line until we hit an empty (white) pixel
217  
-			for( ; x < img_width &&  ! pb_pixel_is_set(img,x,y,threshold); x++ )
  116
+		  // grow the width - scan along the line until we hit an empty (white) pixel
  117
+		  for( ; x < img_width &&  ! pb_pixel_is_set(img,x,y,threshold); x++ )
218 118
 			{
219  
-				// handle horizontal cropping
220  
-				//double ppx = x * sx;
221  
-				//if (ppx < this->crop_ax || ppx > this->crop_bx)
222  
-				//continue;
223  
-
224  
-				// look down to see how large a rectangle below we can make
225  
-				int yy  = y;
226  
-				while( ! pb_pixel_is_set(img,x,yy,threshold) && (yy < img_height-1) )
  119
+			  // handle horizontal cropping
  120
+			  //double ppx = x * sx;
  121
+			  //if (ppx < this->crop_ax || ppx > this->crop_bx)
  122
+			  //continue;
  123
+
  124
+			  // look down to see how large a rectangle below we can make
  125
+			  int yy  = y;
  126
+			  while( ! pb_pixel_is_set(img,x,yy,threshold) && (yy < img_height-1) )
227 127
 				{ 
228  
-					// handle vertical cropping
229  
-					//double ppy = (this->image->height - yy) * sy;
230  
-					//if (ppy < this->crop_ay || ppy > this->crop_by)
231  
-					//continue;
  128
+				  // handle vertical cropping
  129
+				  //double ppy = (this->image->height - yy) * sy;
  130
+				  //if (ppy < this->crop_ay || ppy > this->crop_by)
  131
+				  //continue;
232 132
 
233  
-					yy++;
  133
+				  yy++;
234 134
 				} 	      
235 135
 
236  
-				// now yy is the depth of a line of non-zero pixels
237  
-				// downward we store the smallest depth - that'll be the
238  
-				// height of the rectangle
239  
-				if( yy-y < height ) height = yy-y; // shrink the height to fit
  136
+			  // now yy is the depth of a line of non-zero pixels
  137
+			  // downward we store the smallest depth - that'll be the
  138
+			  // height of the rectangle
  139
+			  if( yy-y < height ) height = yy-y; // shrink the height to fit
240 140
 			} 
241 141
 
242  
-			// whiten the pixels we have used in this rect
243  
-			pb_set_rect( img, startx, starty, x-startx, height, 0xFF );
  142
+		  // whiten the pixels we have used in this rect
  143
+		  pb_set_rect( img, startx, starty, x-startx, height, 0xFF );
244 144
 
245  
-			// add this rectangle to the array
246  
-			(*rect_count)++;
  145
+		  // add this rectangle to the array
  146
+		  (*rect_count)++;
247 147
 
248  
-			if( (*rect_count) > rects_allocated )
  148
+		  if( (*rect_count) > rects_allocated )
249 149
 			{
250  
-				rects_allocated = (*rect_count) + allocation_unit;
  150
+			  rects_allocated = (*rect_count) + allocation_unit;
251 151
 
252  
-				*rects = (stg_rotrect_t*)
253  
-					realloc( *rects, rects_allocated * sizeof(stg_rotrect_t) );
  152
+			  *rects = (stg_rotrect_t*)
  153
+				realloc( *rects, rects_allocated * sizeof(stg_rotrect_t) );
254 154
 			}
255 155
 
256  
-			//  y-invert all the rectangles because we're using conventional
257  
-			// rather than graphics coordinates. this is much faster than
258  
-			// inverting the original image.
259  
-			stg_rotrect_t *latest = &(*rects)[(*rect_count)-1];
260  
-			latest->pose.x = startx;
261  
-			latest->pose.y = img_height-1 - (starty + height);
262  
-			latest->pose.a = 0.0;
263  
-			latest->size.x = x - startx;
264  
-			latest->size.y = height;
265  
-
266  
-			assert( latest->pose.x >= 0 );
267  
-			assert( latest->pose.y >= 0 );
268  
-			assert( latest->pose.x <= img_width );
269  
-			assert( latest->pose.y <= img_height);
270  
-			//assert( latest->size.x > 0 );
271  
-			//assert( latest->size.y > 0 );
272  
-
273  
-// 			if( latest->size.x < 1  || latest->size.y < 1 )
274  
-// 			  printf( "p [%.2f %.2f] s [%.2f %.2f]\n", 
275  
-// 						 latest->pose.x, latest->pose.y, latest->size.x, latest->size.y );
276  
-
277  
-			//printf( "rect %d (%.2f %.2f %.2f %.2f %.2f\n", 
278  
-			//  *rect_count, 
279  
-			//  latest->x, latest->y, latest->a, latest->w, latest->h );
  156
+		  //  y-invert all the rectangles because we're using conventional
  157
+		  // rather than graphics coordinates. this is much faster than
  158
+		  // inverting the original image.
  159
+		  stg_rotrect_t *latest = &(*rects)[(*rect_count)-1];
  160
+		  latest->pose.x = startx;
  161
+		  latest->pose.y = img_height-1 - (starty + height);
  162
+		  latest->pose.a = 0.0;
  163
+		  latest->size.x = x - startx;
  164
+		  latest->size.y = height;
  165
+
  166
+		  assert( latest->pose.x >= 0 );
  167
+		  assert( latest->pose.y >= 0 );
  168
+		  assert( latest->pose.x <= img_width );
  169
+		  assert( latest->pose.y <= img_height);
  170
+		  //assert( latest->size.x > 0 );
  171
+		  //assert( latest->size.y > 0 );
  172
+
  173
+		  // 			if( latest->size.x < 1  || latest->size.y < 1 )
  174
+		  // 			  printf( "p [%.2f %.2f] s [%.2f %.2f]\n", 
  175
+		  // 						 latest->pose.x, latest->pose.y, latest->size.x, latest->size.y );
  176
+
  177
+		  //printf( "rect %d (%.2f %.2f %.2f %.2f %.2f\n", 
  178
+		  //  *rect_count, 
  179
+		  //  latest->x, latest->y, latest->a, latest->w, latest->h );
280 180
 
281 181
 		}
282 182
 	}
283 183
 
284  
-	if( img ) img->release(); // frees all image resources: the
285  
-	// constructor is not available
  184
+  if( img ) img->release(); // frees all image resources: the
  185
+  // constructor is not available
286 186
 
287  
-	return 0; // ok
  187
+  return 0; // ok
288 188
 }
289 189
 
290 190
 // POINTS -----------------------------------------------------------
291 191
 
292 192
 stg_point_t* Stg::stg_unit_square_points_create( void )
293 193
 {
294  
-	stg_point_t * pts = new stg_point_t[4];
295  
-
296  
-	pts[0].x = 0;
297  
-	pts[0].y = 0;
298  
-	pts[1].x = 1;
299  
-	pts[1].y = 0;
300  
-	pts[2].x = 1;
301  
-	pts[2].y = 1;
302  
-	pts[3].x = 0;
303  
-	pts[3].y = 1;
304  
-
305  
-	return pts;
306  
-}
307  
-
308  
-// return a value based on val, but limited minval <= val >= maxval  
309  
-double Stg::constrain( double val, double minval, double maxval )
310  
-{
311  
-	if( val < minval )
312  
-		return minval;
  194
+  stg_point_t * pts = new stg_point_t[4];
313 195
 
314  
-	if( val > maxval )
315  
-		return maxval;
  196
+  pts[0].x = 0;
  197
+  pts[0].y = 0;
  198
+  pts[1].x = 1;
  199
+  pts[1].y = 0;
  200
+  pts[2].x = 1;
  201
+  pts[2].y = 1;
  202
+  pts[3].x = 0;
  203
+  pts[3].y = 1;
316 204
 
317  
-	return val;
  205
+  return pts;
318 206
 }
319 207
 
320  
-
321  
-stg_color_t Stg::stg_color_pack( double r, double g, double b, double a )
322  
-{
323  
-	stg_color_t col=0;
324  
-	col += (stg_color_t)((1.0-a)*255.0)<<24;
325  
-	col += (stg_color_t)(r*255.0)<<16;
326  
-	col += (stg_color_t)(g*255.0)<<8;
327  
-	col += (stg_color_t)(b*255.0);
328  
-
329  
-	return col;
330  
-}
331  
-
332  
-void Stg::stg_color_unpack( stg_color_t col, 
333  
-		double* r, double* g, double* b, double* a )
334  
-{
335  
-	if(a) *a = 1.0 - (((col & 0xFF000000) >> 24) / 255.0);
336  
-	if(r) *r = ((col & 0x00FF0000) >> 16) / 255.0;
337  
-	if(g) *g = ((col & 0x0000FF00) >> 8)  / 255.0;
338  
-	if(b) *b = ((col & 0x000000FF) >> 0)  / 255.0;
339  
-}
340  
-
341  
-
342  
-// DRAW INTERFACE
343  
-
344  
-using namespace Draw;
345  
-
346  
-draw_t* Draw::create( type_t type,
347  
-		vertex_t* verts,
348  
-		size_t vert_count )
  208
+// return a value based on val, but limited minval <= val >= maxval  
  209
+double Stg::constrain( double val, double minval, double maxval )
349 210
 {
350  
-	size_t vert_mem_size = vert_count * sizeof(vertex_t);
  211
+  if( val < minval )
  212
+	return minval;
351 213
 
352  
-	// allocate space for the draw structure and the vertex data behind it
353  
-	draw_t* d = (draw_t*)
354  
-		g_malloc( sizeof(draw_t) + vert_mem_size );
  214
+  if( val > maxval )
  215
+	return maxval;
355 216