mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:42:44 +00:00 
			
		
		
		
	Magnifier: Add 8x magnification and pausing
This adds an option for even more magnification, when you really need to count pixels, as well as pausing the capture by pressing Space and switching between magnification levels with keys 2, 4 & 8.
This commit is contained in:
		
							parent
							
								
									6bdd62b51b
								
							
						
					
					
						commit
						401ea85655
					
				
					 3 changed files with 23 additions and 3 deletions
				
			
		|  | @ -22,13 +22,16 @@ MagnifierWidget::~MagnifierWidget() | |||
| 
 | ||||
| void MagnifierWidget::set_scale_factor(int scale_factor) | ||||
| { | ||||
|     VERIFY(scale_factor == 2 || scale_factor == 4); | ||||
|     VERIFY(scale_factor == 2 || scale_factor == 4 || scale_factor == 8); | ||||
|     m_scale_factor = scale_factor; | ||||
|     update(); | ||||
| } | ||||
| 
 | ||||
| void MagnifierWidget::sync() | ||||
| { | ||||
|     if (m_pause_capture) | ||||
|         return; | ||||
| 
 | ||||
|     auto size = frame_inner_rect().size(); | ||||
|     Gfx::IntSize grab_size { size.width() / m_scale_factor, size.height() / m_scale_factor }; | ||||
|     m_grabbed_bitmap = GUI::WindowServerConnection::the().get_screen_bitmap_around_cursor(grab_size).bitmap(); | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ class MagnifierWidget final : public GUI::Frame { | |||
| public: | ||||
|     virtual ~MagnifierWidget(); | ||||
|     void set_scale_factor(int scale_factor); | ||||
|     void pause_capture(bool pause) { m_pause_capture = pause; } | ||||
| 
 | ||||
| private: | ||||
|     MagnifierWidget(); | ||||
|  | @ -24,4 +25,5 @@ private: | |||
| 
 | ||||
|     int m_scale_factor { 2 }; | ||||
|     RefPtr<Gfx::Bitmap> m_grabbed_bitmap; | ||||
|     bool m_pause_capture { false }; | ||||
| }; | ||||
|  |  | |||
|  | @ -56,24 +56,39 @@ int main(int argc, char** argv) | |||
|     auto size_action_group = make<GUI::ActionGroup>(); | ||||
| 
 | ||||
|     auto two_x_action = GUI::Action::create_checkable( | ||||
|         "&2x", [&](auto&) { | ||||
|         "&2x", { Key_2 }, [&](auto&) { | ||||
|             magnifier.set_scale_factor(2); | ||||
|         }); | ||||
| 
 | ||||
|     auto four_x_action = GUI::Action::create_checkable( | ||||
|         "&4x", [&](auto&) { | ||||
|         "&4x", { Key_4 }, [&](auto&) { | ||||
|             magnifier.set_scale_factor(4); | ||||
|         }); | ||||
| 
 | ||||
|     auto eight_x_action = GUI::Action::create_checkable( | ||||
|         "&8x", { Key_8 }, [&](auto&) { | ||||
|             magnifier.set_scale_factor(8); | ||||
|         }); | ||||
| 
 | ||||
|     auto pause_action = GUI::Action::create_checkable( | ||||
|         "&Pause Capture", { Key_Space }, [&](auto& action) { | ||||
|             magnifier.pause_capture(action.is_checked()); | ||||
|         }); | ||||
| 
 | ||||
|     size_action_group->add_action(two_x_action); | ||||
|     size_action_group->add_action(four_x_action); | ||||
|     size_action_group->add_action(eight_x_action); | ||||
|     size_action_group->set_exclusive(true); | ||||
| 
 | ||||
|     auto& view_menu = window->add_menu("&View"); | ||||
|     view_menu.add_action(two_x_action); | ||||
|     view_menu.add_action(four_x_action); | ||||
|     view_menu.add_action(eight_x_action); | ||||
|     two_x_action->set_checked(true); | ||||
| 
 | ||||
|     view_menu.add_separator(); | ||||
|     view_menu.add_action(pause_action); | ||||
| 
 | ||||
|     auto& help_menu = window->add_menu("&Help"); | ||||
|     help_menu.add_action(GUI::CommonActions::make_about_action("Magnifier", app_icon, window)); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marcus Nilsson
						Marcus Nilsson