1//
2//  PRCCrop.m
3//  PRICE
4//
5//  Created by Riccardo Mottola on Fri Jan 28 2005.
6//  Copyright (c) 2005-2014 Carduus. All rights reserved.
7//
8// This application 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 2 of the License, or (at your option) any later version.
9// 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.
10
11#import "PRCCrop.h"
12#import "MyDocument.h"
13#import "PRCrop.h"
14
15@implementation PRCCrop
16
17- (id)init
18{
19  if ((self = [super init]))
20    {
21      filter = [[PRCrop alloc] init];
22    }
23  return self;
24}
25
26- (IBAction)showFilter:(id)sender
27{
28    [super showFilter:sender];
29
30    if (!cropWindow)
31        [NSBundle loadNibNamed:@"Crop" owner:self];
32    [cropWindow makeKeyAndOrderFront:nil];
33    origWidth = [[[[NSDocumentController sharedDocumentController] currentDocument] activeImage] width];
34    origHeight = [[[[NSDocumentController sharedDocumentController] currentDocument] activeImage] height];
35    [self updateSize];
36
37    [self parametersChanged:self];
38}
39
40- (NSArray *)encodeParameters
41{
42    NSArray    *parameters;
43
44    /* encode parameters */
45    parameters = [NSArray arrayWithObjects:
46        [NSNumber numberWithInt:[topField intValue]],
47        [NSNumber numberWithInt:[bottomField intValue]],
48        [NSNumber numberWithInt:[leftField intValue]],
49        [NSNumber numberWithInt:[rightField intValue]],
50        nil];
51
52    return parameters;
53}
54
55
56- (IBAction)changeTop:(id)sender
57{
58  [self updateSize];
59  [self parametersChanged:self];
60}
61
62- (IBAction)changeBottom:(id)sender
63{
64  [self updateSize];
65  [self parametersChanged:self];
66}
67
68- (IBAction)changeLeft:(id)sender
69{
70  [self updateSize];
71  [self parametersChanged:self];
72}
73
74- (IBAction)changeRight:(id)sender
75{
76  [self updateSize];
77  [self parametersChanged:self];
78}
79
80- (IBAction)resetValues:(id)sender
81{
82  [topField setIntValue:0];
83  [bottomField setIntValue:0];
84  [leftField setIntValue:0];
85  [rightField setIntValue:0];
86
87  [self parametersChanged:self];
88}
89
90- (void)updateSize
91{
92    [widthField setIntValue:(origWidth - [rightField intValue] - [leftField intValue])];
93    [heightField setIntValue:(origHeight - [topField intValue] - [bottomField intValue])];
94}
95
96- (void)closeFilterPanel
97{
98  [cropWindow performClose:nil];
99}
100
101@end
102