On 12/07/2018 at 07:46, xxxxxxxx wrote:
I have a User Area with multiple (vertical) images in it.
Now I want to add a vertical scroll bar to scroll through the images.
But I do not understand fully, the relation between the ua size and the visible area size?
What is the best place to define the visible area?
How do I use SetVisibleArea() when the user area is resized?
A little example would help me for certain!
Here the code.
import c4d
from c4d import bitmaps, gui, plugins, utils, documents
import collections, os, sys
PLUGIN_ID = 10000010 #TestID only!!!!!!!!!!!!
scrollGroup = 1001
class Area(gui.GeUserArea) :
def __init__(self) :
self.bmp = c4d.bitmaps.BaseBitmap()
def Sized(self, w, h) :
print "Sized: ", w,h
return
def DrawMsg(self, x1, y1, x2, y2, msg) :
self.DrawRectangle(x1, y1, x2, y2) #Draws the UA rectangle area
path = os.path.join(os.path.dirname(__file__), "Library", "Airbus_A380.jpg")
result, ismovie = self.bmp.InitWith(path)
x1 = 10
if result == c4d.IMAGERESULT_OK:
y1 = 10
self.DrawBitmap(self.bmp, x1, y1, 200, 200, 0, 0, 200, 200, c4d.BMP_NORMAL) #first
y1 = 220
self.DrawBitmap(self.bmp, x1, y1, 200, 200, 0, 0, 200, 200, c4d.BMP_NORMAL) #second
y1 = 430
self.DrawBitmap(self.bmp, x1, y1, 200, 200, 0, 0, 200, 200, c4d.BMP_NORMAL) #third
class MyDialog(gui.GeDialog) :
def __init__(self, area) :
self.area = area
def CreateLayout(self) :
self.ScrollGroupBegin(scrollGroup, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, c4d.SCROLLGROUP_VERT)
self.GroupBegin(1003, c4d.BFH_CENTER | c4d.BFV_CENTER, cols=1)
self.GroupBorderNoTitle(c4d.BORDER_NONE)
self.GroupBorderSpace(0, 0, 0, 20)
self.AddUserArea(1, c4d.BFH_LEFT | c4d.BFV_TOP)
self.AttachUserArea(self.area, 1)
self.GroupEnd() #end UA group
self.GroupEnd() #end scrollgroup
self.GroupBegin(0, flags=c4d.BFH_FIT, cols=1)
self.AddButton(1027, flags=c4d.BFH_LEFT, initw=100, name="Test") #Test button
self.GroupEnd()
return True
def Command(self, id, msg) :
if (id == 1027) :
print self.GetVisibleArea(scrollGroup)
self.SetVisibleArea(scrollGroup, 0,0,250,250)
self.area.Redraw()
return True
return True
class MBLibrary(plugins.CommandData) :
area = Area()
dialog = None
def Execute(self, doc) :
if self.dialog is None: self.dialog = MyDialog(self.area)
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=500, defaulth=120)
def RestoreLayout(self, sec_ref) :
if self.dialog is None: self.dialog = MyDialog(self.area)
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
pluginString = "MB Library V01"
bmp = bitmaps.BaseBitmap()
dir, f = os.path.split(__file__)
fn = os.path.join(dir, "res", "icon.tif")
bmp.InitWith(fn)
okyn = plugins.RegisterCommandPlugin(id=PLUGIN_ID, str=pluginString, info=0, help=pluginString, dat=MBLibrary(), icon=bmp)
if (okyn) :
print pluginString + " initialized."
else: print "Error initializing " + pluginString