File: StringPlusGUI.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (132 lines) | stat: -rw-r--r-- 3,249 bytes parent folder | download
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
+ String {
	newTextWindow { arg title="Untitled", makeListener=false;
		Document.new(title, this, makeListener);
	}

	openHTMLFile{ arg selectionStart=0, selectionLength=0;
		var webView;

		if (Platform.openHTMLFileAction.notNil) {
			Platform.openHTMLFileAction.value(this, selectionStart, selectionLength);
			^this
		};

		webView = \QWebView.asClass;
		if (webView.notNil) {
			webView = webView.new;
			webView.url_(this);
			webView.front;
			^this;
		};

		this.openDocument(selectionStart, selectionLength)
	}

	openDocument { arg selectionStart=0, selectionLength=0;
		var ideClass;
		if(Document.implementationClass.notNil) {
			Document.open(this, selectionStart, selectionLength);
			^this
		};

		ideClass = \ScIDE.asClass;
		if ( ideClass.notNil ) {
			if ( this.endsWith(".sc") || this.endsWith(".scd") ) {
				ideClass.open(this, selectionStart, selectionLength);
				^this
			}
		};

		this.openOS
	}

	draw {
		this.drawAtPoint(Point(0,0), Font.default, Color.black);
	}
	drawAtPoint { arg point, font, color;
		if(GUI.id === \cocoa)
			{ this.prDrawAtPoint( point, font, color ) }
			{ Pen.stringAtPoint( this, point, font, color ) }
	}
	drawInRect { arg rect, font, color;
		if(GUI.id === \cocoa)
			{ this.prDrawInRect( rect, font, color ) }
			{ Pen.stringInRect( this, rect, font, color ) }
	}
	prDrawAtPoint { arg point, font, color;
		_String_DrawAtPoint
		^this.primitiveFailed
	}
	prDrawInRect { arg rect, font, color;
		_String_DrawInRect
		^this.primitiveFailed
	}
	drawCenteredIn { arg rect, font, color;
		if(GUI.id === \cocoa)
			{ this.drawAtPoint(this.bounds( font ).centerIn(rect), font, color) }
			{ Pen.stringCenteredIn( this, rect, font, color ) }
	}
	drawLeftJustIn { arg rect, font, color;
		var pos, bounds;
		if(GUI.id === \cocoa)
			{
				bounds = this.bounds( font );
				pos = bounds.centerIn(rect);
				pos.x = rect.left + 2;
				this.drawAtPoint(pos, font, color);
			}
			{ Pen.stringLeftJustIn( this, rect, font, color ) }
	}
	drawRightJustIn { arg rect, font, color;
		var pos, bounds;
		if(GUI.id === \cocoa)
			{
				bounds = this.bounds( font );
				pos = bounds.centerIn(rect);
				pos.x = rect.right - 2 - bounds.width;
				this.drawAtPoint(pos, font, color);
			}
			{ Pen.stringRightJustIn( this, rect, font, color ) }
	}

	bounds { arg font;
		if(GUI.id === \swing,{
			// since Swing is not in svn and can't be easily updated
			// let's put this temporary hack/if-statement here
			// rather than pollute everybody else's code with hacks/if-statements
			font = font ?? { Font.default };
			^Rect(0, 0, this.size * font.size * 0.52146, font.size * 1.25)
			// width in Helvetica approx = string size * font size * 0.52146
			// 0.52146 is average of all 32-127 ascii characters widths
		},{
			^GUI.stringBounds(this, font)
		});
	}
	prBounds { arg rect, font;
		_String_GetBounds
		^this.primitiveFailed
	}


	findHelpFile {
		^SCDoc.findHelpFile(this);
	}

	findHelpFileOrElse {
		this.findHelpFile;
	}

	help {
		if (Platform.openHelpFileAction.notNil) {
			Platform.openHelpFileAction.value(this)
		} {
			HelpBrowser.openHelpFor(this);
		}
	}
}

+ Symbol {
	openDocument { arg selectionStart=0, selectionLength=0;
		^this.asString.openDocument(selectionStart, selectionLength)
	}
}