1 # Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
4 # Moonlight List (moonlight-list@lists.ximian.com)
6 # Permission is hereby granted, free of charge, to any person
7 # obtaining a copy of this software and associated documentation
8 # files (the "Software"), to deal in the Software without
9 # restriction, including without limitation the rights to use,
10 # copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the
12 # Software is furnished to do so, subject to the following
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 # OTHER DEALINGS IN THE SOFTWARE.
31 import System
.Windows
.Media
32 import System
.Windows
.Media
.Animation
33 import System
.Windows
.Controls
34 import System
.Windows
.Shapes
37 class MyWindow(Window
):
48 super ("Photo browser")
49 DeleteEvent
+= OnDeleteEvent
50 ExposeEvent
+= OnExposeEvent
52 vbox
= VBox (false, 12)
53 buttonBox
= HButtonBox ()
54 button1
= Button ("Previous")
55 button2
= Button ("Next")
56 buttonBox
.Add (button1
)
57 buttonBox
.Add (button2
)
59 button2
.Clicked
+= OnNextClicked
60 button1
.Clicked
+= OnPrevClicked
62 _silver
= GtkSilver (320, 220)
64 _silver
.Attach (_canvas
)
67 vbox
.PackStart (_silver
)
68 vbox
.PackEnd (buttonBox
)
69 _silver
.SetSizeRequest (320, 240)
72 private def CreateRectangleAtPosition (fileName
as string
, position
as double
, name
as string
):
73 rectangle
= Rectangle ()
75 rectangle
.Height
= 200
76 rectangle
.RadiusX
= 20
77 rectangle
.RadiusY
= 20
78 rectangle
.SetValue (DependencyObject
.NameProperty
, name
)
80 solidBrush
= SolidColorBrush ()
81 solidBrush
.Color
= Color
.FromArgb (255, 255, 255, 255)
83 fillBrush
= ImageBrush ()
85 rectangle
.Fill
= fillBrush
86 rectangle
.Stroke
= solidBrush
87 rectangle
.StrokeThickness
= 2.0
89 _canvas
.Children
.Add (rectangle
)
90 _canvas
.SetLeft (rectangle
, position
)
91 _canvas
.SetTop (rectangle
, 10.0)
92 fillBrush
.ImageSource
= Uri(fileName
, UriKind
.Relative
)
94 rectangle
.MouseEnter
+= OnHover
95 rectangle
.MouseLeave
+= OnUnHover
97 private def CreateNewAnimationForName (name
as string
, pos
as double
):
100 sb
.SetValue (Storyboard
.TargetNameProperty
, name
)
101 sb
.SetValue (Storyboard
.TargetPropertyProperty
, "(Canvas.Left)")
102 animation
= DoubleAnimationUsingKeyFrames ()
103 xaml
= String
.Format ('<SplineDoubleKeyFrame KeyTime="0:0:1" Value="{0}" KeySpline="0.5,0.0 0.5, 1.0" />', pos
)
104 frame
= _silver
.CreateFromString (xaml
, false)
105 animation
.KeyFrames
.Add (frame
)
106 sb
.Children
.Add (animation
)
107 _canvas
.Resources
.Add (sb
)
110 private def OnExposeEvent ():
114 for file
in Directory
.GetFiles ("./", "*.jpg"):
115 CreateRectangleAtPosition (file
, pos
, currentId
.ToString ())
121 private def OnDeleteEvent():
122 Gtk
.Application
.Quit ()
124 private def OnNextClicked ():
125 if (_currentId
== 5):
129 CreateNewAnimationForName (_currentId
.ToString (), -400)
132 CreateNewAnimationForName (_currentId
.ToString (), 10)
134 private def OnPrevClicked ():
135 if (_currentId
== 1):
138 CreateNewAnimationForName (_currentId
.ToString (), 400)
141 CreateNewAnimationForName (_currentId
.ToString (), 10)
143 private def OnHover (sender
as Rectangle
):
144 solid
= sender
.Stroke
as SolidColorBrush
145 solid
.Color
= Color
.FromArgb (255, 255, 0, 0)
147 private def OnUnHover (sender
as Rectangle
):
148 solid
= sender
.Stroke
as SolidColorBrush
149 solid
.Color
= Color
.FromArgb (255, 255, 255, 255)
152 Gtk
.Application
.Init ()
154 myWindow
= MyWindow ()
156 Gtk
.Application
.Run ()