-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new class for common cairo functions. * #25 * NatronGitHub/Natron#970
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
#################################################################### | ||
# | ||
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
#################################################################### | ||
*/ | ||
|
||
#include "CairoHelper.h" | ||
|
||
#include <cmath> | ||
|
||
void CairoHelper::applyRotate(cairo_t *cr, | ||
double rotate, | ||
XY origin) | ||
{ | ||
if (!cr || rotate == 0.) { return; } | ||
|
||
cairo_translate(cr, origin.x, origin.y); | ||
cairo_rotate(cr, -rotate * (M_PI / 180.0)); | ||
cairo_translate(cr, -origin.x, -origin.y); | ||
} | ||
|
||
void CairoHelper::applyFlip(cairo_t *cr, | ||
int height) | ||
{ | ||
if (!cr || height < 1) { return; } | ||
|
||
cairo_scale(cr, 1.0f, -1.0f); | ||
cairo_translate(cr, 0.0f, -height); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
#################################################################### | ||
# | ||
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
#################################################################### | ||
*/ | ||
|
||
#ifndef CAIROHELPER_H | ||
#define CAIROHELPER_H | ||
|
||
#include <cairo.h> | ||
|
||
class CairoHelper | ||
{ | ||
public: | ||
struct XY | ||
{ | ||
double x; | ||
double y; | ||
}; | ||
/** @brief apply rotate */ | ||
static void applyRotate(cairo_t *cr, | ||
double rotate, | ||
XY origin); | ||
/** @brief apply flip */ | ||
static void applyFlip(cairo_t *cr, | ||
int height); | ||
}; | ||
|
||
#endif // CAIROHELPER_H |