mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:12:46 +00:00 
			
		
		
		
	FontEditor: Consolidate GlyphEditor's flip_{horizontally,vertically}
This commit is contained in:
		
							parent
							
								
									d867871bda
								
							
						
					
					
						commit
						894b41ef4d
					
				
					 3 changed files with 7 additions and 29 deletions
				
			
		|  | @ -215,40 +215,19 @@ void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction) | |||
|     update(); | ||||
| } | ||||
| 
 | ||||
| void GlyphEditorWidget::flip_vertically() | ||||
| void GlyphEditorWidget::flip(Gfx::Orientation orientation) | ||||
| { | ||||
|     if (on_undo_event) | ||||
|         on_undo_event(); | ||||
| 
 | ||||
|     auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); | ||||
|     auto matrix = glyph_as_matrix(bitmap); | ||||
|     auto vertical = orientation == Gfx::Orientation::Vertical; | ||||
| 
 | ||||
|     for (int y = 0; y < bitmap.height(); y++) { | ||||
|         for (int x = 0; x < bitmap.width(); x++) { | ||||
|             int source_x = x; | ||||
|             int source_y = bitmap.height() - 1 - y; | ||||
|             bool value = matrix[source_y][source_x]; | ||||
|             bitmap.set_bit_at(x, y, value); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if (on_glyph_altered) | ||||
|         on_glyph_altered(m_glyph); | ||||
|     update(); | ||||
| } | ||||
| 
 | ||||
| void GlyphEditorWidget::flip_horizontally() | ||||
| { | ||||
|     if (on_undo_event) | ||||
|         on_undo_event(); | ||||
| 
 | ||||
|     auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); | ||||
|     auto matrix = glyph_as_matrix(bitmap); | ||||
| 
 | ||||
|     for (int y = 0; y < bitmap.height(); y++) { | ||||
|         for (int x = 0; x < bitmap.width(); x++) { | ||||
|             int source_x = bitmap.width() - 1 - x; | ||||
|             int source_y = y; | ||||
|             int source_x = vertical ? x : bitmap.width() - 1 - x; | ||||
|             int source_y = vertical ? bitmap.height() - 1 - y : y; | ||||
|             bool value = matrix[source_y][source_x]; | ||||
|             bitmap.set_bit_at(x, y, value); | ||||
|         } | ||||
|  |  | |||
|  | @ -28,8 +28,7 @@ public: | |||
|     bool is_glyph_empty(); | ||||
| 
 | ||||
|     void rotate_90(Gfx::RotationDirection); | ||||
|     void flip_vertically(); | ||||
|     void flip_horizontally(); | ||||
|     void flip(Gfx::Orientation); | ||||
| 
 | ||||
|     int preferred_width() const; | ||||
|     int preferred_height() const; | ||||
|  |  | |||
|  | @ -283,11 +283,11 @@ ErrorOr<void> MainWidget::create_actions() | |||
|     }); | ||||
| 
 | ||||
|     m_flip_horizontal_action = GUI::Action::create("Flip Horizontally", { Mod_Ctrl | Mod_Shift, Key_Q }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-horizontal.png"sv)), [&](auto&) { | ||||
|         m_glyph_editor_widget->flip_horizontally(); | ||||
|         m_glyph_editor_widget->flip(Gfx::Orientation::Horizontal); | ||||
|     }); | ||||
| 
 | ||||
|     m_flip_vertical_action = GUI::Action::create("Flip Vertically", { Mod_Ctrl | Mod_Shift, Key_W }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-vertical.png"sv)), [&](auto&) { | ||||
|         m_glyph_editor_widget->flip_vertically(); | ||||
|         m_glyph_editor_widget->flip(Gfx::Orientation::Vertical); | ||||
|     }); | ||||
| 
 | ||||
|     m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 thankyouverycool
						thankyouverycool