gui 0.0.1.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +202 -0
- data/README.md +10 -0
- data/lib/gui.rb +26 -0
- data/lib/gui/context.rb +130 -0
- data/lib/gui/geom.rb +228 -0
- data/lib/gui/selector.rb +66 -0
- data/lib/gui/selector/checks.rb +178 -0
- data/lib/gui/texture.rb +103 -0
- data/lib/gui/version.rb +36 -0
- data/lib/gui/view.rb +134 -0
- data/lib/gui/window.rb +149 -0
- metadata +157 -0
data/lib/gui/window.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# Copyright 2014 Noel Cower
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# -----------------------------------------------------------------------------
|
16
|
+
#
|
17
|
+
# window.rb
|
18
|
+
# Window base class
|
19
|
+
|
20
|
+
|
21
|
+
require 'glfw3'
|
22
|
+
require 'gui/context'
|
23
|
+
require 'gui/view'
|
24
|
+
require 'gui/geom'
|
25
|
+
require 'set'
|
26
|
+
|
27
|
+
|
28
|
+
module GUI
|
29
|
+
|
30
|
+
class Window < View
|
31
|
+
|
32
|
+
MAX_INVALIDATE_LOOPS = 5
|
33
|
+
|
34
|
+
def initialize(width, height, title, context = nil)
|
35
|
+
context ||= Context.__active_context__
|
36
|
+
context.windows << self
|
37
|
+
|
38
|
+
@in_update = []
|
39
|
+
@context = context
|
40
|
+
@glfw_window = ::Glfw::Window.new(width, height, title, nil, context.shared_context)
|
41
|
+
|
42
|
+
@glfw_window.set_size_callback do |window, x, y|
|
43
|
+
unless @in_update.include? :frame
|
44
|
+
@in_update << :frame
|
45
|
+
@frame.size.x = x
|
46
|
+
@frame.size.y = y
|
47
|
+
@in_update.delete :frame
|
48
|
+
invalidate(bounds)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
@glfw_window.set_position_callback do |window, x, y|
|
53
|
+
unless @in_update.include? :frame
|
54
|
+
@in_update << :frame
|
55
|
+
@frame.origin.x = x
|
56
|
+
@frame.origin.y = y
|
57
|
+
@in_update.delete :frame
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
@glfw_window.set_close_callback do |window|
|
62
|
+
@glfw_window.should_close = false
|
63
|
+
close
|
64
|
+
end
|
65
|
+
|
66
|
+
super(Rect[*@glfw_window.position, *@glfw_window.size])
|
67
|
+
end
|
68
|
+
|
69
|
+
def scale_factor
|
70
|
+
@glfw_window.framebuffer_size[0] / @frame.size.x
|
71
|
+
end
|
72
|
+
|
73
|
+
def frame=(new_frame)
|
74
|
+
unless @in_update.include? :frame
|
75
|
+
@glfw_window
|
76
|
+
.set_position(new_frame.origin.x, new_frame.origin.y)
|
77
|
+
.set_size(new_frame.size.x, new_frame.size.y)
|
78
|
+
end
|
79
|
+
super
|
80
|
+
end
|
81
|
+
|
82
|
+
def draw
|
83
|
+
@glfw_window.make_context_current
|
84
|
+
draw
|
85
|
+
super
|
86
|
+
end
|
87
|
+
|
88
|
+
def show
|
89
|
+
@glfw_window.show
|
90
|
+
end
|
91
|
+
|
92
|
+
def hide
|
93
|
+
@glfw_window.hide
|
94
|
+
end
|
95
|
+
|
96
|
+
# May be overridden to change whether clicking the close button actually
|
97
|
+
# closes the window.
|
98
|
+
def close
|
99
|
+
@glfw_window.should_close = true
|
100
|
+
@context.windows.delete(self)
|
101
|
+
end
|
102
|
+
|
103
|
+
def __swap_buffers__
|
104
|
+
return unless @invalidated
|
105
|
+
|
106
|
+
last_ctx = Glfw::Window.current_context
|
107
|
+
begin
|
108
|
+
@glfw_window.make_context_current
|
109
|
+
loops = MAX_INVALIDATE_LOOPS
|
110
|
+
|
111
|
+
begin
|
112
|
+
region = @invalidated
|
113
|
+
@invalidated = nil
|
114
|
+
|
115
|
+
if !region.empty?
|
116
|
+
Gl::glEnable(Gl::GL_SCISSOR_TEST)
|
117
|
+
Gl::glScissor(
|
118
|
+
region.x * scale_factor,
|
119
|
+
(@frame.height - region.bottom) * scale_factor,
|
120
|
+
region.width * scale_factor,
|
121
|
+
region.height * scale_factor
|
122
|
+
)
|
123
|
+
|
124
|
+
# draw_subviews (those within region)
|
125
|
+
|
126
|
+
Gl::glClear(Gl::GL_COLOR_BUFFER_BIT)
|
127
|
+
Gl::glDisable(Gl::GL_SCISSOR_TEST)
|
128
|
+
end
|
129
|
+
|
130
|
+
loops -= 1
|
131
|
+
end until @invalidated.nil? || loops <= 0
|
132
|
+
@glfw_window.swap_buffers
|
133
|
+
|
134
|
+
if @invalidated
|
135
|
+
$stderr.puts "Terminating window invalidation loop after #{MAX_INVALIDATE_LOOPS} runs"
|
136
|
+
end
|
137
|
+
|
138
|
+
ensure
|
139
|
+
if last_ctx
|
140
|
+
last_ctx.make_context_current
|
141
|
+
else
|
142
|
+
Glfw::Window.unset_context
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end # Window
|
148
|
+
|
149
|
+
end # GUI
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Noel Cower
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: glfw3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.5
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: opengl-core
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.3.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: snow-math
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.7'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.7.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.7'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.7.1
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: snow-data
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.3'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.0
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.3.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: stb-image
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '1.0'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.0.1
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 1.0.1
|
113
|
+
description: A GUI gem for Ruby.
|
114
|
+
email: ncower@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files:
|
118
|
+
- README.md
|
119
|
+
- COPYING
|
120
|
+
files:
|
121
|
+
- COPYING
|
122
|
+
- README.md
|
123
|
+
- lib/gui.rb
|
124
|
+
- lib/gui/context.rb
|
125
|
+
- lib/gui/geom.rb
|
126
|
+
- lib/gui/selector.rb
|
127
|
+
- lib/gui/selector/checks.rb
|
128
|
+
- lib/gui/texture.rb
|
129
|
+
- lib/gui/version.rb
|
130
|
+
- lib/gui/view.rb
|
131
|
+
- lib/gui/window.rb
|
132
|
+
homepage: https://github.com/nilium/ruby-gui
|
133
|
+
licenses:
|
134
|
+
- Apache 2.0 License
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.3.1
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.2.1
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Some sort of GUI gem.
|
156
|
+
test_files: []
|
157
|
+
has_rdoc: true
|