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

« back to all changes in this revision

Viewing changes to bear-factory/model-editor/src/bf/code/model_view.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 - Editor library
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
57
57
 
58
58
 
59
59
 
60
 
const wxEventType bf::mark_event::selection_change_event_type = 
 
60
const wxEventType bf::mark_event::selection_change_event_type =
61
61
  wxNewEventType();
62
62
 
63
63
/*----------------------------------------------------------------------------*/
154
154
 * \param that The event to copy from.
155
155
 */
156
156
bf::placement_event::placement_event( const placement_event& that )
157
 
  : wxNotifyEvent(that), m_label(that.m_label), m_left(that.m_left), 
 
157
  : wxNotifyEvent(that), m_label(that.m_label), m_left(that.m_left),
158
158
    m_bottom(that.m_bottom)
159
159
{
160
160
 
241
241
 * \param that The event to copy from.
242
242
 */
243
243
bf::bounding_box_event::bounding_box_event( const bounding_box_event& that )
244
 
  : wxNotifyEvent(that), 
 
244
  : wxNotifyEvent(that),
245
245
    m_left(that.m_left), m_bottom(that.m_bottom),
246
246
    m_width(that.m_width), m_height(that.m_height),
247
247
    m_mark_move_x(that.m_mark_move_x), m_mark_move_y(that.m_mark_move_y)
359
359
/**
360
360
 * \brief Constructor.
361
361
 * \param parent The parent window.
 
362
 * \param id Identifier of the window.
362
363
 * \param m The model displayed.
363
364
 */
364
365
bf::model_view::model_view( wxWindow& parent, wxWindowID id, gui_model& m )
365
366
  : wxWindow(&parent, id), m_background_pattern( 20, 20 ),
366
367
    m_model(m), m_delta(0, 0), m_image_cache(new sprite_image_cache),
367
 
    m_zoom(100)
 
368
    m_zoom(100), m_wireframe_drawing(true)
368
369
{
369
370
  const wxColour dark_gray(127, 127, 127);
370
371
  const wxColour light_gray(192, 192, 192);
523
524
 
524
525
/*----------------------------------------------------------------------------*/
525
526
/**
 
527
 * \brief Toggle the value of the wiriframe drawing.
 
528
 */
 
529
void bf::model_view::toggle_wireframe_mode()
 
530
{
 
531
  m_wireframe_drawing = !m_wireframe_drawing;
 
532
  Refresh();
 
533
} // model_view::toggle_wireframe_mode()
 
534
 
 
535
/*----------------------------------------------------------------------------*/
 
536
/**
 
537
 * \brief Tell if the bounding box and the marks are drawn.
 
538
 */
 
539
bool bf::model_view::get_wireframe_drawing() const
 
540
{
 
541
  return m_wireframe_drawing;
 
542
} // model_view::get_wireframe_drawing()
 
543
 
 
544
/*----------------------------------------------------------------------------*/
 
545
/**
526
546
 * \brief Draw the sprite.
527
547
 */
528
548
void bf::model_view::render()
529
549
{
530
550
  compute_view_size();
531
 
  
 
551
 
532
552
  wxBufferedPaintDC dc( this );
533
553
 
534
554
  if( IsShown() )
543
563
 
544
564
          if ( s != NULL )
545
565
            {
546
 
              draw_marks(dc, *s);
547
 
              draw_bounding_box(dc, *s);
548
 
              draw_resized_bounding_box(dc, *s);
549
 
            }
 
566
              draw_marks(dc, *s);
 
567
              draw_bounding_box(dc, *s);
 
568
              draw_resized_bounding_box(dc, *s);
 
569
            }
550
570
          draw_view_box(dc);
551
571
        }
552
572
    }
595
615
  for ( std::size_t i=0; i!=m.size(); ++i )
596
616
    draw_mark_placement(dc, m[i]);
597
617
 
598
 
  if (  m_drag_info.drag_mode == drag_info::drag_mode_move ) 
 
618
  if (  m_drag_info.drag_mode == drag_info::drag_mode_move )
