Class: Fox::FXBitmapView

Inherits:
FXScrollArea show all
Defined in:
lib/fox16/bitmapview.rb,
lib/fox16/aliases.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

BITMAPVIEW_NORMAL =

Bitmap alignment styles

0
BITMAPVIEW_CENTER_X =
0
BITMAPVIEW_LEFT =
0x00100000
BITMAPVIEW_RIGHT =
0x00200000
BITMAPVIEW_CENTER_Y =
0,         # Centered vertically
BITMAPVIEW_TOP       = 0x00400000
BITMAPVIEW_BOTTOM =

Normal mode is centered Centered horizontally Left-aligned Right-aligned Centered vertically Top-aligned Bottom-aligned

0x00800000

Instance Method Summary collapse

Methods inherited from FXScrollArea

#contentHeight, #contentWidth, #horizontalScrollable?, #scrollCorner, #scrollStyle, #scrollStyle=, #verticalScrollable?

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.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fox16/bitmapview.rb', line 34

def initialize(p, bmp=nil, tgt=nil, sel=0, opts=0, x=0, y=0, w=0, h=0) # :yields: theBitmapView
  super(p, opts, x, y, w, h)
  self.flags |= FLAG_ENABLED
  self.target = tgt
  self.message = sel
  @bitmap = bmp
  @onColor = Fox.FXRGB(0, 0, 0)
  @offColor = backColor
  @grabx = 0
  @graby = 0
end

Instance Method Details

#alignmentObject

Return the current alignment for the bitmap inside the FXBitmapView.



419
420
421
# File 'lib/fox16/aliases.rb', line 419

def alignment # :nodoc:
  getAlignment()
end

#alignment=(mode) ⇒ Object

Set the current alignment for the bitmap inside the FXBitmapView, where mode is some combination of the bitmap alignment flags listed above.



422
423
424
# File 'lib/fox16/aliases.rb', line 422

def alignment=(jst) # :nodoc:
  setAlignment(jst)
end

#bitmapObject

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



401
402
403
# File 'lib/fox16/aliases.rb', line 401

def bitmap # :nodoc:
  getBitmap()
end

#bitmap=(bmp) ⇒ Object

Set the bitmap for this FXBitmapView, where bmp is either nil or a reference to an FXBitmap instance.



404
405
406
# File 'lib/fox16/aliases.rb', line 404

def bitmap=(bmp) # :nodoc:
  setBitmap(bmp)
end

#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

#offColorObject

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



413
414
415
# File 'lib/fox16/aliases.rb', line 413

def offColor # :nodoc:
  getOffColor()
end

#offColor=(clr) ⇒ Object

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



416
417
418
# File 'lib/fox16/aliases.rb', line 416

def offColor=(clr) # :nodoc:
  setOffColor(clr)
end

#onColorObject

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



407
408
409
# File 'lib/fox16/aliases.rb', line 407

def onColor # :nodoc:
  getOnColor()
end

#onColor=(clr) ⇒ Object

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



410
411
412
# File 'lib/fox16/aliases.rb', line 410

def onColor=(clr) # :nodoc:
  setOnColor(clr)
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