hotcocoa 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/History.txt +4 -0
  2. data/bin/hotcocoa +31 -0
  3. data/lib/hotcocoa/application_builder.rb +320 -0
  4. data/lib/hotcocoa/attributed_string.rb +143 -0
  5. data/lib/hotcocoa/behaviors.rb +7 -0
  6. data/lib/hotcocoa/data_sources/combo_box_data_source.rb +44 -0
  7. data/lib/hotcocoa/data_sources/table_data_source.rb +18 -0
  8. data/lib/hotcocoa/delegate_builder.rb +85 -0
  9. data/lib/hotcocoa/graphics/canvas.rb +836 -0
  10. data/lib/hotcocoa/graphics/color.rb +781 -0
  11. data/lib/hotcocoa/graphics/elements/particle.rb +75 -0
  12. data/lib/hotcocoa/graphics/elements/rope.rb +99 -0
  13. data/lib/hotcocoa/graphics/elements/sandpainter.rb +71 -0
  14. data/lib/hotcocoa/graphics/gradient.rb +63 -0
  15. data/lib/hotcocoa/graphics/image.rb +488 -0
  16. data/lib/hotcocoa/graphics/path.rb +325 -0
  17. data/lib/hotcocoa/graphics/pdf.rb +71 -0
  18. data/lib/hotcocoa/graphics.rb +161 -0
  19. data/lib/hotcocoa/kernel_ext.rb +14 -0
  20. data/lib/hotcocoa/kvo_accessors.rb +48 -0
  21. data/lib/hotcocoa/layout_view.rb +448 -0
  22. data/lib/hotcocoa/mapper.rb +227 -0
  23. data/lib/hotcocoa/mapping_methods.rb +40 -0
  24. data/lib/hotcocoa/mappings/alert.rb +25 -0
  25. data/lib/hotcocoa/mappings/application.rb +112 -0
  26. data/lib/hotcocoa/mappings/array_controller.rb +87 -0
  27. data/lib/hotcocoa/mappings/box.rb +39 -0
  28. data/lib/hotcocoa/mappings/button.rb +92 -0
  29. data/lib/hotcocoa/mappings/collection_view.rb +44 -0
  30. data/lib/hotcocoa/mappings/color.rb +28 -0
  31. data/lib/hotcocoa/mappings/column.rb +21 -0
  32. data/lib/hotcocoa/mappings/combo_box.rb +24 -0
  33. data/lib/hotcocoa/mappings/control.rb +33 -0
  34. data/lib/hotcocoa/mappings/font.rb +44 -0
  35. data/lib/hotcocoa/mappings/gradient.rb +15 -0
  36. data/lib/hotcocoa/mappings/image.rb +15 -0
  37. data/lib/hotcocoa/mappings/image_view.rb +43 -0
  38. data/lib/hotcocoa/mappings/label.rb +25 -0
  39. data/lib/hotcocoa/mappings/layout_view.rb +9 -0
  40. data/lib/hotcocoa/mappings/menu.rb +71 -0
  41. data/lib/hotcocoa/mappings/menu_item.rb +47 -0
  42. data/lib/hotcocoa/mappings/movie.rb +13 -0
  43. data/lib/hotcocoa/mappings/movie_view.rb +27 -0
  44. data/lib/hotcocoa/mappings/notification.rb +17 -0
  45. data/lib/hotcocoa/mappings/popup.rb +110 -0
  46. data/lib/hotcocoa/mappings/progress_indicator.rb +68 -0
  47. data/lib/hotcocoa/mappings/scroll_view.rb +29 -0
  48. data/lib/hotcocoa/mappings/search_field.rb +9 -0
  49. data/lib/hotcocoa/mappings/secure_text_field.rb +17 -0
  50. data/lib/hotcocoa/mappings/segmented_control.rb +97 -0
  51. data/lib/hotcocoa/mappings/slider.rb +25 -0
  52. data/lib/hotcocoa/mappings/sort_descriptor.rb +13 -0
  53. data/lib/hotcocoa/mappings/sound.rb +9 -0
  54. data/lib/hotcocoa/mappings/speech_synthesizer.rb +25 -0
  55. data/lib/hotcocoa/mappings/split_view.rb +21 -0
  56. data/lib/hotcocoa/mappings/status_bar.rb +7 -0
  57. data/lib/hotcocoa/mappings/status_item.rb +9 -0
  58. data/lib/hotcocoa/mappings/table_view.rb +110 -0
  59. data/lib/hotcocoa/mappings/text_field.rb +41 -0
  60. data/lib/hotcocoa/mappings/text_view.rb +13 -0
  61. data/lib/hotcocoa/mappings/timer.rb +25 -0
  62. data/lib/hotcocoa/mappings/toolbar.rb +97 -0
  63. data/lib/hotcocoa/mappings/toolbar_item.rb +36 -0
  64. data/lib/hotcocoa/mappings/view.rb +67 -0
  65. data/lib/hotcocoa/mappings/web_view.rb +22 -0
  66. data/lib/hotcocoa/mappings/window.rb +118 -0
  67. data/lib/hotcocoa/mappings/xml_parser.rb +41 -0
  68. data/lib/hotcocoa/mappings.rb +109 -0
  69. data/lib/hotcocoa/mvc.rb +175 -0
  70. data/lib/hotcocoa/notification_listener.rb +62 -0
  71. data/lib/hotcocoa/object_ext.rb +22 -0
  72. data/lib/hotcocoa/plist.rb +45 -0
  73. data/lib/hotcocoa/standard_rake_tasks.rb +17 -0
  74. data/lib/hotcocoa/template.rb +27 -0
  75. data/lib/hotcocoa/virtual_file_system.rb +172 -0
  76. data/lib/hotcocoa.rb +26 -0
  77. data/template/Rakefile +5 -0
  78. data/template/config/build.yml +8 -0
  79. data/template/lib/application.rb +45 -0
  80. data/template/lib/menu.rb +32 -0
  81. data/template/resources/HotCocoa.icns +0 -0
  82. data/test/test_helper.rb +3 -0
  83. data/test/test_hotcocoa.rb +11 -0
  84. metadata +137 -0