599
619
    {
600
 
      
 
620
 
601
621
      mark_placement p
602
 
        ( m_model.get_selected_snapshot
603
 
          ()->get_placement(m_drag_info.picked_mark->get_label()) );
604
 
      
 
622
        ( m_model.get_selected_snapshot
 
623
          ()->get_placement(m_drag_info.picked_mark->get_label()) );
 
624
 
605
625
      p.set_position_x(to_model_x_coordinate(m_drag_info.mouse_position.x));
606
626
      p.set_position_y(to_model_y_coordinate(m_drag_info.mouse_position.y));
607
627
 
631
651
void bf::model_view::draw_mark_placement_cross
632
652
( wxDC& dc, const mark_placement& m ) const
633
653
{
 
654
  if ( !m_wireframe_drawing )
 
655
    return;
 
656
 
634
657
  const wxPoint center
635
658
    ( to_local_x_coordinate(m.get_position_x()),
636
659
      to_local_y_coordinate(m.get_position_y()) );
696
719
/**
697
720
 * \brief Draw the bounding box of the action.
698
721
 * \param dc The device context for the drawings.
 
722
 * \param s The snapshot for which we draw the bounding box.
699
723
 */
700
724
void bf::model_view::draw_bounding_box( wxDC& dc, const snapshot& s ) const
701
725
{
 
726
  if ( !m_wireframe_drawing )
 
727
    return;
 
728
 
702
729
  const wxRect r
703
730
    ( to_local_rect
704
731
      ( 0, 0,  s.get_width(), s.get_height() ) );
715
742
/**
716
743
 * \brief Draw the bounding box of the action during a modification of size.
717
744
 * \param dc The device context for the drawings.
 
745
 * \param s The snapshot for which we draw the bounding box.
718
746
 */
719
747
void bf::model_view::draw_resized_bounding_box
720
748
( wxDC& dc, const snapshot& s ) const
721
749
{
722
 
  if ( m_drag_info.drag_mode == drag_info::drag_mode_size ) 
 
750
  if ( m_drag_info.drag_mode == drag_info::drag_mode_size )
723
751
    {
724
752
      wxRect r = get_drag_mode_size_box();
725
753
 
726
754
      const wxRect re
727
 
        ( to_local_x_coordinate(r.x), to_local_y_coordinate(r.y),
728
 
          to_local_size(r.width), to_local_size(r.height) );
729
 
      
 
755
        ( to_local_x_coordinate(r.x), to_local_y_coordinate(r.y),
 
756
          to_local_size(r.width), to_local_size(r.height) );
 
757
 
730
758
      dc.SetBrush( wxBrush(*wxBLACK, wxTRANSPARENT) );
731
759
      dc.SetPen( wxPen(*wxGREEN, 1, wxDOT) );
732
 
      
 
760
 
733
761
      dc.DrawRectangle(re);
734
762
    }
735
763
} // model_view::draw_bounding_box()
738
766
/**
739
767
 * \brief Draw the grip around the bounding box of the action.
740
768
 * \param dc The device context for the drawings.
 
769
 * \param s The snapshot for which we display the grips around the bounding box.
741
770
 */
742
771
void bf::model_view::draw_grip( wxDC& dc, const snapshot& s ) const
743
772
{
749
778
 
750
779
  dc.DrawRectangle
751
780
    ( to_local_rect
752
 
      ( s.get_width(), 
753
 
        s.get_height(), s_grip_size, s_grip_size ) );
754
 
 
755
 
  dc.DrawRectangle
756
 
    ( to_local_rect
757
 
      ( -s_grip_size, s.get_height(), 
758
 
        s_grip_size, s_grip_size ) );
759
 
 
760
 
  dc.DrawRectangle
761
 
    ( to_local_rect
762
 
      ( s.get_width(), -s_grip_size, 
763
 
        s_grip_size, s_grip_size ) );
764
 
  
 
781
      ( s.get_width(),
 
782
        s.get_height(), s_grip_size, s_grip_size ) );
 
783
 
 
784
  dc.DrawRectangle
 
785
    ( to_local_rect
 
786
      ( -s_grip_size, s.get_height(),
 
787
        s_grip_size, s_grip_size ) );
 
788
 
 
789
  dc.DrawRectangle
 
790
    ( to_local_rect
 
791
      ( s.get_width(), -s_grip_size,
 
792
        s_grip_size, s_grip_size ) );
 
793
 
765
794
  dc.DrawRectangle
766
795
    ( to_local_rect
767
796
      ( -s_grip_size, (s.get_height()-s_grip_size)/2,
768
 
        s_grip_size, s_grip_size ));
769
 
  
770
 
  dc.DrawRectangle
771
 
    ( to_local_rect
772
 
      ( (s.get_width()-s_grip_size)/2, 
773
 
        s.get_height(), s_grip_size, s_grip_size ) );
774
 
 
775
 
  dc.DrawRectangle
776
 
    ( to_local_rect
777
 
      ( (s.get_width()-s_grip_size)/2, -s_grip_size, 
778
 
        s_grip_size, s_grip_size ) );
779
 
 
780
 
  dc.DrawRectangle
781
 
    ( to_local_rect
782
 
      ( s.get_width(), 
783
 
        (s.get_height()-s_grip_size)/2,
784
 
        s_grip_size, s_grip_size ) );
 
797
        s_grip_size, s_grip_size ));
 
798
 
 
799
  dc.DrawRectangle
 
800
    ( to_local_rect
 
801
      ( (s.get_width()-s_grip_size)/2,
 
802
        s.get_height(), s_grip_size, s_grip_size ) );
 
803
 
 
804
  dc.DrawRectangle
 
805
    ( to_local_rect
 
806
      ( (s.get_width()-s_grip_size)/2, -s_grip_size,
 
807
        s_grip_size, s_grip_size ) );
 
808
 
 
809
  dc.DrawRectangle
 
810
    ( to_local_rect
 
811
      ( s.get_width(),
 
812
        (s.get_height()-s_grip_size)/2,
 
813
        s_grip_size, s_grip_size ) );
785
814
} // model_view::draw_grip()
786
815
 
