Skip to content

Commit

Permalink
Change SwtShoes to Swt::Shoes. Close #6
Browse files Browse the repository at this point in the history
Note, this commit doesn't change the directory structure of specs.
  • Loading branch information
wasnotrice committed Jun 1, 2012
1 parent 76efabe commit c176f22
Show file tree
Hide file tree
Showing 36 changed files with 530 additions and 512 deletions.
2 changes: 1 addition & 1 deletion bin/swt-shoooes
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ case "${MACHTYPE:-}" in
esac

jruby --1.9 ${swt_opt:-} -rrubygems -Ilib -rshoes -rshoes/configuration -e \
"Shoes.configuration.framework = 'swt_shoes'; require '$1';"
"Shoes.configuration.framework = 'shoes/swt'; require '$1';"
2 changes: 1 addition & 1 deletion bin/swt-shoooes.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
call jruby --1.9 -e "$:<< 'lib'; require 'shoes'; require 'shoes/configuration'; Shoes.configuration.framework = 'swt_shoes'; require '%1' "
call jruby --1.9 -e "$:<< 'lib'; require 'shoes'; require 'shoes/configuration'; Shoes.configuration.framework = 'shoes/swt'; require '%1' "
4 changes: 2 additions & 2 deletions bin/swt-shoooesd
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ ENV['log_level'] = 'debug'

require 'shoes'
require 'shoes/configuration'
Shoes.configuration.framework = 'swt_shoes'
Shoes.configuration.framework = 'shoes/swt'

require ARGV[0]

puts "Exiting ./shooesd. Have a good day!"

exit 0
exit 0
2 changes: 1 addition & 1 deletion bin/swt-shoooesd.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
call jruby --1.9 --debug -e "$:<< 'lib'; require 'shoes'; require 'shoes/configuration'; Shoes.configuration.framework = 'swt_shoes'; require '%1' "
call jruby --1.9 --debug -e "$:<< 'lib'; require 'shoes'; require 'shoes/configuration'; Shoes.configuration.framework = 'shoes/swt'; require '%1' "
28 changes: 14 additions & 14 deletions lib/swt_shoes.rb → lib/shoes/swt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def window(*a, &b)
Shoes.app(*a, &b)
end

require 'swt_shoes/element_methods'
require 'swt_shoes/animation'
require 'swt_shoes/app'
#require 'swt_shoes/window'
require 'swt_shoes/flow'
require 'swt_shoes/button'
require 'swt_shoes/line'
require 'swt_shoes/oval'
require 'swt_shoes/shape'
require 'swt_shoes/color'
require 'swt_shoes/sound'

module SwtShoes
require 'shoes/swt/element_methods'
require 'shoes/swt/animation'
require 'shoes/swt/app'
#require 'shoes/swt/window'
require 'shoes/swt/flow'
require 'shoes/swt/button'
require 'shoes/swt/line'
require 'shoes/swt/oval'
require 'shoes/swt/shape'
require 'shoes/swt/color'
require 'shoes/swt/sound'

module Shoes::Swt
module Shoes
def self.app(opts={}, &blk)
Shoes::App.new(opts, &blk)
Expand All @@ -34,7 +34,7 @@ def self.logger
end

def self.display
Swt::Widgets::Display.getCurrent
::Swt::Widgets::Display.getCurrent
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions lib/shoes/swt/animation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'shoes/timer_base'

module Shoes
module Swt
module Animation
def gui_init
# Wrap the animation block so we can count frames.
# Note that the task re-calls itself on each run.
task = Proc.new do
@blk.call(@current_frame)
@current_frame += 1
@app.gui_container.redraw
::Swt.display.timer_exec (2000 / @framerate), task
end
::Swt.display.timer_exec (2000 / @framerate), task
end

#def stop
#end

#def start
#end
end
end
end

module Shoes
class Animation
include Shoes::Swt::Animation
end
end
52 changes: 52 additions & 0 deletions lib/shoes/swt/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'swt'

#require 'shoes/framework_adapters/swt_shoes/window'

module Shoes
module Swt

# Shoes::App.new creates a new Shoes application window!
# The default window is a [flow]
#
module App

def gui_init
self.gui_container = container = ::Swt::Widgets::Shell.new(::Swt.display, ::Swt::SWT::CLOSE)
layout = ::Swt::Layout::RowLayout.new
container.setLayout(layout)

opts = self.opts

container.setSize(self.width, self.height)
container.setText(self.title)

container.addListener(::Swt::SWT::Close, main_window_on_close)
end


def gui_open
self.gui_container.open

::Swt.event_loop { ::Swt.display.isDisposed }

Shoes.logger.debug "::Swt.display disposed... exiting Shoes::App.new"
end

private
def main_window_on_close
lambda {
Shoes.logger.debug "main_window on_close block begin... disposing ::Swt.display"
::Swt.display.dispose
Shoes.logger.debug "::Swt.display disposed"
}
end
end
end
end

module Shoes
class App
include Shoes::Swt::App
end
end

48 changes: 48 additions & 0 deletions lib/shoes/swt/button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Shoes
module Swt
module Button

def gui_button_init
# Create a button on the specified _shell_
#def initialize(container, text = 'Button', opts = {}, &blk)
self.gui_element = button = ::Swt::Widgets::Button.new(self.gui_container, ::Swt::SWT::PUSH)
button.setText(self.text)
#@native_widget.setBounds(10, 10, 150, 30)

button.addSelectionListener(self.click_event_lambda) if click_event_lambda
button.pack
end

