Hello!
I am drawing a BaseBitmap in a GeUserArea that is in a scroll group using the workaround @m_adam employed in this post:
Redrawing GeUserArea in ScrollGroup with Slider Input
The GeUserArea scales properly with this workaround when not it's smaller than the scrollgroup, but I'm unable to get it to stay in the center of the scrollgroup as it becomes larger. The GeUserArea shifts to the top left, which is undesired.
Code:
import c4d, random
from c4d import gui
GADGET_ID_GEUSERAREA = 10000
SCROLL_ID = 10001
SLIDER_ID = 10002
class ExampleGeUserArea(c4d.gui.GeUserArea):
width = 400
height = 500
bmp_cache = None
def GetBitmap(self):
bmp = c4d.bitmaps.BaseBitmap()
bmp.Init(self.width,self.height)
for h in range(self.height):
for w in range(self.width):
r = random.randint(0, 70)
bmp.SetPixel(w, h, r, r, r)
return bmp
def DrawMsg(self, x1, y1, x2, y2, msg):
print("DrawMsg: x1: %d, y1: %d, x2: %d, y2: %s"%(x1,y1,x2,y2))
self.OffScreenOn()
self.SetClippingRegion(x1, y1, x2, y2)
self.DrawSetPen(c4d.Vector(1,0,0))
self.DrawRectangle(x1, y1, x2, y2)
if self.bmp_cache == None:
self.bmp_cache = self.GetBitmap()
self.DrawBitmap(self.bmp_cache, x1, y1, x2, y2, 0, 0,
w=self.bmp_cache.GetBw(),
h=self.bmp_cache.GetBh(),
mode=c4d.BMP_NORMAL)
def Message(self, msg, result):
# Catch the draw message to cancel it (return True)
# and call ourself the DrawMsg with the dimension we expect
if msg.GetId() == c4d.BFM_DRAW:
self.DrawMsg(0, 0, self.width, self.height, c4d.BaseContainer())
return True
return c4d.gui.GeUserArea.Message(self, msg, result)
def GetMinSize(self):
print("GetMinSize: self.width: %d, self.height: %d"%(self.width,self.height))
return self.width,self.height
class ExampleDialog(c4d.gui.GeDialog):
geUserArea = ExampleGeUserArea()
def DrawUA(self,scale):
print("DrawUserArea", int(400*scale), int(500*scale))
self.geUserArea.width = int(400*scale)
self.geUserArea.height = int(500*scale)
self.LayoutChanged(SCROLL_ID)
def CreateLayout(self):
self.SetTitle("GeUserArea")
if self.ScrollGroupBegin(SCROLL_ID, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, c4d.SCROLLGROUP_HORIZ | c4d.SCROLLGROUP_VERT):
self.AddUserArea(GADGET_ID_GEUSERAREA, c4d.BFH_CENTER | c4d.BFH_SCALE | c4d.BFV_CENTER | c4d.BFV_SCALE, initw=gui.SizePix(400), inith=gui.SizePix(500))
self.AttachUserArea(self.geUserArea, GADGET_ID_GEUSERAREA)
self.GroupEnd()
self.AddEditSlider(SLIDER_ID, c4d.BFH_SCALEFIT | c4d.BFV_CENTER)
return True
def InitValues(self):
self.SetFloat(SLIDER_ID, 1.0, min = 0.01, max = 2, step = 0.01)
return True
def Command(self,id,msg):
if id == SLIDER_ID:
self.DrawUA(msg[c4d.BFM_ACTION_VALUE])
return True
def main():
global dlg
dlg = ExampleDialog()
dlg.Open(c4d.DLG_TYPE_ASYNC, pluginid=1234567, defaultw=300, defaulth=300)
if __name__ == "__main__":
main()
Is there a way to get this GeUserArea to scale up into the scrollgroup from the center?
Thank you!