787
816
/*----------------------------------------------------------------------------*/
817
846
  double max_x=0;
818
847
  double max_y=0;
819
848
 
820
 
  if ( m_model.has_active_action() ) 
 
849
  if ( m_model.has_active_action() )
821
850
    m_model.get_active_action().get_bounds(min_x, min_y, max_x, max_y);
822
851
 
823
852
  m_view_origin.set( min_x-5, min_y-5 );
862
891
 */
863
892
double bf::model_view::to_model_y_coordinate( double y ) const
864
893
{
865
 
  return m_view_size.y + m_view_origin.y 
 
894
  return m_view_size.y + m_view_origin.y
866
895
    - 100 * ( y + m_delta.y ) / (double)m_zoom;
867
896
} // model_view::to_model_y_coordinate()
868
897
 
946
975
 * \brief Check if a given position is in a anchor.
947
976
 * \param point The considered position.
948
977
 */
949
 
bool bf::model_view::coordinate_in_anchors(const wxPoint point) 
 
978
bool bf::model_view::coordinate_in_anchors(const wxPoint point)
950
979
{
951
980
  bool grip = true;
952
981
 
955
984
  const snapshot* snap =
956
985
    m_model.get_active_action().get_snapshot_before_or_at_date
957
986
    (m_player.get_date());
958
 
  
959
 
  if ( snap ) 
 
987
 
 
988
  if ( snap )
960
989
    {
961
990
      const wxRect box
962
 
        ( to_local_rect( 0, 0,  snap->get_width(), snap->get_height() ) );
 
991
        ( to_local_rect( 0, 0,  snap->get_width(), snap->get_height() ) );
963
992
      const wxSize s( grip_size, grip_size );
964
993
      wxPoint mouse_pos;
965
 
      
 
994
 
966
995
      const wxRect top_left( box.GetTopLeft() - s, s );
967
996
      const wxRect top_right( box.GetTopRight() - wxSize(0, grip_size), s );
968
997
      const wxRect bottom_left
969
 
        ( box.GetBottomLeft() - wxSize(grip_size, 0), s );
 
998
        ( box.GetBottomLeft() - wxSize(grip_size, 0), s );
970
999
      const wxRect bottom_right( box.GetBottomRight(), s );
971
 
      
 
1000
 
972
1001
      if ( top_left.Contains(point) )
973
 
        {
974
 
          m_drag_info.mouse_origin = box.GetBottomRight();
975
 
          mouse_pos = box.GetTopLeft();
976
 
          m_drag_info.mark_move_x = true;
977
 
        }
 
1002
        {
 
1003
          m_drag_info.mouse_origin = box.GetBottomRight();
 
1004
          mouse_pos = box.GetTopLeft();
 
1005
          m_drag_info.mark_move_x = true;
 
1006
        }
978
1007
      else if ( top_right.Contains(point) )
979
 
        {
980
 
          m_drag_info.mouse_origin = box.GetBottomLeft();
981
 
          mouse_pos = box.GetTopRight();
982
 
        }
 
1008
        {
 
1009
          m_drag_info.mouse_origin = box.GetBottomLeft();
 
1010
          mouse_pos = box.GetTopRight();
 
1011
        }
983
1012
      else if ( bottom_left.Contains(point) )
984
 
        {
985
 
          m_drag_info.mouse_origin = box.GetTopRight();
986
 
          mouse_pos = box.GetBottomLeft();
987
 
          m_drag_info.mark_move_x = true;
988
 
          m_drag_info.mark_move_y = true;
989
 
        }
 
1013
        {
 
1014
          m_drag_info.mouse_origin = box.GetTopRight();
 
1015
          mouse_pos = box.GetBottomLeft();
 
1016
          m_drag_info.mark_move_x = true;
 
1017
          m_drag_info.mark_move_y = true;
 
1018
        }
990
1019
      else if ( bottom_right.Contains(point) )
991
 
        {
992
 
          m_drag_info.mouse_origin = box.GetTopLeft();
993
 
          mouse_pos = box.GetBottomRight();
994
 
          m_drag_info.mark_move_y = true;
995
 
        }
 
1020
        {
 
1021
          m_drag_info.mouse_origin = box.GetTopLeft();
 
1022
          mouse_pos = box.GetBottomRight();
 
1023
          m_drag_info.mark_move_y = true;
 
1024
        }
996
1025
      else
997
 
        {
998
 
          const wxCoord h((wxCoord)to_local_size(snap->get_height())/ 2);
999
 
          const wxCoord w((wxCoord)to_local_size(snap->get_width())/ 2);
1000
 
          const wxRect middle_left
1001
 
            ( box.GetLeft() - grip_size,
1002
 
              box.GetTop() + h - grip_size / 2, grip_size, grip_size );
1003
 
          const wxRect middle_right
1004
 
            ( box.GetRight(), box.GetTop() + h - grip_size / 2,
1005
 
              grip_size, grip_size );
1006
 
          const wxRect middle_bottom
1007
 
            ( box.GetLeft() + w - grip_size / 2,
1008
 
              box.GetTop() - grip_size, grip_size, grip_size );
1009
 
          const wxRect middle_top
1010
 
            ( box.GetLeft() + w - grip_size / 2,
1011
 
              box.GetBottom(), grip_size, grip_size );
1012
 
          
1013
 
          if ( middle_left.Contains(point) )
1014
 
            {
1015
 
              m_drag_info.mouse_origin = box.GetTopRight();
1016
 
              mouse_pos = box.GetTopLeft();
1017
 
              m_drag_info.y_active = false;
1018
 
              m_drag_info.mark_move_x = true;
1019
 
            }
1020
 
          else if ( middle_right.Contains(point) )
1021
 
            {
1022
 
              m_drag_info.mouse_origin = box.GetTopLeft();
1023
 
              mouse_pos = box.GetTopRight();
1024
 
              m_drag_info.y_active = false;
1025
 
            }
1026
 
          else if ( middle_bottom.Contains(point) )
1027
 
            {
1028
 
              m_drag_info.mouse_origin = box.GetBottomLeft();
1029
 
              mouse_pos = box.GetTopLeft();
1030
 
              m_drag_info.x_active = false;
1031
 
            }
1032
 
          else if ( middle_top.Contains(point) )
1033
 
            {
1034
 
              m_drag_info.mouse_origin = box.GetTopLeft();
1035
 
              mouse_pos = box.GetBottomRight();
1036
 
              m_drag_info.x_active = false;
1037
 
              m_drag_info.mark_move_y = true;
1038
 
            }
1039
 
          else
1040
 
            grip = false;
1041
 
        }
1042
 
      
 
1026
        {
 
1027
          const wxCoord h((wxCoord)to_local_size(snap->get_height())/ 2);
 
1028
          const wxCoord w((wxCoord)to_local_size(snap->get_width())/ 2);
 
1029
          const wxRect middle_left
 
1030
            ( box.GetLeft() - grip_size,
 
1031
              box.GetTop() + h - grip_size / 2, grip_size, grip_size );
 
1032
          const wxRect middle_right
 
1033
            ( box.GetRight(), box.GetTop() + h - grip_size / 2,
 
1034
              grip_size, grip_size );
 
1035
          const wxRect middle_bottom
 
1036
            ( box.GetLeft() + w - grip_size / 2,
 
1037
              box.GetTop() - grip_size, grip_size, grip_size );
 
1038
          const wxRect middle_top
 
1039
            ( box.GetLeft() + w - grip_size / 2,
 
1040
              box.GetBottom(), grip_size, grip_size );
 
1041
 
 
1042
          if ( middle_left.Contains(point) )
 
1043
            {
 
1044
              m_drag_info.mouse_origin = box.GetTopRight();
 
1045
              mouse_pos = box.GetTopLeft();
 
1046
              m_drag_info.y_active = false;
 
1047
              m_drag_info.mark_move_x = true;
 
1048
            }
 
1049
          else if ( middle_right.Contains(point) )
 
1050
            {
 
1051
              m_drag_info.mouse_origin = box.GetTopLeft();
 
1052
              mouse_pos = box.GetTopRight();
 
1053
              m_drag_info.y_active = false;
 
1054
            }
 
1055
          else if ( middle_bottom.Contains(point) )
 
1056
            {
 
1057
              m_drag_info.mouse_origin = box.GetBottomLeft();
 
1058
              mouse_pos = box.GetTopLeft();
 
1059
              m_drag_info.x_active = false;
 
1060
            }
 
1061
          else if ( middle_top.Contains(point) )
 
1062
            {
 
1063
              m_drag_info.mouse_origin = box.GetTopLeft();
 
1064
              mouse_pos = box.GetBottomRight();
 
1065
              m_drag_info.x_active = false;
 
1066
              m_drag_info.mark_move_y = true;
 
1067
            }
 
1068
          else
 
1069
            grip = false;
 
1070
        }
 
1071
 
1043
1072
      if ( grip )
1044
 
        {
1045
 
          m_drag_info.drag_mode = drag_info::drag_mode_size;
1046
 
          m_drag_info.mouse_position = mouse_pos;
1047
 
        }
 
1073
        {
 
1074
          m_drag_info.drag_mode = drag_info::drag_mode_size;
 
1075
          m_drag_info.mouse_position = mouse_pos;
 
1076
        }
1048
1077
    }
1049
 
   
 
1078
 
1050
1079
  return grip;
1051
1080
} // model_view::coordinate_in_anchors()
1052
1081
 
1053
1082
/*----------------------------------------------------------------------------*/
1054
1083
/**
1055
1084
 * \brief Update the position of the mouse according to the constraints.
1056
 
 * \param mouse_position The position of the mouse in the level.
 
1085
 * \param position The position of the mouse in the model.
1057
1086
 */
1058
1087
void bf::model_view::update_mouse_position( const wxPoint& position )
1059
1088
{
1076
1105
  if ( m_model.has_active_action() )
1077
1106
    {
1078
1107
      const snapshot* s =
1079
 
        m_model.get_active_action().get_snapshot_before_or_at_date
1080
 
        (m_player.get_date());
 
1108
        m_model.get_active_action().get_snapshot_before_or_at_date
 
1109
        (m_player.get_date());
1081
1110
 
1082
1111
       snapshot::const_mark_placement_iterator it;
1083
1112
 
1084
 
       for ( it = s->mark_placement_begin(); 
1085
 
             ( it!= s->mark_placement_end() ) && ( result == NULL ); ++it )
1086
 
         if ( ( (double)point.x <= to_local_x_coordinate(it->get_position_x())
1087
 
                + (double)s_point_size ) &&
1088
 
              ( (double)point.x >= to_local_x_coordinate(it->get_position_x())
1089
 
                - (double)s_point_size ) &&
1090
 
              ( (double)point.y <= to_local_y_coordinate(it->get_position_y())
1091
 
                + (double)s_point_size ) &&
1092
 
              ( (double)point.y >= to_local_y_coordinate(it->get_position_y())
1093
 
                - (double)s_point_size ) )
1094
 
           result = it->get_mark();
 
1113
       for ( it = s->mark_placement_begin();
 
1114
             ( it!= s->mark_placement_end() ) && ( result == NULL ); ++it )
 
1115
         if ( ( (double)point.x <= to_local_x_coordinate(it->get_position_x())
 
1116
                + (double)s_point_size ) &&
 
1117
              ( (double)point.x >= to_local_x_coordinate(it->get_position_x())
 
1118
                - (double)s_point_size ) &&
 
1119
              ( (double)point.y <= to_local_y_coordinate(it->get_position_y())
 
1120
                + (double)s_point_size ) &&
 
1121
              ( (double)point.y >= to_local_y_coordinate(it->get_position_y())
 
1122
                - (double)s_point_size ) )
 
1123
           result = it->get_mark();
1095
1124
    }
1096
1125
 
1097
1126
  return result;
1107
1136
  if ( m_model.has_active_action() && m_drag_info.picked_mark )
1108
1137
    {
1109
1138
      placement_event event
1110
 
        ( m_drag_info.picked_mark->get_label(), 
1111
 
          to_model_x_coordinate(point.x),
1112
 
          to_model_y_coordinate(point.y),
1113
 
          placement_event::move_event_type, GetId() );
 
1139
        ( m_drag_info.picked_mark->get_label(),
 
1140
          to_model_x_coordinate(point.x),
 
1141
          to_model_y_coordinate(point.y),
 
1142
          placement_event::move_event_type, GetId() );
1114
1143
      event.SetEventObject(this);
1115
1144
      ProcessEvent(event);
1116
1145
    }
1123
1152
wxRect bf::model_view::get_drag_mode_size_box() const
1124
1153
{
1125
1154
  CLAW_PRECOND( m_drag_info.drag_mode == drag_info::drag_mode_size );
1126
 
  
 
1155
 
1127
1156
  wxRect result;
1128
1157
 
1129
1158
  const snapshot* snap =
1130
1159
    m_model.get_active_action().get_snapshot_before_or_at_date
1131
1160
    (m_player.get_date());
1132
 
  
1133
 
  if ( snap ) 
 
1161
 
 
1162
  if ( snap )
1134
1163
    {
1135
1164
      if ( m_drag_info.x_active )
1136
 
        {
1137
 
          result.x =
1138
 
            to_model_x_coordinate
1139
 
            ( std::min( m_drag_info.mouse_position.x, 
1140
 
                        m_drag_info.mouse_origin.x ));
1141
 
          result.width =
1142
 
            to_model_size
1143
 
            ( std::abs( m_drag_info.mouse_position.x - 
1144
 
                        m_drag_info.mouse_origin.x ) + 1 );
1145
 
        }
 
1165
        {
 
1166
          result.x =
 
1167
            to_model_x_coordinate
 
1168
            ( std::min( m_drag_info.mouse_position.x,
 
1169
                        m_drag_info.mouse_origin.x ));
 
1170
          result.width =
 
1171
            to_model_size
 
1172
            ( std::abs( m_drag_info.mouse_position.x -
 
1173
                        m_drag_info.mouse_origin.x ) + 1 );
 
1174
        }
1146
1175
      else
1147
 
        {
1148
 
          result.x = to_model_x_coordinate(m_drag_info.mouse_origin.x);
1149
 
          result.width = (int)snap->get_width();
1150
 
        }
1151
 
      
 
1176
        {
 
1177
          result.x = to_model_x_coordinate(m_drag_info.mouse_origin.x);
 
1178
          result.width = (int)snap->get_width();
 
1179
        }
 
1180
 
1152
1181
      if ( m_drag_info.y_active )
1153
 
        {
1154
 
          result.y = 
1155
 
            to_model_y_coordinate
1156
 
            ( std::min( m_drag_info.mouse_position.y, 
1157
 
                        m_drag_info.mouse_origin.y ) );
1158
 
          result.height = 
1159
 
            to_model_size
1160
 
            ( std::abs( m_drag_info.mouse_position.y - 
1161
 
                        m_drag_info.mouse_origin.y ) + 1);
1162
 
        }
 
1182
        {
 
1183
          result.y =
 
1184
            to_model_y_coordinate
 
1185
            ( std::min( m_drag_info.mouse_position.y,
 
1186
                        m_drag_info.mouse_origin.y ) );
 
1187
          result.height =
 
1188
            to_model_size
 
1189
            ( std::abs( m_drag_info.mouse_position.y -
 
1190
                        m_drag_info.mouse_origin.y ) + 1);
 
1191
        }
1163
1192
      else
1164
 
        {
1165
 
          result.y = to_model_y_coordinate(m_drag_info.mouse_origin.y);
1166
 
          result.height = snap->get_height();
1167
 
        }
 
1193
        {
 
1194
          result.y = to_model_y_coordinate(m_drag_info.mouse_origin.y);
 
1195
          result.height = snap->get_height();
 
1196
        }
1168
1197
    }
1169
1198
 
1170
1199
  return result;
1177
1206
void bf::model_view::apply_drag_mode_size()
1178
1207
{
1179
1208
  CLAW_PRECOND( m_drag_info.drag_mode == drag_info::drag_mode_size );
1180
 
  
 
1209
 
1181
1210
  wxRect box = get_drag_mode_size_box();
1182
1211
 
1183
1212
   const snapshot* snap =
1184
1213
    m_model.get_active_action().get_snapshot_before_or_at_date
1185
1214
    (m_player.get_date());
1186
 
  
1187
 
  if ( snap ) 
 
1215
 
 
1216
  if ( snap )
1188
1217
    {
1189
1218
      if ( (box.x != 0)
1190
 
           || (box.y != 0)
1191
 
           || (box.width != snap->get_width())
1192
 
           || (box.height != snap->get_height()) )
1193
 
        {
1194
 
          bounding_box_event event
1195
 
            ( box.x, box.y, box.width, box.height, 
1196
 
              m_drag_info.mark_move_x, m_drag_info.mark_move_y,
1197
 
              bounding_box_event::change_event_type, GetId() );
1198
 
          event.SetEventObject(this);
1199
 
          ProcessEvent(event);
1200
 
        }
 
1219
           || (box.y != 0)
 
1220
           || (box.width != snap->get_width())
 
1221
           || (box.height != snap->get_height()) )
 
1222
        {
 
1223
          bounding_box_event event
 
1224
            ( box.x, box.y, box.width, box.height,
 
1225
              m_drag_info.mark_move_x, m_drag_info.mark_move_y,
 
1226
              bounding_box_event::change_event_type, GetId() );
 
1227
          event.SetEventObject(this);
 
1228
          ProcessEvent(event);
 
1229
        }
1201
1230
    }
1202
1231
} // model_view::apply_drag_mode_size()
1203
1232
 
1204
1233
/*----------------------------------------------------------------------------*/
1205
1234
/**
1206
1235
 * \brief Send the event "selection_change".
1207
 
 * \param value The name of the new selected mark.
 
1236
 * \param label The name of the new selected mark.
1208
1237
 */
1209
 
void bf::model_view::send_event_selection_change(const std::string& label) 
 
1238
void bf::model_view::send_event_selection_change(const std::string& label)
1210
1239
{
1211
1240
  mark_event event
1212
1241
    ( label, mark_event::selection_change_event_type, GetId() );
1219
1248
 * \brief Draw the content of the window.
1220
1249
 * \param event The paint event.
1221
1250
 */
1222
 
void bf::model_view::on_paint(wxPaintEvent& event)
 
1251
void bf::model_view::on_paint( wxPaintEvent& WXUNUSED(event) )
1223
1252
{
1224
1253
  render();
1225
1254
} // model_view::on_paint()
1235
1264
    {
1236
1265
      if ( event.LeftIsDown() )
1237
1266
        {
1238
 
          update_mouse_position(event.GetPosition());
 
1267
          update_mouse_position(event.GetPosition());
1239
1268
 
1240
 
          if ( (m_drag_info.drag_mode == drag_info::drag_mode_pick) &&
1241
 
               ( ( std::abs(event.GetPosition().x - 
1242
 
                            m_drag_info.mouse_origin.x) >= 10 )
1243
 
                 || ( std::abs(event.GetPosition().y - 
1244
 
                               m_drag_info.mouse_origin.y) >= 10 ) ) )
1245
 
               m_drag_info.drag_mode = drag_info::drag_mode_move;
 
1269
          if ( (m_drag_info.drag_mode == drag_info::drag_mode_pick) &&
 
1270
               ( ( std::abs(event.GetPosition().x -
 
1271
                            m_drag_info.mouse_origin.x) >= 10 )
 
1272
                 || ( std::abs(event.GetPosition().y -
 
1273
                               m_drag_info.mouse_origin.y) >= 10 ) ) )
 
1274
               m_drag_info.drag_mode = drag_info::drag_mode_move;
1246
1275
        }
1247
 
      else 
 
1276
      else
1248
1277
        m_drag_info.clear();
1249
1278
 
1250
1279
      Refresh();
1258
1287
 */
1259
1288
void bf::model_view::on_left_down( wxMouseEvent& event )
1260
1289
{
 
1290
  if ( !m_model.has_active_action() )
 
1291
    return;
 
1292
 
1261
1293
  const mark* m = find_mark_at( event.GetPosition() );
1262
1294
  m_drag_info.clear();
1263
1295
  m_drag_info.mouse_origin = event.GetPosition();
1285
1317
  switch ( m_drag_info.drag_mode )
1286
1318
    {
1287
1319
    case drag_info::drag_mode_pick:
1288
 
      if ( m_drag_info.picked_mark != NULL ) 
1289
 
        send_event_selection_change(m_drag_info.picked_mark->get_label());
 
1320
      if ( m_drag_info.picked_mark != NULL )
 
1321
        send_event_selection_change(m_drag_info.picked_mark->get_label());
1290
1322
      break;
1291
1323
    case drag_info::drag_mode_move:
1292
 
      if ( m_drag_info.picked_mark != NULL ) 
1293
 
        move_mark(event.GetPosition());
 
1324
      if ( m_drag_info.picked_mark != NULL )
 
1325
        move_mark(event.GetPosition());
1294
1326
      break;
1295
1327
    case drag_info::drag_mode_size:
1296
1328
      apply_drag_mode_size();
1297
1329
      break;
1298
1330
    default:
1299
 
        break;
 
1331
        break;
1300
1332
    }
1301
1333
 
1302
1334
  m_drag_info.clear();