def move(left, top)
super(left, top)
unless gui_element.disposed?
# If this element is part of a layout, we need to pop it into its own
# composite layer before moving it, so the rest of of the elements in
# the layout can reflow.
if gui_container.get_layout
old_gui_container = self.gui_container
self.gui_container = ::Swt::Widgets::Composite.new(@app.gui_container, ::Swt::SWT::NO_BACKGROUND)
self.gui_element.dispose
self.gui_container.set_layout nil
self.gui_element = ::Swt::Widgets::Button.new(gui_container, ::Swt::SWT::PUSH).tap do |button|
button.set_text(self.text)
button.add_selection_listener(self.click_event_lambda) if click_event_lambda
button.pack
end
self.gui_container.set_bounds(0, 0, @app.gui_container.size.x, @app.gui_container.size.y)
self.gui_container.move_above(old_gui_container)
old_gui_container.layout
end
self.gui_element.set_location left, top
self.gui_element.redraw
end
end
end
end
end

module Shoes
class Button
include Shoes::Swt::Button
end
end
15 changes: 15 additions & 0 deletions lib/shoes/swt/color.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Shoes
module Swt
module Color
def to_native
::Swt::Graphics::Color.new(Shoes.display, @red, @green, @blue)
end
end
end
end

module Shoes
class Color
include Shoes::Swt::Color
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'white_shoes/element_methods'


module SwtShoes
module Shoes
module Swt
module ElementMethods

#def stack(opts={}, &blk)
Expand All @@ -12,7 +13,7 @@ module ElementMethods
#end

#def flow(opts = {}, &blk)
# swt_flow = SwtShoes::Shoes::Flow.new(container, opts, &blk)
# swt_flow = Shoes::Swt::Shoes::Flow.new(container, opts, &blk)
#end

#
Expand Down Expand Up @@ -64,7 +65,7 @@ def oval(*opts)
paint_callback: lambda do |event, shape|
#return if hidden?
gc = event.gc
gc.set_antialias Swt::SWT::ON
gc.set_antialias ::Swt::SWT::ON
gc.set_line_width shape.style[:strokewidth]
gc.setForeground(shape.style[:stroke].to_native)
gc.draw_oval(shape.left, shape.top, shape.width, shape.height)
Expand All @@ -80,10 +81,11 @@ def shape(*opts)
super(*opts, args)
end
end
end
end

module Shoes
class App
include SwtShoes::ElementMethods
include Shoes::Swt::ElementMethods
end
end
47 changes: 47 additions & 0 deletions lib/shoes/swt/flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Shoes
module Swt
# flow takes these options
# :margin - integer - add this many pixels to all 4 sides of the layout

module Flow

def gui_flow_init
self.gui_container = container = ::Swt::Widgets::Composite.new(self.parent_gui_container, ::Swt::SWT::NO_BACKGROUND)

# RowLayout is horizontal by default, wrapping by default
layout = ::Swt::Layout::RowLayout.new

# set the margins
set_margin(layout)

if self.width && self.height
container.setSize(self.width, self.height)
end

container.setLayout(layout)
end

def gui_flow_add_to_parent
#self.parent_gui_container.add(self.gui_container)
end

# Add this many pixels to margins on layout
def set_margin(layout)
if margin_pixels = self.margin
layout.marginTop = margin_pixels
layout.marginRight = margin_pixels
layout.marginBottom = margin_pixels
layout.marginLeft = margin_pixels
end
end
end
end
end


module Shoes
class Flow
include Shoes::Swt::Flow
end
end

32 changes: 32 additions & 0 deletions lib/shoes/swt/line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Shoes
module Swt
module Line
attr_reader :gui_container, :gui_element
attr_reader :gui_paint_callback

def gui_init
# @gui_opts must be provided if this shape is responsible for
# drawing itself. If this shape is part of another shape, then
# @gui_opts should be nil
if @gui_opts
@gui_container = @gui_opts[:container]
default_paint_callback = lambda do |event|
gc = event.gc
gc.set_antialias ::Swt::SWT::ON
gc.set_foreground self.stroke.to_native
gc.set_line_width self.style[:strokewidth]
gc.draw_line(@left, @top, right, bottom)
end
@gui_paint_callback = @gui_opts[:paint_callback] || default_paint_callback
@gui_container.add_paint_listener(@gui_paint_callback)
end
end
end
end
end

module Shoes
class Line
include Shoes::Swt::Line
end
end
34 changes: 34 additions & 0 deletions lib/shoes/swt/oval.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Shoes
module Swt
module Oval
attr_reader :gui_container, :gui_element
attr_reader :gui_paint_callback

# FIXME: This (mostly) duplicates Shoes::Swt::Line#gui_init
def gui_init
# @gui_opts must be provided if this shape is responsible for
# drawing itself. If this shape is part of another shape, then
# @gui_opts should be nil
if @gui_opts
@gui_container = @gui_opts[:container]
@gui_paint_callback = lambda do |event|
gc = event.gc
gc.set_antialias ::Swt::SWT::ON
gc.set_background self.fill.to_native
gc.fill_oval(@left, @top, @width, @height)
gc.set_foreground self.stroke.to_native
gc.set_line_width self.style[:strokewidth]
gc.draw_oval(@left, @top, @width, @height)
end
@gui_container.add_paint_listener(@gui_paint_callback)
end
end
end
end
end

module Shoes
class Oval
include Shoes::Swt::Oval
end
end
Loading

0 comments on commit c176f22

Please sign in to comment.