@@ -0,0 +1,25 @@
1
+ HotCocoa::Mappings.map :alert => :NSAlert do
2
+
3
+ defaults :default => "OK", :alternate => nil, :other => nil, :info => "", :show => true
4
+
5
+ def alloc_with_options(options)
6
+ if options[:message]
7
+ alert = NSAlert.alertWithMessageText options.delete(:message),
8
+ defaultButton:options.delete(:default),
9
+ alternateButton:options.delete(:alternate),
10
+ otherButton:options.delete(:other),
11
+ informativeTextWithFormat:options.delete(:info)
12
+ end
13
+ end
14
+
15
+ custom_methods do
16
+
17
+ def show
18
+ runModal
19
+ end
20
+
21
+ end
22
+
23
+ delegating "alertShowHelp:", :to => :show_help?
24
+
25
+ end
@@ -0,0 +1,112 @@
1
+ HotCocoa::Mappings.map :application => :NSApplication do
2
+
3
+ def alloc_with_options(options)
4
+ NSApplication.sharedApplication
5
+ end
6
+
7
+ def handle_block(application, &block)
8
+ application.load_application_menu
9
+ block.call(application)
10
+ application.run
11
+ end
12
+
13
+ custom_methods do
14
+
15
+ def load_application_menu
16
+ begin
17
+ require 'lib/menu'
18
+ o = Object.new
19
+ o.extend HotCocoa
20
+ setMainMenu(o.application_menu)
21
+ rescue LoadError => e
22
+ end
23
+ end
24
+
25
+ def name=(name)
26
+ @name = name
27
+ end
28
+
29
+ def name
30
+ @name
31
+ end
32
+
33
+ def menu=(menu)
34
+ setMainMenu(menu)
35
+ end
36
+
37
+ =begin
38
+ def menu(path=nil)
39
+ if path
40
+ find_menu(mainMenu, path)
41
+ else
42
+ mainMenu
43
+ end
44
+ end
45
+ =end
46
+ def menu; mainMenu; end
47
+
48
+ def on_hide(menu)
49
+ hide(menu)
50
+ end
51
+
52
+ def on_about(menu)
53
+ orderFrontStandardAboutPanel(menu)
54
+ end
55
+
56
+ def on_hide_others(menu)
57
+ hideOtherApplications(menu)
58
+ end
59
+
60
+ def on_show_all(menu)
61
+ unhideAllApplications(menu)
62
+ end
63
+
64
+ def on_quit(menu)
65
+ terminate(menu)
66
+ end
67
+
68
+ private
69
+
70
+ def find_menu(menu, path)
71
+ key = path.keys.first
72
+ value = path.values.first
73
+ menu = menu[key]
74
+ if value.kind_of?(Array)
75
+ find_menu(menu, value.first)
76
+ else
77
+ menu[value]
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ delegating "application:delegateHandlesKey:", :to => :delegate_handles_key?, :parameters => [:delegateHandlesKey]
84
+ delegating "application:openFile:", :to => :open_file, :parameters => [:openFile]
85
+ delegating "application:openFiles:", :to => :open_files, :parameters => [:openFiles]
86
+ delegating "application:openFileWithoutUI:", :to => :open_file_without_ui, :parameters => [:openFileWithoutUI]
87
+ delegating "application:openTempFile:", :to => :open_temp_file, :parameters => [:openTempFile]
88
+ delegating "application:printFile:", :to => :print_file
89
+ delegating "application:printFiles:withSettings:showPrintPanels:", :to => :print_files
90
+ delegating "application:willPresentError:", :to => :will_present_error
91
+ delegating "applicationDidBecomeActive:", :to => :did_become_active
92
+ delegating "applicationDidChangeScreenParameters:", :to => :did_change_screen_parameters
93
+ delegating "applicationDidFinishLaunching:", :to => :did_finish_launching
94
+ delegating "applicationDidHide:", :to => :did_hide
95
+ delegating "applicationDidResignActive:", :to => :resign_active
96
+ delegating "applicationDidUnhide:", :to => :did_unhide
97
+ delegating "applicationDidUpdate:", :to => :did_update
98
+ delegating "applicationDockMenu:", :to => :dock_menu
99
+ delegating "applicationOpenUntitledFile:", :to => :open_untitled_file
100
+ delegating "applicationShouldHandleReopen:hasVisibleWindows:", :to => :should_handle_reopen?, :parameters => [:hasVisibleWindows]
101
+ delegating "applicationShouldOpenUntitledFile:", :to => :should_open_untitled_file?
102
+ delegating "applicationShouldTerminate:", :to => :should_terminate?
103
+ delegating "applicationShouldTerminateAfterLastWindowClosed:", :to => :should_terminate_after_last_window_closed?
104
+ delegating "applicationWillBecomeActive:", :to => :will_become_active
105
+ delegating "applicationWillFinishLaunching:", :to => :will_finish_launching
106
+ delegating "applicationWillHide:", :to => :will_hide
107
+ delegating "applicationWillResignActive:", :to => :will_resign_active
108
+ delegating "applicationWillTerminate:", :to => :will_terminate
109
+ delegating "applicationWillUnhide:", :to => :will_unhide
110
+ delegating "applicationWillUpdate:", :to => :will_update
111
+
112
+ end
@@ -0,0 +1,87 @@
1
+ HotCocoa::Mappings.map :array_controller => :NSArrayController do
2
+
3
+ def init_with_options(array_controller, options)
4
+ result = array_controller.init
5
+ if options.has_key?(:for)
6
+ result.addObjects(options.delete(:for))
7
+ end
8
+ result
9
+ end
10
+
11
+ custom_methods do
12
+
13
+ def avoids_empty_selection?
14
+ avoidsEmptySelection
15
+ end
16
+
17
+ def preserves_selection?
18
+ preservesSelection
19
+ end
20
+
21
+ def rearrange_automatically=(value)
22
+ setAutomaticallyRearrangesObjects(value)
23
+ end
24
+
25
+ def rearrange_automatically?
26
+ automaticallyRearrangesObjects
27
+ end
28
+
29
+ def selects_inserted=(value)
30
+ setSelectsInsertedObjects(value)
31
+ end
32
+
33
+ def selects_inserted?
34
+ selectsInsertedObjects
35
+ end
36
+
37
+ def <<(object)
38
+ addObject(object)
39
+ end
40
+
41
+ def [](index)
42
+ arrangedObjects[index]
43
+ end
44
+
45
+ def each(&block)
46
+ arrangedObjects.each(&block)
47
+ end
48
+
49
+ def selected
50
+ selectedObjects.first
51
+ end
52
+
53
+ def sort_by=(sort_descriptors)
54
+ sort_descriptors = [sort_descriptors] if sort_descriptors.kind_of?(Hash)
55
+ descriptors = sort_descriptors.collect do |descriptor|
56
+ selector = descriptor.delete(:selector)
57
+ ascending = (descriptor.values.first == :ascending)
58
+ if selector
59
+ NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending: ascending, selector: selector)
60
+ else
61
+ NSSortDescriptor.alloc.initWithKey(descriptor.keys.first.to_s, ascending: ascending)
62
+ end
63
+ end
64
+ setSortDescriptors(descriptors)
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ =begin
72
+ array :avoids_empty_selection => true,
73
+ :preserves_selection => false,
74
+ :selects_inserted => false,
75
+ :rearrange_automatically => true,
76
+ :sort_by => {:name => :ascending}
77
+
78
+ array_controller = NSArrayController.new
79
+
80
+ array_controller.setAvoidsEmptySelection(false)
81
+ array_controller.setPreservesSelection(false)
82
+ array_controller.setSelectsInsertedObjects(false)
83
+ array_controller.setAutomaticallyRearrangesObjects(true)
84
+
85
+ array_controller.setSortDescriptors(NSArray.arrayWithObject(NSSortDescriptor.alloc.initWithKey("name", ascending: false)))
86
+ array_controller.addObject Icon.new("Rich", image(:file => "rich.jpg"))
87
+ =end
@@ -0,0 +1,39 @@
1
+ HotCocoa::Mappings.map :box => :NSBox do
2
+
3
+ defaults :frame => DefaultEmptyRect, :layout => {}
4
+
5
+ constant :title_position, {
6
+ :none => NSNoTitle,
7
+ :above_top => NSAboveTop,
8
+ :top => NSAtTop,
9
+ :below_top => NSBelowTop,
10
+ :above_bottom => NSAboveBottom,
11
+ :bottom => NSAtBottom,
12
+ :below_bottom => NSBelowBottom
13
+ }
14
+
15
+ constant :type, {
16
+ :primary => NSBoxPrimary,
17
+ :secondary => NSBoxSecondary,
18
+ :separator => NSBoxSeparator,
19
+ :old => NSBoxOldStyle,
20
+ :custom => NSBoxCustom
21
+ }
22
+
23
+ def init_with_options(box, options)
24
+ box.initWithFrame options.delete(:frame)
25
+ end
26
+
27
+ custom_methods do
28
+
29
+ def type=(value)
30
+ setBoxType(value)
31
+ end
32
+
33
+ def border=(value)
34
+ setBorderType(value)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,92 @@
1
+ HotCocoa::Mappings.map :button => :NSButton do
2
+
3
+ defaults :bezel => :rounded,
4
+ :frame => DefaultEmptyRect,
5
+ :layout => {}
6
+
7
+ constant :bezel, {
8
+ :rounded => NSRoundedBezelStyle,
9
+ :regular_square => NSRegularSquareBezelStyle,
10
+ :thick_square => NSThickSquareBezelStyle,
11
+ :thicker_square => NSThickerSquareBezelStyle,
12
+ :disclosure => NSDisclosureBezelStyle,
13
+ :shadowless_square => NSShadowlessSquareBezelStyle,
14
+ :circular => NSCircularBezelStyle,
15
+ :textured_square => NSTexturedSquareBezelStyle,
16
+ :help_button => NSHelpButtonBezelStyle,
17
+ :small_square => NSSmallSquareBezelStyle,
18
+ :textured_rounded => NSTexturedRoundedBezelStyle,
19
+ :round_rect => NSRoundRectBezelStyle,
20
+ :recessed => NSRecessedBezelStyle,
21
+ :rounded_disclosure => NSRoundedDisclosureBezelStyle
22
+ }
23
+
24
+ constant :type, {
25
+ :momentary_light => NSMomentaryLightButton,
26
+ :push_on_push_off => NSPushOnPushOffButton,
27
+ :toggle => NSToggleButton,
28
+ :switch => NSSwitchButton,
29
+ :radio => NSRadioButton,
30
+ :momentary_change => NSMomentaryChangeButton,
31
+ :on_off => NSOnOffButton,
32
+ :momentary_push_in => NSMomentaryPushInButton,
33
+ :momentary_push => NSMomentaryPushButton
34
+ }
35
+
36
+ constant :state, {
37
+ :on => NSOnState,
38
+ :off => NSOffState,
39
+ :mixed => NSMixedState
40
+ }
41
+
42
+ constant :image_position, {
43
+ :text_only => NSNoImage,
44
+ :image_only => NSImageOnly,
45
+ :overlaps => NSImageOverlaps,
46
+ :left => NSImageLeft,
47
+ :right => NSImageRight,
48
+ :below => NSImageBelow,
49
+ :above => NSImageAbove
50
+ }
51
+
52
+ def init_with_options(button, options)
53
+ button.initWithFrame options.delete(:frame)
54
+ end
55
+
56
+ custom_methods do
57
+
58
+ def bezel=(value)
59
+ setBezelStyle(value)
60
+ end
61
+
62
+ def type=(value)
63
+ setButtonType(value)
64
+ end
65
+
66
+ def state=(value)
67
+ case value
68
+ when :on
69
+ value = NSOnState
70
+ when :off
71
+ value = NSOffState
72
+ when :mixed
73
+ value = NSMixedState
74
+ end
75
+ setState(value)
76
+ end
77
+
78
+ def on?
79
+ state == NSOnState
80
+ end
81
+
82
+ def off?
83
+ state == NSOffState
84
+ end
85
+
86
+ def mixed?
87
+ state == NSMixedState
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,44 @@
1
+ HotCocoa::Mappings.map :collection_view => :NSCollectionView do
2
+
3
+ defaults :layout => {}, :frame => [0,0,100,100]
4
+
5
+ def init_with_options(collection_view, options)
6
+ collection_view.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def item_prototype
12
+ itemPrototype
13
+ end
14
+
15
+ def item_view
16
+ item_prototype ? item_prototype.view : nil
17
+ end
18
+
19
+ def item_view=(view)
20
+ item = NSCollectionViewItem.alloc.init
21
+ item.setView(view)
22
+ view.collection_item = item if view.respond_to?(:collection_item=)
23
+ setItemPrototype(item)
24
+ end
25
+
26
+ def rows=(value)
27
+ setMaxNumberOfRows(value)
28
+ end
29
+
30
+ def rows
31
+ maxNumberOfRows
32
+ end
33
+
34
+ def columns=(value)
35
+ setMaxNumberOfColumns(value)
36
+ end
37
+
38
+ def columns
39
+ maxNumberOfColumns
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,28 @@
1
+ HotCocoa::Mappings.map :color => :NSColor do
2
+
3
+ def alloc_with_options(options)
4
+ if options.has_key?(:name)
5
+ color = eval("NSColor.#{options.delete(:name)}Color")
6
+ color = color.colorWithAlphaComponent(options.delete(:alpha)) if options.has_key?(:alpha)
7
+ return color
8
+ elsif options.has_key?(:rgb)
9
+ calibrated = !options.delete(:device)
10
+ rgb = options.delete(:rgb)
11
+ red = ((rgb >> 16) & 0xff)/255.0
12
+ green = ((rgb >> 8) & 0xff)/255.0
13
+ blue = (rgb & 0xff)/255.0
14
+ alpha = options.delete(:alpha) || 1.0
15
+ if calibrated
16
+ return NSColor.colorWithCalibratedRed red, green:green, blue:blue, alpha:alpha
17
+ else
18
+ return NSColor.colorWithDeviceRed red, green:green, blue:blue, alpha:alpha
19
+ end
20
+ elsif (options.keys & [:red, :green, :blue]).size == 3
21
+ alpha = (options.delete(:alpha) or 1.0)
22
+ return NSColor.colorWithCalibratedRed options.delete(:red), green:options.delete(:green), blue:options.delete(:blue), alpha:alpha
23
+ else
24
+ raise "Cannot create color with the provided options"
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,21 @@
1
+ HotCocoa::Mappings.map :column => :NSTableColumn do
2
+
3
+ defaults :title => 'Column'
4
+
5
+ def init_with_options(column, options)
6
+ column.initWithIdentifier(options.delete(:id))
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def title
12
+ headerCell.stringValue
13
+ end
14
+
15
+ def title=(newTitle)
16
+ headerCell.stringValue = newTitle
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,24 @@
1
+ HotCocoa::Mappings.map :combo_box => :NSComboBox do
2
+
3
+ defaults :selectable => true, :editable => true, :completes => true, :layout => {}
4
+
5
+ def init_with_options(combo_box, options)
6
+ combo_box.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def data=(data_source)
12
+ setUsesDataSource(true)
13
+ data_source = HotCocoa::ComboBoxDataSource.new(data_source) if data_source.kind_of?(Array)
14
+ setDataSource(data_source)
15
+ end
16
+
17
+ end
18
+
19
+ delegating "comboBoxSelectionDidChange:", :to => :selection_did_change
20
+ delegating "comboBoxSelectionIsChanging:", :to => :selection_is_changing
21
+ delegating "comboBoxWillDismiss:", :to => :will_dismiss
22
+ delegating "comboBoxWillPopUp:", :to => :will_pop_up
23
+
24
+ end
@@ -0,0 +1,33 @@
1
+ HotCocoa::Mappings.map :control => :NSControl do
2
+
3
+ constant :alignment, {
4
+ :left => NSLeftTextAlignment,
5
+ :right => NSRightTextAlignment,
6
+ :center => NSCenterTextAlignment,
7
+ :justified => NSJustifiedTextAlignment,
8
+ :natural => NSNaturalTextAlignment
9
+ }
10
+
11
+ custom_methods do
12
+
13
+ include HotCocoa::Mappings::TargetActionConvenience
14
+
15
+ def text=(text)
16
+ setStringValue(text)
17
+ end
18
+
19
+ def to_i
20
+ intValue
21
+ end
22
+
23
+ def to_f
24
+ doubleValue
25
+ end
26
+
27
+ def to_s
28
+ stringValue
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,44 @@
1
+ HotCocoa::Mappings.map :font => :NSFont do
2
+
3
+ constant :trait, {
4
+ :italic => NSItalicFontMask,
5
+ :bold => NSBoldFontMask,
6
+ :unbold => NSUnboldFontMask,
7
+ :nonstandard_character_set => NSNonStandardCharacterSetFontMask,
8
+ :narrow => NSNarrowFontMask,
9
+ :expanded => NSExpandedFontMask,
10
+ :condensed => NSCondensedFontMask,
11
+ :small_caps => NSSmallCapsFontMask,
12
+ :poster => NSPosterFontMask,
13
+ :compressed => NSCompressedFontMask,
14
+ :fixed_pitch => NSFixedPitchFontMask,
15
+ :unitalic => NSUnitalicFontMask
16
+ }
17
+
18
+ def alloc_with_options(options)
19
+ font = nil
20
+ {
21
+ :label => :labelFontOfSize,
22
+ :system => :systemFontOfSize,
23
+ :control_content => :controlContentFontOfSize,
24
+ :menu_bar => :menuBarFontOfSize,
25
+ :message => :messageFontOfSize,
26
+ :palette => :paletteFontOfSize,
27
+ :small_system => :smallSystemFontOfSize,
28
+ :title_bar => :titleBarFontOfSize,
29
+ :tool_tip => :toolTipFontOfSize,
30
+ :user_fixed => :userFixedPitchFontOfSize,
31
+ :user => :userFontOfSize
32
+ }.each do |key, method|
33
+ if options.has_key?(key)
34
+ font = eval("NSFont.#{method}(#{options.delete(key)})")
35
+ break
36
+ end
37
+ end
38
+ font = NSFont.fontWithName(options.delete(:name), size:(options.delete(:size) || 0)) if options.has_key?(:name)
39
+ raise "Cannot create font with the provided options" unless font
40
+ font = NSFontManager.sharedFontManager.convertFont(font, toHaveTrait:options.delete(:trait)) if options[:trait]
41
+ font
42
+ end
43
+
44
+ end
@@ -0,0 +1,15 @@
1
+ HotCocoa::Mappings.map :gradient => :NSGradient do
2
+
3
+ def alloc_with_options(options)
4
+ if options[:colors]
5
+ if options[:locations]
6
+ NSGradient.alloc.initWithColors options.delete(:colors), atLocations:options.delete(:locations), colorSpace:(options.delete(:color_space) || NSColorSpace.deviceRGBColorSpace)
7
+ else
8
+ NSGradient.alloc.initWithColors(options.delete(:colors))
9
+ end
10
+ elsif options[:start] && option[:end]
11
+ NSGradient.alloc.initWithStartingColor options.delete(:start), endingColor:options.delete(:end)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ HotCocoa::Mappings.map :image => :NSImage do
2
+
3
+ def alloc_with_options(options)
4
+ if options.has_key?(:file)
5
+ NSImage.alloc.initWithContentsOfFile(options.delete(:file))
6
+ elsif options.has_key?(:url)
7
+ NSImage.alloc.initByReferencingURL(NSURL.alloc.initWithString(options.delete(:url)))
8
+ elsif options.has_key?(:named)
9
+ NSImage.imageNamed(options.delete(:named))
10
+ else
11
+ NSImage.alloc.init
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,43 @@
1
+ HotCocoa::Mappings.map :image_view => :NSImageView do
2
+
3
+ defaults :layout => {}, :frame_style => :none
4
+
5
+ constant :frame_style, {
6
+ :none => NSImageFrameNone,
7
+ :photo => NSImageFramePhoto,
8
+ :bezel => NSImageFrameGrayBezel,
9
+ :groove => NSImageFrameGroove,
10
+ :button => NSImageFrameButton
11
+ }
12
+
13
+ constant :scale, {
14
+ :fit => NSScaleToFit,
15
+ :none => NSScaleNone,
16
+ :proportionally => NSScaleProportionally
17
+ }
18
+
19
+ def init_with_options(image_view, options)
20
+ image_view.initWithFrame options.delete(:frame)
21
+ end
22
+
23
+ custom_methods do
24
+
25
+ def frame_style=(value)
26
+ setImageFrameStyle(value)
27
+ end
28
+
29
+ def url=(url)
30
+ setImage(NSImage.alloc.initByReferencingURL(NSURL.alloc.initWithString(url)))
31
+ end
32
+
33
+ def file=(file)
34
+ setImage(NSImage.alloc.initWithContentsOfFile(file))
35
+ end
36
+
37
+ def scale=(value)
38
+ setImageScaling(value)
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,25 @@
1
+ HotCocoa::Mappings.map :label => :NSTextField do
2
+
3
+ constant :text_align, {
4
+ :right => NSRightTextAlignment,
5
+ :left => NSLeftTextAlignment,
6
+ :center => NSCenterTextAlignment
7
+ }
8
+
9
+ defaults :selectable => false, :bordered => false, :drawsBackground => false, :frame => DefaultEmptyRect, :layout => {}
10
+
11
+ def init_with_options(text_field, options)
12
+ tf = text_field.initWithFrame options.delete(:frame)
13
+ tf.editable = false
14
+ tf
15
+ end
16
+
17
+ custom_methods do
18
+
19
+ def text_align=(value)
20
+ setAlignment(value)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,9 @@
1
+ HotCocoa::Mappings.map :layout_view => :"HotCocoa::LayoutView" do
2
+
3
+ defaults :frame => DefaultEmptyRect, :layout => {}
4
+
5
+ def init_with_options(view, options)
6
+ view.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ end