~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-factory/bear-editor/src/bf/code/slider_ctrl.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 - Model editor
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
29
29
#include "bf/slider_ctrl.hpp"
30
30
 
31
31
#include <wx/dcbuffer.h>
 
32
#include <wx/settings.h>
32
33
 
33
34
const unsigned int bf::slider_ctrl::s_slider_border = 8;
34
35
 
35
 
const wxEventType bf::slider_event::value_change_event_type = 
 
36
const wxEventType bf::slider_event::value_change_event_type =
36
37
  wxNewEventType();
37
38
 
38
39
const wxEventType bf::tick_event::move_event_type = wxNewEventType();
112
113
 * \brief Constructor.
113
114
 * \param initial_value The initial value of the tick.
114
115
 * \param new_value The new value of the tick.
 
116
 * \param copy Tell if the user asks to copy the data associated with the
 
117
 *        previous position (?).
115
118
 * \param t The type of the event.
116
119
 * \param id The id of the window that generates the event.
117
120
 */
118
121
bf::tick_event::tick_event
119
 
( double initial_value, double new_value, bool copy, 
 
122
( double initial_value, double new_value, bool copy,
120
123
  wxEventType t, wxWindowID id )
121
 
  : wxNotifyEvent(t, id), 
 
124
  : wxNotifyEvent(t, id),
122
125
    m_initial_value(initial_value), m_new_value(new_value), m_copy(copy)
123
126
{
124
127
 
132
135
bf::tick_event::tick_event( const tick_event& that )
133
136
  : wxNotifyEvent(that), m_initial_value(that.m_initial_value),
134
137
    m_new_value(that.m_new_value), m_copy(that.m_copy)
135
 
 
138
{
136
139
} // tick_event::tick_event()
137
140
 
138
141
/*----------------------------------------------------------------------------*/
204
207
 * \param max_value The maximum value of the slider.
205
208
 */
206
209
bf::slider_ctrl::slider_ctrl
207
 
( wxWindow* parent, wxWindowID id, double value, double min_value, 
 
210
( wxWindow* parent, wxWindowID id, double value, double min_value,
208
211
  double max_value )
209
212
  : super( parent, id ), m_drag_info(NULL),
210
213
    m_value(value), m_min_value(min_value), m_max_value(max_value),
262
265
 */
263
266
void bf::slider_ctrl::set_value( double value )
264
267
{
265
 
  if ( m_value != value) 
 
268
  if ( m_value != value)
266
269
    {
267
 
      m_value = value;      
 
270
      m_value = value;
268
271
      render();
269
272
    }
270
273
} // slider_ctrl::set_value()
281
284
  if ( m_value > m_max_value )
282
285
    m_value = m_max_value;
283
286
 
284
 
  render(); 
 
287
  render();
285
288
} // slider_ctrl::set_value()
286
289
 
287
290
/*----------------------------------------------------------------------------*/
292
295
bool bf::slider_ctrl::has_tick( double value ) const
293
296
{
294
297
  bool result = false;
295
 
  
 
298
 
296
299
  ticks::const_iterator it;
297
 
  for ( it = m_ticks->begin(); ( it != m_ticks->end() ) && ! result; ++it) 
298
 
    if ( *it == value ) 
 
300
  for ( it = m_ticks->begin(); ( it != m_ticks->end() ) && !result; ++it)
 
301
    if ( *it == value )
299
302
      result = true;
300
 
  
 
303
 
301
304
  return result;
302
305
} // slider_ctrl::has_tick()
303
306
 
305
308
/**
306
309
 * \brief Send the event "value_change".
307
310
 */
308
 
void bf::slider_ctrl::send_event_change_value() 
 
311
void bf::slider_ctrl::send_event_change_value()
309
312
{
310
313
  slider_event event
311
314
    ( m_value, slider_event::value_change_event_type, GetId() );
321
324
 * \param copy Indicates if the move is a copy.
322
325
 */
323
326
void bf::slider_ctrl::send_event_move_tick
324
 
(double initial_value, double new_value, bool copy) 
 
327
(double initial_value, double new_value, bool copy)
325
328
{
326
329
  tick_event event
327
330
    ( initial_value, new_value, copy, tick_event::move_event_type, GetId() );
328
331
  event.SetEventObject(this);
329
332
  ProcessEvent(event);
330
333
 
331
 
  if ( ! event.IsAllowed() ) 
 
334
  if ( !event.IsAllowed() )
332
335
    {
333
336
      set_value(m_drag_info->initial_value);
334
337
      send_event_change_value();
359
362
  dc.DrawLine( s_slider_border, GetSize().y / 2 - 2,
360
363
               GetSize().x - s_slider_border, GetSize().y / 2 - 2 );
361
364
 
362
 
  dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));  
 
365
  dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
363
366
  dc.SetBrush(*wxTRANSPARENT_BRUSH);
364
367
  dc.DrawRoundedRectangle( 1, 1, GetSize().x - 2, GetSize().y - 2, 3 );
365
368
} // slider_ctrl::render_slider()
372
375
void bf::slider_ctrl::render_value( wxDC& dc ) const
373
376
{
374
377
  wxPoint pos(get_position(m_value),GetSize().y / 2);
375
 
    
 
378
 
376
379
  dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
377
380
  dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
378
381
  wxPoint p3[5];
387
390
  wxPoint p[4];
388
391
  p[0] = wxPoint( pos.x, pos.y + 3 );
389
392
  p[1] = wxPoint( pos.x - 3, pos.y );
390
 
  p[2] = wxPoint( pos.x - 3, pos.y - 8 );  
 
393
  p[2] = wxPoint( pos.x - 3, pos.y - 8 );
391
394
  p[3] = wxPoint( pos.x + 3, pos.y - 8 );
392
395
  dc.DrawLines(4, p);
393
396
} // slider_ctrl::render_value()
403
406
    if ( m_drag_info->drag_mode == drag_info::drag_mode_tick_move )
404
407
      {
405
408
        double v = get_value(m_drag_info->mouse_position.x);
406
 
        
407
 
        if ( has_tick(v) ) 
 
409
 
 
410
        if ( has_tick(v) )
408
411
          {
409
412
            render_tick( dc, get_position(m_drag_info->initial_value),
410
413
                         *wxRED, *wxTRANSPARENT_BRUSH);
429
432
  if ( m_ticks )
430
433
    {
431
434
      ticks::const_iterator it;
432
 
      
 
435
 
433
436
      for (it = m_ticks->begin(); it != m_ticks->end(); ++it )
434
437
        render_tick(dc,*it);
435
438
    }
443
446
 */
444
447
void bf::slider_ctrl::render_tick( wxDC& dc, tick t ) const
445
448
{
446
 
  if ( t == m_value ) 
 
449
  if ( t == m_value )
447
450
    {
448
451
      wxBrush brush(*wxBLACK);
449
452
      render_tick( dc, get_position(t), *wxBLACK, brush);
461
464
 * \param brush The brush.
462
465
 */
463
466
void bf::slider_ctrl::render_tick
464
 
( wxDC& dc, unsigned int position, const wxColour& colour, 
 
467
( wxDC& dc, unsigned int position, const wxColour& colour,
465
468
  const wxBrush& brush ) const
466
469
{
467
470
  wxPen pen(colour);
470
473
 
471
474
  wxPoint p[3];
472
475
  wxPoint pos(position,GetSize().y / 2);
473
 
  
 
476
 
474
477
  p[0] = wxPoint( pos.x, pos.y+5 );
475
478
  p[1] = wxPoint( pos.x+4, pos.y +9 );
476
479
  p[2] = wxPoint( pos.x-4, pos.y +9 );
487
490
{
488
491
  double result;
489
492
 
490
 
  if ( pos < (int)(s_slider_border)) 
 
493
  if ( pos < (int)(s_slider_border))
491
494
    result = 0;
492
 
  else if ( pos > (int)(s_slider_border + get_slider_width()) ) 
 
495
  else if ( pos > (int)(s_slider_border + get_slider_width()) )
493
496
    result = m_max_value;
494
497
  else
495
498
    {
496
 
      pos = pos - s_slider_border;
497
 
      
498
 
      result = 
499
 
        ( (double)pos * ( m_max_value - m_min_value ) ) / 
 
499
      pos -= s_slider_border;
 
500
 
 
501
      result =
 
502
        ( (double)pos * ( m_max_value - m_min_value ) ) /
500
503
        (double)get_slider_width() + m_min_value;
501
 
      
 
504
 
502
505
      if ( result < m_min_value )
503
506
        result = m_min_value;
504
 
      
 
507
 
505
508
      if ( result > m_max_value )
506
509
        result = m_max_value;
507
510
    }
508
511
 
509
512
  result = (double)((int)((result+0.0005) * 1000)) / 1000;
510
 
  
 
513
 
511
514
  return result;
512
515
} // slider_ctrl::get_value()
513
516
 
519
522
unsigned int bf::slider_ctrl::get_position( double value ) const
520
523
{
521
524
  return  s_slider_border + (unsigned int)
522
 
    ( ( ( value - m_min_value ) * (double)(get_slider_width() ) ) / 
 
525
    ( ( ( value - m_min_value ) * (double)(get_slider_width() ) ) /
523
526
      ( m_max_value - m_min_value ) );
524
527
} // slider_ctrl::get_position()
525
528
 
533
536
  double result = v;
534
537
  double min_dist = m_max_value + 1;
535
538
 
536
 
  if ( m_ticks ) 
 
539
  if ( m_ticks )
537
540
    {
538
541
      slider_ctrl::ticks::const_iterator it;
539
 
      
 
542
 
540
543
      for (it = m_ticks->begin(); it != m_ticks->end(); ++it )
541
544
        {
542
545
          double dist;
543
 
          if ( *it > v ) 
 
546
          if ( *it > v )
544
547
            dist = *it - v;
545
548
          else
546
549
            dist = v - *it;
547
 
          
 
550
 
548
551
          if ( dist < min_dist )
549
552
            {
550
553
              result = *it;
552
555
            }
553
556
        }
554
557
    }
555
 
  
 
558
 
556
559
  return result;
557
560
} // slider_ctrl::nearest_tick()
558
561
 
600
603
 * \brief Event sent to a resized window.
601
604
 * \param event The event.
602
605
 */
603
 
void bf::slider_ctrl::on_size(wxSizeEvent& event)
 
606
void bf::slider_ctrl::on_size( wxSizeEvent& WXUNUSED(event) )
604
607
{
605
608
  Refresh();
606
609
} // slider_ctrl::on_size()
610
613
 * \brief Draw the content of the window.
611
614
 * \param event The paint event.
612
615
 */
613
 
void bf::slider_ctrl::on_paint(wxPaintEvent& event)
 
616
void bf::slider_ctrl::on_paint( wxPaintEvent& WXUNUSED(event) )
614
617
{
615
618
  render();
616
619
} // slider_ctrl::on_paint()
620
623
 * \brief The user start a click in the frame.
621
624
 * \param event The mouse event that occured.
622
625
 */
623
 
void bf::slider_ctrl::on_mouse_left_down(wxMouseEvent& event)
 
626
void bf::slider_ctrl::on_mouse_left_down( wxMouseEvent& event )
624
627
{
625
628
  wxPoint point( event.GetX(), event.GetY() );
626
629
 
627
 
  if ( event.ControlDown() ) 
 
630
  if ( event.ControlDown() )
628
631
    {
629
632
      double v = get_value(point.x);
630
633
      v = nearest_tick(v);
631
 
      
 
634
 
632
635
      if ( has_tick(v) )
633
636
        {
634
637
          m_drag_info = new drag_info();
635
 
          m_drag_info->drag_mode = drag_info::drag_mode_tick_move;          
 
638
          m_drag_info->drag_mode = drag_info::drag_mode_tick_move;
636
639
          m_drag_info->initial_value = v;
637
640
          m_drag_info->mouse_origin = point;
638
641
          m_drag_info->mouse_position = m_drag_info->mouse_origin;
643
646
      m_drag_info = new drag_info();
644
647
      m_drag_info->drag_mode = drag_info::drag_mode_move;
645
648
      m_drag_info->mouse_origin = point;
646
 
      m_drag_info->mouse_position = m_drag_info->mouse_origin;      
 
649
      m_drag_info->mouse_position = m_drag_info->mouse_origin;
647
650
    }
648
651
} // slider_ctrl::on_mouse_left_down()
649
652
 
652
655
 * \brief The user clicked in the frame.
653
656
 * \param event The mouse event that occured.
654
657
 */
655
 
void bf::slider_ctrl::on_mouse_move(wxMouseEvent& event)
 
658
void bf::slider_ctrl::on_mouse_move( wxMouseEvent& event )
656
659
{
657
660
  const wxPoint point( event.GetX(),event.GetY() );
658
 
  
659
 
  if ( event.LeftIsDown() )    
 
661
 
 
662
  if ( event.LeftIsDown() )
660
663
    if ( m_drag_info != NULL )
661
664
      {
662
665
        m_drag_info->mouse_position = point;
663
666
        double v = get_value(point.x);
664
 
        
665
 
        if ( m_drag_info->drag_mode == drag_info::drag_mode_move ) 
 
667
 
 
668
        if ( m_drag_info->drag_mode == drag_info::drag_mode_move )
666
669
          {
667
670
            if ( event.ShiftDown() )
668
671
              v = nearest_tick(v);
669
672
          }
670
 
        
 
673
 
671
674
        if ( v != m_value )
672
675
          {
673
676
            set_value(v);
681
684
 * \brief The user click in the frame.
682
685
 * \param event The mouse event that occured.
683
686
 */
684
 
void bf::slider_ctrl::on_mouse_left_up(wxMouseEvent& event)
 
687
void bf::slider_ctrl::on_mouse_left_up( wxMouseEvent& event )
685
688
{
686
689
  const wxPoint point( event.GetX(),event.GetY() );
687
 
  
 
690
 
688
691
  if ( m_drag_info == NULL )
689
692
    event.Skip();
690
693
  else
691
694
    {
692
695
      m_drag_info->mouse_position = point;
693
 
      if ( m_drag_info->drag_mode == drag_info::drag_mode_tick_move ) 
 
696
      if ( m_drag_info->drag_mode == drag_info::drag_mode_tick_move )
694
697
        {
695
698
          apply_drag_mode_tick_move
696
 
            ( event.ControlDown(), event.AltDown() );
 
699
            ( event.ControlDown(), event.AltDown() );
697
700
          delete m_drag_info;
698
701
          m_drag_info = NULL;
699
702
          render();
700
703
        }
701
 
      else if ( m_drag_info->drag_mode == drag_info::drag_mode_move ) 
 
704
      else if ( m_drag_info->drag_mode == drag_info::drag_mode_move )
702
705
        apply_drag_mode_move( event.ShiftDown() );
703
 
      
 
706
 
704
707
      if ( m_drag_info != NULL )
705
708
        {
706
709
          m_drag_info = NULL;
714
717
 * \brief The user double click in the frame.
715
718
 * \param event The mouse event that occured.
716
719
 */
717
 
void bf::slider_ctrl::on_mouse_left_dclick(wxMouseEvent& event)
 
720
void bf::slider_ctrl::on_mouse_left_dclick( wxMouseEvent& event )
718
721
{
719
722
  double v = get_value(event.GetX());
720
723