ObjFW
OFCanvas.h
1 /*
2  * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFImage.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
34 @protocol OFCanvas <OFObject>
38 @property (retain, nonatomic) OFColor *backgroundColor;
39 
47 - (void)clearRect: (OFRect)rect;
48 
62 - (void)drawImage: (OFImage *)image
63  sourceRect: (OFRect)sourceRect
64  destinationRect: (OFRect)destinationRect;
65 @end
66 
73 OF_SUBCLASSING_RESTRICTED
74 @interface OFCanvas: OFObject <OFCanvas>
75 {
76  OFMutableImage *_destinationImage;
77  size_t _width;
78  OFRect _rect;
79  void *_pixels;
80  OFPixelFormat _pixelFormat;
81  OFColor *_backgroundColor;
82 }
83 
90 + (instancetype)canvasWithDestinationImage: (OFMutableImage *)image;
91 
92 - (instancetype)init OF_UNAVAILABLE;
93 
101 - (instancetype)initWithDestinationImage: (OFMutableImage *)image;
102 @end
103 
104 OF_ASSUME_NONNULL_END
A protocol for a canvas that can be drawn to.
An implementation of <OFCanvas> that draws to an OFImage.
Definition: OFCanvas.h:74
A class for storing a color.
Definition: OFColor.h:30
The root class for all other classes inside ObjFW.
Definition: OFObject.h:954
instancetype retain()
Increases the retain count.
A class representing a mutable image.
Definition: OFMutableImage.h:29
A rectangle.
Definition: OFObject.h:343
A class representing an image.
Definition: OFImage.h:115