Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
glwindow changes + depwarns (#194)
Browse files Browse the repository at this point in the history
* accompany new changes from GLWindow

* Fix deprecations

* include new glwindow
  • Loading branch information
SimonDanisch authored Aug 17, 2017
1 parent d7f584d commit 2f422f3
Show file tree
Hide file tree
Showing 29 changed files with 182 additions and 190 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ julia 0.6
StaticArrays 0.6.0
GeometryTypes 0.4.1

GLWindow 0.6 # 0.6 for fullscreen
GLWindow 0.7 # 0.7 for reactive_run_till_now
GLAbstraction 0.5
ModernGL 0.1.0

Expand Down
18 changes: 7 additions & 11 deletions examples/ExampleRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function flatten_paths(path::String, paths = String[])
paths
end

type RunnerConfig
mutable struct RunnerConfig
resolution
make_docs
files
Expand Down Expand Up @@ -368,7 +368,7 @@ end
to_toggle(v0, b) = !v0


import GLWindow: poll_reactive, poll_glfw, sleep_pessimistic
import GLWindow: reactive_run_till_now, poll_glfw, sleep_pessimistic


function inner_test(path, config, window, break_loop, runthrough, increase)
Expand All @@ -377,21 +377,18 @@ function inner_test(path, config, window, break_loop, runthrough, increase)
display_msg(test_module, config)
timings = Float64[]
frames = 0;
@eval poll_glfw()
@eval poll_reactive()
@eval poll_reactive()
yield()
poll_glfw()
reactive_run_till_now()
while !break_loop[] && isopen(config.rootscreen)
tic()
t = time()
poll_glfw()
if Base.n_avail(Reactive._messages) > 0
poll_reactive()
poll_reactive() # two times for secondary signals
reactive_run_till_now() # two times for secondary signals
render_frame(config.rootscreen)
swapbuffers(config.rootscreen)
end
frames += 1
t = toq()
t = time() - t
if length(timings) < 1000 && frames > 2
push!(timings, t)
end
Expand Down Expand Up @@ -453,7 +450,6 @@ function make_tests(config)
end

failed = fill(false, length(config.files))
Reactive.stop() # stop Reactive! We be pollin' ourselves!
io = nothing
while i <= length(config.files) && isopen(config.rootscreen)
path = config.files[i]
Expand Down
2 changes: 1 addition & 1 deletion examples/interactive/mario_game.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can move mario around with the arrow keys
"""
const record_interactive = true

type Mario{T}
mutable struct Mario{T}
x ::T
y ::T
vx ::T
Expand Down
2 changes: 1 addition & 1 deletion examples/introduction/video_recording.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ for i=1:10 # record 10 frames
# if you call @async renderloop(window) you can replace this part with yield
GLWindow.render_frame(window)
GLWindow.swapbuffers(window)
GLWindow.poll_reactive()
GLWindow.reactive_run_till_now()

# add the frame from the current window
GLVisualize.add_frame!(io, window, buffer)
Expand Down
6 changes: 3 additions & 3 deletions examples/parallel/simulation3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function p_empty!()
end


function solve_particles!{N, T}(
function solve_particles!(
positions::AbstractVector{Point{N, T}}, s, dt::T = T(0.01)
)
) where {N, T}
P = Point{N, T}
# since Points are immutable, and we don't have comprehensions yet, there is
# a map(index _> ..., ::Point) which we can use
Expand All @@ -70,7 +70,7 @@ end
Generic implementation of initialising `N` dimensional points on an `N` dimensional
Sphere.
"""
function startpositions{T}(N, radius::T, n)
function startpositions(N, radius::T, n) where T
sphere = HyperSphere(Point{N, T}(0), T(radius))
n = N == 3 ? floor(Int, sqrt(n)) : n # n must be n^2 for 3D Sphere
decompose(Point{N, T}, sphere, n)
Expand Down
2 changes: 1 addition & 1 deletion examples/sprites/distancefield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dfield = map(timesignal) do t
Float32[xy_data(x,y,tpi) + 0.5f0 for x=1:n2, y=1:n2]
end
Base.rand(m::MersenneTwister, ::Type{N0f8}) = N0f8(rand(m, UInt8))
Base.rand{T <: Colorant}(m::MersenneTwister, ::Type{T}) = T(ntuple(x->rand(m, eltype(T)), Val{length(T)})...)
Base.rand(m::MersenneTwister, ::Type{T}) where {T <: Colorant} = T(ntuple(x->rand(m, eltype(T)), Val{length(T)})...)

distfield = visualize((DISTANCEFIELD, positions),
stroke_width=4f0,
Expand Down
6 changes: 1 addition & 5 deletions src/GLVisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import GLAbstraction: N0f8
export N0f8 # reexport for examples/tests
using Base.Iterators: filter
import Base: merge, convert, show
if VERSION >= v"0.6.0-dev.1015"
using Base.Iterators: Repeated, repeated
else
using Base.Repeated
end
using Base.Iterators: Repeated, repeated

import AxisArrays, ImageAxes, Images
const HasAxesArray{T, N} = Union{AxisArrays.AxisArray{T, N}, Images.ImageMetadata.ImageMetaAxis{T, N}}
Expand Down
10 changes: 5 additions & 5 deletions src/StructsOfArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module StructsOfArrays

export StructOfArrays, ScalarRepeat

immutable StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N}
struct StructOfArrays{T,N,U<:Tuple} <: AbstractArray{T,N}
arrays::U
end


type ScalarRepeat{T}
mutable struct ScalarRepeat{T}
scalar::T
end
Base.ndims(::ScalarRepeat) = 1
Base.getindex(s::ScalarRepeat, i...) = s.scalar
#should setindex! really be allowed? It will set the index for the whole row...
Base.setindex!{T}(s::ScalarRepeat{T}, value, i...) = (s.scalar = T(value))
Base.setindex!(s::ScalarRepeat{T}, value, i...) where {T} = (s.scalar = T(value))
Base.eltype{T}(::ScalarRepeat{T}) = T

Base.start(::ScalarRepeat) = 1
Expand Down Expand Up @@ -85,7 +85,7 @@ Base.convert{T,S,N}(::Type{StructOfArrays{T}}, A::AbstractArray{S,N}) =
Base.convert{T,N}(::Type{StructOfArrays}, A::AbstractArray{T,N}) =
convert(StructOfArrays{T,N}, A)

function Base.size{T, N, U}(A::StructOfArrays{T, N, U})
function Base.size(A::StructOfArrays{T, N, U}) where {T, N, U}
for elem in A.arrays
if isa(elem, AbstractArray)
return size(elem)
Expand All @@ -104,7 +104,7 @@ end
)
end

