summaryrefslogtreecommitdiffstats
path: root/pdb/groups/unit.pdb
blob: 676e8133c26ecbd95a6ce4839ba1d58027ffa968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 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 General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# "Perlized" from C source by Manish Singh <yosh@gimp.org>

sub unit_get_number_of_units {
    $blurb = 'Returns the number of units.';

    $help = 'This procedure returns the number of defined units.';

    &mitch_pdb_misc('1999');

    @outargs = (
	{ name => 'num_units', type => 'int32', libdef => 'GIMP_UNIT_END',
	  desc => 'The number of units', wrap => 1 }
    );

    %invoke = (
	code => <<'CODE'
{
  num_units = _gimp_unit_get_number_of_units (gimp);
}
CODE
    );
}

sub unit_get_number_of_built_in_units {
    $blurb = 'Returns the number of built-in units.';

    $help = <<'HELP';
This procedure returns the number of defined units built-in to GIMP.
HELP

    &mitch_pdb_misc('1999');

    @outargs = (
	{ name => 'num_units', type => 'int32', libdef => 'GIMP_UNIT_END',
	  desc => 'The number of built-in units', wrap => 1 }
    );

    %invoke = (
	code => <<'CODE'
{
  num_units = _gimp_unit_get_number_of_built_in_units (gimp);
}
CODE
    );
}

sub unit_new {
    $blurb = "Creates a new unit and returns it's integer ID.";

    $help = <<'HELP';
This procedure creates a new unit and returns it's integer ID. Note that the
new unit will have it's deletion flag set to TRUE, so you will have to set it
to FALSE with gimp_unit_set_deletion_flag() to make it persistent.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'identifier', type => 'string', wrap => 1, non_empty => 1,
	  desc => "The new unit's identifier" },
	{ name => 'factor', type => 'float',
	  desc => "The new unit's factor" },
	{ name => 'digits', type => 'int32',
	  desc => "The new unit's digits" },
	{ name => 'symbol', type => 'string', non_empty => 1,
	  desc => "The new unit's symbol" },
	{ name => 'abbreviation', type => 'string', non_empty => 1,
	  desc => "The new unit's abbreviation" },
	{ name => 'singular', type => 'string', non_empty => 1,
	  desc => "The new unit's singular form" },
	{ name => 'plural', type => 'string', non_empty => 1,
	  desc => "The new unit's plural form" }
    );

    @outargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The new unit's ID",
	  wrap => 1, libdef => 'GIMP_UNIT_INCH' }
    );

    %invoke = (
	code => <<'CODE'
{
  unit_id = _gimp_unit_new (gimp, identifier, factor, digits,
                            symbol, abbreviation, singular, plural);
}
CODE
    );
}

sub unit_get_deletion_flag {
    $blurb = "Returns the deletion flag of the unit.";

    $help = <<'HELP';
This procedure returns the deletion flag of the unit. If this value is TRUE the
unit's definition will not be saved in the user's unitrc file on gimp exit.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'deletion_flag', type => 'boolean',
	  desc => "The unit's deletion flag" }
    );

    %invoke = (
	code => <<'CODE'
{
  deletion_flag = _gimp_unit_get_deletion_flag (gimp, unit_id);
}
CODE
    );
}

sub unit_set_deletion_flag {
    $blurb = 'Sets the deletion flag of a unit.';

    $help = <<'HELP';
This procedure sets the unit's deletion flag. If the deletion flag of a unit is
TRUE on gimp exit, this unit's definition will not be saved in the user's
unitrc.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 },
	{ name => 'deletion_flag', type => 'boolean',
	  desc => 'The new deletion flag of the unit' }
    );

    %invoke = (
	code => <<'CODE'
{
  _gimp_unit_set_deletion_flag (gimp, unit_id, deletion_flag);
}
CODE
    );
}

