mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 01:32:45 +00:00 
			
		
		
		
	 160bda7228
			
		
	
	
		160bda7228
		
	
	
	
	
		
			
			https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
 | |
|  * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
 | |
|  * Copyright (c) 2022, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include "Tool.h"
 | |
| 
 | |
| namespace PixelPaint {
 | |
| 
 | |
| class BrushTool : public Tool {
 | |
| public:
 | |
|     BrushTool() = default;
 | |
|     virtual ~BrushTool() override = default;
 | |
| 
 | |
|     virtual void on_mousedown(Layer*, MouseEvent&) override;
 | |
|     virtual void on_mousemove(Layer*, MouseEvent&) override;
 | |
|     virtual void on_mouseup(Layer*, MouseEvent&) override;
 | |
|     virtual GUI::Widget* get_properties_widget() override;
 | |
|     virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Crosshair; }
 | |
| 
 | |
|     void set_size(int size) { m_size = size; }
 | |
|     int size() const { return m_size; }
 | |
| 
 | |
|     void set_hardness(int hardness) { m_hardness = hardness; }
 | |
|     int hardness() const { return m_hardness; }
 | |
| 
 | |
|     double get_falloff(double distance)
 | |
|     {
 | |
|         double multiplicand = hardness() == 100 ? 1.0 : 1.0 / (100 - hardness());
 | |
|         return (1.0 - double { distance / size() }) * multiplicand;
 | |
|     }
 | |
| 
 | |
| protected:
 | |
|     virtual Color color_for(GUI::MouseEvent const& event);
 | |
|     virtual void draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& point);
 | |
|     virtual void draw_line(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& start, Gfx::IntPoint const& end);
 | |
| 
 | |
| private:
 | |
|     RefPtr<GUI::Widget> m_properties_widget;
 | |
|     int m_size { 20 };
 | |
|     int m_hardness { 80 };
 | |
|     bool m_was_drawing { false };
 | |
|     bool m_has_clicked { false };
 | |
|     Gfx::IntPoint m_last_position;
 | |
| };
 | |
| 
 | |
| }
 |