function _getindex{T}(x::T, i)
function _getindex(x::T, i) where T
is_tuple_struct(T) ? x[i] : getfield(x, i)
end
@generated function Base.setindex!{T}(A::StructOfArrays{T}, x, i::Integer...)
Expand Down
22 changes: 11 additions & 11 deletions src/boundingbox.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
AbsoluteRectangle{N,T}(mini::Vec{N,T}, maxi::Vec{N,T}) = HyperRectangle{N,T}(mini, maxi-mini)
AbsoluteRectangle(mini::Vec{N,T}, maxi::Vec{N,T}) where {N,T} = HyperRectangle{N,T}(mini, maxi-mini)

(::Type{AABB})(a) = AABB{Float32}(a)
function (B::Type{AABB{T}}){T}(a::Pyramid)
AABB(a) = AABB{Float32}(a)
function (B::Type{AABB{T}})(a::Pyramid) where T
w,h = a.width/T(2), a.length
m = Vec{3,T}(a.middle)
B(m-Vec{3,T}(w,w,0), m+Vec{3,T}(w, w, h))
end
(B::Type{AABB{T}}){T}(a::Cube) = B(origin(a), widths(a))
(B::Type{AABB{T}}){T}(a::AbstractMesh) = B(vertices(a))
(B::Type{AABB{T}}){T}(a::NativeMesh) = B(gpu_data(a.data[:vertices]))
(B::Type{AABB{T}})(a::Cube) where {T} = B(origin(a), widths(a))
(B::Type{AABB{T}})(a::AbstractMesh) where {T} = B(vertices(a))
(B::Type{AABB{T}})(a::NativeMesh) where {T} = B(gpu_data(a.data[:vertices]))


function (B::Type{AABB{T}}){T}(
function (B::Type{AABB{T}})(
positions, scale, rotation,
primitive::AABB{T}
)
) where T

