Ruby GTK3移行後のメインリポジトリ
Revision | 151a0572fd896a9b542fbbc8771c712b3284672c (tree) |
---|---|
Zeit | 2014-05-01 23:52:11 |
Autor | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
add kinoko.rb
@@ -0,0 +1,599 @@ | ||
1 | +# -*- coding: utf-8 -*- | |
2 | +# | |
3 | +# Copyright (C) 2004-2014 by Shyouzou Sugitani <shy@users.sourceforge.jp> | |
4 | +# | |
5 | +# This program is free software; you can redistribute it and/or modify it | |
6 | +# under the terms of the GNU General Public License (version 2) as | |
7 | +# published by the Free Software Foundation. It is distributed in the | |
8 | +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | |
9 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
10 | +# PURPOSE. See the GNU General Public License for more details. | |
11 | +# | |
12 | + | |
13 | +# TODO: | |
14 | +# - きのことサーフェスの間に他のウインドウが入ることができてしまうのを直す. | |
15 | +# - NAYUKI/2.0 | |
16 | +# - 透明度の設定 | |
17 | + | |
18 | +require 'gettext' | |
19 | +require "gtk3" | |
20 | + | |
21 | +require "ninix/config" | |
22 | +require "ninix/seriko" | |
23 | +require "ninix/pix" | |
24 | + | |
25 | +module Kinoko | |
26 | + | |
27 | + class Menu | |
28 | + include GetText | |
29 | + | |
30 | + bindtextdomain("ninix-aya") | |
31 | + | |
32 | + def initialize(accelgroup) | |
33 | + @parent = nil | |
34 | + ui_info = <<-EOS | |
35 | + <ui> | |
36 | + <popup name='popup'> | |
37 | + <menuitem action='Settings'/> | |
38 | + <menu action='Skin'> | |
39 | + </menu> | |
40 | + <separator/> | |
41 | + <menuitem action='Exit'/> | |
42 | + </popup> | |
43 | + </ui> | |
44 | + EOS | |
45 | + @__menu_list = { | |
46 | + 'settings' => [['Settings', nil, _('Settings...(_O)'), nil, | |
47 | + '', lambda {|a, b| return @parent.handle_request('NOTIFY', 'edit_preferences')}], | |
48 | + '/ui/popup/Settings'], | |
49 | + 'skin' => [['Skin', nil, _('Skin(_K)'), nil], | |
50 | + nil, '/ui/popup/Skin'], | |
51 | + 'exit' => [['Exit', nil, _('Exit(_Q)'), nil, | |
52 | + '', lambda {|a, b| return @parent.handle_request('NOTIFY', 'close')}], | |
53 | + '/ui/popup/Exit'], | |
54 | + } | |
55 | + @__skin_list = nil | |
56 | + actions = Gtk::ActionGroup.new('Actions') | |
57 | + entry = [] | |
58 | + for value in @__menu_list.values() | |
59 | + entry << value[0] | |
60 | + end | |
61 | + actions.add_actions(entry) | |
62 | + ui_manager = Gtk::UIManager.new() | |
63 | + ui_manager.insert_action_group(actions, 0) | |
64 | + ui_manager.add_ui(ui_info) | |
65 | + @__popup_menu = ui_manager.get_widget('/ui/popup') | |
66 | + for key in @__menu_list.keys | |
67 | + path = @__menu_list[key][-1] | |
68 | + @__menu_list[key][1] = ui_manager.get_widget(path) | |
69 | + end | |
70 | + end | |
71 | + | |
72 | + def set_responsible(parent) | |
73 | + @parent = parent | |
74 | + end | |
75 | + | |
76 | + def popup(button) | |
77 | + skin_list = @parent.handle_request('GET', 'get_skin_list') | |
78 | + set_skin_menu(skin_list) | |
79 | + @__popup_menu.popup(nil, nil, button, Gtk.current_event_time()) | |
80 | + end | |
81 | + | |
82 | + def set_skin_menu(list) ## FIXME | |
83 | + key = 'skin' | |
84 | + if list | |
85 | + menu = Gtk.Menu() | |
86 | + for skin in list | |
87 | + item = Gtk.MenuItem(skin['title']) | |
88 | + item.signal_connect( | |
89 | + 'activate', | |
90 | + lambda {|a, k| return @parent.handle_request('NOTIFY', 'select_skin', k)}, | |
91 | + [skin]) | |
92 | + menu.add(item) | |
93 | + item.show() | |
94 | + end | |
95 | + @__menu_list[key][1].set_submenu(menu) | |
96 | + menu.show() | |
97 | + @__menu_list[key][1].show() | |
98 | + else | |
99 | + @__menu_list[key][1].hide() | |
100 | + end | |
101 | + end | |
102 | + end | |
103 | + | |
104 | + class Nayuki | |
105 | + | |
106 | + def initialize() | |
107 | + end | |
108 | + end | |
109 | + | |
110 | + class Kinoko | |
111 | + | |
112 | + def initialize(skin_list) | |
113 | + @skin_list = skin_list | |
114 | + @skin = nil | |
115 | + end | |
116 | + | |
117 | + def edit_preferences() | |
118 | + end | |
119 | + | |
120 | + def finalize() | |
121 | + @__running = false | |
122 | + self.target.detach_observer(self) | |
123 | + if self.skin != nil | |
124 | + self.skin.destroy() | |
125 | + end | |
126 | + end | |
127 | + | |
128 | + def observer_update(event, args) | |
129 | + if self.skin == nil | |
130 | + return | |
131 | + end | |
132 | + if ['set position', 'set surface'].include?(event) | |
133 | + self.skin.set_position() | |
134 | + self.skin.show() | |
135 | + elsif event == 'set scale' | |
136 | + scale = self.target.get_surface_scale() | |
137 | + self.skin.set_scale(scale) | |
138 | + elsif event == 'hide' | |
139 | + side = args | |
140 | + if side == 0 # sakura side | |
141 | + self.skin.hide() | |
142 | + end | |
143 | + elsif event == 'iconified' | |
144 | + self.skin.hide() | |
145 | + elsif event == 'deiconified' | |
146 | + self.skin.show() | |
147 | + elsif event == 'finalize' | |
148 | + self.finalize() | |
149 | + elsif event == 'move surface' | |
150 | + side, xoffset, yoffset = args | |
151 | + if side == 0 # sakura side | |
152 | + self.skin.set_position(xoffset, yoffset) | |
153 | + end | |
154 | + elsif event == 'raise' | |
155 | + side = args | |
156 | + if side == 0 # sakura side | |
157 | + self.skin.set_position() ## FIXME | |
158 | + end | |
159 | + else | |
160 | + ##logging.debug('OBSERVER(kinoko): ignore - {0}'.format(event)) | |
161 | + end | |
162 | + end | |
163 | + | |
164 | + def load_skin() | |
165 | + scale = @target.get_surface_scale() | |
166 | + @skin = Skin.new(@accelgroup) | |
167 | + @skin.set_responsible(@target) | |
168 | + @skin.load(@data, scale) | |
169 | + print("SKIN: ", @skin, "\n") | |
170 | + end | |
171 | + | |
172 | + def handle_request(event_type, event, *arglist, **argdict) | |
173 | + #assert ['GET', 'NOTIFY'].include?(event_type) | |
174 | + handlers = { | |
175 | + 'get_target_window' => lambda {|a| return self.target.surface.window[0].window}, # XXX | |
176 | + 'get_kinoko_position' => self.target.get_kinoko_position, | |
177 | + } | |
178 | + handler = handlers.get(event, | |
179 | + getattr(self, event, | |
180 | + lambda {|a| return nil})) ## FIXME | |
181 | + result = handler(*arglist, **argdict) | |
182 | + if event_type == 'GET' | |
183 | + return result | |
184 | + end | |
185 | + end | |
186 | + | |
187 | + def load(data, target) | |
188 | + @data = data | |
189 | + @target = target | |
190 | + @target.attach_observer(self) | |
191 | + @accelgroup = Gtk::AccelGroup.new() | |
192 | + load_skin() | |
193 | + if @skin == nil | |
194 | + return 0 | |
195 | + else | |
196 | + self.send_event('OnKinokoObjectCreate') | |
197 | + end | |
198 | + @__running = true | |
199 | + GLib::Timeout.add(10) { do_idle_tasks } # 10[ms] | |
200 | + return 1 | |
201 | + end | |
202 | + | |
203 | + def do_idle_tasks() | |
204 | + if @__running | |
205 | + return true | |
206 | + else | |
207 | + return false | |
208 | + end | |
209 | + end | |
210 | + | |
211 | + def close() | |
212 | + self.finalize() | |
213 | + self.send_event('OnKinokoObjectDestroy') | |
214 | + end | |
215 | + | |
216 | + def send_event(event) | |
217 | + if not ['OnKinokoObjectCreate', 'OnKinokoObjectDestroy', | |
218 | + 'OnKinokoObjectChanging', 'OnKinokoObjectChanged', | |
219 | + 'OnKinokoObjectInstalled'].include?(event) | |
220 | + ## 'OnBatteryLow', 'OnBatteryCritical', | |
221 | + ## 'OnSysResourceLow', 'OnSysResourceCritical' | |
222 | + return | |
223 | + end | |
224 | + args = [@data['title'], | |
225 | + @data['ghost'], | |
226 | + @data['category']] | |
227 | + @target.notify_event(event, *args) | |
228 | + end | |
229 | + | |
230 | + def get_skin_list() | |
231 | + return @skin_list | |
232 | + end | |
233 | + | |
234 | + def select_skin(args) | |
235 | + self.send_event('OnKinokoObjectChanging') | |
236 | + self.skin.destroy() | |
237 | + self.data = args | |
238 | + self.load_skin() | |
239 | + if self.skin == nil | |
240 | + return 0 | |
241 | + else | |
242 | + self.send_event('OnKinokoObjectChanged') | |
243 | + end | |
244 | + return 1 | |
245 | + end | |
246 | + end | |
247 | + | |
248 | + class Skin | |
249 | + | |
250 | + def initialize(accelgroup) | |
251 | + @frame_buffer = [] | |
252 | + @accelgroup = accelgroup | |
253 | + @parent = nil | |
254 | + @__menu = Menu.new(@accelgroup) | |
255 | + @__menu.set_responsible(self) | |
256 | + end | |
257 | + | |
258 | + def get_seriko | |
259 | + return @seriko | |
260 | + end | |
261 | + | |
262 | + def set_responsible(parent) | |
263 | + @parent = parent | |
264 | + end | |
265 | + | |
266 | + def handle_request(event_type, event, *arglist, **argdict) | |
267 | + #assert ['GET', 'NOTIFY'].include?(event_type) | |
268 | + handlers = { | |
269 | + } | |
270 | +# handler = handlers.get(event, getattr(self, event, nil)) | |
271 | +# if handler == nil | |
272 | + if not handlers.include?(event) | |
273 | + result = @parent.handle_request(event_type, event, *arglist, **argdict) | |
274 | + else | |
275 | +# result = handler(*arglist, **argdict) | |
276 | + ## FIXME | |
277 | + result = class_eval(event) #( *arglist, **argdict) | |
278 | + end | |
279 | + if event_type == 'GET' | |
280 | + return result | |
281 | + end | |
282 | + end | |
283 | + | |
284 | + def load(data, scale) | |
285 | + @data = data | |
286 | + @__scale = scale | |
287 | + @__shown = false | |
288 | + @surface_id = 0 # dummy | |
289 | + @window = Pix::TransparentWindow.new() | |
290 | + ##self.window.set_title(''.join(('surface.', name))) | |
291 | + @window.set_skip_taskbar_hint(true) | |
292 | + @window.signal_connect('delete_event') do |w, e| | |
293 | + delete(w, e) | |
294 | + end | |
295 | + @window.add_accel_group(@accelgroup) ## FIXME | |
296 | + if @data['animation'] != nil | |
297 | + path = File.join(@data['dir'], @data['animation']) | |
298 | + actors = {'' => Seriko.get_actors(NConfig.create_from_file(path))} | |
299 | + else | |
300 | + base = File.basename(@data['base'], ".*") | |
301 | + ext = File.extname(@data['base']) | |
302 | + path = File.join(@data['dir'], base + 'a.txt') | |
303 | + if File.exists?(path) | |
304 | + actors = {'' => Seriko.get_actors(NConfig.create_from_file(path))} | |
305 | + else | |
306 | + actors = {'' => []} | |
307 | + end | |
308 | + end | |
309 | + print("ACTORS: ", actors, "\n") | |
310 | + @seriko = Seriko::Controler.new(actors) | |
311 | + @seriko.set_responsible(self) ## FIXME | |
312 | + path = File.join(@data['dir'], @data['base']) | |
313 | + print("PATH: ", path, "\n") | |
314 | + begin | |
315 | + @image_surface = Pix.create_surface_from_file(path) | |
316 | + w = [8, (@image_surface.width * @__scale / 100).to_i].max | |
317 | + h = [8, (@image_surface.height * @__scale / 100).to_i].max | |
318 | + rescue #except: ## FIXME | |
319 | + @parent.handle_request('NOTIFY', 'close') | |
320 | + return | |
321 | + end | |
322 | + print("SURFACE: ", w, " , ", h, "\n") | |
323 | + @path = path | |
324 | + @w, @h = w, h | |
325 | + @darea = @window.darea # @window.get_child() | |
326 | + @darea.set_events(Gdk::Event::EXPOSURE_MASK| | |
327 | + Gdk::Event::BUTTON_PRESS_MASK| | |
328 | + Gdk::Event::BUTTON_RELEASE_MASK| | |
329 | + Gdk::Event::POINTER_MOTION_MASK| | |
330 | + Gdk::Event::LEAVE_NOTIFY_MASK) | |
331 | + @darea.signal_connect('button_press_event') do |w, e| | |
332 | + button_press(w, e) | |
333 | + end | |
334 | + @darea.signal_connect('button_release_event') do |w, e| | |
335 | + button_release(w, e) | |
336 | + end | |
337 | + @darea.signal_connect('motion_notify_event') do |w, e| | |
338 | + motion_notify(w, e) | |
339 | + end | |
340 | + @darea.signal_connect('leave_notify_event') do |w, e| | |
341 | + leave_notify(w, e) | |
342 | + end | |
343 | + @darea.signal_connect('draw') do |w, cr| | |
344 | + redraw(w, cr) | |
345 | + end | |
346 | + @window.update_size(@w, @h) | |
347 | + set_position() | |
348 | + target_window = @parent.handle_request('GET', 'get_target_window') | |
349 | + if @data['ontop'] | |
350 | + @window.set_transient_for(target_window) | |
351 | + else | |
352 | + target_window.set_transient_for(@window) | |
353 | + end | |
354 | + show() | |
355 | + @seriko.reset(self, '') # XXX | |
356 | + @seriko.start(self) | |
357 | + @seriko.invoke_kinoko(self) | |
358 | + end | |
359 | + | |
360 | + def get_surface_id ## FIXME | |
361 | + return @surface_id | |
362 | + end | |
363 | + | |
364 | + def get_preference(name) # dummy | |
365 | + if name == 'animation_quality' | |
366 | + return 1.0 | |
367 | + else | |
368 | + return nil | |
369 | + end | |
370 | + end | |
371 | + | |
372 | + def show() | |
373 | + if not @__shown | |
374 | + @window.show_all() | |
375 | + @__shown = true | |
376 | + end | |
377 | + end | |
378 | + | |
379 | + def hide() | |
380 | + if @__shown | |
381 | + @window.hide_all() | |
382 | + @__shown = false | |
383 | + end | |
384 | + end | |
385 | + | |
386 | + def append_actor(frame, actor) | |
387 | + @seriko.append_actor(frame, actor) | |
388 | + end | |
389 | + | |
390 | + def set_position(xoffset=0, yoffset=0) | |
391 | + base_x, base_y = @parent.handle_request('GET', 'get_kinoko_position', @data['baseposition']) | |
392 | + a, b = [[0.5, 1], [0.5, 0], [0, 0.5], [1, 0.5], [0, 1], | |
393 | + [1, 1], [0, 0], [1, 0], [0.5, 0.5]][@data['baseadjust']] | |
394 | + offsetx = (@data['offsetx'] * @__scale / 100).to_i | |
395 | + offsety = (@data['offsety'] * @__scale / 100).to_i | |
396 | + @x = base_x - (@w * a).to_i + offsetx + xoffset | |
397 | + @y = base_y - (@h * b).to_i + offsety + yoffset | |
398 | + @window.move(@x, @y) | |
399 | + end | |
400 | + | |
401 | + def set_scale(scale) | |
402 | + @__scale = scale | |
403 | + reset_surface() | |
404 | + set_position() | |
405 | + end | |
406 | + | |
407 | + def get_surface() ## FIXME | |
408 | + return nil | |
409 | + end | |
410 | + | |
411 | + def redraw(widget, cr) | |
412 | + scale = @__scale | |
413 | + cr.scale(scale / 100.0, scale / 100.0) | |
414 | + cr.set_source(@image_surface, 0, 0) | |
415 | + cr.set_operator(Cairo::OPERATOR_SOURCE) | |
416 | + cr.paint() | |
417 | + print("REDRAW: ", cr, "\n") | |
418 | + end | |
419 | + | |
420 | + def get_image_surface(surface_id) | |
421 | + path = File.join(@data['dir'], | |
422 | + 'surface'+ surface_id.to_s + '.png') | |
423 | + if File.exists?(path) | |
424 | + surface = Pix.create_surface_from_file(path) | |
425 | + else | |
426 | + surface = nil | |
427 | + end | |
428 | + return surface | |
429 | + end | |
430 | + | |
431 | + def create_image_surface(surface_id) | |
432 | + if surface_id != nil and surface_id != '' | |
433 | + surface = get_image_surface(surface_id) | |
434 | + else | |
435 | + surface = Pix.create_surface_from_file(@path) | |
436 | + end | |
437 | + return surface | |
438 | + end | |
439 | + | |
440 | + def update_frame_buffer() | |
441 | + print("UPDATE FRAME: ", @seriko.get_base_id, "\n") | |
442 | + new_surface = create_image_surface(@seriko.get_base_id) | |
443 | + #assert new_surface != nil | |
444 | + # draw overlays | |
445 | + for surface_id, x, y, method in @seriko.iter_overlays() | |
446 | + print("OVERLAY: ", surface_id, x, y, method, "\n") | |
447 | + if 1#begin | |
448 | + overlay_surface = get_image_surface(surface_id) | |
449 | + else#rescue #except: | |
450 | + continue | |
451 | + end | |
452 | + # overlay surface | |
453 | + cr = Cairo::Context.new(new_surface) | |
454 | + cr.set_source(overlay_surface, x, y) | |
455 | + cr.mask(overlay_surface, x, y) | |
456 | + #del cr | |
457 | + end | |
458 | + #self.darea.queue_draw_area(0, 0, w, h) | |
459 | + @image_surface = new_surface | |
460 | + @darea.queue_draw() | |
461 | + end | |
462 | + | |
463 | + def terminate() | |
464 | + @seriko.terminate(self) | |
465 | + end | |
466 | + | |
467 | + def add_overlay(actor, surface_id, x, y, method) | |
468 | + @seriko.add_overlay(self, actor, surface_id, x, y, method) | |
469 | + end | |
470 | + | |
471 | + def remove_overlay(actor) | |
472 | + @seriko.remove_overlay(actor) | |
473 | + end | |
474 | + | |
475 | + def move_surface(xoffset, yoffset) | |
476 | + @window.move(@x + xoffset, @y + yoffset) | |
477 | + end | |
478 | + | |
479 | + def reset_surface() ## FIXME | |
480 | + @seriko.reset(self, '') # XXX | |
481 | + path = os.path.join(os.fsencode(@data['dir']), | |
482 | + os.fsencode(@data['base'])) | |
483 | + w, h = ninix.pix.get_png_size(path) | |
484 | + w = [8, (w * @__scale / 100).to_i].max | |
485 | + h = [8, (h * @__scale / 100).to_i].max | |
486 | + @w, @h = w, h # XXX | |
487 | + @window.update_size(w, h) | |
488 | + @window.queue_resize() | |
489 | + @seriko.start(self) | |
490 | + @seriko.invoke_kinoko(self) | |
491 | + end | |
492 | + | |
493 | + def set_surface(surface_id, restart=1) ## FIXME | |
494 | + path = os.path.join(os.fsencode(@data['dir']), | |
495 | + 'surface' + os.fsencode(str(surface_id)) + '.png') | |
496 | + if os.path.exists(path) | |
497 | + @path = path | |
498 | + else | |
499 | + #self.path = None | |
500 | + @path = File.join(@data['dir'], @data['base']) | |
501 | + end | |
502 | + end | |
503 | + | |
504 | + def invoke(actor_id, update=0) | |
505 | + @seriko.invoke(self, actor_id, update) | |
506 | + end | |
507 | + | |
508 | + def delete() #widget, event) | |
509 | + @parent.handle_request('NOTIFY', 'close') | |
510 | + end | |
511 | + | |
512 | + def destroy() | |
513 | + @seriko.destroy() | |
514 | + @window.destroy() | |
515 | + end | |
516 | + | |
517 | + def button_press(widget, event) ## FIXME | |
518 | + @x_root = event.x_root | |
519 | + @y_root = event.y_root | |
520 | + if event.event_type == Gdk::Event::BUTTON_PRESS | |
521 | + click = 1 | |
522 | + else | |
523 | + click = 2 | |
524 | + end | |
525 | + button = event.button | |
526 | + if button == 3 and click == 1 | |
527 | + @__menu.popup(button) | |
528 | + end | |
529 | + return true | |
530 | + end | |
531 | + | |
532 | + def button_release(widget, event) ## FIXME | |
533 | + end | |
534 | + | |
535 | + def motion_notify(widget, event) ## FIXME | |
536 | + end | |
537 | + | |
538 | + def leave_notify(widget, event) ## FIXME | |
539 | + end | |
540 | + end | |
541 | + | |
542 | + class TEST | |
543 | + | |
544 | + def initialize(path) | |
545 | + @win = Pix::TransparentWindow.new | |
546 | + @win.signal_connect('destroy') do | |
547 | + Gtk.main_quit | |
548 | + end | |
549 | + @win.darea.signal_connect('draw') do |w, cr| | |
550 | + expose_cb(w, cr) | |
551 | + end | |
552 | + @surface = Pix.create_surface_from_file(path, true, true) | |
553 | + @win.set_default_size(@surface.width, @surface.height) | |
554 | + @win.show_all | |
555 | + require "ninix/home" | |
556 | + kinoko_list = Home.search_kinoko() | |
557 | + kinoko = Kinoko.new(kinoko_list) | |
558 | + print("K: ", kinoko, "\n") | |
559 | + kinoko.load(kinoko_list.sample, self) | |
560 | + Gtk.main | |
561 | + end | |
562 | + | |
563 | + def notify_event(event, *args) # dummy | |
564 | + end | |
565 | + | |
566 | + def handle_request(type, event, *a) # dummy | |
567 | + if event == 'get_kinoko_position' | |
568 | + return 0, 0 | |
569 | + end | |
570 | + end | |
571 | + | |
572 | + def attach_observer(arg) # dummy | |
573 | + end | |
574 | + | |
575 | + def get_surface_scale() # dummy | |
576 | + return 100 | |
577 | + end | |
578 | + | |
579 | + def expose_cb(widget, cr) | |
580 | + cr.set_source(@surface, 0, 0) | |
581 | + cr.set_operator(Cairo::OPERATOR_SOURCE) | |
582 | + cr.paint | |
583 | + region = Cairo::Region.new() | |
584 | + data = @surface.data | |
585 | + for i in 0..(data.size / 4 - 1) | |
586 | + if (data[i * 4 + 3].ord) != 0 | |
587 | + x = i % @surface.width | |
588 | + y = i / @surface.width | |
589 | + region.union!(x, y, 1, 1) | |
590 | + end | |
591 | + end | |
592 | + @win.input_shape_combine_region(region) | |
593 | + end | |
594 | + end | |
595 | +end | |
596 | + | |
597 | +$:.unshift(File.dirname(__FILE__)) | |
598 | + | |
599 | +Kinoko::TEST.new(ARGV.shift) |
@@ -83,9 +83,12 @@ module Pix | ||
83 | 83 | # ##self.input_shape_combine_region(region) |
84 | 84 | # _gtkhack.gtkwindow_set_input_shape(self, cr.get_target()) |
85 | 85 | |
86 | -# def update_size(self, w, h): | |
86 | + def update_size(w, h) | |
87 | 87 | # self.get_child().set_size_request(w, h) # XXX |
88 | 88 | # self.queue_resize() |
89 | + @darea.set_size_request(w, h) # XXX | |
90 | + queue_resize() | |
91 | + end | |
89 | 92 | |
90 | 93 | # def size_allocate(self, widget, event): |
91 | 94 | # new_x, new_y = self.__position |
@@ -22,13 +22,14 @@ module Seriko | ||
22 | 22 | |
23 | 23 | def initialize(seriko) |
24 | 24 | @seriko = seriko |
25 | - self.request_parent = lambda {|a| return nil} # dummy | |
25 | +# self.request_parent = lambda {|a| return nil} # dummy | |
26 | + @parent = nil | |
26 | 27 | @exclusive_actor = nil |
27 | 28 | @base_id = nil |
28 | 29 | @timeout_id = nil |
29 | 30 | reset_overlays() |
30 | 31 | @queue = [] |
31 | - @fps = Controler.DEFAULT_FPS | |
32 | + @fps = DEFAULT_FPS | |
32 | 33 | @next_tick = 0 |
33 | 34 | @prev_tick = 0 # XXX |
34 | 35 | @active = [] |
@@ -36,22 +37,27 @@ module Seriko | ||
36 | 37 | @dirty = true |
37 | 38 | end |
38 | 39 | |
39 | - def set_responsible(request_method) | |
40 | - self.request_parent = request_method | |
40 | + def set_responsible(parent) #(request_method) | |
41 | + ##self.request_parent = request_method | |
42 | + @parent = parent | |
41 | 43 | end |
42 | 44 | |
43 | 45 | def set_base_id(window, surface_id) |
44 | 46 | if surface_id == '-2' |
45 | 47 | terminate(window) |
46 | - @base_id = window.surface_id | |
48 | + @base_id = window.get_surface_id | |
47 | 49 | elsif surface_id == '-1' |
48 | - @base_id = window.surface_id | |
50 | + @base_id = window.get_surface_id | |
49 | 51 | else |
50 | 52 | @base_id = surface_id |
51 | 53 | end |
52 | 54 | @dirty = true |
53 | 55 | end |
54 | 56 | |
57 | + def get_base_id() | |
58 | + return @base_id | |
59 | + end | |
60 | + | |
55 | 61 | def move_surface(xoffset, yoffset) |
56 | 62 | @move = [xoffset, yoffset] |
57 | 63 | end |
@@ -68,7 +74,7 @@ module Seriko | ||
68 | 74 | last_actor = actor |
69 | 75 | frame, actor = get_actor_next(window) |
70 | 76 | end |
71 | - if last_actor != nil and last_actor.exclusive and \ | |
77 | + if last_actor != nil and last_actor.exclusive? and \ | |
72 | 78 | last_actor.terminate_flag and @exclusive_actor == nil # XXX |
73 | 79 | invoke_restart(window) |
74 | 80 | end |
@@ -76,18 +82,20 @@ module Seriko | ||
76 | 82 | |
77 | 83 | def get_actor_next(window) |
78 | 84 | if not @active.empty? |
79 | - @active.sort(key=lambda {|x| return x[0]}) | |
85 | + @active.sort {|x| x[0]} # (key=lambda {|x| return x[0]}) | |
80 | 86 | if @active[0][0] <= @next_tick |
81 | - return @active.pop(0) | |
87 | + return @active.shift | |
82 | 88 | end |
83 | 89 | end |
84 | 90 | return nil, nil |
85 | 91 | end |
86 | 92 | |
87 | 93 | def update(window) |
88 | - current_tick = GLib.get_monotonic_time() # [microsec] | |
89 | - quality = self.request_parent('GET', 'get_preference', 'animation_quality') | |
90 | - @fps = Controler.DEFAULT_FPS * quality | |
94 | + ##current_tick = GLib.get_monotonic_time() # [microsec] | |
95 | + ## FIXME: GLib.get_monotonic_time | |
96 | + current_tick = (Time.now.to_f * 1000000).to_i # [microsec] | |
97 | + quality = @parent.handle_request('GET', 'get_preference', 'animation_quality') | |
98 | + @fps = DEFAULT_FPS * quality | |
91 | 99 | if @prev_tick == 0 ## First time |
92 | 100 | delta_tick = 1000.0 / @fps # [msec] |
93 | 101 | else |
@@ -104,8 +112,7 @@ module Seriko | ||
104 | 112 | window.move_surface(*@move) |
105 | 113 | @move = nil |
106 | 114 | end |
107 | - @timeout_id = GLib.timeout_add((1000.0 / @fps).to_i, # [msec] | |
108 | - @update, window) | |
115 | + @timeout_id = GLib::Timeout.add((1000.0 / @fps).to_i) { update(window) } # [msec] | |
109 | 116 | return false |
110 | 117 | end |
111 | 118 |
@@ -131,7 +138,6 @@ module Seriko | ||
131 | 138 | begin |
132 | 139 | del @overlays[actor] |
133 | 140 | rescue # except KeyError: |
134 | - pass | |
135 | 141 | end |
136 | 142 | @dirty = true |
137 | 143 | end |
@@ -157,7 +163,7 @@ module Seriko | ||
157 | 163 | @queue << actor |
158 | 164 | return |
159 | 165 | end |
160 | - if actor.exclusive | |
166 | + if actor.exclusive? | |
161 | 167 | lock_exclusive(window, actor) |
162 | 168 | end |
163 | 169 | actor.invoke(window, @next_tick) |
@@ -261,11 +267,11 @@ module Seriko | ||
261 | 267 | terminate(window) |
262 | 268 | @next_tick = 0 |
263 | 269 | @prev_tick = 0 # XXX |
264 | - set_base_id(window, window.surface_id) | |
270 | + set_base_id(window, window.get_surface_id) | |
265 | 271 | if @seriko.include?(surface_id) |
266 | 272 | @base_id = surface_id |
267 | 273 | else |
268 | - @base_id = window.surface_id | |
274 | + @base_id = window.get_surface_id | |
269 | 275 | end |
270 | 276 | @dirty = true # XXX |
271 | 277 | end |
@@ -276,8 +282,7 @@ module Seriko | ||
276 | 282 | if @timeout_id != nil |
277 | 283 | GLib.source_remove(@timeout_id) |
278 | 284 | end |
279 | - @timeout_id = GLib.timeout_add((1000.0 / @fps).to_i, # [msec] | |
280 | - @update, window) | |
285 | + @timeout_id = GLib::Timeout.add((1000.0 / @fps).to_i) { update(window) } # [msec] | |
281 | 286 | end |
282 | 287 | |
283 | 288 | def terminate(window) |
@@ -311,7 +316,7 @@ module Seriko | ||
311 | 316 | end |
312 | 317 | |
313 | 318 | def iter_overlays() |
314 | - actors = list(@overlays.keys()) | |
319 | + actors = @overlays.keys() | |
315 | 320 | temp = [] |
316 | 321 | for actor in actors |
317 | 322 | temp << [actor.get_id(), actor] |
@@ -323,13 +328,16 @@ module Seriko | ||
323 | 328 | temp << actor |
324 | 329 | end |
325 | 330 | actors = temp |
331 | + result = [] | |
326 | 332 | for actor in actors |
327 | 333 | surface_id, x, y, method = @overlays[actor] |
328 | 334 | ##logging.debug( |
329 | 335 | ## 'actor={0:d}, id={1}, x={2:d}, y={3:d}'.format( |
330 | 336 | ## actor.get_id(), surface_id, x, y)) |
331 | - yield surface_id, x, y, method | |
337 | + #yield surface_id, x, y, method | |
338 | + result << [surface_id, x, y, method] | |
332 | 339 | end |
340 | + return result | |
333 | 341 | end |
334 | 342 | end |
335 | 343 |
@@ -343,7 +351,15 @@ module Seriko | ||
343 | 351 | @last_method = nil |
344 | 352 | @exclusive = 0 |
345 | 353 | @post_proc = nil |
346 | - @terminate_flag = 1 | |
354 | + @terminate_flag = true | |
355 | + end | |
356 | + | |
357 | + def exclusive? | |
358 | + if @exclusive != 0 | |
359 | + return true | |
360 | + else | |
361 | + return false | |
362 | + end | |
347 | 363 | end |
348 | 364 | |
349 | 365 | def set_post_proc(proc, args) |
@@ -372,18 +388,17 @@ module Seriko | ||
372 | 388 | end |
373 | 389 | |
374 | 390 | def invoke(window, base_frame) |
375 | - @terminate_flag = 0 | |
391 | + @terminate_flag = false | |
376 | 392 | end |
377 | 393 | |
378 | 394 | def update(window, base_frame) |
379 | 395 | if @terminate_flag |
380 | - return False | |
396 | + return false | |
381 | 397 | end |
382 | - pass | |
383 | 398 | end |
384 | 399 | |
385 | 400 | def terminate() |
386 | - @terminate_flag = 1 | |
401 | + @terminate_flag = true | |
387 | 402 | if @post_proc != nil |
388 | 403 | proc, args = @post_proc |
389 | 404 | @post_proc = nil |
@@ -405,23 +420,23 @@ module Seriko | ||
405 | 420 | 'interpolate', 'reduce', 'replace', 'asis'] |
406 | 421 | |
407 | 422 | def show_pattern(window, surface, method, args) |
408 | - if Actor.OVERLAY_SET.include?(@last_method) | |
423 | + if OVERLAY_SET.include?(@last_method) | |
409 | 424 | window.remove_overlay(self) |
410 | 425 | end |
411 | 426 | if method == 'move' |
412 | - window.seriko.move_surface(args[0], args[1]) ## FIXME | |
413 | - elsif Actor.OVERLAY_SET.include?(method) | |
427 | + window.get_seriko.move_surface(args[0], args[1]) ## FIXME | |
428 | + elsif OVERLAY_SET.include?(method) | |
414 | 429 | window.add_overlay(self, surface, args[0], args[1], method) |
415 | 430 | elsif method == 'base' |
416 | - window.seriko.set_base_id(window, surface) ## FIXME | |
431 | + window.get_seriko.set_base_id(window, surface) ## FIXME | |
417 | 432 | elsif method == 'start' |
418 | 433 | window.invoke(args[0], update=1) |
419 | 434 | elsif method == 'alternativestart' |
420 | 435 | window.invoke(args.sample, update=1) |
421 | 436 | elsif method == 'stop' |
422 | - window.seriko.stop_actor(args[0]) ## FIXME | |
437 | + window.get_seriko.stop_actor(args[0]) ## FIXME | |
423 | 438 | elsif method == 'alternativestop' |
424 | - window.seriko.stop_actor(args.sample) ## FIXME | |
439 | + window.get_seriko.stop_actor(args.sample) ## FIXME | |
425 | 440 | else |
426 | 441 | raise RuntimeError('should not reach here') |
427 | 442 | end |
@@ -440,14 +455,14 @@ module Seriko | ||
440 | 455 | |
441 | 456 | def invoke(window, base_frame) |
442 | 457 | terminate() |
443 | - @terminate_flag = 0 | |
458 | + @terminate_flag = false | |
444 | 459 | @pattern = 0 |
445 | 460 | update(window, base_frame) |
446 | 461 | end |
447 | 462 | |
448 | 463 | def update(window, base_frame) |
449 | 464 | if @terminate_flag |
450 | - return False | |
465 | + return false | |
451 | 466 | end |
452 | 467 | if @pattern == 0 |
453 | 468 | @surface_id = window.get_surface() |
@@ -459,7 +474,7 @@ module Seriko | ||
459 | 474 | end |
460 | 475 | show_pattern(window, surface, method, args) |
461 | 476 | window.append_actor(base_frame + interval, self) |
462 | - return False | |
477 | + return false | |
463 | 478 | end |
464 | 479 | end |
465 | 480 |
@@ -479,14 +494,14 @@ module Seriko | ||
479 | 494 | |
480 | 495 | def invoke(window, base_frame) |
481 | 496 | terminate() |
482 | - @terminate_flag = 0 | |
497 | + @terminate_flag = false | |
483 | 498 | reset() |
484 | 499 | window.append_actor(base_frame + @wait, self) |
485 | 500 | end |
486 | 501 | |
487 | 502 | def update(window, base_frame) |
488 | 503 | if @terminate_flag |
489 | - return False | |
504 | + return false | |
490 | 505 | end |
491 | 506 | if @pattern == 0 |
492 | 507 | @surface_id = window.get_surface() |
@@ -500,7 +515,7 @@ module Seriko | ||
500 | 515 | end |
501 | 516 | show_pattern(window, surface, method, args) |
502 | 517 | window.append_actor(base_frame + @wait, self) |
503 | - return False | |
518 | + return false | |
504 | 519 | end |
505 | 520 | end |
506 | 521 |
@@ -515,7 +530,7 @@ module Seriko | ||
515 | 530 | |
516 | 531 | def invoke(window, base_frame) |
517 | 532 | terminate() |
518 | - @terminate_flag = 0 | |
533 | + @terminate_flag = false | |
519 | 534 | @wait = 0 |
520 | 535 | @pattern = 0 |
521 | 536 | update(window, base_frame) |
@@ -523,7 +538,7 @@ module Seriko | ||
523 | 538 | |
524 | 539 | def update(window, base_frame) |
525 | 540 | if @terminate_flag |
526 | - return False | |
541 | + return false | |
527 | 542 | end |
528 | 543 | if @pattern == 0 |
529 | 544 | @surface_id = window.get_surface() |
@@ -540,7 +555,7 @@ module Seriko | ||
540 | 555 | if @wait >= 0 |
541 | 556 | window.append_actor(base_frame + @wait, self) |
542 | 557 | end |
543 | - return False | |
558 | + return false | |
544 | 559 | end |
545 | 560 | end |
546 | 561 |
@@ -553,7 +568,7 @@ module Seriko | ||
553 | 568 | |
554 | 569 | def invoke(window, base_frame) |
555 | 570 | terminate() |
556 | - @terminate_flag = 0 | |
571 | + @terminate_flag = false | |
557 | 572 | @wait = 0 |
558 | 573 | @pattern = 0 |
559 | 574 | update(window, base_frame) |
@@ -561,7 +576,7 @@ module Seriko | ||
561 | 576 | |
562 | 577 | def update(window, base_frame) |
563 | 578 | if @terminate_flag |
564 | - return False | |
579 | + return false | |
565 | 580 | end |
566 | 581 | if @pattern == 0 |
567 | 582 | @surface_id = window.get_surface() |
@@ -578,7 +593,7 @@ module Seriko | ||
578 | 593 | if @wait >= 0 |
579 | 594 | window.append_actor(base_frame + @wait, self) |
580 | 595 | end |
581 | - return False | |
596 | + return false | |
582 | 597 | end |
583 | 598 | end |
584 | 599 |
@@ -586,11 +601,9 @@ module Seriko | ||
586 | 601 | class Mayuna < Actor |
587 | 602 | |
588 | 603 | def set_exclusive() |
589 | - pass | |
590 | 604 | end |
591 | 605 | |
592 | 606 | def show_pattern(window, surface, method, args) |
593 | - pass | |
594 | 607 | end |
595 | 608 | end |
596 | 609 |