sub unit_get_identifier {
    $blurb = "Returns the textual identifier of the unit.";

    $help = <<'HELP';
This procedure returns the textual identifier of the unit. For built-in units
it will be the english singular form of the unit's name. For user-defined units
this should equal to the singular form.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'identifier', type => 'string',
	  desc => "The unit's textual identifier" }
    );

    %invoke = (
	code => <<'CODE'
{
  identifier = g_strdup (_gimp_unit_get_identifier (gimp, unit_id));
}
CODE
    );
}

sub unit_get_factor {
    $blurb = "Returns the factor of the unit.";

    $help = <<'HELP';
This procedure returns the unit's factor which indicates how many units make up
an inch. Note that asking for the factor of "pixels" will produce an error.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'factor', type => 'float',
	  desc => "The unit's factor" }
    );

    %invoke = (
	code => <<'CODE'
{
  factor = _gimp_unit_get_factor (gimp, unit_id);
}
CODE
    );
}

sub unit_get_digits {
    $blurb = "Returns the number of digits of the unit.";

    $help = <<'HELP';
This procedure returns the number of digits you should provide in input or
output functions to get approximately the same accuracy as with two digits and
inches. Note that asking for the digits of "pixels" will produce an error.
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'digits', type => 'int32',
	  desc => "The unit's number of digits" }
    );

    %invoke = (
	code => <<'CODE'
{
  digits = _gimp_unit_get_digits (gimp, unit_id);
}
CODE
    );
}

sub unit_get_symbol {
    $blurb = "Returns the symbol of the unit.";

    $help = <<'HELP';
This procedure returns the symbol of the unit ("''" for inches).
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'symbol', type => 'string',
	  desc => "The unit's symbol" }
    );

    %invoke = (
	code => <<'CODE'
{
  symbol = g_strdup (_gimp_unit_get_symbol (gimp, unit_id));
}
CODE
    );
}

sub unit_get_abbreviation {
    $blurb = "Returns the abbreviation of the unit.";

    $help = <<'HELP';
This procedure returns the abbreviation of the unit ("in" for inches).
HELP

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'abbreviation', type => 'string',
	  desc => "The unit's abbreviation" }
    );

    %invoke = (
	code => <<'CODE'
{
  abbreviation = g_strdup (_gimp_unit_get_abbreviation (gimp, unit_id));
}
CODE
    );
}

sub unit_get_singular {
    $blurb = "Returns the singular form of the unit.";
    $help  = 'This procedure returns the singular form of the unit.';

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'singular', type => 'string',
	  desc => "The unit's singular form" }
    );

    %invoke = (
	code => <<'CODE'
{
  singular = g_strdup (_gimp_unit_get_singular (gimp, unit_id));
}
CODE
    );
}

sub unit_get_plural {
    $blurb = "Returns the plural form of the unit.";
    $help  = 'This procedure returns the plural form of the unit.';

    &mitch_pdb_misc('1999');

    @inargs = (
	{ name => 'unit_id', type => 'unit',
	  desc => "The unit's integer ID", wrap => 1 }
    );

    @outargs = (
	{ name => 'plural', type => 'string',
	  desc => "The unit's plural form" }
    );

    %invoke = (
	code => <<'CODE'
{
  plural = g_strdup (_gimp_unit_get_plural (gimp, unit_id));
}
CODE
    );
}


@headers = qw("libgimpbase/gimpbase.h"
              "core/gimpunit.h");

@procs = qw(unit_get_number_of_units unit_get_number_of_built_in_units
	    unit_new unit_get_deletion_flag unit_set_deletion_flag
            unit_get_identifier unit_get_factor unit_get_digits
            unit_get_symbol unit_get_abbreviation unit_get_singular
            unit_get_plural);

%exports = (app => [@procs], lib => [@procs]);

$desc = 'Units';
$doc_title = 'gimpunit';
$doc_short_desc = 'Provides a collection of predefined units and functions for creating user-defined units.';
$doc_long_desc = 'Provides a collection of predefined units and functions for creating user-defined units.';
$doc_see_also = '#GimpUnitMenu, #GimpSizeEntry';

1;