jonathan: thuban/Thuban/UI baserenderer.py, 1.18, 1.19 layerproperties.py, 1.1, 1.2 rasterlayerproperties.py, 1.2, 1.3 renderer.py, 1.58, 1.59
cvs@intevation.de
cvs at intevation.de
Wed Mar 23 16:30:29 CET 2005
Author: jonathan
Update of /thubanrepository/thuban/Thuban/UI
In directory doto:/tmp/cvs-serv32375/Thuban/UI
Modified Files:
baserenderer.py layerproperties.py rasterlayerproperties.py
renderer.py
Log Message:
Add support for adjusting the opacity of a raster layer.
Index: baserenderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/baserenderer.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- baserenderer.py 18 Feb 2005 14:54:17 -0000 1.18
+++ baserenderer.py 23 Mar 2005 15:30:27 -0000 1.19
@@ -488,7 +488,8 @@
if img_data is not None:
data = (width, height, img_data)
- self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW")
+ self.draw_raster_data(layer, fmin[0]+offx, offy-fmax[1],
+ data, "RAW")
data = None
def projected_raster_layer(self, layer, srcProj, dstProj, extents,
@@ -522,8 +523,8 @@
raise NotImplementedError
- def draw_raster_data(self, x, y, data, format="BMP"):
- """Draw the raster image in data onto the DC with the top
+ def draw_raster_data(self, layer, x, y, data, format="BMP"):
+ """Draw the layer's raster image held in data onto the DC with the top
left corner at (x,y)
The raster image data is a tuple of the form
Index: layerproperties.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/layerproperties.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- layerproperties.py 27 Jan 2005 14:19:41 -0000 1.1
+++ layerproperties.py 23 Mar 2005 15:30:27 -0000 1.2
@@ -56,7 +56,7 @@
text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, self.layer.Title())
text_title.SetInsertionPointEnd()
- sizer.Add(text_title, 1, wxGROW | wxRIGHT, 00)
+ sizer.Add(text_title, 1, wxGROW | wxRIGHT, 0)
panelBox.Add(sizer, 0, wxGROW | wxALL, 4)
Index: rasterlayerproperties.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/rasterlayerproperties.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rasterlayerproperties.py 16 Feb 2005 21:14:47 -0000 1.2
+++ rasterlayerproperties.py 23 Mar 2005 15:30:27 -0000 1.3
@@ -19,6 +19,8 @@
from Thuban.version import versions
+ID_RB_MASK = 4002
+
class RasterLayerProperties(LayerProperties):
def __init__(self, parent, name, layer, *args, **kw):
@@ -88,16 +90,32 @@
else:
choices = ["None", "Bitmap", "Alpha"]
- self.maskRadioBox = wxRadioBox(panel, -1, _("Mask Type"),
+ self.maskRadioBox = wxRadioBox(panel, ID_RB_MASK, _("Mask Type"),
choices=choices)
#self.maskCB = wxCheckBox(panel, -1, _("Use Mask"))
maskBox.Add(self.maskRadioBox, 0, wxRIGHT, 10)
+ self.opBox = wxBoxSizer(wxHORIZONTAL)
+ self.opSpinLabel = wxStaticText(panel, -1, _("Opacity:"))
+ self.opBox.Add(self.opSpinLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4)
+ self.opSpin = wxSpinCtrl(panel, -1,
+ str(self.layer.Opacity()*255),
+ initial = self.layer.Opacity()*255,
+ min=0, max=255)
+ self.opBox.Add(self.opSpin, 0, wxALL, 4)
+ maskBox.Add(self.opBox, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
+
rasterBox.Add(maskBox, 0, wxALL, 4)
+ #rasterBox.Add(opBox, 0, wxALL, 4)
+
panelBox.Add(rasterBox, 1, wxGROW | wxALL, 4)
self.maskRadioBox.SetSelection(self.old_state["mask_type"])
+ self.OnMaskSelect(None)
+
+ EVT_RADIOBOX(self, ID_RB_MASK, self.OnMaskSelect)
+
def OnTry(self, event):
self.set_state()
@@ -109,6 +127,12 @@
self.maskRadioBox.SetSelection(self.old_state["mask_type"])
self.set_state()
+ def OnMaskSelect(self, event):
+ allowOpacity = self.maskRadioBox.GetSelection()==2
+ self.opSpin.Enable(allowOpacity)
+ self.opSpinLabel.Enable(allowOpacity)
+
def set_state(self):
self.layer.SetMaskType(self.maskRadioBox.GetSelection())
+ self.layer.SetOpacity(self.opSpin.GetValue()/255.0)
return True
Index: renderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/renderer.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- renderer.py 18 Feb 2005 14:54:17 -0000 1.58
+++ renderer.py 23 Mar 2005 15:30:27 -0000 1.59
@@ -16,6 +16,8 @@
import cStringIO
+import array
+
from Thuban import _
from wxPython.wx import wxPoint, wxRect, wxPen, wxBrush, wxFont, \
@@ -135,9 +137,10 @@
return ret
- def draw_raster_data(self, x,y, data, format = 'BMP'):
+ def draw_raster_data(self, layer, x,y, data, format = 'BMP'):
mask = None
+ alpha = None
width = data[0]
height = data[1]
image_data, mask_data, alpha_data = data[2]
@@ -152,7 +155,9 @@
mask = wxBitmapFromBits(mask_data, width, height, 1)
mask = wxMask(mask)
elif alpha_data is not None:
- image.SetAlphaData(alpha_data)
+ # alpha_data is already in the right format
+ alpha = alpha_data
+
else:
stream = cStringIO.StringIO(image_data)
image = wxImageFromStream(stream, raster_format_map[format])
@@ -163,10 +168,29 @@
elif alpha_data is not None:
stream = cStringIO.StringIO(alpha_data)
alpha = wxImageFromStream(stream, raster_format_map[format])
- image.SetAlpha(alpha.GetData()[:])
+ alpha = alpha.GetData()[:] # XXX: do we need to copy this?
+
+ #
+ # if we are using the alpha_data then scale down the alpha values
+ # by the layer's opacity using a string translation table
+ #
+ if alpha is not None:
+ lo = layer.Opacity()
+ if lo == 0:
+ return
+ elif lo == 1:
+ a = alpha
+ else:
+ tr = [int(i*lo) for i in range(256)]
+ table = array.array('B', tr).tostring()
+ a = alpha.translate(table)
+
+ image.SetAlphaData(a)
bitmap = wxBitmapFromImage(image)
- bitmap.SetMask(mask)
+
+ if mask is not None:
+ bitmap.SetMask(mask)
self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), True)
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)