ti = TransformationIterator(positions, scale, rotation)
B(ti, primitive)
end
function (B::Type{AABB{T}}){T}(instances::Instances)
function (B::Type{AABB{T}})(instances::Instances) where T
ti = TransformationIterator(instances)
B(ti, B(instances.primitive))
end
Expand All @@ -38,9 +38,9 @@ function transform(translation, scale, rotation, points)
AABB{Float32}(_min, _max-_min)
end

function (B::Type{AABB{T}}){T}(
function (B::Type{AABB{T}})(
ti::TransformationIterator, primitive::AABB{T}
)
) where T
state = start(ti)
if done(ti, state)
return primitive
Expand Down
6 changes: 3 additions & 3 deletions src/camera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function cubeside_const_lift(_, id, mousehover)
Vec3f0(1)
end
import Base: +
Base.clamp{T}(x::T) = clamp(x, T(0),T(1))
+{T}(a::RGBA{T}, b::Number) = RGBA{T}(clamp(comp1(a)+b), clamp(comp2(a)+b), clamp(comp3(a)+b), clamp(alpha(a)+b))
Base.clamp(x::T) where {T} = clamp(x, T(0),T(1))
+(a::RGBA{T}, b::Number) where {T} = RGBA{T}(clamp(comp1(a)+b), clamp(comp2(a)+b), clamp(comp3(a)+b), clamp(alpha(a)+b))

function cubeside_color(id, mousehover, startcolors, colortex)
index = mousehover[2]
Expand All @@ -39,7 +39,7 @@ function colored_cube()
cube_steering = merge(map(GLNormalMesh, quads))
end

Base.middle{T}(r::SimpleRectangle{T}) = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))
Base.middle(r::SimpleRectangle{T}) where {T} = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))


function get_rotation(m)
Expand Down
6 changes: 3 additions & 3 deletions src/documentation.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

pretty_print(x::Signal) = string(value(x))
pretty_print(x::Vector) = string("[", first(x), "...", last(x), "]")
pretty_print{T}(x::Matrix{T}) = string("Matrix{", T, "}")
pretty_print(x::Matrix{T}) where {T} = string("Matrix{", T, "}")
pretty_print(x::DataType) = string(x.name.name)
pretty_print(x) = string(x)

print_type(x::Function) = string(x.env.name)
print_type(x::Symbol) = string(":", x)
function print_type{T<:Tuple}(x::Type{T})
function print_type(x::Type{T}) where T<:Tuple
"($(join(map(print_type, x.parameters), ", ")))"
end
function print_type(x::TypeVar)
Expand Down Expand Up @@ -84,7 +84,7 @@ end
_tuple(x) = (x,)
_tuple(x::Core.SimpleVector) = tuple(x...)
_tuple(x::Tuple) = x
_tuple{T<:Tuple}(x::Type{T}) = tuple(x.parameters...)
_tuple(x::Type{T}) where {T<:Tuple} = tuple(x.parameters...)

