@@ -81,6 +81,9 @@ public bool snap
8181 private int m_offset_x = 0 ;
8282 private int m_offset_y = 0 ;
8383
84+ private float m_fl_offset_x = 0 ;
85+ private float m_fl_offset_y = 0 ;
86+
8487 private float m_scale = 2 ;
8588 private float m_CHR_size = 0 ; // current calculated CHR side size depending on a current m_scale
8689
@@ -135,6 +138,9 @@ public void reset()
135138 m_offset_x = m_scr_half_width ;
136139 m_offset_y = m_scr_half_height ;
137140
141+ m_fl_offset_x = ( float ) m_scr_half_width ;
142+ m_fl_offset_y = ( float ) m_scr_half_height ;
143+
138144 m_changed_pixel_x = - 1 ;
139145 m_changed_pixel_y = - 1 ;
140146
@@ -199,8 +205,11 @@ private void Layout_MouseMove(object sender, MouseEventArgs e)
199205 {
200206 if ( m_mode == EMode . m_build )
201207 {
202- m_offset_x += e . X - m_last_mouse_x ;
203- m_offset_y += e . Y - m_last_mouse_y ;
208+ m_fl_offset_x += ( e . X - m_last_mouse_x ) / m_scale ;
209+ m_fl_offset_y += ( e . Y - m_last_mouse_y ) / m_scale ;
210+
211+ m_offset_x = ( int ) m_fl_offset_x ;
212+ m_offset_y = ( int ) m_fl_offset_y ;
204213
205214 clamp_offsets ( ) ;
206215
@@ -360,17 +369,20 @@ private void clamp_offsets()
360369 {
361370 int ws_half_side_scaled = ( int ) ( utils . CONST_LAYOUT_WORKSPACE_HALF_SIDE * m_scale ) ;
362371
363- int width_border_val = transform_to_img_pos ( ws_half_side_scaled , m_scr_half_width , 0 ) ;
364- int height_border_val = transform_to_img_pos ( ws_half_side_scaled , m_scr_half_height , 0 ) ;
372+ float width_border_val = ( float ) transform_to_img_pos ( ws_half_side_scaled , m_scr_half_width , 0 ) ;
373+ float height_border_val = ( float ) transform_to_img_pos ( ws_half_side_scaled , m_scr_half_height , 0 ) ;
365374
366- int width_pbox_border_dt = m_pix_box . Width - width_border_val ;
367- int height_pbox_border_dt = m_pix_box . Height - height_border_val ;
375+ float width_pbox_border_dt = ( float ) m_pix_box . Width - width_border_val ;
376+ float height_pbox_border_dt = ( float ) m_pix_box . Height - height_border_val ;
368377
369- m_offset_x = m_offset_x > width_border_val ? width_border_val : m_offset_x ;
370- m_offset_x = m_offset_x < width_pbox_border_dt ? width_pbox_border_dt : m_offset_x ;
378+ m_fl_offset_x = m_fl_offset_x > width_border_val ? width_border_val : m_fl_offset_x ;
379+ m_fl_offset_x = m_fl_offset_x < width_pbox_border_dt ? width_pbox_border_dt : m_fl_offset_x ;
371380
372- m_offset_y = m_offset_y > height_border_val ? height_border_val : m_offset_y ;
373- m_offset_y = m_offset_y < height_pbox_border_dt ? height_pbox_border_dt : m_offset_y ;
381+ m_fl_offset_y = m_fl_offset_y > height_border_val ? height_border_val : m_fl_offset_y ;
382+ m_fl_offset_y = m_fl_offset_y < height_pbox_border_dt ? height_pbox_border_dt : m_fl_offset_y ;
383+
384+ m_offset_x = ( int ) m_fl_offset_x ;
385+ m_offset_y = ( int ) m_fl_offset_y ;
374386 }
375387
376388 private void check_and_update_pixel ( int _X , int _Y )
@@ -585,7 +597,7 @@ private void calc_CHR_size_and_draw_grid( bool _draw_grid )
585597 {
586598 if ( step < utils . CONST_CHR_SIDE_PIXELS_CNT )
587599 {
588- // highlight lines that are multiples of 8 by more brighter color
600+ // highlight lines that are multiple of 8 by more brighter color
589601 // to highlight CHRs aligned by sprite's offset.
590602 // draw the main grid by a more darker color
591603 if ( ( ( x_pos - spr_offs_x ) % utils . CONST_CHR_SIDE_PIXELS_CNT ) == 0 )
@@ -598,7 +610,10 @@ private void calc_CHR_size_and_draw_grid( bool _draw_grid )
598610 }
599611 }
600612
601- m_gfx . DrawLine ( m_pen , offs_x , 0 , offs_x , m_pix_box . Height ) ;
613+ if ( offs_x >= 0 && offs_x < m_pix_box . Width )
614+ {
615+ m_gfx . DrawLine ( m_pen , offs_x , 0 , offs_x , m_pix_box . Height ) ;
616+ }
602617 }
603618 else
604619 {
@@ -624,7 +639,7 @@ private void calc_CHR_size_and_draw_grid( bool _draw_grid )
624639
625640 if ( step < utils . CONST_CHR_SIDE_PIXELS_CNT )
626641 {
627- // highlight lines that are multiples of 8 by more brighter color
642+ // highlight lines that are multiple of 8 by more brighter color
628643 // to highlight CHRs aligned by sprite's offset.
629644 // draw the main grid by a more darker color
630645 if ( ( ( y_pos - spr_offs_y ) % utils . CONST_CHR_SIDE_PIXELS_CNT ) == 0 )
@@ -637,7 +652,10 @@ private void calc_CHR_size_and_draw_grid( bool _draw_grid )
637652 }
638653 }
639654
640- m_gfx . DrawLine ( m_pen , 0 , offs_y , m_pix_box . Height , offs_y ) ;
655+ if ( offs_y >= 0 && offs_y < m_pix_box . Height )
656+ {
657+ m_gfx . DrawLine ( m_pen , 0 , offs_y , m_pix_box . Width , offs_y ) ;
658+ }
641659 }
642660 }
643661 }
@@ -665,11 +683,14 @@ public void centering()
665683 rect . Height += utils . CONST_CHR_SIDE_PIXELS_CNT ;
666684 }
667685
668- int spr_center_x = rect . X + ( rect . Width >> 1 ) ;
669- int spr_center_y = rect . Y + ( rect . Height >> 1 ) ;
686+ float spr_center_x = ( float ) ( rect . X + ( rect . Width >> 1 ) ) ;
687+ float spr_center_y = ( float ) ( rect . Y + ( rect . Height >> 1 ) ) ;
688+
689+ m_fl_offset_x = ( float ) m_scr_half_width - spr_center_x ;
690+ m_fl_offset_y = ( float ) m_scr_half_height - spr_center_y ;
670691
671- m_offset_x = m_scr_half_width - spr_center_x ;
672- m_offset_y = m_scr_half_height - spr_center_y ;
692+ m_offset_x = ( int ) m_fl_offset_x ;
693+ m_offset_y = ( int ) m_fl_offset_y ;
673694
674695 update ( ) ;
675696 }
0 commit comments