Class: Fox::FXBitmapView

Inherits:
FXScrollArea show all
Defined in:
rdoc-sources/FXBitmapView.rb,
lib/fox16/bitmapview.rb

Overview

The FXBitmapView widget displays a scrollable view of a bitmap.

Bitmap alignment styles

BITMAPVIEW_NORMAL:: Normal mode is centered BITMAPVIEW_CENTER_X:: Centered horizontally BITMAPVIEW_LEFT:: Left-aligned BITMAPVIEW_RIGHT:: Right-aligned BITMAPVIEW_CENTER_Y:: Centered vertically BITMAPVIEW_TOP:: Top-aligned BITMAPVIEW_BOTTOM:: Bottom-aligned

Events

SEL_RIGHTBUTTONPRESS:: sent when the right mouse button goes down; the message data is an FXEvent instance. SEL_RIGHTBUTTONRELEASE:: sent when the right mouse button goes up; the message data is an FXEvent instance.

Constant Summary collapse

BITMAPVIEW_NORMAL =

Bitmap alignment styles

0
BITMAPVIEW_CENTER_X =

Normal mode is centered

0
BITMAPVIEW_LEFT =

Centered horizontally

0x00100000
BITMAPVIEW_RIGHT =

Left-aligned

0x00200000
BITMAPVIEW_CENTER_Y =

Right-aligned

0,         # Centered vertically
BITMAPVIEW_TOP       = 0x00400000
BITMAPVIEW_BOTTOM =

Top-aligned

0x00800000

Instance Attribute Summary collapse

Attributes inherited from FXScrollArea

#contentHeight, #contentWidth, #horizontalScrollBar, #scrollStyle, #verticalScrollBar, #viewportHeight, #viewportWidth, #xPosition, #yPosition

Attributes inherited from FXWindow

#accelTable, #backColor, #defaultCursor, #dragCursor, #first, #focus, #key, #last, #layoutHints, #next, #numChildren, #owner, #parent, #prev, #root, #selector, #shell, #target, #x, #y

Attributes inherited from FXDrawable

#height, #visual, #width

Attributes inherited from FXId

#app, #userData, #xid

Instance Method Summary collapse

Methods inherited from FXScrollArea

#horizontalScrollable?, #position, #scrollCorner, #setPosition, #verticalScrollable?

Methods inherited from FXComposite

#maxChildHeight, #maxChildWidth

Methods inherited from FXWindow

#acceptDrop, #acquireClipboard, #acquireSelection, #active?, #addHotKey, after?, #after?, before?, #before?, #beginDrag, #canFocus?, #changeFocus, #childAtIndex, #childOf?, #children, #clearDragRectangle, #clearShape, colorType, colorTypeName, commonAncestor, #composeContext, #composite?, #contains?, #containsChild?, #createComposeContext, #cursorPosition, #default?, #defaultHeight, #defaultWidth, deleteType, deleteTypeName, #destroy, #destroyComposeContext, #didAccept, #disable, #doesSaveUnder?, #dragging?, #dropDisable, #dropEnable, #dropEnabled?, #dropFinished, #dropTarget?, #each_child, #each_child_recursive, #enable, #enabled?, #endDrag, #forceRefresh, #getChildAt, #getDNDData, #getHeightForWidth, #getWidthForHeight, #grab, #grabKeyboard, #grabbed?, #grabbedKeyboard?, #handleDrag, #hasClipboard?, #hasFocus?, #hasSelection?, #height, #height=, #hide, imageType, #inFocusChain?, #indexOfChild, #initial?, #inquireDNDAction, #inquireDNDTypes, #killFocus, #linkAfter, #linkBefore, #lower, #move, octetType, octetTypeName, #offeredDNDType?, #position, #raiseWindow, #recalc, #releaseClipboard, #releaseSelection, #remHotKey, #removeChild, #repaint, #reparent, #resize, #scroll, #setCursorPosition, #setDNDData, #setDefault, #setDragRectangle, #setFocus, #setInitial, #setShape, #shell?, #show, #shown?, stringType, textType, textTypeName, #tr, #translateCoordinatesFrom, #translateCoordinatesTo, #underCursor?, #ungrab, #ungrabKeyboard, #update, urilistType, urilistTypeName, utf16Type, utf16TypeName, utf8Type, utf8TypeName, #visible=, #width, #width=

Methods included from Responder2

#connect

Methods inherited from FXDrawable

#resize

Methods inherited from FXId

#created?, #destroy, #runOnUiThread

Methods inherited from FXObject

#bind, #handle, #load, #save, subclasses

Constructor Details

#initialize(p, bmp = nil, tgt = nil, sel = 0, opts = 0, x = 0, y = 0, w = 0, h = 0) ⇒ FXBitmapView

Return an initialized FXBitmapView instance.



40
41
# File 'rdoc-sources/FXBitmapView.rb', line 40

def initialize(p, bmp=nil, target=nil, selector=0, opts=0, x=0, y=0, width=0, height=0) # :yields: theBitmapView
end

Instance Attribute Details

#alignmentObject

Return the current alignment for the bitmap inside the FXBitmapView.



35
36
37
# File 'rdoc-sources/FXBitmapView.rb', line 35

def alignment
  @alignment
end

#bitmapObject

Return a reference to the bitmap (an FXBitmap instance) for this FXBitmapView, or nil if no bitmap has been set.



26
27
28
# File 'rdoc-sources/FXBitmapView.rb', line 26

def bitmap
  @bitmap
end

#offColorObject

Return the color used for the “off” bits in the bitmap.



32
33
34
# File 'rdoc-sources/FXBitmapView.rb', line 32

def offColor
  @offColor
end

#onColorObject

Return the color used for the “on” bits in the bitmap.



29
30
31
# File 'rdoc-sources/FXBitmapView.rb', line 29

def onColor
  @onColor
end

Instance Method Details

#canFocusObject



56
57
58
# File 'lib/fox16/bitmapview.rb', line 56

def canFocus
  true
end

#createObject



46
47
48
49
# File 'lib/fox16/bitmapview.rb', line 46

def create
  super
  bitmap.create unless bitmap.nil?
end

#detachObject



51
52
53
54
# File 'lib/fox16/bitmapview.rb', line 51

def detach
  super
  bitmap.detach unless bitmap.nil?
end

#getContentHeightObject



64
65
66
# File 'lib/fox16/bitmapview.rb', line 64

def getContentHeight
  bitmap.nil? ? 1 : bitmap.height
end

#getContentWidthObject



60
61
62
# File 'lib/fox16/bitmapview.rb', line 60

def getContentWidth
  bitmap.nil? ? 1 : bitmap.width
end

#layoutObject



68
69
70
71
72
# File 'lib/fox16/bitmapview.rb', line 68

def layout
  super
  update
  self.flags &= ~FLAG_DIRTY
end

#onMotion(sender, sel, ev) ⇒ Object

Handle real or simulated mouse motion



154
155
156
157
158
159
160
# File 'lib/fox16/bitmapview.rb', line 154

def onMotion(sender, sel, ev)
  if (flags & FLAG_SCROLLING) != 0
    setPosition(ev.win_x - @grabx, ev.win_y - @graby)
    return 1
  end
  return 0
end

#onPaint(sender, sel, event) ⇒ Object

Handle expose (paint) event



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fox16/bitmapview.rb', line 75

def onPaint(sender, sel, event)
  FXDCWindow.new(self, event) do |dc|
    unless bitmap.nil?
      ww = bitmap.width
      hh = bitmap.height
      xx = pos_x
      yy = pos_y
      if ww < viewport_w
        if (options & BITMAPVIEW_LEFT) != 0
          xx = 0
        elsif (options & BITMAPVIEW_RIGHT) != 0
          xx = viewport_w - ww
        else
          xx = (viewport_w - ww)/2
        end
      end
      if hh < viewport_h
        if (options & BITMAPVIEW_TOP) != 0
          yy = 0
        elsif (options & BITMAPVIEW_BOTTOM) != 0
          yy = viewport_h - hh
        else
          yy = (viewport_h - hh)/2
        end
      end
      dc.foreground = onColor
      dc.background = offColor
      dc.drawBitmap(bitmap, xx, yy)
      dc.foreground = backColor
      xl = xx; xr = xx + ww
      yt = yy; yb = yy + hh
      xl = 0 if (xl < 0)
      xr = viewport_w if (xr > viewport_w)
      yt = 0 if (yt < 0)
      yb = viewport_h if (yb > viewport_h)
      dc.fillRectangle(0, 0, xr, yt)
      dc.fillRectangle(0, yt, xl, viewport_h - yt)
      dc.fillRectangle(xr, 0, viewport_w - xr, yb)
      dc.fillRectangle(xl, yb, viewport_w - xl, viewport_h - yb)
    else
      dc.foreground = backColor
      dc.fillRectangle(0, 0, width, height)
    end
  end
end

#onRightBtnPress(sender, sel, ev) ⇒ Object

Handle right mouse button press



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fox16/bitmapview.rb', line 122

def onRightBtnPress(sender, sel, ev)
  self.flags &= ~FLAG_TIP
  handle(self, Fox.FXSEL(SEL_FOCUS_SELF, 0), ev)
  if enabled?
    grab
    if target && target.handle(self, Fox.FXSEL(SEL_RIGHTBUTTONPRESS, message), ev) != 0
      return 1
    end
    self.flags &= ~FLAG_UPDATE
    self.flags |= FLAG_PRESSED|FLAG_SCROLLING
    @grabx = ev.win_x - pos_x
    @graby = ev.win_y - pos_y
    return 1
  end
  return 0
end

#onRightBtnRelease(sender, sel, ev) ⇒ Object

Handle right mouse button release



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/fox16/bitmapview.rb', line 140

def onRightBtnRelease(sender, sel, ev)
  if enabled?
    ungrab
    self.flags &= ~(FLAG_PRESSED|FLAG_SCROLLING)
    self.flags |= FLAG_UPDATE
    if target && target.handle(self, Fox.FXSEL(SEL_RIGHTBUTTONPRESS, message), ev) != 0
      return 1
    end
    return 1
  end
  return 0
end