function all_docs(io = STDOUT)
method_table = methods(GLVisualize._default)
Expand Down
6 changes: 3 additions & 3 deletions src/gui/buttons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function toggle(ispressed::Signal{Bool}, screen, default=true; signal=Signal(def
signal
end

function toggle{T<:Union{Int, Tuple, RenderObject}}(id1::Union{Signal{T}, T}, screen, default=true; signal=Signal(default))
function toggle(id1::Union{Signal{T}, T}, screen, default=true; signal=Signal(default)) where T<:Union{Int, Tuple, RenderObject}
m2id = mouse2id(screen)
is_clicked = droprepeats(map(screen.inputs[:mouse_buttons_pressed]) do mbp
if GLAbstraction.singlepressed(mbp, GLFW.MOUSE_BUTTON_LEFT)
Expand Down Expand Up @@ -141,10 +141,10 @@ function slider(
end


function widget{T <: Range}(
function widget(
r::Signal{T}, screen::Screen;
args...
)
) where T <: Range
slider(value(r), screen; args...)
end
function playbutton(screen; icon_size = 10mm)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/color_chooser.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
_clamp(x) = Point2f0(clamp(x[1], 0, 1), clamp(x[2], 0, 1))
function widget{T<:RGBA}(
function widget(
color::Signal{T}, window;
area=(30, 30),
kw_args...
)
) where T<:RGBA
@materialize mouse_buttons_pressed, mouseposition = window.inputs
color_button = visualize(
(ROUNDED_RECTANGLE, zeros(Point2f0, 1));
Expand Down
14 changes: 7 additions & 7 deletions src/gui/line_edit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ function edit_line(
end


function widget{T}(
function widget(
line::Vector{Point{2,T}}, window;
direction_restriction = Vec2f0(1),
clampto = (-Inf, Inf),
kw_args...
)
) where T
vis, sig = edit_line(
line, direction_restriction, clampto, window;
kw_args...
Expand Down Expand Up @@ -98,14 +98,14 @@ function dragg_gpu(v0, dragg)
return id, index, p0
end

immutable ClampFunctor{T}
struct ClampFunctor{T}
a::T
b::T
end

clampU8{T}(x::RGBA{T}) = RGBA{T}(ntuple(i->clamp(getfield(x, i), 0.,1.), Val{4})...)
clampU8(x::RGBA{T}) where {T} = RGBA{T}(ntuple(i->clamp(getfield(x, i), 0.,1.), Val{4})...)
channel_color(channel, value) = RGBA{Float32}(ntuple(i->i==channel ? value : 0.0f0, Val{3})..., 1f0)
function c_setindex{T}(color::RGBA{T}, val, channel)
function c_setindex(color::RGBA{T}, val, channel) where T
v = clamp.(val, 0, 1)
RGBA{T}(
1==channel ? v : comp1(color),
Expand All @@ -124,7 +124,7 @@ function edit_color(tex, buff, index_value, channel, maxval)
nothing
end

function widget{T<:Colorant}(colormap::VecTypes{T}, window;
function widget(colormap::VecTypes{T}, window;
area = (300, 30),
slider_colors = (
RGBA{Float32}(0.78125,0.1796875,0.41796875),
Expand All @@ -134,7 +134,7 @@ function widget{T<:Colorant}(colormap::VecTypes{T}, window;
),
knob_scale = 9f0,
kw_args...
)
) where T<:Colorant
colors = map(GLAbstraction.gl_promote(T), to_cpu_mem(value(colormap)))
N = length(colors)
color_tex = GLAbstraction.gl_convert(Texture, colormap)
Expand Down
14 changes: 7 additions & 7 deletions src/gui/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function slide(startvalue, slide_pos, range::Range)
clamp(val, range)
end

function widget{T <: Union{StaticVector, Real}}(x::T, inputs, numberwidth=5;kw_args...)
function widget(x::T, inputs, numberwidth=5;kw_args...) where T <: Union{StaticVector, Real}
widget(typemin(T):eps(T):typemax(T), inputs, numberwidth; start_value=x, kw_args...)
end

Expand All @@ -60,18 +60,18 @@ function range_default{T<:Integer}(::Type{T})
T(-100):T(1):T(100)
end

function calc_val{T<:AbstractFloat}(sval::T, val, range)
function calc_val(sval::T, val, range) where T<:AbstractFloat
clamp(sval+(val*step(range)), first(range), last(range))
end
function calc_val{T<:Integer}(sval::T, val, range)
function calc_val(sval::T, val, range) where T<:Integer
clamp(sval+(round(T, val)*step(range)), first(range), last(range))
end
function widget{T <: StaticVector}(
function widget(
slider_value::Signal{T}, window;
numberwidth = 5, range = range_default(T),
text_scale = 4mm,
kw_args...
)
) where T <: StaticVector
last_x = 0f0
le_sigs = []
gap = text_scale * 2f0 # 2 characters gap
Expand All @@ -96,11 +96,11 @@ function widget{T <: StaticVector}(

Context(le_tuple...), map(T, le_sigs...)
end
function widget{T <: Real}(
function widget(
slider_value::Signal{T}, window;
text_scale = 4mm,
numberwidth = 5, range = range_default(T), kw_args...
)
) where T <: Real
@materialize mouse_buttons_pressed, mouseposition = window.inputs
startvalue = value(slider_value)
slider_value_str = map(printforslider, slider_value)
Expand Down
Loading

0 comments on commit 2f422f3

Please sign in to comment.