mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Compare commits
15 Commits
41c0b27937
...
v0.23.0
| Author | SHA1 | Date | |
|---|---|---|---|
| da16ab1ec9 | |||
| eb5d170733 | |||
| 14e9d4946f | |||
| e3b8a9b102 | |||
| 458731a534 | |||
| d1d87db070 | |||
| 6e8948bd81 | |||
| 01a9187a57 | |||
| 186ad220cc | |||
| f82c0953b2 | |||
| a2d44ea2dc | |||
| c46664778a | |||
| c597a67ca6 | |||
| 55382a7c14 | |||
| 883de3db9f |
30
assets/shaders/fragment/g_buffer.glsl
Normal file
30
assets/shaders/fragment/g_buffer.glsl
Normal file
@@ -0,0 +1,30 @@
|
||||
# version 330 core
|
||||
|
||||
layout(location = 0) out vec3 fragPosition;
|
||||
layout (location = 1) out vec4 fragColor;
|
||||
layout (location = 2) out vec3 fragNormal;
|
||||
layout (location = 3) out vec3 fragUV;
|
||||
|
||||
in vec3 outPosition, outColor, outNormal, outUV, outFragPos, outCameraPos;
|
||||
out vec4 outputFragColor;
|
||||
flat in int outHasTexture;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
void main() {
|
||||
vec3 result;
|
||||
|
||||
if (outHasTexture == 0) {
|
||||
result = outColor;
|
||||
} else {
|
||||
result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
|
||||
}
|
||||
|
||||
fragPosition = outPosition;
|
||||
fragColor = vec4(result, 1.0);
|
||||
fragNormal = outNormal;
|
||||
fragUV = outUV;
|
||||
|
||||
float gamma = 2.2;
|
||||
outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
|
||||
}
|
||||
63
assets/shaders/fragment/lighting.glsl
Normal file
63
assets/shaders/fragment/lighting.glsl
Normal file
@@ -0,0 +1,63 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
@include "light_struct"
|
||||
const int DIRECTIONAL = 0;
|
||||
const int POINT = 1;
|
||||
const int SPOT = 2;
|
||||
|
||||
in vec2 outTexCoords;
|
||||
flat in Light outLight[1];
|
||||
|
||||
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
|
||||
vec4 directionalLight(Light light) {
|
||||
vec3 norm = normalize(texture(normal, outTexCoords).rgb);
|
||||
vec3 diffuse_color = texture(diffuse, outTexCoords).rgb;
|
||||
vec3 fragPos = texture(position, outTexCoords).rgb;
|
||||
|
||||
vec3 lightDir = normalize(light.position - fragPos);
|
||||
float diff = max(dot(norm, lightDir), 0);
|
||||
|
||||
vec3 _ambient = light.ambient;
|
||||
vec3 _diffuse = light.diffuse * diff;
|
||||
vec3 _specular = light.specular;
|
||||
|
||||
return vec4(_diffuse + _ambient + _specular, 1.0);
|
||||
}
|
||||
|
||||
vec4 pointLight(Light light) {
|
||||
return vec4(0.25, 0.25, 0.25, 1);
|
||||
}
|
||||
|
||||
vec4 spotLight(Light light) {
|
||||
return vec4(0.5, 0.5, 0.5, 1);
|
||||
}
|
||||
|
||||
vec4 calculateLighting(Light light) {
|
||||
vec4 result;
|
||||
|
||||
// switch(light.type) {
|
||||
// case DIRECTIONAL: {
|
||||
// result = directionalLight(light);
|
||||
// }
|
||||
// case SPOT: {
|
||||
// result = spotLight(light);
|
||||
// }
|
||||
// default: {
|
||||
// result = pointLight(light);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (light.type == DIRECTIONAL) {
|
||||
result = directionalLight(light);
|
||||
} else {
|
||||
result = pointLight(light);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
FragColor = texture(diffuse, outTexCoords) * calculateLighting(outLight[0]);
|
||||
}
|
||||
11
assets/shaders/include/light_struct.glsl
Normal file
11
assets/shaders/include/light_struct.glsl
Normal file
@@ -0,0 +1,11 @@
|
||||
struct Light {
|
||||
int type;
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
|
||||
vec3 diffuse;
|
||||
vec3 ambient;
|
||||
vec3 specular;
|
||||
|
||||
float intensity;
|
||||
};
|
||||
28
assets/shaders/vertex/g_buffer.glsl
Normal file
28
assets/shaders/vertex/g_buffer.glsl
Normal file
@@ -0,0 +1,28 @@
|
||||
# version 330 core
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in vec3 inNormal;
|
||||
layout(location = 3) in vec3 inUV;
|
||||
|
||||
uniform mat4 projection, view, model;
|
||||
uniform int hasTexture;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
out vec3 outPosition, outColor, outNormal, outUV;
|
||||
out vec3 outFragPos, outViewPos, outCameraPos;
|
||||
flat out int outHasTexture;
|
||||
|
||||
void main() {
|
||||
// projection * view * model * position
|
||||
outPosition = inPosition;
|
||||
outColor = inColor;
|
||||
outNormal= normalize(transpose(inverse(mat3(model))) * inNormal);
|
||||
outUV = inUV;
|
||||
outHasTexture = hasTexture;
|
||||
outCameraPos = cameraPos;
|
||||
|
||||
outFragPos = vec3(model * vec4(inPosition, 1.0));
|
||||
|
||||
gl_Position = projection * view * model * vec4(inPosition, 1.0);
|
||||
}
|
||||
17
assets/shaders/vertex/lighting.glsl
Normal file
17
assets/shaders/vertex/lighting.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 330 core
|
||||
@include "light_struct"
|
||||
|
||||
layout (location = 0) in vec3 inPosition;
|
||||
layout (location = 1) in vec2 inTexCoords;
|
||||
|
||||
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
uniform Light light[1];
|
||||
|
||||
out vec2 outTexCoords;
|
||||
flat out Light outLight[1];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||
outTexCoords = inTexCoords;
|
||||
outLight = light;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def draw_fill
|
||||
if @width * width_scale > height * height_scale
|
||||
if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height
|
||||
draw_fill_width
|
||||
else
|
||||
draw_fill_height
|
||||
|
||||
@@ -7,8 +7,8 @@ module CyberarmEngine
|
||||
@title_size = 56
|
||||
@caption_size = 24
|
||||
|
||||
@title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222)
|
||||
@caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222)
|
||||
@title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222, static: true)
|
||||
@caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222, static: true)
|
||||
|
||||
@spacer_width = 256
|
||||
@spacer_height = 6
|
||||
|
||||
@@ -31,6 +31,18 @@ module CyberarmEngine
|
||||
window.show_cursor = boolean
|
||||
end
|
||||
|
||||
def find_element_by_tag(container, tag, list = [])
|
||||
return unless container
|
||||
|
||||
container.children.each do |child|
|
||||
list << child if child.style.tag == tag
|
||||
|
||||
find_element_by_tag(child, tag, list) if child.is_a?(CyberarmEngine::Element::Container)
|
||||
end
|
||||
|
||||
list.first
|
||||
end
|
||||
|
||||
def draw_rect(x, y, width, height, color, z = 0, mode = :default)
|
||||
Gosu.draw_rect(x, y, width, height, color, z, mode)
|
||||
end
|
||||
|
||||
@@ -34,6 +34,10 @@ module CyberarmEngine
|
||||
true
|
||||
end
|
||||
|
||||
def needs_repaint?
|
||||
true
|
||||
end
|
||||
|
||||
def drop(filename)
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,19 @@ module CyberarmEngine
|
||||
if e != GL_NO_ERROR
|
||||
warn "OpenGL error detected by handler at: #{caller[0]}"
|
||||
warn " #{gluErrorString(e)} (#{e})\n"
|
||||
exit if window.exit_on_opengl_error?
|
||||
exit if Window.instance&.exit_on_opengl_error?
|
||||
end
|
||||
end
|
||||
|
||||
def preload_default_shaders
|
||||
shaders = %w[g_buffer lighting]
|
||||
shaders.each do |shader|
|
||||
Shader.new(
|
||||
name: shader,
|
||||
includes_dir: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/include",
|
||||
vertex: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/vertex/#{shader}.glsl",
|
||||
fragment: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/fragment/#{shader}.glsl"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module CyberarmEngine
|
||||
class GBuffer
|
||||
attr_reader :screen_vbo, :vertices, :uvs
|
||||
attr_reader :width, :height
|
||||
|
||||
def initialize(width:, height:)
|
||||
@width = width
|
||||
|
||||
@@ -62,11 +62,11 @@ module CyberarmEngine
|
||||
|
||||
def update
|
||||
# TOP
|
||||
@top.x = @element.x # + @element.border_thickness_left
|
||||
@top.x = @element.x + @element.style.border_thickness_left
|
||||
@top.y = @element.y
|
||||
@top.z = @element.z
|
||||
|
||||
@top.width = @element.width
|
||||
@top.width = @element.width - @element.style.border_thickness_left
|
||||
@top.height = @element.style.border_thickness_top
|
||||
|
||||
# RIGHT
|
||||
|
||||
@@ -65,6 +65,8 @@ module CyberarmEngine
|
||||
|
||||
set_border_thickness
|
||||
set_border_color
|
||||
|
||||
root.gui_state.request_repaint
|
||||
end
|
||||
|
||||
def safe_style_fetch(*args)
|
||||
@@ -166,10 +168,10 @@ module CyberarmEngine
|
||||
return if self.is_a?(ToolTip)
|
||||
|
||||
if old_width != width || old_height != height
|
||||
(root&.gui_state || @gui_state).request_recalculate
|
||||
else
|
||||
stylize
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
stylize
|
||||
end
|
||||
|
||||
def default_events
|
||||
@@ -256,6 +258,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def enabled=(boolean)
|
||||
root.gui_state.request_repaint if @enabled != boolean
|
||||
|
||||
@enabled = boolean
|
||||
|
||||
recalculate
|
||||
@@ -267,6 +271,10 @@ module CyberarmEngine
|
||||
@enabled
|
||||
end
|
||||
|
||||
def focused?
|
||||
@focus
|
||||
end
|
||||
|
||||
def visible?
|
||||
@visible
|
||||
end
|
||||
@@ -278,18 +286,21 @@ module CyberarmEngine
|
||||
def toggle
|
||||
@visible = !@visible
|
||||
root.gui_state.request_recalculate
|
||||
root.gui_state.request_repaint
|
||||
end
|
||||
|
||||
def show
|
||||
bool = visible?
|
||||
@visible = true
|
||||
root.gui_state.request_recalculate unless bool
|
||||
root.gui_state.request_repaint unless bool
|
||||
end
|
||||
|
||||
def hide
|
||||
bool = visible?
|
||||
@visible = false
|
||||
root.gui_state.request_recalculate if bool
|
||||
root.gui_state.request_repaint if bool
|
||||
end
|
||||
|
||||
def draw
|
||||
@@ -423,9 +434,9 @@ module CyberarmEngine
|
||||
|
||||
pairs_ << a_ unless pairs_.last == a_
|
||||
|
||||
pairs_.sum { |pair| pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
|
||||
pairs_.sum { |pair| + @style.padding_top + @style.border_thickness_top + pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
|
||||
else
|
||||
@children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
|
||||
@style.padding_top + @style.border_thickness_top + @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
|
||||
end
|
||||
end
|
||||
|
||||
@@ -440,23 +451,23 @@ module CyberarmEngine
|
||||
def dimensional_size(size, dimension)
|
||||
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
|
||||
|
||||
new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
|
||||
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
||||
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
||||
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
||||
else
|
||||
size
|
||||
end
|
||||
|
||||
# Handle fill behavior
|
||||
if @parent && @style.fill &&
|
||||
(dimension == :width && @parent.is_a?(Flow) ||
|
||||
dimension == :height && @parent.is_a?(Stack))
|
||||
return space_available_width - noncontent_width if dimension == :width && @parent.is_a?(Flow)
|
||||
return space_available_height - noncontent_height if dimension == :height && @parent.is_a?(Stack)
|
||||
|
||||
# Handle min_width/height and max_width/height
|
||||
else
|
||||
size
|
||||
end
|
||||
|
||||
if @parent && @style.fill # Handle fill behavior
|
||||
if dimension == :width && @parent.is_a?(Flow)
|
||||
return space_available_width - noncontent_width
|
||||
|
||||
elsif dimension == :height && @parent.is_a?(Stack)
|
||||
return space_available_height - noncontent_height
|
||||
end
|
||||
|
||||
else # Handle min_width/height and max_width/height
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size > @style.send(:"max_#{dimension}")
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
||||
end
|
||||
|
||||
new_size
|
||||
@@ -479,6 +490,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_canvas.background = _background
|
||||
update_background
|
||||
end
|
||||
@@ -497,6 +510,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background_nine_slice=(_image_path)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_nine_slice_canvas.image = _image_path
|
||||
update_background_nine_slice
|
||||
end
|
||||
@@ -521,6 +536,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background_image=(image_path)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
|
||||
update_background_image
|
||||
end
|
||||
|
||||
@@ -42,6 +42,10 @@ module CyberarmEngine
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def remove(element)
|
||||
root.gui_state.request_recalculate if @children.delete(element)
|
||||
end
|
||||
|
||||
def clear(&block)
|
||||
@children.clear
|
||||
|
||||
@@ -122,6 +126,9 @@ module CyberarmEngine
|
||||
|
||||
layout
|
||||
|
||||
old_width = @width
|
||||
old_height = @height
|
||||
|
||||
if is_root?
|
||||
@width = @style.width = window.width
|
||||
@height = @style.height = window.height
|
||||
@@ -178,6 +185,8 @@ module CyberarmEngine
|
||||
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||
end
|
||||
|
||||
def layout
|
||||
@@ -242,6 +251,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
return :handled
|
||||
end
|
||||
@@ -257,6 +267,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
return :handled
|
||||
end
|
||||
@@ -278,7 +289,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value
|
||||
@children.map { |c| c.class }.join(", ")
|
||||
@children.map(&:class).join(", ")
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
||||
@@ -32,6 +32,7 @@ module CyberarmEngine
|
||||
@text_input.filter = @filter
|
||||
@text_input.text = text
|
||||
@last_text_value = text
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
|
||||
@offset_x = 0
|
||||
@offset_y = 0
|
||||
@@ -79,10 +80,22 @@ module CyberarmEngine
|
||||
@show_caret = true
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
|
||||
root.gui_state.request_repaint
|
||||
|
||||
publish(:changed, value)
|
||||
end
|
||||
|
||||
if @last_caret_position != @text_input.caret_pos
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@show_caret = true
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
end
|
||||
|
||||
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
|
||||
@show_caret = !@show_caret
|
||||
@@ -203,20 +216,35 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def focus(sender)
|
||||
super
|
||||
|
||||
@focus = true
|
||||
window.text_input = @text_input
|
||||
@text_input.caret_pos = @text_input.selection_start = @text_input.text.length
|
||||
|
||||
update_styles(:active)
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def enter(sender)
|
||||
_has_focus = @focus
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles(:hover)
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
super
|
||||
:handled
|
||||
end
|
||||
|
||||
@focus = _has_focus
|
||||
def leave(sender)
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
@@ -45,8 +45,8 @@ module CyberarmEngine
|
||||
@scale_y = 1
|
||||
end
|
||||
|
||||
@width = _width || @image.width.floor * @scale_x
|
||||
@height = _height || @image.height.floor * @scale_y
|
||||
@width = _width || (@image.width * @scale_x).floor
|
||||
@height = _height || (@image.height * @scale_y).floor
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
@@ -52,6 +52,7 @@ module CyberarmEngine
|
||||
@marquee_animation_time = Gosu.milliseconds if @marquee_offset > range
|
||||
|
||||
update_background
|
||||
root.gui_state.request_repaint
|
||||
end
|
||||
|
||||
def type=(type)
|
||||
@@ -77,9 +78,13 @@ module CyberarmEngine
|
||||
def value=(decimal)
|
||||
raise "value must be number" unless decimal.is_a?(Numeric)
|
||||
|
||||
old_value = @fraction
|
||||
|
||||
@fraction = decimal.clamp(0.0, 1.0)
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @fraction != old_value
|
||||
|
||||
publish(:changed, @fraction)
|
||||
@fraction
|
||||
end
|
||||
|
||||
@@ -97,6 +97,8 @@ module CyberarmEngine
|
||||
position_handle
|
||||
@handle.recalculate
|
||||
|
||||
root.gui_state.request_repaint
|
||||
|
||||
publish(:changed, @value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,6 +36,9 @@ module CyberarmEngine
|
||||
@text.color = @style.color
|
||||
end
|
||||
|
||||
old_width = @width
|
||||
old_height = @height
|
||||
|
||||
@width = 0
|
||||
@height = 0
|
||||
|
||||
@@ -50,7 +53,7 @@ module CyberarmEngine
|
||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
@text.z = @z + 3
|
||||
|
||||
if (text_alignment = @options[:text_align])
|
||||
if (text_alignment = @options[:text_align] || @options[:text_h_align])
|
||||
case text_alignment
|
||||
when :left
|
||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@@ -65,11 +68,22 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
if is_a?(Button)
|
||||
@text.y = @y + height / 2 - @text.height / 2
|
||||
if (vertical_alignment = @options[:text_v_align])
|
||||
case vertical_alignment
|
||||
when :center
|
||||
@text.y = if @text.height <= height
|
||||
@y + height / 2 - @text.height / 2
|
||||
else
|
||||
@style.border_thickness_top + @style.padding_top + @y
|
||||
end
|
||||
when :bottom
|
||||
@text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom)
|
||||
end
|
||||
end
|
||||
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||
end
|
||||
|
||||
def handle_text_wrapping(max_width)
|
||||
@@ -150,6 +164,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
old_value = @raw_text
|
||||
@raw_text = value.to_s.chomp
|
||||
|
||||
old_width = width
|
||||
@@ -161,6 +176,8 @@ module CyberarmEngine
|
||||
recalculate
|
||||
end
|
||||
|
||||
root.gui_state.request_repaint if old_value != @raw_text
|
||||
|
||||
publish(:changed, self.value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module CyberarmEngine
|
||||
|
||||
def initialize(options, block = nil)
|
||||
if options.dig(:theme, :ToggleButton, :checkmark_image)
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:Label][:text_size]
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:TextBlock][:text_size]
|
||||
super(get_image(options.dig(:theme, :ToggleButton, :checkmark_image)), options, block)
|
||||
|
||||
@_image = @image
|
||||
|
||||
@@ -27,6 +27,8 @@ module CyberarmEngine
|
||||
@pending_recalculate_request = false
|
||||
@pending_element_recalculate_requests = []
|
||||
|
||||
@needs_repaint = false
|
||||
|
||||
@menu = nil
|
||||
@min_drag_distance = 0
|
||||
@mouse_pos = Vector.new
|
||||
@@ -55,7 +57,7 @@ module CyberarmEngine
|
||||
@menu.draw
|
||||
end
|
||||
|
||||
if @tip.value.length.positive?
|
||||
if @tip && @tip.value.length.positive?
|
||||
Gosu.flush
|
||||
|
||||
@tip.draw
|
||||
@@ -66,6 +68,12 @@ module CyberarmEngine
|
||||
|
||||
@root_container.debug_draw
|
||||
end
|
||||
|
||||
@needs_repaint = false
|
||||
end
|
||||
|
||||
def needs_repaint?
|
||||
@needs_repaint
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -88,9 +96,19 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
@menu&.update
|
||||
|
||||
super
|
||||
|
||||
if @active_width != window.width || @active_height != window.height
|
||||
request_recalculate
|
||||
@root_container.publish(:window_size_changed)
|
||||
end
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
|
||||
return unless window.has_focus?
|
||||
return unless window.current_state == self
|
||||
|
||||
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
|
||||
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
||||
@@ -127,14 +145,6 @@ module CyberarmEngine
|
||||
|
||||
@last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y)
|
||||
@mouse_pos = @last_mouse_pos.clone
|
||||
|
||||
if @active_width != window.width || @active_height != window.height
|
||||
request_recalculate
|
||||
@root_container.publish(:window_size_changed)
|
||||
end
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
@@ -253,6 +263,12 @@ module CyberarmEngine
|
||||
@pending_focus_element = element
|
||||
end
|
||||
|
||||
def request_repaint
|
||||
# puts caller[0..4]
|
||||
# puts
|
||||
@needs_repaint = true
|
||||
end
|
||||
|
||||
def show_menu(list_box)
|
||||
@menu = list_box
|
||||
end
|
||||
|
||||
@@ -76,6 +76,7 @@ module CyberarmEngine
|
||||
border_radius: 0,
|
||||
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
||||
text_align: :center,
|
||||
text_v_align: :center,
|
||||
text_wrap: :none,
|
||||
|
||||
hover: {
|
||||
@@ -106,6 +107,10 @@ module CyberarmEngine
|
||||
text_static: false # static text causes issues correctly displaying caret position
|
||||
},
|
||||
|
||||
EditBox: { # < EditLine
|
||||
text_v_align: :top
|
||||
},
|
||||
|
||||
Image: { # < Element
|
||||
color: Gosu::Color::WHITE,
|
||||
tileable: false,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.21.0".freeze
|
||||
VERSION = "0.23.0".freeze
|
||||
end
|
||||
|
||||
@@ -41,6 +41,7 @@ module CyberarmEngine
|
||||
|
||||
@states = []
|
||||
@exit_on_opengl_error = false
|
||||
preload_default_shaders if respond_to?(:preload_default_shaders)
|
||||
|
||||
setup if defined?(setup)
|
||||
end
|
||||
@@ -141,10 +142,14 @@ module CyberarmEngine
|
||||
|
||||
def pop_state
|
||||
@states.pop
|
||||
|
||||
current_state.request_repaint if current_state&.is_a?(GuiState)
|
||||
end
|
||||
|
||||
def shift_state
|
||||
@states.shift
|
||||
|
||||
current_state.request_repaint if current_state&.is_a?(GuiState)
|
||||
end
|
||||
|
||||
def has_focus?
|
||||
|
||||
Reference in New Issue
Block a user