Skip to content

Instantly share code, notes, and snippets.

View Groogy's full-sized avatar

Groogy Groogy

View GitHub Profile
alias Vector4f32 = Boleite::Vector4f32
alias Vector2f32 = Boleite::Vector2f32
struct SimpleVertex < Boleite::Vertex
@pos = Vector4f32.zero
@color = Vector4f32.zero
@uv = Vector2f32.zero
def initialize
end
require "crystal-clear"
class FooBar
invariants do
@val != nil
end
def initialize(@val = nil)
@val = 5
end
require "boleite"
require "./ego/*"
require "./ego/serializers/*"
app = EgoApplication.new # Inherits from Boleite::Application, defines how to get the configuration
app.state_stack.push GameState.new(app)
app.run
@Groogy
Groogy / problem.cr
Last active September 23, 2017 16:47
class Page
# ....
private def render_glyph_to_texture(glyph, width, height) : Nil
bitmap = @face.value.glyph.value.bitmap
buffer = Bytes.new bitmap.buffer, bitmap.width * bitmap.rows
show_pixels bitmap.buffer, bitmap.width, bitmap.rows
@texture.update(bitmap.buffer, bitmap.width, bitmap.rows, 0, 0, 8)
end
def show_pixels(pixels, width, height)
@Groogy
Groogy / text_usage.cr
Last active September 24, 2017 20:27
font = Boleite::Font.new app.graphics, "/usr/share/fonts/TTF/arial.ttf"
text = Boleite::Text.new font, "Hello world?\nHello new line!"
text.size = 150u32
text.default_color = Boleite::Color.blue
text.position = Boleite::Vector2f.new 10.0, 10.0
text.formatter.add /(Hello)/, Boleite::Color.green
text.formatter.add /(\!|\?)/, Boleite::Color.black
renderer.draw text
@Groogy
Groogy / test.cr
Last active October 1, 2017 10:39
# Papierkorb suggestion
class Foo
include CrystalClear
requires var > 5
ensures result.query?
assert def foo # Apply contract semantics to method
# Code
end
class Foo
include CrystalClear
def on_contract_fail(contract, condition, method) # some args with info
# Default behaviour but you can overide it in this method
raise CrystalClear::ContractError.new("Failed #{self.class} #{contract} contract: #{condition}"
end
end
abstract class Container < Widget
includes CrystalClear
@children = [] of Widget
requires child.parent.nil?
ensures @children.count child == 1
def add(child)
@children << child
child.parent = self
class Boleite::GUI
abstract class Widget
Cute.signal mouse_enter
Cute.signal mouse_leave
Cute.signal mouse_over(x : Float64, y : Float64)
Cute.signal left_click(x : Float64, y : Float64)
Cute.signal right_click(x : Float64, y : Float64)
Cute.signal key_pressed
Cute.signal key_released
Cute.signal text_entered
class WidgetInput < InputReceiver
def initialize(widget)
register WidgetLeftClick ->widget.left_click.emit
end
end