mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:32:44 +00:00 
			
		
		
		
	FontEditor: Standardize Gfx::RotationDirections for rotate_90()
This commit is contained in:
		
							parent
							
								
									fb00d3ed25
								
							
						
					
					
						commit
						d867871bda
					
				
					 3 changed files with 8 additions and 12 deletions
				
			
		|  | @ -189,21 +189,22 @@ static Vector<Vector<u8>> glyph_as_matrix(Gfx::GlyphBitmap const& bitmap) | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GlyphEditorWidget::rotate_90(Direction direction) | void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction) | ||||||
| { | { | ||||||
|     if (on_undo_event) |     if (on_undo_event) | ||||||
|         on_undo_event(); |         on_undo_event(); | ||||||
| 
 | 
 | ||||||
|     auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); |     auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); | ||||||
|     auto matrix = glyph_as_matrix(bitmap); |     auto matrix = glyph_as_matrix(bitmap); | ||||||
|  |     auto clockwise = direction == Gfx::RotationDirection::Clockwise; | ||||||
| 
 | 
 | ||||||
|     for (int y = 0; y < bitmap.height(); y++) { |     for (int y = 0; y < bitmap.height(); y++) { | ||||||
|         for (int x = 0; x < bitmap.width(); x++) { |         for (int x = 0; x < bitmap.width(); x++) { | ||||||
|             int source_x = (direction == Counterclockwise) ? max(bitmap.width() - 1 - y, 0) : y; |             int source_x = clockwise ? y : max(bitmap.width() - 1 - y, 0); | ||||||
|             int source_y = (direction == Counterclockwise) ? x : bitmap.width() - 1 - x; |             int source_y = clockwise ? bitmap.width() - 1 - x : x; | ||||||
|             bool value = false; |             bool value = false; | ||||||
|             if (source_x < bitmap.width() && source_y < bitmap.height()) { |             if (source_x < bitmap.width() && source_y < bitmap.height()) { | ||||||
|                 value = (direction == Counterclockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x]; |                 value = (!clockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x]; | ||||||
|             } |             } | ||||||
|             bitmap.set_bit_at(x, y, value); |             bitmap.set_bit_at(x, y, value); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -21,18 +21,13 @@ public: | ||||||
|         Move |         Move | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     enum Direction { |  | ||||||
|         Clockwise, |  | ||||||
|         Counterclockwise |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     virtual ~GlyphEditorWidget() override = default; |     virtual ~GlyphEditorWidget() override = default; | ||||||
| 
 | 
 | ||||||
|     int glyph() const { return m_glyph; } |     int glyph() const { return m_glyph; } | ||||||
|     void set_glyph(int); |     void set_glyph(int); | ||||||
|     bool is_glyph_empty(); |     bool is_glyph_empty(); | ||||||
| 
 | 
 | ||||||
|     void rotate_90(Direction); |     void rotate_90(Gfx::RotationDirection); | ||||||
|     void flip_vertically(); |     void flip_vertically(); | ||||||
|     void flip_horizontally(); |     void flip_horizontally(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -275,11 +275,11 @@ ErrorOr<void> MainWidget::create_actions() | ||||||
|     m_glyph_tool_actions.set_exclusive(true); |     m_glyph_tool_actions.set_exclusive(true); | ||||||
| 
 | 
 | ||||||
|     m_rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) { |     m_rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) { | ||||||
|         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Counterclockwise); |         m_glyph_editor_widget->rotate_90(Gfx::RotationDirection::CounterClockwise); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) { |     m_rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) { | ||||||
|         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Clockwise); |         m_glyph_editor_widget->rotate_90(Gfx::RotationDirection::Clockwise); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     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_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&) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 thankyouverycool
						thankyouverycool