~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-engine/core/src/gui/code/visual_component.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  Bear Engine
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
28
28
 */
29
29
#include "gui/visual_component.hpp"
30
30
 
 
31
#include "input/key_info.hpp"
 
32
 
31
33
#include "visual/scene_line.hpp"
 
34
#include "visual/scene_rectangle.hpp"
32
35
 
33
36
#include <algorithm>
34
37
#include <claw/assert.hpp>
44
47
 */
45
48
bear::gui::visual_component::visual_component( visual_component* owner )
46
49
  : m_box(0, 0, 0, 0), m_owner(owner), m_focused_component(-1),
47
 
    m_visible(true), m_input_priority(false), m_border_color(0, 0, 0, 0)
 
50
    m_visible(true), m_input_priority(false), m_enabled(true),
 
51
    m_top_left_border_color(0, 0, 0, 0),
 
52
    m_bottom_right_border_color(0, 0, 0, 0), m_background_color(0, 0, 0, 0)
48
53
{
49
54
  if (m_owner)
50
55
    m_owner->add_component(this);
68
73
void bear::gui::visual_component::render
69
74
( std::list<visual::scene_element>& e ) const
70
75
{
71
 
  if (m_visible)
 
76
  if (!m_visible)
 
77
    return;
 
78
 
 
79
  scene_element_list sub_e;
 
80
 
 
81
  // display the current component
 
82
  display( e );
 
83
 
 
84
  // display the sub components
 
85
  for ( component_list::const_iterator it=m_components.begin();
 
86
        it!=m_components.end();
 
87
        ++it )
 
88
    (*it)->render( sub_e );
 
89
 
 
90
  // the scene elements are placed in the current component, so we adjust
 
91
  // their position according to our position.
 
92
  for ( scene_element_list::iterator it=sub_e.begin(); it!=sub_e.end(); ++it )
 
93
    it->set_position( it->get_position() + m_box.bottom_left() );
 
94
 
 
95
  e.insert( e.end(), sub_e.begin(), sub_e.end() );
 
96
 
 
97
  // and we draw the borders and the background of the current component
 
98
  visual::rectangle_type box
 
99
    (visual::position_type(0, 0), visual::position_type( width(), height() ));
 
100
 
 
101
  if ( get_border_size() != 0 )
72
102
    {
73
 
      scene_element_list sub_e;
74
 
 
75
 
      // display the current component
76
 
      display( e );
77
 
      
78
 
      // display the sub components
79
 
      for ( component_list::const_iterator it=m_components.begin();
80
 
            it!=m_components.end();
81
 
            ++it )
82
 
        (*it)->render( sub_e );
83
 
 
84
 
      // the scene elements are placed in the current component, so we adjust
85
 
      // thein position according to our position.
86
 
      for ( scene_element_list::iterator it=sub_e.begin(); it!=sub_e.end();
87
 
            ++it )
88
 
        it->set_position( it->get_position() + m_box.position );
89
 
 
90
 
      e.insert( e.end(), sub_e.begin(), sub_e.end() );
91
 
 
92
 
      // and we draw the border of the current component
93
 
      std::vector<visual::position_type> p(5, visual::position_type(0, 0));
94
 
 
95
 
      p[1].x += width();
96
 
      p[2].x += width();
97
 
      p[2].y += height();
98
 
      p[3].y += height();
99
 
 
100
 
      e.push_back( visual::scene_line(left(), top(), m_border_color, p, 1) );
 
103
      std::vector<visual::position_type> line(3);
 
104
      line[0] = box.bottom_left();
 
105
      line[1] = box.bottom_right();
 
106
      line[2] = box.top_right();
 
107
 
 
108
      if ( m_bottom_right_border_color.components.alpha != 0 )
 
109
        e.push_front
 
110
          ( visual::scene_line
 
111
            (left(), bottom(), m_bottom_right_border_color, line,
 
112
             get_border_size()) );
 
113
 
 
114
      line[1] = box.top_left();
 
115
 
 
116
      if ( m_top_left_border_color.components.alpha != 0 )
 
117
        e.push_front
 
118
          ( visual::scene_line
 
119
            (left(), bottom(), m_top_left_border_color, line,
 
120
             get_border_size()) );
101
121
    }
 
122
 
 
123
  if ( m_background_color.components.alpha != 0 )
 
124
    e.push_front
 
125
      ( visual::scene_rectangle(left(), bottom(), m_background_color, box) );
102
126
} // visual_component::render()
103
127
 
104
128
/*----------------------------------------------------------------------------*/
108
132
 */
109
133
bool bear::gui::visual_component::key_pressed( const input::key_info& key )
110
134
{
 
135
  if ( !is_enabled() )
 
136
    return false;
 
137
 
111
138
  bool result;
112
139
 
113
140
  if (m_input_priority)
115
142
      result = on_key_press(key);
116
143
 
117
144
      if ( !result )
118
 
        if ( m_focused_component >= 0)
 
145
        if ( m_focused_component >= 0 )
119
146
          result = m_components[m_focused_component]->key_pressed(key);
120
147
    }
121
 
  else if ( m_focused_component >= 0)
 
148
  else if ( m_focused_component >= 0 )
122
149
    {
123
150
      result = m_components[m_focused_component]->key_pressed(key);
124
151
 
138
165
 */
139
166
bool bear::gui::visual_component::char_pressed( const input::key_info& key )
140
167
{
 
168
  if ( !is_enabled() )
 
169
    return false;
 
170
 
141
171
  bool result;
142
172
 
143
173
  if (m_input_priority)
145
175
      result = on_char_pressed(key);
146
176
 
147
177
      if ( !result )
148
 
        if ( m_focused_component >= 0)
 
178
        if ( m_focused_component >= 0 )
149
179
          result = m_components[m_focused_component]->char_pressed(key);
150
180
    }
151
 
  else if ( m_focused_component >= 0)
 
181
  else if ( m_focused_component >= 0 )
152
182
    {
153
183
      result = m_components[m_focused_component]->char_pressed(key);
154
184
 
170
200
bool bear::gui::visual_component::button_pressed
171
201
( input::joystick::joy_code button, unsigned int joy_index )
172
202
{
 
203
  if ( !is_enabled() )
 
204
    return false;
 
205
 
173
206
  bool result;
174
207
 
175
208
  if (m_input_priority)
205
238
( input::mouse::mouse_code key,
206
239
  const claw::math::coordinate_2d<unsigned int>& pos )
207
240
{
 
241
  if ( !is_enabled() )
 
242
    return false;
 
243
 
208
244
  bool result;
209
245
 
210
246
  if (m_input_priority)
227
263
 
228
264
/*----------------------------------------------------------------------------*/
229
265
/**
 
266
 * \brief Inform the component that a mouse button had been released.
 
267
 * \param key The value of the released button.
 
268
 * \param pos The current position of the cursor.
 
269
 */
 
270
bool bear::gui::visual_component::mouse_released
 
271
( input::mouse::mouse_code key,
 
272
  const claw::math::coordinate_2d<unsigned int>& pos )
 
273
{
 
274
  if ( !is_enabled() )
 
275
    return false;
 
276
 
 
277
  bool result;
 
278
 
 
279
  if (m_input_priority)
 
280
    {
 
281
      result = on_mouse_released(key, pos);
 
282
 
 
283
      if ( !result )
 
284
        result = broadcast_mouse_released(key, pos);
 
285
    }
 
286
  else
 
287
    {
 
288
      result = broadcast_mouse_released(key, pos);
 
289
 
 
290
      if ( !result )
 
291
        result = on_mouse_released(key, pos);
 
292
    }
 
293
 
 
294
  return result;
 
295
} // visual_component::mouse_released()
 
296
 
 
297
/*----------------------------------------------------------------------------*/
 
298
/**
 
299
 * \brief Inform the component that a mouse button had been maintained.
 
300
 * \param key The value of the maintained button.
 
301
 * \param pos The current position of the cursor.
 
302
 */
 
303
bool bear::gui::visual_component::mouse_maintained
 
304
( input::mouse::mouse_code key,
 
305
  const claw::math::coordinate_2d<unsigned int>& pos )
 
306
{
 
307
  if ( !is_enabled() )
 
308
    return false;
 
309
 
 
310
  bool result;
 
311
 
 
312
  if (m_input_priority)
 
313
    {
 
314
      result = on_mouse_maintained(key, pos);
 
315
 
 
316
      if ( !result )
 
317
        result = broadcast_mouse_maintained(key, pos);
 
318
    }
 
319
  else
 
320
    {
 
321
      result = broadcast_mouse_maintained(key, pos);
 
322
 
 
323
      if ( !result )
 
324
        result = on_mouse_maintained(key, pos);
 
325
    }
 
326
 
 
327
  return result;
 
328
} // visual_component::mouse_maintained()
 
329
 
 
330
/*----------------------------------------------------------------------------*/
 
331
/**
230
332
 * \brief Inform the component that the mouse has been moved.
231
333
 * \param pos The new position of the cursor.
232
334
 */
233
335
bool bear::gui::visual_component::mouse_move
234
336
( const claw::math::coordinate_2d<unsigned int>& pos )
235
337
{
 
338
  if ( !is_enabled() )
 
339
    return false;
 
340
 
236
341
  bool result;
237
342
 
238
343
  if (m_input_priority)
255
360
 
256
361
/*----------------------------------------------------------------------------*/
257
362
/**
 
363
 * \brief Adjust the size of the component to fit its sub components.
 
364
 * \param margin The margin around the children.
 
365
 */
 
366
void bear::gui::visual_component::fit( visual::size_type margin )
 
367
{
 
368
  size_type min_x( std::numeric_limits<size_type>::max() );
 
369
  size_type min_y( std::numeric_limits<size_type>::max() );
 
370
  size_type max_x( std::numeric_limits<size_type>::min() );
 
371
  size_type max_y( std::numeric_limits<size_type>::min() );
 
372
 
 
373
  component_list::const_iterator it;
 
374
  for ( it=m_components.begin(); it!=m_components.end(); ++it )
 
375
    {
 
376
      min_x = std::min( min_x, (*it)->left() );
 
377
      min_y = std::min( min_y, (*it)->bottom() );
 
378
      max_x = std::max( max_x, (*it)->right() );
 
379
      max_y = std::max( max_y, (*it)->top() );
 
380
    }
 
381
 
 
382
  const size_type delta_x = min_x - margin;
 
383
  const size_type delta_y = min_y - margin;
 
384
 
 
385
  for ( it=m_components.begin(); it!=m_components.end(); ++it )
 
386
    (*it)->set_bottom_left
 
387
      ( (*it)->left() - delta_x, (*it)->bottom() - delta_y );
 
388
 
 
389
  set_size( max_x - delta_x + margin, max_y - delta_y + margin );
 
390
} // visual_component::fit()
 
391
 
 
392
/*----------------------------------------------------------------------------*/
 
393
/**
258
394
 * \brief Set the size of the component to its maximum size.
259
395
 */
260
396
void bear::gui::visual_component::set_size_maximum()
261
397
{
262
 
  set_size( std::numeric_limits<unsigned int>::max(),
263
 
            std::numeric_limits<unsigned int>::max() );
 
398
  set_size( std::numeric_limits<size_type>::max(),
 
399
            std::numeric_limits<size_type>::max() );
264
400
} // visual_component::set_size()
265
401
 
266
402
/*----------------------------------------------------------------------------*/
268
404
 * \brief Set the size of the component.
269
405
 * \param size The new size.
270
406
 */
271
 
void bear::gui::visual_component::set_size
272
 
( const claw::math::coordinate_2d<unsigned int>& size )
 
407
void bear::gui::visual_component::set_size( const size_box_type& size )
273
408
{
274
409
  set_size( size.x, size.y );
275
410
} // visual_component::set_size()
280
415
 * \param w The new width.
281
416
 * \param h The new height.
282
417
 */
283
 
void bear::gui::visual_component::set_size( unsigned int w, unsigned int h )
 
418
void bear::gui::visual_component::set_size( size_type w, size_type h )
284
419
{
285
 
  const unsigned int old_w = m_box.width;
286
 
  const unsigned int old_h = m_box.height;
 
420
  const size_type old_w = m_box.width();
 
421
  const size_type old_h = m_box.height();
287
422
 
288
 
  m_box.width = w;
289
 
  m_box.height = h;
 
423
  m_box.set( left(), bottom(), m_box.left() + w, m_box.bottom() + h );
290
424
 
291
425
  stay_in_owner();
292
426
 
293
 
  if ( (old_w != m_box.width) || (old_h != m_box.height) )
 
427
  if ( (old_w != m_box.width()) || (old_h != m_box.height()) )
294
428
    on_resized();
295
429
} // visual_component::set_size()
296
430
 
299
433
 * \brief Set the width of the component.
300
434
 * \param w The new width.
301
435
 */
302
 
void bear::gui::visual_component::set_width( unsigned int w )
 
436
void bear::gui::visual_component::set_width( size_type w )
303
437
{
304
438
  set_size( w, height() );
305
439
} // visual_component::set_width()
309
443
 * \brief Set the height of the component.
310
444
 * \param h The new height.
311
445
 */
312
 
void bear::gui::visual_component::set_height( unsigned int h )
 
446
void bear::gui::visual_component::set_height( size_type h )
313
447
{
314
448
  set_size( width(), h );
315
449
} // visual_component::set_height()
320
454
 * \param pos The new position.
321
455
 */
322
456
void bear::gui::visual_component::set_position
323
 
( const claw::math::coordinate_2d<unsigned int>& pos )
 
457
( const position_type& pos )
324
458
{
325
459
  set_position( pos.x, pos.y );
326
460
} // visual_component::set_position()
331
465
 * \param x The new x-coordinate.
332
466
 * \param y The new y-coordinate.
333
467
 */
334
 
void bear::gui::visual_component::set_position( unsigned int x, unsigned int y )
 
468
void  bear::gui::visual_component::set_position
 
469
( coordinate_type x, coordinate_type y )
335
470
{
336
 
  const unsigned int w = m_box.width;
337
 
  const unsigned int h = m_box.height;
338
 
 
339
 
  m_box.position.x = x;
340
 
  m_box.position.y = y;
341
 
  stay_in_owner();
342
 
 
343
 
  if ( (w != m_box.width) || (h != m_box.height) )
344
 
    on_resized();
345
 
} // visual_component::set_size()
 
471
  set_bottom_left(x, y);
 
472
} // visual_component::set_position()
346
473
 
347
474
/*----------------------------------------------------------------------------*/
348
475
/**
378
505
 
379
506
/*----------------------------------------------------------------------------*/
380
507
/**
 
508
 * \brief Set the left position of the component in its owner.
 
509
 * \param x The new position.
 
510
 */
 
511
void bear::gui::visual_component::set_left( coordinate_type x )
 
512
{
 
513
  set_bottom_left( x, bottom() );
 
514
} // visual_component::set_left()
 
515
 
 
516
/*----------------------------------------------------------------------------*/
 
517
/**
 
518
 * \brief Set the right position of the component in its owner.
 
519
 * \param x The new position.
 
520
 */
 
521
void bear::gui::visual_component::set_right( coordinate_type x )
 
522
{
 
523
  set_bottom_left( x - width(), bottom() );
 
524
} // visual_component::set_right()
 
525
 
 
526
/*----------------------------------------------------------------------------*/
 
527
/**
 
528
 * \brief Set the top position of the component in its owner.
 
529
 * \param y The new position.
 
530
 */
 
531
void bear::gui::visual_component::set_top( coordinate_type y )
 
532
{
 
533
  set_bottom_left( left(), y - height() );
 
534
} // visual_component::set_top()
 
535
 
 
536
/*----------------------------------------------------------------------------*/
 
537
/**
 
538
 * \brief Set the bottom position of the component in its owner.
 
539
 * \param x The new position.
 
540
 */
 
541
void bear::gui::visual_component::set_bottom( coordinate_type y )
 
542
{
 
543
  set_bottom_left( left(), y );
 
544
} // visual_component::set_bottom()
 
545
 
 
546
/*----------------------------------------------------------------------------*/
 
547
/**
 
548
 * \brief Set the top-left position of the component in its owner.
 
549
 * \param x The new x-position.
 
550
 * \param y The new y-position.
 
551
 */
 
552
void bear::gui::visual_component::set_top_left
 
553
( coordinate_type x, coordinate_type y )
 
554
{
 
555
  set_bottom_left( x, y - height() );
 
556
} // visual_component::set_top_left()
 
557
 
 
558
/*----------------------------------------------------------------------------*/
 
559
/**
 
560
 * \brief Set the bottom-left position of the component in its owner.
 
561
 * \param x The new x-position.
 
562
 * \param y The new y-position.
 
563
 */
 
564
void bear::gui::visual_component::set_bottom_left
 
565
( coordinate_type x, coordinate_type y )
 
566
{
 
567
  const coordinate_type w = m_box.width();
 
568
  const coordinate_type h = m_box.height();
 
569
 
 
570
  m_box.left(x);
 
571
  m_box.bottom(y);
 
572
  stay_in_owner();
 
573
 
 
574
  if ( (w != m_box.width()) || (h != m_box.height()) )
 
575
    on_resized();
 
576
} // visual_component::set_bottom_left()
 
577
 
 
578
/*----------------------------------------------------------------------------*/
 
579
/**
 
580
 * \brief Set the top-right position of the component in its owner.
 
581
 * \param x The new x-position.
 
582
 * \param y The new y-position.
 
583
 */
 
584
void bear::gui::visual_component::set_top_right
 
585
( coordinate_type x, coordinate_type y )
 
586
{
 
587
  set_bottom_left( x - width(), y - height() );
 
588
} // visual_component::set_top_right()
 
589
 
 
590
/*----------------------------------------------------------------------------*/
 
591
/**
 
592
 * \brief Set the bottom-right position of the component in its owner.
 
593
 * \param x The new x-position.
 
594
 * \param y The new y-position.
 
595
 */
 
596
void bear::gui::visual_component::set_bottom_right
 
597
( coordinate_type x, coordinate_type y )
 
598
{
 
599
  set_bottom_left( x - width(), y );
 
600
} // visual_component::set_bottom_right()
 
601
 
 
602
/*----------------------------------------------------------------------------*/
 
603
/**
381
604
 * \brief Get the width of the component.
382
605
 */
383
 
unsigned int bear::gui::visual_component::width() const
 
606
bear::gui::size_type bear::gui::visual_component::width() const
384
607
{
385
 
  return m_box.width;
 
608
  return m_box.width();
386
609
} // visual_component::width()
387
610
 
388
611
/*----------------------------------------------------------------------------*/
389
612
/**
390
613
 * \brief Get the height of the component.
391
614
 */
392
 
unsigned int bear::gui::visual_component::height() const
 
615
bear::gui::size_type bear::gui::visual_component::height() const
393
616
{
394
 
  return m_box.height;
 
617
  return m_box.height();
395
618
} // visual_component::height()
396
619
 
397
620
/*----------------------------------------------------------------------------*/
398
621
/**
399
622
 * \brief Get the x-coordinate of the component's left edge.
400
623
 */
401
 
unsigned int bear::gui::visual_component::left() const
 
624
bear::gui::coordinate_type bear::gui::visual_component::left() const
402
625
{
403
626
  return m_box.left();
404
627
} // visual_component::left()
407
630
/**
408
631
 * \brief Get the x-coordinate of the component's right edge.
409
632
 */
410
 
unsigned int bear::gui::visual_component::right() const
 
633
bear::gui::coordinate_type bear::gui::visual_component::right() const
411
634
{
412
635
  return m_box.right();
413
636
} // visual_component::right()
416
639
/**
417
640
 * \brief Get the y-coordinate of the component's bottom edge.
418
641
 */
419
 
unsigned int bear::gui::visual_component::bottom() const
 
642
bear::gui::coordinate_type bear::gui::visual_component::bottom() const
420
643
{
421
644
  return m_box.bottom();
422
645
} // visual_component::bottom()
425
648
/**
426
649
 * \brief Get the y-coordinate of the component's top edge.
427
650
 */
428
 
unsigned int bear::gui::visual_component::top() const
 
651
bear::gui::coordinate_type bear::gui::visual_component::top() const
429
652
{
430
653
  return m_box.top();
431
654
} // visual_component::top()
434
657
/**
435
658
 * \brief Get the coordinates of the component's top left corner.
436
659
 */
437
 
claw::math::coordinate_2d<unsigned int>
438
 
bear::gui::visual_component::top_left() const
 
660
bear::gui::position_type bear::gui::visual_component::top_left() const
439
661
{
440
 
  return claw::math::coordinate_2d<unsigned int>( left(), top() );
 
662
  return m_box.top_left();
441
663
} // visual_component::top_left()
442
664
 
443
665
/*----------------------------------------------------------------------------*/
444
666
/**
445
667
 * \brief Get the coordinates of the component's top right corner.
446
668
 */
447
 
claw::math::coordinate_2d<unsigned int>
448
 
bear::gui::visual_component::top_right() const
 
669
bear::gui::position_type bear::gui::visual_component::top_right() const
449
670
{
450
 
  return claw::math::coordinate_2d<unsigned int>( right(), top() );
 
671
  return m_box.top_right();
451
672
} // visual_component::top_right()
452
673
 
453
674
/*----------------------------------------------------------------------------*/
454
675
/**
455
676
 * \brief Get the coordinates of the component's bottom left corner.
456
677
 */
457
 
claw::math::coordinate_2d<unsigned int>
458
 
bear::gui::visual_component::bottom_left() const
 
678
bear::gui::position_type bear::gui::visual_component::bottom_left() const
459
679
{
460
 
  return claw::math::coordinate_2d<unsigned int>( left(), bottom() );
 
680
  return m_box.bottom_left();
461
681
} // visual_component::bottom_left()
462
682
 
463
683
/*----------------------------------------------------------------------------*/
464
684
/**
465
685
 * \brief Get the coordinates of the component's bottom right corner.
466
686
 */
467
 
claw::math::coordinate_2d<unsigned int>
468
 
bear::gui::visual_component::bottom_right() const
 
687
bear::gui::position_type bear::gui::visual_component::bottom_right() const
469
688
{
470
 
  return claw::math::coordinate_2d<unsigned int>( right(), bottom() );
 
689
  return m_box.bottom_right();
471
690
} // visual_component::bottom_right()
472
691
 
473
692
/*----------------------------------------------------------------------------*/
474
693
/**
475
694
 * \brief Get the size of the component.
476
695
 */
477
 
claw::math::coordinate_2d<unsigned int>
478
 
bear::gui::visual_component::get_size() const
 
696
bear::gui::size_box_type bear::gui::visual_component::get_size() const
479
697
{
480
 
  return claw::math::coordinate_2d<unsigned int>( m_box.width, m_box.height );
 
698
  return m_box.size();
481
699
} // visual_component::get_size()
482
700
 
483
701
/*----------------------------------------------------------------------------*/
484
702
/**
485
703
 * \brief Get the position of the component in its owner.
486
704
 */
487
 
const claw::math::coordinate_2d<unsigned int>&
488
 
bear::gui::visual_component::get_position() const
 
705
bear::gui::position_type bear::gui::visual_component::get_position() const
489
706
{
490
 
  return m_box.position;
 
707
  return m_box.bottom_left();
491
708
} // visual_component::get_position()
492
709
 
493
710
/*----------------------------------------------------------------------------*/
494
711
/**
495
712
 * \brief Get the rectangle bounding this component.
496
713
 */
497
 
const claw::math::rectangle<unsigned int>&
 
714
const bear::gui::rectangle_type&
498
715
bear::gui::visual_component::get_rectangle() const
499
716
{
500
717
  return m_box;
511
728
 
512
729
/*----------------------------------------------------------------------------*/
513
730
/**
 
731
 * \brief Get the size of the borders.
 
732
 */
 
733
bear::gui::size_type bear::gui::visual_component::get_border_size() const
 
734
{
 
735
  return 1;
 
736
} // visual_component::get_border_size()
 
737
 
 
738
/*----------------------------------------------------------------------------*/
 
739
/**
514
740
 * \brief Set the color of the border.
515
741
 * \param clr The new color.
516
742
 */
517
 
void bear::gui::visual_component::set_border_color
518
 
( const claw::graphic::rgba_pixel& clr )
 
743
void bear::gui::visual_component::set_border_color( const color_type& clr )
519
744
{
520
 
  m_border_color = clr;
 
745
  set_top_left_border_color( clr );
 
746
  set_bottom_right_border_color( clr );
521
747
} // visual_component::set_border_color()
522
748
 
523
749
/*----------------------------------------------------------------------------*/
524
750
/**
 
751
 * \brief Set the color of the top and left borders.
 
752
 * \param clr The new color.
 
753
 */
 
754
void
 
755
bear::gui::visual_component::set_top_left_border_color( const color_type& clr )
 
756
{
 
757
  m_top_left_border_color = clr;
 
758
} // visual_component::set_top_left_border_color()
 
759
 
 
760
/*----------------------------------------------------------------------------*/
 
761
/**
 
762
 * \brief Get the color of the top and left borders.
 
763
 */
 
764
const bear:: gui::color_type&
 
765
bear::gui::visual_component::get_top_left_border_color() const
 
766
{
 
767
  return m_top_left_border_color;
 
768
} // visual_component::get_top_left_border_color()
 
769
 
 
770
/*----------------------------------------------------------------------------*/
 
771
/**
 
772
 * \brief Set the color of the bottom and right borders.
 
773
 * \param clr The new color.
 
774
 */
 
775
void bear::gui::visual_component::set_bottom_right_border_color
 
776
( const color_type& clr )
 
777
{
 
778
  m_bottom_right_border_color = clr;
 
779
} // visual_component::set_bottom_right_border_color()
 
780
 
 
781
/*----------------------------------------------------------------------------*/
 
782
/**
 
783
 * \brief Get the color of the bottom and right borders.
 
784
 */
 
785
const bear::gui::color_type&
 
786
bear::gui::visual_component::get_bottom_right_border_color() const
 
787
{
 
788
  return m_bottom_right_border_color;
 
789
} // visual_component::get_bottom_right_border_color()
 
790
 
 
791
/*----------------------------------------------------------------------------*/
 
792
/**
 
793
 * \brief Set the color of the background.
 
794
 * \param clr The new color.
 
795
 */
 
796
void bear::gui::visual_component::set_background_color( const color_type& clr )
 
797
{
 
798
  m_background_color = clr;
 
799
} // visual_component::set_background_color()
 
800
 
 
801
/*----------------------------------------------------------------------------*/
 
802
/**
 
803
 * \brief Get the color of the background.
 
804
 * \param clr The new color.
 
805
 */
 
806
const bear::gui::color_type&
 
807
bear::gui::visual_component::get_background_color() const
 
808
{
 
809
  return m_background_color;
 
810
} // visual_component::get_background_color()
 
811
 
 
812
/*----------------------------------------------------------------------------*/
 
813
/**
 
814
 * \brief Disable this component.
 
815
 */
 
816
void bear::gui::visual_component::disable()
 
817
{
 
818
  m_enabled = false;
 
819
} // visual_component::disable()
 
820
 
 
821
/*----------------------------------------------------------------------------*/
 
822
/**
 
823
 * \brief Enable this component.
 
824
 */
 
825
void bear::gui::visual_component::enable()
 
826
{
 
827
  m_enabled = true;
 
828
} // visual_component::enable()
 
829
 
 
830
/*----------------------------------------------------------------------------*/
 
831
/**
 
832
 * \brief Tell if this compontent is enabled.
 
833
 */
 
834
bool bear::gui::visual_component::is_enabled() const
 
835
{
 
836
  return m_enabled;
 
837
} // visual_component::is_enabled()
 
838
 
 
839
/*----------------------------------------------------------------------------*/
 
840
/**
 
841
 * \brief Set the focus on this component.
 
842
 */
 
843
void bear::gui::visual_component::set_focus()
 
844
{
 
845
  // all parent controls up to the top component
 
846
  std::list<visual_component*> s;
 
847
  visual_component* c;
 
848
 
 
849
  for ( c = this; c!=NULL; c=c->m_owner )
 
850
    s.push_front(c);
 
851
 
 
852
  std::list<visual_component*>::const_iterator it_parent(s.begin());
 
853
  std::list<visual_component*>::const_iterator it_child(it_parent);
 
854
  ++it_child;
 
855
 
 
856
  for ( ; it_child!=s.end(); ++it_parent, ++it_child )
 
857
    (*it_parent)->set_focus(*it_child);
 
858
 
 
859
  for ( it_parent=s.begin(); it_parent!=s.end(); ++it_parent )
 
860
    (*it_parent)->on_focused();
 
861
} // visual_component::set_focus()
 
862
 
 
863
/*----------------------------------------------------------------------------*/
 
864
/**
 
865
 * \brief Get the child component having the focus.
 
866
 */
 
867
bear::gui::visual_component* bear::gui::visual_component::get_focus() const
 
868
{
 
869
  if ( m_focused_component < 0 )
 
870
    return NULL;
 
871
  else
 
872
    return m_components[m_focused_component];
 
873
} // visual_component::get_focus()
 
874
 
 
875
/*----------------------------------------------------------------------------*/
 
876
/**
525
877
 * \brief Add a component in this component.
526
878
 * \param that The component to add.
527
879
 */
638
990
 
639
991
/*----------------------------------------------------------------------------*/
640
992
/**
 
993
 * \brief Tell the focused component that a mouse button has been released.
 
994
 * \param key The pressed key.
 
995
 * \param pos The current position of the cursor.
 
996
 * \return true if the key has been processed.
 
997
 */
 
998
bool bear::gui::visual_component::on_mouse_released
 
999
( input::mouse::mouse_code key,
 
1000
  const claw::math::coordinate_2d<unsigned int>& pos )
 
1001
{
 
1002
  return false;
 
1003
} // visual_component::on_mouse_released()
 
1004
 
 
1005
/*----------------------------------------------------------------------------*/
 
1006
/**
 
1007
 * \brief Tell the focused component that a mouse button has been maintained.
 
1008
 * \param key The pressed key.
 
1009
 * \param pos The current position of the cursor.
 
1010
 * \return true if the key has been processed.
 
1011
 */
 
1012
bool bear::gui::visual_component::on_mouse_maintained
 
1013
( input::mouse::mouse_code key,
 
1014
  const claw::math::coordinate_2d<unsigned int>& pos )
 
1015
{
 
1016
  return false;
 
1017
} // visual_component::on_mouse_maintained()
 
1018
 
 
1019
/*----------------------------------------------------------------------------*/
 
1020
/**
641
1021
 * \brief Tell the component that the mouse has been moved.
642
1022
 * \param pos The new position of the cursor.
643
1023
 * \return true if the button has been processed.
650
1030
 
651
1031
/*----------------------------------------------------------------------------*/
652
1032
/**
 
1033
 * \brief Tell the component he received the focus.
 
1034
 */
 
1035
void bear::gui::visual_component::on_focused()
 
1036
{
 
1037
 
 
1038
} // visual_component::on_focused()
 
1039
 
 
1040
/*----------------------------------------------------------------------------*/
 
1041
/**
653
1042
 * \brief Inform the sub components that the mouse has been moved.
654
1043
 * \param pos The new position of the cursor.
655
1044
 */
668
1057
 
669
1058
/*----------------------------------------------------------------------------*/
670
1059
/**
671
 
 * \brief Inform the sub components that the mouse has been moved.
 
1060
 * \brief Inform the sub components that a mouse button has been pressed.
672
1061
 * \param button The pressed key.
673
1062
 * \param pos The current position of the cursor.
674
1063
 * \return true if the key has been processed.
689
1078
 
690
1079
/*----------------------------------------------------------------------------*/
691
1080
/**
 
1081
 * \brief Inform the sub components that a mouse button has been released.
 
1082
 * \param button The pressed key.
 
1083
 * \param pos The current position of the cursor.
 
1084
 * \return true if the key has been processed.
 
1085
 */
 
1086
bool bear::gui::visual_component::broadcast_mouse_released
 
1087
( input::mouse::mouse_code button,
 
1088
  const claw::math::coordinate_2d<unsigned int>& pos )
 
1089
{
 
1090
  bool result(false);
 
1091
  component_list::iterator it;
 
1092
 
 
1093
  for (it=m_components.begin(); !result && (it!=m_components.end()); ++it)
 
1094
    if ( (*it)->m_box.includes(pos) )
 
1095
      result = (*it)->mouse_released( button, pos - (*it)->get_position() );
 
1096
 
 
1097
  return result;
 
1098
} // visual_component::broadcast_mouse_released()
 
1099
 
 
1100
/*----------------------------------------------------------------------------*/
 
1101
/**
 
1102
 * \brief Inform the sub components that a mouse button has been maintained.
 
1103
 * \param button The pressed key.
 
1104
 * \param pos The current position of the cursor.
 
1105
 * \return true if the key has been processed.
 
1106
 */
 
1107
bool bear::gui::visual_component::broadcast_mouse_maintained
 
1108
( input::mouse::mouse_code button,
 
1109
  const claw::math::coordinate_2d<unsigned int>& pos )
 
1110
{
 
1111
  bool result(false);
 
1112
  component_list::iterator it;
 
1113
 
 
1114
  for (it=m_components.begin(); !result && (it!=m_components.end()); ++it)
 
1115
    if ( (*it)->m_box.includes(pos) )
 
1116
      result = (*it)->mouse_maintained( button, pos - (*it)->get_position() );
 
1117
 
 
1118
  return result;
 
1119
} // visual_component::broadcast_mouse_maintained()
 
1120
 
 
1121
/*----------------------------------------------------------------------------*/
 
1122
/**
692
1123
 * \brief Adjust the width and the height of the component to stay in the owner.
693
1124
 */
694
1125
void bear::gui::visual_component::stay_in_owner()
695
1126
{
696
1127
  if (m_owner)
697
1128
    {
698
 
      if ( m_box.position.x >= m_owner->width() )
699
 
        m_box.position.x = m_owner->width() - 1;
700
 
 
701
 
      if ( m_box.position.y >= m_owner->height() )
702
 
        m_box.position.y = m_owner->height() - 1;
703
 
 
704
 
      if ( m_box.right() >= m_owner->width() )
705
 
        m_box.width = m_owner->width() - m_box.position.x;
706
 
 
707
 
      if ( m_box.bottom() >= m_owner->height() )
708
 
        m_box.height = m_owner->height() - m_box.position.y;
 
1129
      coordinate_type n_left(m_box.left());
 
1130
      coordinate_type n_right(m_box.right());
 
1131
      coordinate_type n_bottom(m_box.bottom());
 
1132
      coordinate_type n_top(m_box.top());
 
1133
 
 
1134
      if ( n_left >= m_owner->width() )
 
1135
        n_left = m_owner->width();
 
1136
 
 
1137
      if ( n_bottom >= m_owner->height() )
 
1138
        n_bottom = m_owner->height();
 
1139
 
 
1140
      if ( n_right >= m_owner->width() )
 
1141
        n_right = m_owner->width();
 
1142
 
 
1143
      if ( n_top >= m_owner->height() )
 
1144
        n_top = m_owner->height();
 
1145
 
 
1146
      m_box.set( n_left, n_bottom, n_right, n_top );
709
1147
    }
710
1148
} // visual_component::stay_in_owner()
 
1149
 
 
1150
/*----------------------------------------------------------------------------*/
 
1151
/**
 
1152
 * \brief Set the focus on a given component.
 
1153
 * \param c The component on which the focus is set.
 
1154
 */
 
1155
void bear::gui::visual_component::set_focus( visual_component* c )
 
1156
{
 
1157
  int i(0);
 
1158
  bool stop(false);
 
1159
  m_focused_component = -1;
 
1160
 
 
1161
  for ( component_list::const_iterator it=m_components.begin();
 
1162
        !stop && (it != m_components.end()); ++it, ++i )
 
1163
    if ( *it == c )
 
1164
      {
 
1165
        m_focused_component = i;
 
1166
        stop = true;
 
1167
      }
 
1168
} // visual_component::set_focus()