gsuper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26061bffdb06a06a920cb9b70bfb19aeee586288
4
+ data.tar.gz: d94954e297f594577b0462f0689a35b8dc458947
5
+ SHA512:
6
+ metadata.gz: fc1a1848327bcdc4e9195b927614d77cf04189b943f803396c06118cd72550042681357ab4aa467f8d785fa672f45fc72ac0fdeb86fa75a0358da0d115551c70
7
+ data.tar.gz: 55e2c7897a0c58ad3ac9fa4bed35b86d7e1fb9f56ba42db8ec20d5bd2447e6ab837ea8e1c9b3156cd9d7738b649ce012bbc6a41dbd21a9128881c5d77b89c492
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gsuper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,341 @@
1
+ gsuper Copyright (C) 2016 Yoteichi <plonk@piano.email.ne.jp>.
2
+
3
+ GNU GENERAL PUBLIC LICENSE
4
+ Version 2, June 1991
5
+
6
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
7
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+
11
+ Preamble
12
+
13
+ The licenses for most software are designed to take away your
14
+ freedom to share and change it. By contrast, the GNU General Public
15
+ License is intended to guarantee your freedom to share and change free
16
+ software--to make sure the software is free for all its users. This
17
+ General Public License applies to most of the Free Software
18
+ Foundation's software and to any other program whose authors commit to
19
+ using it. (Some other Free Software Foundation software is covered by
20
+ the GNU Lesser General Public License instead.) You can apply it to
21
+ your programs, too.
22
+
23
+ When we speak of free software, we are referring to freedom, not
24
+ price. Our General Public Licenses are designed to make sure that you
25
+ have the freedom to distribute copies of free software (and charge for
26
+ this service if you wish), that you receive source code or can get it
27
+ if you want it, that you can change the software or use pieces of it
28
+ in new free programs; and that you know you can do these things.
29
+
30
+ To protect your rights, we need to make restrictions that forbid
31
+ anyone to deny you these rights or to ask you to surrender the rights.
32
+ These restrictions translate to certain responsibilities for you if you
33
+ distribute copies of the software, or if you modify it.
34
+
35
+ For example, if you distribute copies of such a program, whether
36
+ gratis or for a fee, you must give the recipients all the rights that
37
+ you have. You must make sure that they, too, receive or can get the
38
+ source code. And you must show them these terms so they know their
39
+ rights.
40
+
41
+ We protect your rights with two steps: (1) copyright the software, and
42
+ (2) offer you this license which gives you legal permission to copy,
43
+ distribute and/or modify the software.
44
+
45
+ Also, for each author's protection and ours, we want to make certain
46
+ that everyone understands that there is no warranty for this free
47
+ software. If the software is modified by someone else and passed on, we
48
+ want its recipients to know that what they have is not the original, so
49
+ that any problems introduced by others will not reflect on the original
50
+ authors' reputations.
51
+
52
+ Finally, any free program is threatened constantly by software
53
+ patents. We wish to avoid the danger that redistributors of a free
54
+ program will individually obtain patent licenses, in effect making the
55
+ program proprietary. To prevent this, we have made it clear that any
56
+ patent must be licensed for everyone's free use or not licensed at all.
57
+
58
+ The precise terms and conditions for copying, distribution and
59
+ modification follow.
60
+
61
+ GNU GENERAL PUBLIC LICENSE
62
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
63
+
64
+ 0. This License applies to any program or other work which contains
65
+ a notice placed by the copyright holder saying it may be distributed
66
+ under the terms of this General Public License. The "Program", below,
67
+ refers to any such program or work, and a "work based on the Program"
68
+ means either the Program or any derivative work under copyright law:
69
+ that is to say, a work containing the Program or a portion of it,
70
+ either verbatim or with modifications and/or translated into another
71
+ language. (Hereinafter, translation is included without limitation in
72
+ the term "modification".) Each licensee is addressed as "you".
73
+
74
+ Activities other than copying, distribution and modification are not
75
+ covered by this License; they are outside its scope. The act of
76
+ running the Program is not restricted, and the output from the Program
77
+ is covered only if its contents constitute a work based on the
78
+ Program (independent of having been made by running the Program).
79
+ Whether that is true depends on what the Program does.
80
+
81
+ 1. You may copy and distribute verbatim copies of the Program's
82
+ source code as you receive it, in any medium, provided that you
83
+ conspicuously and appropriately publish on each copy an appropriate
84
+ copyright notice and disclaimer of warranty; keep intact all the
85
+ notices that refer to this License and to the absence of any warranty;
86
+ and give any other recipients of the Program a copy of this License
87
+ along with the Program.
88
+
89
+ You may charge a fee for the physical act of transferring a copy, and
90
+ you may at your option offer warranty protection in exchange for a fee.
91
+
92
+ 2. You may modify your copy or copies of the Program or any portion
93
+ of it, thus forming a work based on the Program, and copy and
94
+ distribute such modifications or work under the terms of Section 1
95
+ above, provided that you also meet all of these conditions:
96
+
97
+ a) You must cause the modified files to carry prominent notices
98
+ stating that you changed the files and the date of any change.
99
+
100
+ b) You must cause any work that you distribute or publish, that in
101
+ whole or in part contains or is derived from the Program or any
102
+ part thereof, to be licensed as a whole at no charge to all third
103
+ parties under the terms of this License.
104
+
105
+ c) If the modified program normally reads commands interactively
106
+ when run, you must cause it, when started running for such
107
+ interactive use in the most ordinary way, to print or display an
108
+ announcement including an appropriate copyright notice and a
109
+ notice that there is no warranty (or else, saying that you provide
110
+ a warranty) and that users may redistribute the program under
111
+ these conditions, and telling the user how to view a copy of this
112
+ License. (Exception: if the Program itself is interactive but
113
+ does not normally print such an announcement, your work based on
114
+ the Program is not required to print an announcement.)
115
+
116
+ These requirements apply to the modified work as a whole. If
117
+ identifiable sections of that work are not derived from the Program,
118
+ and can be reasonably considered independent and separate works in
119
+ themselves, then this License, and its terms, do not apply to those
120
+ sections when you distribute them as separate works. But when you
121
+ distribute the same sections as part of a whole which is a work based
122
+ on the Program, the distribution of the whole must be on the terms of
123
+ this License, whose permissions for other licensees extend to the
124
+ entire whole, and thus to each and every part regardless of who wrote it.
125
+
126
+ Thus, it is not the intent of this section to claim rights or contest
127
+ your rights to work written entirely by you; rather, the intent is to
128
+ exercise the right to control the distribution of derivative or
129
+ collective works based on the Program.
130
+
131
+ In addition, mere aggregation of another work not based on the Program
132
+ with the Program (or with a work based on the Program) on a volume of
133
+ a storage or distribution medium does not bring the other work under
134
+ the scope of this License.
135
+
136
+ 3. You may copy and distribute the Program (or a work based on it,
137
+ under Section 2) in object code or executable form under the terms of
138
+ Sections 1 and 2 above provided that you also do one of the following:
139
+
140
+ a) Accompany it with the complete corresponding machine-readable
141
+ source code, which must be distributed under the terms of Sections
142
+ 1 and 2 above on a medium customarily used for software interchange; or,
143
+
144
+ b) Accompany it with a written offer, valid for at least three
145
+ years, to give any third party, for a charge no more than your
146
+ cost of physically performing source distribution, a complete
147
+ machine-readable copy of the corresponding source code, to be
148
+ distributed under the terms of Sections 1 and 2 above on a medium
149
+ customarily used for software interchange; or,
150
+
151
+ c) Accompany it with the information you received as to the offer
152
+ to distribute corresponding source code. (This alternative is
153
+ allowed only for noncommercial distribution and only if you
154
+ received the program in object code or executable form with such
155
+ an offer, in accord with Subsection b above.)
156
+
157
+ The source code for a work means the preferred form of the work for
158
+ making modifications to it. For an executable work, complete source
159
+ code means all the source code for all modules it contains, plus any
160
+ associated interface definition files, plus the scripts used to
161
+ control compilation and installation of the executable. However, as a
162
+ special exception, the source code distributed need not include
163
+ anything that is normally distributed (in either source or binary
164
+ form) with the major components (compiler, kernel, and so on) of the
165
+ operating system on which the executable runs, unless that component
166
+ itself accompanies the executable.
167
+
168
+ If distribution of executable or object code is made by offering
169
+ access to copy from a designated place, then offering equivalent
170
+ access to copy the source code from the same place counts as
171
+ distribution of the source code, even though third parties are not
172
+ compelled to copy the source along with the object code.
173
+
174
+ 4. You may not copy, modify, sublicense, or distribute the Program
175
+ except as expressly provided under this License. Any attempt
176
+ otherwise to copy, modify, sublicense or distribute the Program is
177
+ void, and will automatically terminate your rights under this License.
178
+ However, parties who have received copies, or rights, from you under
179
+ this License will not have their licenses terminated so long as such
180
+ parties remain in full compliance.
181
+
182
+ 5. You are not required to accept this License, since you have not
183
+ signed it. However, nothing else grants you permission to modify or
184
+ distribute the Program or its derivative works. These actions are
185
+ prohibited by law if you do not accept this License. Therefore, by
186
+ modifying or distributing the Program (or any work based on the
187
+ Program), you indicate your acceptance of this License to do so, and
188
+ all its terms and conditions for copying, distributing or modifying
189
+ the Program or works based on it.
190
+
191
+ 6. Each time you redistribute the Program (or any work based on the
192
+ Program), the recipient automatically receives a license from the
193
+ original licensor to copy, distribute or modify the Program subject to
194
+ these terms and conditions. You may not impose any further
195
+ restrictions on the recipients' exercise of the rights granted herein.
196
+ You are not responsible for enforcing compliance by third parties to
197
+ this License.
198
+
199
+ 7. If, as a consequence of a court judgment or allegation of patent
200
+ infringement or for any other reason (not limited to patent issues),
201
+ conditions are imposed on you (whether by court order, agreement or
202
+ otherwise) that contradict the conditions of this License, they do not
203
+ excuse you from the conditions of this License. If you cannot
204
+ distribute so as to satisfy simultaneously your obligations under this
205
+ License and any other pertinent obligations, then as a consequence you
206
+ may not distribute the Program at all. For example, if a patent
207
+ license would not permit royalty-free redistribution of the Program by
208
+ all those who receive copies directly or indirectly through you, then
209
+ the only way you could satisfy both it and this License would be to
210
+ refrain entirely from distribution of the Program.
211
+
212
+ If any portion of this section is held invalid or unenforceable under
213
+ any particular circumstance, the balance of the section is intended to
214
+ apply and the section as a whole is intended to apply in other
215
+ circumstances.
216
+
217
+ It is not the purpose of this section to induce you to infringe any
218
+ patents or other property right claims or to contest validity of any
219
+ such claims; this section has the sole purpose of protecting the
220
+ integrity of the free software distribution system, which is
221
+ implemented by public license practices. Many people have made
222
+ generous contributions to the wide range of software distributed
223
+ through that system in reliance on consistent application of that
224
+ system; it is up to the author/donor to decide if he or she is willing
225
+ to distribute software through any other system and a licensee cannot
226
+ impose that choice.
227
+
228
+ This section is intended to make thoroughly clear what is believed to
229
+ be a consequence of the rest of this License.
230
+
231
+ 8. If the distribution and/or use of the Program is restricted in
232
+ certain countries either by patents or by copyrighted interfaces, the
233
+ original copyright holder who places the Program under this License
234
+ may add an explicit geographical distribution limitation excluding
235
+ those countries, so that distribution is permitted only in or among
236
+ countries not thus excluded. In such case, this License incorporates
237
+ the limitation as if written in the body of this License.
238
+
239
+ 9. The Free Software Foundation may publish revised and/or new versions
240
+ of the General Public License from time to time. Such new versions will
241
+ be similar in spirit to the present version, but may differ in detail to
242
+ address new problems or concerns.
243
+
244
+ Each version is given a distinguishing version number. If the Program
245
+ specifies a version number of this License which applies to it and "any
246
+ later version", you have the option of following the terms and conditions
247
+ either of that version or of any later version published by the Free
248
+ Software Foundation. If the Program does not specify a version number of
249
+ this License, you may choose any version ever published by the Free Software
250
+ Foundation.
251
+
252
+ 10. If you wish to incorporate parts of the Program into other free
253
+ programs whose distribution conditions are different, write to the author
254
+ to ask for permission. For software which is copyrighted by the Free
255
+ Software Foundation, write to the Free Software Foundation; we sometimes
256
+ make exceptions for this. Our decision will be guided by the two goals
257
+ of preserving the free status of all derivatives of our free software and
258
+ of promoting the sharing and reuse of software generally.
259
+
260
+ NO WARRANTY
261
+
262
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
263
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
264
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
265
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
266
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
267
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
268
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
269
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
270
+ REPAIR OR CORRECTION.
271
+
272
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
273
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
274
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
275
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
276
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
277
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
278
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
279
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
280
+ POSSIBILITY OF SUCH DAMAGES.
281
+
282
+ END OF TERMS AND CONDITIONS
283
+
284
+ How to Apply These Terms to Your New Programs
285
+
286
+ If you develop a new program, and you want it to be of the greatest
287
+ possible use to the public, the best way to achieve this is to make it
288
+ free software which everyone can redistribute and change under these terms.
289
+
290
+ To do so, attach the following notices to the program. It is safest
291
+ to attach them to the start of each source file to most effectively
292
+ convey the exclusion of warranty; and each file should have at least
293
+ the "copyright" line and a pointer to where the full notice is found.
294
+
295
+ <one line to give the program's name and a brief idea of what it does.>
296
+ Copyright (C) <year> <name of author>
297
+
298
+ This program is free software; you can redistribute it and/or modify
299
+ it under the terms of the GNU General Public License as published by
300
+ the Free Software Foundation; either version 2 of the License, or
301
+ (at your option) any later version.
302
+
303
+ This program is distributed in the hope that it will be useful,
304
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
305
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306
+ GNU General Public License for more details.
307
+
308
+ You should have received a copy of the GNU General Public License along
309
+ with this program; if not, write to the Free Software Foundation, Inc.,
310
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
311
+
312
+ Also add information on how to contact you by electronic and paper mail.
313
+
314
+ If the program is interactive, make it output a short notice like this
315
+ when it starts in an interactive mode:
316
+
317
+ Gnomovision version 69, Copyright (C) year name of author
318
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
319
+ This is free software, and you are welcome to redistribute it
320
+ under certain conditions; type `show c' for details.
321
+
322
+ The hypothetical commands `show w' and `show c' should show the appropriate
323
+ parts of the General Public License. Of course, the commands you use may
324
+ be called something other than `show w' and `show c'; they could even be
325
+ mouse-clicks or menu items--whatever suits your program.
326
+
327
+ You should also get your employer (if you work as a programmer) or your
328
+ school, if any, to sign a "copyright disclaimer" for the program, if
329
+ necessary. Here is a sample; alter the names:
330
+
331
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
332
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
333
+
334
+ <signature of Ty Coon>, 1 April 1989
335
+ Ty Coon, President of Vice
336
+
337
+ This General Public License does not permit incorporating your program into
338
+ proprietary programs. If your program is a subroutine library, you may
339
+ consider it more useful to permit linking proprietary applications with the
340
+ library. If this is what you want to do, use the GNU Lesser General
341
+ Public License instead of this License.
@@ -0,0 +1,37 @@
1
+ # GSuper
2
+
3
+ デスクトップ配信などで画面上にメッセージを重ね合わせたい時に使える、字
4
+ 幕表示プログラムです。
5
+
6
+ X Window System で使われることを想定しており、デスクトップ合成機能付き
7
+ のウィンドウマネージャーと使う必要があります。
8
+
9
+ ## インストール
10
+
11
+ 次のようにインストールしてください。
12
+
13
+ $ gem install gsuper
14
+
15
+ ## 使い方
16
+
17
+ `gsuper`コマンドで起動し、緑色の字幕ウィンドウとテキスト入力用のメイン
18
+ ウィンドウが表示されます。
19
+
20
+ 字幕ウィンドウは右下のハンドルをドラッグして大きさを変えることができ、
21
+ それ以外の場所をドラッグするとウィンドウが移動します。
22
+
23
+ メッセージを編集するには、メインウィンドウのテキストエリアを使います。
24
+ メインウィンドウ右上の「字幕操作」トグルボタンをオフにすると字幕ウィン
25
+ ドウの背景が透明になり、字幕の下にあるウィンドウが自由に操作できるよう
26
+ になります。
27
+
28
+ 字幕を表示したままメインウィンドウを閉じることができ、その場合システム
29
+ トレイのアイコンをダブルクリックして再び呼び出すことができます。
30
+
31
+ プログラムを終了する場合は、システムトレイアイコンの右クリックメニュー
32
+ から「終了」を選択してください。
33
+
34
+ ## 貢献
35
+
36
+ バグ報告やプルリクエストは Github の https://github.com/plonk/gsuper
37
+ までどうぞ。
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gsuper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gsuper'
3
+
4
+ GSuper::Program.new.run
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gsuper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gsuper"
8
+ spec.version = GSuper::VERSION
9
+ spec.authors = ["Yoteichi"]
10
+ spec.email = ["plonk@piano.email.ne.jp"]
11
+
12
+ spec.summary = %q{program to superimpose text on screen}
13
+ spec.description = %q{program superimpose text on screen}
14
+ spec.homepage = "https://github.com/plonk/gsuper/"
15
+ spec.licenses = "GPL-2"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_dependency "gtk2", "~> 3.0.7"
26
+ spec.add_dependency "toml-rb", "~> 0.3.12"
27
+ end
@@ -0,0 +1,4 @@
1
+ require "gsuper/version"
2
+ require "gsuper/color"
3
+ require "gsuper/super_window"
4
+ require "gsuper/program"
@@ -0,0 +1,31 @@
1
+ require 'gtk2'
2
+
3
+ module GSuper
4
+
5
+ module Color
6
+ def gdk_color(arr)
7
+ raise 'format error' unless arr.size.between?(3,4) && arr.all? { |ch| ch.between?(0.0,1.0) }
8
+ r, g, b, = arr
9
+ return Gdk::Color.new(r * 65535, g * 65535, b * 65535)
10
+ end
11
+ module_function :gdk_color
12
+
13
+ def gdk_alpha(arr)
14
+ raise 'format error unless' unless arr.size == 4
15
+ _, _, _, alpha = arr
16
+ return alpha * 65535
17
+ end
18
+ module_function :gdk_alpha
19
+
20
+ def pango_triple(color)
21
+ return [color.red, color.green, color.blue].map { |u16| u16 / 65535.0 }
22
+ end
23
+ module_function :pango_triple
24
+
25
+ def pango_quadruple(color, alpha)
26
+ return pango_triple(color) + [alpha / 65535.0]
27
+ end
28
+ module_function :pango_quadruple
29
+ end
30
+
31
+ end
@@ -0,0 +1,182 @@
1
+ require 'gtk2'
2
+ require 'gsuper/settings'
3
+
4
+ =begin
5
+
6
+ +-------------------------------------------------+--------+
7
+ | gsuper | _ [] X |
8
+ +-------------------------------------------------+--------+
9
+ | x: [ 320] y: [ 480] |
10
+ | [font button] [color button] [color button] [X] outline |
11
+ | +------------------------------------------------------+ |
12
+ | | blah blah blah blah blah... | |
13
+ | | | |
14
+ | | | |
15
+ | | | |
16
+ | | | |
17
+ | | | |
18
+ | | | |
19
+ | | | |
20
+ | | | |
21
+ | +------------------------------------------------------+ |
22
+ | [ OK ] |
23
+ +----------------------------------------------------------+
24
+
25
+ =end
26
+
27
+ require_relative 'color'
28
+
29
+ module GSuper
30
+
31
+ class Program
32
+ include Gtk
33
+
34
+ def create_popup_menu
35
+ menu = Menu.new
36
+ [MenuItem.new('終了').tap { |item|
37
+ item.signal_connect('activate') {
38
+ Gtk.main_quit
39
+ }
40
+ }].each do |item|
41
+ menu.add(item)
42
+ end
43
+ menu.show_all
44
+ return menu
45
+ end
46
+
47
+ def create_main_window(super_window)
48
+ return Window.new.tap { |window|
49
+ window.signal_connect("delete-event") {
50
+ window.hide
51
+ true
52
+ }
53
+
54
+ window.border_width = 18
55
+
56
+ VBox.new(false, 18).tap { |vbox|
57
+ HBox.new(false, 12).tap { |hbox|
58
+ font_button = FontButton.new.tap { |font_button|
59
+ font_button.font_name = @settings['font']
60
+ }
61
+ font_button.signal_connect('font-set') {
62
+ @settings['font'] = super_window.font_name = font_button.font_name
63
+ }
64
+ color_hbox = HBox.new(true, 0).tap { |color_hbox|
65
+ color_button1 = ColorButton.new.tap { |b|
66
+ b.color = super_window.text_color
67
+ b.signal_connect('color-set') {
68
+ super_window.text_color = b.color
69
+ @settings['text-color'] = Color::pango_triple(b.color)
70
+ }
71
+ }
72
+ color_button2 = ColorButton.new.tap { |b|
73
+ b.color = super_window.shadow_color
74
+ b.signal_connect('color-set') {
75
+ super_window.shadow_color = b.color
76
+ @settings['shadow-color'] = Color::pango_triple(b.color)
77
+ }
78
+ }
79
+ color_hbox.pack_start(color_button1, false)
80
+ color_hbox.pack_start(color_button2, false)
81
+ }
82
+
83
+ toggle_button = ToggleButton.new("字幕操作")
84
+ toggle_button.active = super_window.interactive?
85
+ toggle_button.modify_bg(Gtk::STATE_ACTIVE, Color::gdk_color([0, 1.0, 0]))
86
+ toggle_button.signal_connect('toggled') {
87
+ toggle_button.active =
88
+ super_window.interactive = !super_window.interactive?
89
+ }
90
+
91
+ hbox.pack_start(font_button, false)
92
+ hbox.pack_start(color_hbox, false)
93
+ hbox.pack_start(toggle_button, false)
94
+
95
+ vbox.pack_start(hbox, false)
96
+ }
97
+
98
+ text_view = TextView.new
99
+ text_view.wrap_mode = TextTag::WRAP_WORD_CHAR
100
+ text_view.buffer.signal_connect('changed') {
101
+ @settings['text'] = super_window.text = text_view.buffer.text
102
+ }
103
+ ScrolledWindow.new.tap { |sw|
104
+ sw.hscrollbar_policy = POLICY_AUTOMATIC
105
+ sw.vscrollbar_policy = POLICY_AUTOMATIC
106
+ text_view.buffer.text = @settings['text']
107
+
108
+ sw.add(text_view)
109
+ vbox.pack_start(sw)
110
+ }
111
+
112
+ window.add(vbox)
113
+ }
114
+ }
115
+ end
116
+
117
+ def create_status_icon(popup_menu, super_window, main_window)
118
+ status_icon = StatusIcon.new
119
+ status_icon.title = "gsuper"
120
+ status_icon.tooltip = "gsuper"
121
+ status_icon.pixbuf = Gdk::Pixbuf.new(File.dirname(__FILE__) + '/images/icon.png')
122
+ status_icon.signal_connect("activate") {|s|
123
+ main_window.present
124
+ # p [:activate, @present]
125
+ }
126
+ status_icon.signal_connect('popup-menu') do |widget, button, time|
127
+ # p [:"popup-menu", widget, button, time]
128
+ popup_menu.popup(nil, nil, button, time)
129
+ end
130
+ status_icon.signal_connect('scroll-event') do |widget, event|
131
+ # p [:"scroll-event", widget, event]
132
+ end
133
+ return status_icon
134
+ end
135
+
136
+ def create_super_window
137
+ super_window = SuperWindow.new
138
+ super_window.text = @settings['text']
139
+ super_window.font_name = @settings['font']
140
+ super_window.text_color = Color::gdk_color @settings['text-color']
141
+ super_window.shadow_color = Color::gdk_color @settings['shadow-color']
142
+ super_window.resize(@settings['super-width'], @settings['super-height'])
143
+ super_window.move(@settings['super-x'], @settings['super-y'])
144
+ super_window.signal_connect('configure-event') do |_widget, config|
145
+ @settings['super-x'] = config.x
146
+ @settings['super-y'] = config.y
147
+ @settings['super-width'] = config.width
148
+ @settings['super-height'] = config.height
149
+ false
150
+ end
151
+ return super_window
152
+ end
153
+
154
+ def run
155
+ @present = true
156
+ @settings = Settings.load
157
+
158
+ at_exit {
159
+ # STDERR.puts "saving settings"
160
+ Settings.save(@settings)
161
+ }
162
+
163
+ @super_window = create_super_window
164
+ @super_window.show
165
+
166
+ @window = create_main_window(@super_window)
167
+ menu = create_popup_menu
168
+ @status_icon = create_status_icon(menu, @super_window, @window)
169
+
170
+ @window.show_all
171
+
172
+ Gtk.main
173
+ end
174
+
175
+ end
176
+
177
+ end
178
+
179
+ if __FILE__ == $0
180
+ GSuper::Program.new.run
181
+ end
182
+
@@ -0,0 +1,52 @@
1
+ require "toml"
2
+ require "fileutils"
3
+
4
+ module GSuper
5
+
6
+ module Settings
7
+ def default
8
+ {
9
+ "font" => "Sans Bold 24",
10
+ "super-x" => 0,
11
+ "super-y" => 0,
12
+ "super-width" => 640,
13
+ "super-height" => 480,
14
+ "text" => "",
15
+ "text-color" => [1.0, 0.5, 0.0],
16
+ "shadow-color" => [0.0, 0.0, 1.0],
17
+ }
18
+ end
19
+ module_function :default
20
+
21
+ def filepath
22
+ ENV['HOME'] + '/.config/gsuper/settings.tml'
23
+ end
24
+ module_function :filepath
25
+
26
+ def load
27
+ begin
28
+ user = TOML.load_file(filepath)
29
+ rescue Errno::ENOENT
30
+ # 設定ファイルが見付からないが、別に構わない
31
+ user = {}
32
+ rescue TOML::ParseError => e
33
+ STDERR.puts "Error: corrupt settings file, ignoring"
34
+ STDERR.puts e
35
+ user = {}
36
+ end
37
+ return default.merge(user)
38
+ end
39
+ module_function :load
40
+
41
+ def save(settings)
42
+ difference = (settings.to_a - default.to_a).to_h
43
+ toml = TOML.dump(difference)
44
+ FileUtils.mkdir_p(File.dirname(filepath))
45
+ File.open(filepath, "w") do |f|
46
+ f.write(toml)
47
+ end
48
+ end
49
+ module_function :save
50
+ end
51
+
52
+ end
@@ -0,0 +1,242 @@
1
+ require 'gsuper/color'
2
+
3
+ module GSuper
4
+
5
+ # 字幕ウィンドウを表わすクラス。
6
+ class SuperWindow < Gtk::Window
7
+ include Color
8
+ BACKGROUND_COLOR = Color::gdk_color([0.0, 1.0, 0.0])
9
+ BACKGROUND_ALPHA = 0.5
10
+
11
+ attr_reader :font_name, :text_color, :shadow_color, :text
12
+
13
+ def initialize
14
+ super()
15
+
16
+ @font_name = 'Sans Bold 24'
17
+ @text_color = Color::gdk_color([1.0, 0.5, 0.0])
18
+ @shadow_color = Color::gdk_color([0.0, 0.0, 1.0])
19
+ @text = ""
20
+
21
+ @interactive = true
22
+
23
+ self.app_paintable = true
24
+
25
+ signal_connect('expose-event') do
26
+ if @interactive
27
+ exposed_interactive
28
+ else
29
+ exposed_noninteractive
30
+ end
31
+ end
32
+
33
+ self.events = Gdk::Event::BUTTON_PRESS_MASK |
34
+ Gdk::Event::BUTTON_RELEASE_MASK |
35
+ Gdk::Event::POINTER_MOTION_MASK
36
+
37
+ signal_connect('screen-changed') do
38
+ screen_changed
39
+ end
40
+
41
+ signal_connect('configure-event') do
42
+ # p :configure
43
+ invalidate
44
+ set_responsive(interactive?)
45
+ # exposeを誘発するためにfalseを返す
46
+ false
47
+ end
48
+
49
+ button_pressed = false
50
+ press_point = nil
51
+ move = nil
52
+ signal_connect('button-press-event') do |_, ev_button|
53
+ button_pressed = true
54
+ w, h = size
55
+ if ev_button.x.between?(w - 30, w - 1) &&
56
+ ev_button.y.between?(h - 30, h - 1)
57
+ move = false
58
+ press_point = [(w - ev_button.x), (h - ev_button.y)]
59
+ else
60
+ move = true
61
+ press_point = [ev_button.x, ev_button.y]
62
+ end
63
+ # p :press
64
+ end
65
+
66
+ signal_connect('button-release-event') do
67
+ button_pressed = false
68
+ press_point = nil
69
+ move = nil
70
+ # p :release
71
+ end
72
+
73
+ signal_connect('motion-notify-event') do |_, ev_motion|
74
+ if interactive? && button_pressed
75
+ if move
76
+ move(ev_motion.x_root - press_point[0], ev_motion.y_root - press_point[1])
77
+ else
78
+ w = ev_motion.x + press_point[0]
79
+ h = ev_motion.y + press_point[1]
80
+ resize([w, 100].max, [h, 100].max)
81
+ # invalidate
82
+ # set_responsive(true)
83
+ end
84
+ end
85
+ # p :pointer_motion
86
+ end
87
+
88
+ # self.decorated = false
89
+
90
+ self.set_default_size(640,480)
91
+
92
+ @alpha_supported = false
93
+ screen_changed
94
+
95
+ # GDK window を作る。
96
+ realize
97
+
98
+ window.override_redirect = true
99
+ set_responsive(true)
100
+ end
101
+
102
+ def font_name=(font)
103
+ @font_name = font
104
+ invalidate
105
+ end
106
+
107
+ def text_color=(color)
108
+ raise TypeError unless color.is_a? Gdk::Color
109
+ @text_color = color
110
+ invalidate
111
+ end
112
+
113
+ def shadow_color=(color)
114
+ raise TypeError unless color.is_a? Gdk::Color
115
+ @shadow_color = color
116
+ invalidate
117
+ end
118
+
119
+ def text=(str)
120
+ @text = str
121
+ invalidate
122
+ end
123
+
124
+ def exposed_interactive
125
+ cr = window.create_cairo_context
126
+
127
+ if @alpha_supported
128
+ cr.set_source_rgba(*pango_triple(BACKGROUND_COLOR), BACKGROUND_ALPHA)
129
+ else
130
+ cr.set_source_rgb(*pango_triple(BACKGROUND_COLOR))
131
+ end
132
+
133
+ cr.set_operator(Cairo::OPERATOR_SOURCE)
134
+ cr.paint
135
+
136
+ draw_text(cr)
137
+
138
+ cr.set_source_rgb(0.5, 0.5, 0.5)
139
+ w, h = size
140
+ cr.fill do
141
+ cr.rectangle(w - 30, h - 3, w, h)
142
+ cr.rectangle(w - 3, h - 30, w, h)
143
+ end
144
+
145
+ cr.destroy
146
+
147
+ return false
148
+ end
149
+
150
+ def exposed_noninteractive
151
+ cr = window.create_cairo_context
152
+
153
+ if @alpha_supported
154
+ cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
155
+ else
156
+ cr.set_source_rgb(0.0, 0.0, 0.0)
157
+ end
158
+
159
+ cr.set_operator(Cairo::OPERATOR_SOURCE)
160
+ cr.paint
161
+
162
+ draw_text(cr)
163
+
164
+ cr.destroy
165
+
166
+ return false
167
+ end
168
+
169
+ def draw_text(cr)
170
+ # p [:draw_text, font_name]
171
+ desc = Pango::FontDescription.new(font_name)
172
+
173
+ layout = create_pango_layout
174
+ layout.width = size[0] * Pango::SCALE
175
+ layout.font_description = desc
176
+ layout.text = text
177
+
178
+ offset = shadow_offset(desc)
179
+
180
+ cr.move_to(offset, offset)
181
+ cr.set_source_rgba(*pango_triple(@shadow_color), 1.0)
182
+ cr.show_pango_layout(layout)
183
+
184
+ cr.move_to(0, 0)
185
+ cr.set_source_rgba(*pango_triple(@text_color), 1.0)
186
+ cr.show_pango_layout(layout)
187
+ end
188
+
189
+ # 右下に二度打ちで「影」を落とす。そのオフセットは線の太さの半分にし
190
+ # たいとする。
191
+ def shadow_offset(desc)
192
+ raise TypeError unless desc.is_a? Pango::FontDescription
193
+ dpi = window.screen.resolution
194
+
195
+ font_px = pt_to_px(desc.size.fdiv(Pango::SCALE), dpi)
196
+ return ( font_px * (1/12.0) * (desc.weight.to_i / 400.0) * (1/3.0) ).round
197
+ end
198
+
199
+ def pt_to_px(point, dpi)
200
+ point / 72.0 * dpi
201
+ end
202
+
203
+ def interactive?
204
+ @interactive
205
+ end
206
+
207
+ def interactive=(flag)
208
+ @interactive = flag
209
+ set_responsive(flag)
210
+ invalidate
211
+ end
212
+
213
+ def set_responsive(responsive)
214
+ if responsive
215
+ width, height = size
216
+ region = Gdk::Region.new(Gdk::Rectangle.new(0, 0, width, height))
217
+ else
218
+ region = Gdk::Region.new(Gdk::Rectangle.new(0, 0, 0, 0))
219
+ end
220
+ window.input_shape_combine_region(region, 0, 0)
221
+ end
222
+
223
+ def invalidate
224
+ window.invalidate(window.clip_region, true)
225
+ window.process_updates(true)
226
+ end
227
+
228
+ def screen_changed
229
+ colormap = self.screen.rgba_colormap
230
+ if colormap
231
+ # puts 'alpha channel supported'
232
+ @alpha_supported = true
233
+ self.colormap = colormap
234
+ else
235
+ STDERR.puts 'Warning: alpha channel NOT supported'
236
+ @alpha_supported = false
237
+ self.colormap = self.screen.rgb_colormap
238
+ end
239
+ end
240
+ end
241
+
242
+ end
@@ -0,0 +1,3 @@
1
+ module GSuper
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gsuper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoteichi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gtk2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: toml-rb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.12
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.12
83
+ description: program superimpose text on screen
84
+ email:
85
+ - plonk@piano.email.ne.jp
86
+ executables:
87
+ - gsuper
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/gsuper
101
+ - gsuper.gemspec
102
+ - lib/gsuper.rb
103
+ - lib/gsuper/color.rb
104
+ - lib/gsuper/images/icon.png
105
+ - lib/gsuper/program.rb
106
+ - lib/gsuper/settings.rb
107
+ - lib/gsuper/super_window.rb
108
+ - lib/gsuper/version.rb
109
+ homepage: https://github.com/plonk/gsuper/
110
+ licenses:
111
+ - GPL-2
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: program to superimpose text on screen
133
+ test_files: []