-
Notifications
You must be signed in to change notification settings - Fork 41
/
ImageWell_mac.js
125 lines (120 loc) · 4.83 KB
/
ImageWell_mac.js
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
module.exports = (function() {
var Container = require('Container');
var $ = process.bridge.objc;
var utilities = require('Utilities');
/**
* @class ImageWell
* @description The image well class creates a way to display photos, icons or other imagery.
* @extends Container
*/
/**
* @new
* @memberof ImageWell
* @description Creates a new imagewell object.
*/
function ImageWell(properties, options, inherited) {
options = options || {};
options.delegates = options.delegates || [];
this.nativeClass = this.nativeClass || $.NSImageView;
this.nativeViewClass = this.nativeViewClass || $.NSImageView;
Container.call(this, properties, options, inherited || true);
this.native('setEditable', $.YES);
this.native('setImageAlignment', $.NSImageAlignCenter);
this.native('setImageFrameStyle', $.NSImageFrameNone);
this.animates = false;
this.alignment = "center";
utilities.setProperties(this, properties, inherited);
}
ImageWell.prototype = Object.create(Container.prototype);
ImageWell.prototype.constructor = ImageWell;
/**
* @member image
* @type {string}
* @memberof ImageWell
* @description Gets or sets the image to use, this can be any URL including the app:// schema,
* or a named system image.
*/
Object.defineProperty(ImageWell.prototype, 'image', {
get:function() { return this.private.currentImage; },
set:function(e) {
this.private.currentImage = e;
var img = utilities.makeNSImage(e);
if(!img) {
console.log('Error, image was invalid: \"' + e + '\"');
} else {
this.nativeView('setImage',img);
img('release');
}
}
});
Object.defineProperty(ImageWell.prototype, 'readonly', {
get:function() { return this.nativeView('editable') === $.NO ? true : false; },
set:function(e) { this.nativeView('setEditable', e ? $.NO : $.YES); }
});
/*
TODO: Support this on Windows
Object.defineProperty(ImageWell.prototype, 'alignment', {
get:function() {
var align = this.nativeView('imageAlignment');
if(align === $.NSImageAlignCenter) return "center";
else if (align === $.NSImageAlignTop) return "top";
else if (align === $.NSImageAlignTopLeft) return "top-left";
else if (align === $.NSImageAlignTopRight) return "top-right";
else if (align === $.NSImageAlignLeft) return "left";
else if (align === $.NSImageAlignBottom) return "bottom";
else if (align === $.NSImageAlignBottomLeft) return "bottom-left";
else if (align === $.NSImageAlignBottomRight) return "bottom-right";
else return "right";
},
set:function(e) {
if(e === "center") this.nativeView('setImageAlignment', $.NSImageAlignCenter);
else if(e === "top") this.nativeView('setImageAlignment', $.NSImageAlignTop);
else if(e === "top-left") this.nativeView('setImageAlignment', $.NSImageAlignTopLeft);
else if(e === "top-right") this.nativeView('setImageAlignment', $.NSImageAlignTopRight);
else if(e === "left") this.nativeView('setImageAlignment', $.NSImageAlignLeft);
else if(e === "bottom") this.nativeView('setImageAlignment', $.NSImageAlignBottom);
else if(e === "bottom-left") this.nativeView('setImageAlignment', $.NSImageAlignBottomLeft);
else if(e === "bottom-right") this.nativeView('setImageAlignment', $.NSImageAlignBottomRight);
else if(e === "right") this.nativeView('setImageAlignment', $.NSImageAlignRight);
}
}); */
/**
* @member scale
* @type {string}
* @memberof ImageWell
* @description Gets or sets the scaling of the image, this can be "constrain", "fit", "contain" or "none"
* @default "constrain"
*/
Object.defineProperty(ImageWell.prototype, 'scale', {
get:function() {
var scaling = this.nativeView('imageScaling');
if(scaling === $.NSImageScaleProportionallyDown) {
return "constrain";
} else if (scaling === $.NSImageScaleAxesIndependently) {
return "fit";
} else if (scaling === $.NSImageScaleProportionallyUpOrDown) {
return "contain";
} else {
return "none";
}
},
set:function(e) {
if(e === "constrain") {
this.nativeView('setImageScaling', $.NSImageScaleProportionallyDown);
} else if(e === "fit") {
this.nativeView('setImageScaling', $.NSImageScaleAxesIndependently);
} else if(e === "contain") {
this.nativeView('setImageScaling', $.NSImageScaleProportionallyUpOrDown);
} else if(e === "none") {
this.nativeView('setImageScaling', $.NSImageScaleNone);
}
}
});
/*
TODO: Support this on Windows
Object.defineProperty(ImageWell.prototype, 'animates', {
get:function() { return this.nativeView('animates') === $.YES ? true : false; },
set:function(e) { this.nativeView('setAnimates', e ? $.YES : $.NO); }
});*/
return ImageWell;
})();