@@ -34,11 +34,11 @@ CanvasUi::CanvasUi()
3434{
3535 // Set default hotkeys
3636 using namespace app ;
37- #if defined( CINDER_MSW )
37+ #if defined( CINDER_MSW ) || defined( CINDER_MAC )
3838 // On Windows, use ACCEL_DOWN (which maps to CTRL_DOWN)
3939 unsigned int modifier = KeyEvent::ACCEL_DOWN;
4040#else
41- // On Linux/Mac , use CTRL_DOWN directly for consistency with Windows behavior
41+ // On Linux, use CTRL_DOWN directly for consistency with Windows behavior
4242 unsigned int modifier = KeyEvent::CTRL_DOWN;
4343#endif
4444 mHotkeysZoomIn .emplace_back ( KeyEvent::KEY_PLUS, modifier );
@@ -51,6 +51,9 @@ CanvasUi::CanvasUi()
5151 mHotkeysReset .emplace_back ( KeyEvent::KEY_0, modifier );
5252 mHotkeysReset .emplace_back ( KeyEvent::KEY_KP0, modifier );
5353
54+ mHotkeysOneToOne .emplace_back ( KeyEvent::KEY_1, modifier );
55+ mHotkeysOneToOne .emplace_back ( KeyEvent::KEY_KP1, modifier );
56+
5457 // Set default pan mouse buttons: Alt+Left, Middle, or Right mouse
5558 mPanMouseButtons .emplace_back ( app::MouseEvent::LEFT_DOWN, app::MouseEvent::ALT_DOWN );
5659 mPanMouseButtons .emplace_back ( app::MouseEvent::MIDDLE_DOWN, 0 );
@@ -307,6 +310,20 @@ void CanvasUi::zoomOut( bool disableAnimation )
307310 }
308311}
309312
313+ void CanvasUi::viewOnetoOne ( bool disableAnimation )
314+ {
315+ vec2 centerViewport = mViewport .getSize () * 0 .5f ; // Center of viewport in viewport-local coordinates
316+
317+ // Calculate the zoom factor needed to reach 1.0
318+ float zoomFactor = 1 .0f / mZoom ;
319+
320+ if ( mAnimationEnabled && ! disableAnimation ) {
321+ startZoomAnimation ( zoomFactor, centerViewport );
322+ } else {
323+ zoomByStep ( zoomFactor, centerViewport );
324+ }
325+ }
326+
310327// Helper to set zoom and position with proper constraints
311328void CanvasUi::setZoomAndPosition ( float newZoom, const vec2& newPositionViewport )
312329{
@@ -633,6 +650,12 @@ void CanvasUi::keyDown( app::KeyEvent& event )
633650 else if ( matchesHotkey ( event, mHotkeysReset ) ) {
634651 if ( isBounded () )
635652 fitAll ();
653+ else
654+ viewOnetoOne ();
655+ event.setHandled ();
656+ }
657+ else if ( matchesHotkey ( event, mHotkeysOneToOne ) ) {
658+ viewOnetoOne ();
636659 event.setHandled ();
637660 }
638661}
@@ -777,6 +800,10 @@ void CanvasUi::setHotkeysReset( const std::vector<HotkeyBinding>& hotkeys )
777800 mHotkeysReset = hotkeys;
778801}
779802
803+ void CanvasUi::setHotkeysOneToOne ( const std::vector<HotkeyBinding>& hotkeys )
804+ {
805+ mHotkeysOneToOne = hotkeys;
806+ }
780807
781808bool CanvasUi::matchesHotkey ( const app::KeyEvent& event, const std::vector<HotkeyBinding>& hotkeys ) const
782809{
@@ -908,4 +935,4 @@ void CanvasUi::setAllowPanOutside( bool allow )
908935 mConstrainZoomToContent = false ;
909936}
910937
911- } // namespace cinder
938+ } // namespace cinder
0 commit comments