Created
June 12, 2012 04:07
-
-
Save masuidrive/2914857 to your computer and use it in GitHub Desktop.
MobiRuby progress at June 12, 2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# http://www.flickr.com/photos/masuidrive/7178967237/ | |
# | |
def _S(str) | |
Mobi::Cocoa::NSString._stringWithUTF8String(str) | |
end | |
C = Mobi::C | |
class Mobi::Cocoa::CGRect < Mobi::C::Struct | |
define Mobi::C::Float, :x, | |
Mobi::C::Float, :y, | |
Mobi::C::Float, :width, | |
Mobi::C::Float, :height | |
end | |
def CGRectMake(x,y,w,h) | |
rect = Mobi::Cocoa::CGRect.new | |
rect[:x] = x.to_f | |
rect[:y] = y.to_f | |
rect[:width] = w.to_f | |
rect[:height] = h.to_f | |
rect | |
end | |
screen_rect = Mobi::Cocoa::UIScreen._mainScreen._bounds | |
window = Mobi::Cocoa::UIWindow._alloc._initWithFrame screen_rect | |
window._setBackgroundColor Mobi::Cocoa::UIColor._redColor | |
window._makeKeyAndVisible | |
rect = CGRectMake(0,32,screen_rect[:width],100) | |
label = Mobi::Cocoa::UILabel._alloc._initWithFrame rect | |
label._setBackgroundColor Mobi::Cocoa::UIColor._clearColor | |
label._setTextColor Mobi::Cocoa::UIColor._whiteColor | |
label._setText _S("MobiRuby") | |
label._setTextAlignment C::Int(1) # UITextAlignmentCenter | |
window._addSubview label | |
class MyAlertView < Mobi::Cocoa::UIAlertView | |
define Mobi::C::Void, :didPresentAlertView, Mobi::C::Pointer do | |
p "MyAlertView::didPresentAlertView" | |
end | |
define Mobi::C::Void, :alertView, Mobi::C::Pointer, :clickedButtonAtIndex, Mobi::C::SInt32 do |me, index| | |
if index.value == 1 | |
app = Mobi::Cocoa::UIApplication._sharedApplication | |
url = Mobi::Cocoa::NSURL._URLWithString(_S("http://mobiruby.org")) | |
run | |
app._openURL url | |
else | |
run | |
end | |
end | |
end | |
def run | |
#alert = MyAlertView._alloc. | |
alert = MyAlertView._alloc._initWithTitle _S("Hello"), | |
:message, _S("I am MobiRuby"), | |
:delegate, Mobi::C::Pointer.new, #nil, | |
:cancelButtonTitle, _S("I know!"), | |
:otherButtonTitles, _S("What's?"), Mobi::C::Pointer.new # nil | |
alert._setDelegate alert | |
alert._show | |
end | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment