1 /*
2  *   This file is part of darktable,
3  *   Copyright (C) 2015-2020 darktable developers.
4  *
5  *   darktable is free software: you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, either version 3 of the License, or
8  *   (at your option) any later version.
9  *
10  *   darktable is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "lua/cairo.h"
20 #include "common/darktable.h"
21 #include "gui/draw.h"
22 #include "lua/call.h"
23 #include "lua/lua.h"
24 #include "lua/types.h"
25 
26 
_draw_line(lua_State * L)27 static int _draw_line(lua_State *L)
28 {
29   cairo_t *cr;
30   luaA_to(L, dt_lua_cairo_t, &cr, 1);
31   lua_Number left = luaL_checknumber(L, 2);
32   lua_Number top = luaL_checknumber(L, 3);
33   lua_Number right = luaL_checknumber(L, 4);
34   lua_Number bottom = luaL_checknumber(L, 5);
35 
36   dt_draw_line(cr, left, top, right, bottom);
37 
38   return 0;
39 }
40 
_save(lua_State * L)41 static int _save(lua_State *L)
42 {
43   cairo_t *cr;
44   luaA_to(L, dt_lua_cairo_t, &cr, 1);
45 
46   cairo_save(cr);
47 
48   return 0;
49 }
50 
_restore(lua_State * L)51 static int _restore(lua_State *L)
52 {
53   cairo_t *cr;
54   luaA_to(L, dt_lua_cairo_t, &cr, 1);
55 
56   cairo_restore(cr);
57 
58   return 0;
59 }
60 
_new_sub_path(lua_State * L)61 static int _new_sub_path(lua_State *L)
62 {
63   cairo_t *cr;
64   luaA_to(L, dt_lua_cairo_t, &cr, 1);
65 
66   cairo_new_sub_path(cr);
67 
68   return 0;
69 }
70 
_scale(lua_State * L)71 static int _scale(lua_State *L)
72 {
73   cairo_t *cr;
74   luaA_to(L, dt_lua_cairo_t, &cr, 1);
75   lua_Number x = luaL_checknumber(L, 2);
76   lua_Number y = luaL_checknumber(L, 3);
77 
78   cairo_scale(cr, x, y);
79 
80   return 0;
81 }
82 
_translate(lua_State * L)83 static int _translate(lua_State *L)
84 {
85   cairo_t *cr;
86   luaA_to(L, dt_lua_cairo_t, &cr, 1);
87   lua_Number x = luaL_checknumber(L, 2);
88   lua_Number y = luaL_checknumber(L, 3);
89 
90   cairo_translate(cr, x, y);
91 
92   return 0;
93 }
94 
_rotate(lua_State * L)95 static int _rotate(lua_State *L)
96 {
97   cairo_t *cr;
98   luaA_to(L, dt_lua_cairo_t, &cr, 1);
99   lua_Number a = luaL_checknumber(L, 2);
100 
101   cairo_rotate(cr, a);
102 
103   return 0;
104 }
105 
_move_to(lua_State * L)106 static int _move_to(lua_State *L)
107 {
108   cairo_t *cr;
109   luaA_to(L, dt_lua_cairo_t, &cr, 1);
110   lua_Number x = luaL_checknumber(L, 2);
111   lua_Number y = luaL_checknumber(L, 3);
112 
113   cairo_move_to(cr, x, y);
114 
115   return 0;
116 }
117 
_line_to(lua_State * L)118 static int _line_to(lua_State *L)
119 {
120   cairo_t *cr;
121   luaA_to(L, dt_lua_cairo_t, &cr, 1);
122   lua_Number x = luaL_checknumber(L, 2);
123   lua_Number y = luaL_checknumber(L, 3);
124 
125   cairo_line_to(cr, x, y);
126 
127   return 0;
128 }
129 
_arc(lua_State * L)130 static int _arc(lua_State *L)
131 {
132   cairo_t *cr;
133   luaA_to(L, dt_lua_cairo_t, &cr, 1);
134   lua_Number x = luaL_checknumber(L, 2);
135   lua_Number y = luaL_checknumber(L, 3);
136   lua_Number r = luaL_checknumber(L, 4);
137   lua_Number a1 = luaL_checknumber(L, 5);
138   lua_Number a2 = luaL_checknumber(L, 6);
139 
140   cairo_arc(cr, x, y, r, a1, a2);
141 
142   return 0;
143 }
144 
_arc_negative(lua_State * L)145 static int _arc_negative(lua_State *L)
146 {
147   cairo_t *cr;
148   luaA_to(L, dt_lua_cairo_t, &cr, 1);
149   lua_Number x = luaL_checknumber(L, 2);
150   lua_Number y = luaL_checknumber(L, 3);
151   lua_Number r = luaL_checknumber(L, 4);
152   lua_Number a1 = luaL_checknumber(L, 5);
153   lua_Number a2 = luaL_checknumber(L, 6);
154 
155   cairo_arc_negative(cr, x, y, r, a1, a2);
156 
157   return 0;
158 }
159 
_rectangle(lua_State * L)160 static int _rectangle(lua_State *L)
161 {
162   cairo_t *cr;
163   luaA_to(L, dt_lua_cairo_t, &cr, 1);
164   lua_Number x = luaL_checknumber(L, 2);
165   lua_Number y = luaL_checknumber(L, 3);
166   lua_Number w = luaL_checknumber(L, 4);
167   lua_Number h = luaL_checknumber(L, 5);
168 
169   cairo_rectangle(cr, x, y, w, h);
170 
171   return 0;
172 }
173 
dt_lua_init_cairo(lua_State * L)174 int dt_lua_init_cairo(lua_State *L)
175 {
176   int cairo_type = dt_lua_init_gpointer_type(L, dt_lua_cairo_t);
177 
178   lua_pushcfunction(L, _draw_line);
179   dt_lua_gtk_wrap(L);
180   lua_pushcclosure(L, dt_lua_type_member_common, 1);
181   dt_lua_type_register_const_type(L, cairo_type, "draw_line");
182 
183   lua_pushcfunction(L, _save);
184   dt_lua_gtk_wrap(L);
185   lua_pushcclosure(L, dt_lua_type_member_common, 1);
186   dt_lua_type_register_const_type(L, cairo_type, "save");
187 
188   lua_pushcfunction(L, _restore);
189   dt_lua_gtk_wrap(L);
190   lua_pushcclosure(L, dt_lua_type_member_common, 1);
191   dt_lua_type_register_const_type(L, cairo_type, "restore");
192 
193   lua_pushcfunction(L, _new_sub_path);
194   dt_lua_gtk_wrap(L);
195   lua_pushcclosure(L, dt_lua_type_member_common, 1);
196   dt_lua_type_register_const_type(L, cairo_type, "new_sub_path");
197 
198   lua_pushcfunction(L, _scale);
199   dt_lua_gtk_wrap(L);
200   lua_pushcclosure(L, dt_lua_type_member_common, 1);
201   dt_lua_type_register_const_type(L, cairo_type, "scale");
202 
203   lua_pushcfunction(L, _translate);
204   dt_lua_gtk_wrap(L);
205   lua_pushcclosure(L, dt_lua_type_member_common, 1);
206   dt_lua_type_register_const_type(L, cairo_type, "translate");
207 
208   lua_pushcfunction(L, _rotate);
209   dt_lua_gtk_wrap(L);
210   lua_pushcclosure(L, dt_lua_type_member_common, 1);
211   dt_lua_type_register_const_type(L, cairo_type, "rotate");
212 
213   lua_pushcfunction(L, _move_to);
214   dt_lua_gtk_wrap(L);
215   lua_pushcclosure(L, dt_lua_type_member_common, 1);
216   dt_lua_type_register_const_type(L, cairo_type, "move_to");
217 
218   lua_pushcfunction(L, _line_to);
219   dt_lua_gtk_wrap(L);
220   lua_pushcclosure(L, dt_lua_type_member_common, 1);
221   dt_lua_type_register_const_type(L, cairo_type, "line_to");
222 
223   lua_pushcfunction(L, _arc);
224   dt_lua_gtk_wrap(L);
225   lua_pushcclosure(L, dt_lua_type_member_common, 1);
226   dt_lua_type_register_const_type(L, cairo_type, "arc");
227 
228   lua_pushcfunction(L, _arc_negative);
229   dt_lua_gtk_wrap(L);
230   lua_pushcclosure(L, dt_lua_type_member_common, 1);
231   dt_lua_type_register_const_type(L, cairo_type, "arc_negative");
232 
233   lua_pushcfunction(L, _rectangle);
234   dt_lua_gtk_wrap(L);
235   lua_pushcclosure(L, dt_lua_type_member_common, 1);
236   dt_lua_type_register_const_type(L, cairo_type, "rectangle");
237 
238   return 0;
239 }
240 
241 
242 
243 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
244 // vim: shiftwidth=2 expandtab tabstop=2 cindent
245 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
246