- Timestamp:
- 09/22/08 03:11:32 (2 months ago)
- Files:
-
- 1 modified
-
lang/ruby/misc/fitview.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/misc/fitview.rb
r19657 r19701 19 19 # 20 20 21 require 'kconv' 21 22 require 'sdl' 22 23 … … 26 27 EXTS = ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.jpeg'] 27 28 28 FONT PATH = 'C:\Windows\Fonts\GOTHIC.TTF'29 FONTSIZE = 3229 FONTS_PATH = ['c:\hoge\sys\mplus_j12r.bdf', 'c:\hoge\sys\mplus_f12r.bdf'] 30 FONTSIZE = 12 30 31 31 32 class SDL::Surface … … 61 62 if entries.length==0 62 63 puts "no image: #{File.expand_path('.')}" 63 raise QuitException64 raise SelectDirectoryEvent 64 65 end 65 66 … … 85 86 @table[page] = image.scale_transform(scale) 86 87 rescue SDL::Error 88 text = "cannot open #{path}" 87 89 surface = SDL::Surface.plain_surface(SCREEN.w, SCREEN.h, SCREEN.format) 88 text = "cannot open #{path}" 89 DEFAULT_FONT.draw_solid_utf8(surface, text, 0, 0, 255, 255, 255) 90 draw_text(surface, text, 0, 0) 90 91 @table[page] = surface 91 92 end … … 101 102 end 102 103 def next_page 103 @curpage = @curpage==self.length-1 ? 0 : @curpage+1 104 if @curpage==self.length-1 105 raise SelectDirectoryEvent 106 end 107 @curpage = @curpage+1 104 108 self.load(@curpage) 105 109 end 106 110 def prev_page 107 @curpage = @curpage==0 ? self.length - 1 : @curpage-1 111 if @curpage==0 112 raise SelectDirectoryEvent 113 end 114 @curpage = @curpage-1 108 115 self.load(@curpage) 109 116 end 110 117 end 111 112 class QuitException < Exception 113 end 114 115 begin 116 if ARGV.length==0 117 puts 'no input' 118 raise QuitException 119 end 120 121 SDL.init(SDL::INIT_VIDEO) 122 SDL::TTF.init 123 124 DEFAULT_FONT = SDL::TTF.open(FONTPATH, FONTSIZE) 125 126 SDL::Screen.open(WIDTH, HEIGHT, 0, SDL::HWSURFACE|SDL::HWACCEL|SDL::FULLSCREEN) 127 SCREEN = SDL::Screen.get 128 129 input_path = ARGV[0] 118 def fitview(input_path) 130 119 basename = File.basename(input_path) 131 120 entries, curpage = open_path(input_path) … … 164 153 if upview || image.h <= SCREEN.h 165 154 upview = false 166 image , scale, enough= pages.prev_page155 image = pages.prev_page 167 156 else 168 157 upview = true … … 178 167 end 179 168 end 169 end 170 171 def dirselect 172 dirs = Dir.entries('.').reject{|file| !File.directory?(file)} 173 select = 0 174 loop do 175 SCREEN.fill(0) 176 SCREEN.draw_rect(0, select*FONTSIZE, SCREEN.w, FONTSIZE, 255, true, 100) 177 dirs.each_with_index{|dir, i| 178 draw_text(SCREEN, dir, 0, i*FONTSIZE) 179 } 180 SCREEN.update 181 case event = SDL::Event.wait 182 when SDL::Event::Quit 183 raise QuitException 184 when SDL::Event::KeyDown 185 case event.sym 186 when SDL::Key::Q, SDL::Key::ESCAPE 187 raise QuitException 188 when SDL::Key::LEFT, SDL::Key::RIGHT 189 return dirs[select] 190 when SDL::Key::UP 191 select = select==0? dirs.length-1 : select-1 192 when SDL::Key::DOWN 193 select = select==dirs.length-1? 0 : select+1 194 end 195 end 196 end 197 end 198 def draw_text(surface, text, x, y) 199 DEFAULT_FONT.put(surface, text.tojis, 0, y, 255, 255, 255) 200 end 201 202 class SelectDirectoryEvent < Exception 203 end 204 class QuitException < Exception 205 end 206 207 begin 208 if ARGV.length==0 209 puts 'no input' 210 raise QuitException 211 end 212 213 SDL.init(SDL::INIT_VIDEO) 214 215 DEFAULT_FONT = SDL::Kanji.open(FONTS_PATH[0], FONTSIZE) 216 FONTS_PATH[1..-1].each{|font| 217 DEFAULT_FONT.add(font) 218 } 219 220 SDL::Screen.open(WIDTH, HEIGHT, 0, SDL::HWSURFACE|SDL::HWACCEL|SDL::FULLSCREEN) 221 SCREEN = SDL::Screen.get 222 223 image_path = ARGV[0] 224 loop do 225 begin 226 fitview(image_path) 227 rescue SelectDirectoryEvent 228 while dir = dirselect 229 if dir == '.' 230 image_path = '.' 231 break 232 else 233 Dir.chdir(dir) 234 end 235 end 236 end 237 end 238 180 239 rescue SDL::Error => error 181 240 puts error.message
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)