]> gitweb.factorcode.org Git - factor.git/blob - extra/images/viewer/viewer.factor
Fix conflict in images vocab
[factor.git] / extra / images / viewer / viewer.factor
1 ! Copyright (C) 2007 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors images images.loader io.pathnames kernel
4 namespaces opengl opengl.gl sequences strings ui ui.gadgets
5 ui.gadgets.panes ui.render ;
6 IN: images.viewer
7
8 TUPLE: image-gadget < gadget { image image } ;
9
10 M: image-gadget pref-dim*
11     image>> dim>> ;
12
13 : draw-image ( image -- )
14     0 0 glRasterPos2i 1.0 -1.0 glPixelZoom
15     [ dim>> first2 GL_RGBA GL_UNSIGNED_BYTE ]
16     [ bitmap>> ] bi glDrawPixels ;
17
18 M: image-gadget draw-gadget* ( gadget -- )
19     image>> draw-image ;
20
21 : <image-gadget> ( image -- gadget )
22     \ image-gadget new-gadget
23         swap >>image ;
24
25 : image-window ( path -- gadget )
26     [ load-image <image-gadget> dup ] [ open-window ] bi ;
27
28 GENERIC: image. ( object -- )
29
30 : default-image. ( path -- )
31     <image-gadget> gadget. ;
32
33 M: string image. ( image -- ) load-image default-image. ;
34
35 M: pathname image. ( image -- ) load-image default-image. ;
36
37 M: image image. ( image -- ) default-image. ;