oekaki 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/oekaki.rb +110 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a27f5af487ea898b5181c9a5b00a22fb349977e
|
4
|
+
data.tar.gz: 7ca20a06f6a5eb32d9854cce806145bf51f991b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ad4b564825a84d70153ec5917aef990fd3bf5bdce7e656000017769046b5ddc55adb298bf18f3ce5c4c028c8fb5c5d9a9d36201307416edd0a305811c7a1290
|
7
|
+
data.tar.gz: 868f0fc94f16fcc70e97fa42d526c0e2cdefce38e989e647d8eb241d3ad4873564f57a04568db684450240482b1437e8a3244f460a67e75fe4d8e222e70e47a3
|
data/lib/oekaki.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
|
3
|
+
module Oekaki
|
4
|
+
W = Gtk::Window.new
|
5
|
+
class Tool
|
6
|
+
def initialize
|
7
|
+
@drawable = W.window
|
8
|
+
@gc = Gdk::GC.new(@drawable)
|
9
|
+
@colormap = Gdk::Colormap.system
|
10
|
+
@color = Gdk::Color.new(0, 0, 0)
|
11
|
+
@fontdesc = Pango::FontDescription.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def color(r, g, b)
|
15
|
+
@color = Gdk::Color.new(r, g, b)
|
16
|
+
@colormap.alloc_color(@color, false, true)
|
17
|
+
@color
|
18
|
+
end
|
19
|
+
|
20
|
+
def rectangle(fill, x, y, width, height, color = nil)
|
21
|
+
set_color(color)
|
22
|
+
@drawable.draw_rectangle(@gc, fill, x, y, width, height)
|
23
|
+
end
|
24
|
+
|
25
|
+
def arc(fill, x, y, width, height, d1, d2, color = nil)
|
26
|
+
set_color(color)
|
27
|
+
@drawable.draw_arc(@gc, fill, x, y, width, height, d1, d2)
|
28
|
+
end
|
29
|
+
|
30
|
+
def point(x, y, color = nil)
|
31
|
+
set_color(color)
|
32
|
+
@drawable.draw_point(@gc, x, y)
|
33
|
+
end
|
34
|
+
|
35
|
+
def line(x1, y1, x2, y2, color = nil)
|
36
|
+
set_color(color)
|
37
|
+
@drawable.draw_lines(@gc, [[x1, y1], [x2, y2]])
|
38
|
+
end
|
39
|
+
|
40
|
+
def lines(array, color = nil)
|
41
|
+
set_color(color)
|
42
|
+
@drawable.draw_lines(@gc, array)
|
43
|
+
end
|
44
|
+
|
45
|
+
def polygon(fill, array, color = nil)
|
46
|
+
set_color(color)
|
47
|
+
@drawable.draw_polygon(@gc, fill, array)
|
48
|
+
end
|
49
|
+
|
50
|
+
def text(str, x, y, size, color = nil)
|
51
|
+
set_color(color)
|
52
|
+
@fontdesc.set_size(size)
|
53
|
+
layout = Pango::Layout.new(W.pango_context)
|
54
|
+
layout.font_description = @fontdesc
|
55
|
+
layout.text = str
|
56
|
+
@drawable.draw_layout(@gc, x, y, layout)
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_color(color)
|
60
|
+
@color = color if color
|
61
|
+
@gc.set_foreground(@color)
|
62
|
+
end
|
63
|
+
|
64
|
+
def load_pic(filename)
|
65
|
+
GdkPixbuf::Pixbuf.new(file: filename)
|
66
|
+
end
|
67
|
+
|
68
|
+
def save_pic(img, filename, type = "png")
|
69
|
+
img.save(filename, type)
|
70
|
+
end
|
71
|
+
|
72
|
+
def show_pic(img, x, y)
|
73
|
+
@drawable.draw_pixbuf(@gc, img, 0, 0, x, y, img.width, img.height, Gdk::RGB::DITHER_NONE, 0, 0)
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_pic(x, y, width, height)
|
77
|
+
GdkPixbuf::Pixbuf.from_drawable(nil, @drawable, x, y, width, height)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Event < Tool
|
82
|
+
def initialize
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
86
|
+
def draw(&bk)
|
87
|
+
W.signal_connect("expose_event", &bk)
|
88
|
+
end
|
89
|
+
|
90
|
+
def timer(interval, &bk)
|
91
|
+
Gtk.timeout_add(interval, &bk)
|
92
|
+
end
|
93
|
+
|
94
|
+
def key_in(&bk)
|
95
|
+
W.signal_connect("key_press_event", &bk)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.app(width: 300, height: 300, title: "gtk", &bk)
|
100
|
+
W.title = title
|
101
|
+
W.set_size_request(width, height)
|
102
|
+
W.set_app_paintable(true)
|
103
|
+
W.realize
|
104
|
+
|
105
|
+
Event.new.instance_eval(&bk)
|
106
|
+
|
107
|
+
W.show
|
108
|
+
Gtk.main
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oekaki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- obelisk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple drawing module with GTK+
|
14
|
+
email: obelisk_1968@mail.goo.ne.jp
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/oekaki.rb
|
20
|
+
homepage: http://obelisk.hatenablog.com/
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Draw with GTK+
|
44
|
+
test_files: []
|