c4d.gui.GeUserArea
¶
This class helps you to create custom gadgets for dialogs in Cinema 4D.
Note
Just take care about the lifetime of your
GeUserArea
instance. If you pass an instance of this class to a dialog, a reference is hold by the dialog and released when the dialog is freed. That also means that each instance of yourGeUserArea
class is still alive until the host-dialog is freed, even you dont hold a reference to it. If you want to use the same instance of yourGeUserArea
class on the next time you open the dialog, you have to store the instance in the class scope. See the following example.
The class to create custom user areas.
c4d.gui.
GeUserArea
¶
GeUserArea.Init()
GeUserArea.InitValues()
GeUserArea.DrawMsg()
GeUserArea.GetMinSize()
GeUserArea.InputEvent()
GeUserArea.CoreMessage()
GeUserArea.Timer()
GeUserArea.Message()
GeUserArea.Sized()
GeUserArea.Redraw()
GeUserArea.SendParentMessage()
GeUserArea.GetId()
GeUserArea.GetWidth()
GeUserArea.GetHeight()
GeUserArea.IsEnabled()
GeUserArea.HasFocus()
GeUserArea.SetTimer()
GeUserArea.GetInputState()
GeUserArea.GetInputEvent()
GeUserArea.KillEvents()
GeUserArea.IsHotkeyDown()
GeUserArea.GetColorRGB()
GeUserArea.DrawSetPen()
GeUserArea.DrawSetTextCol()
GeUserArea.DrawLine()
GeUserArea.DrawRectangle()
GeUserArea.DrawBitmap()
GeUserArea.DrawText()
GeUserArea.DrawBezier()
GeUserArea.DrawBorder()
GeUserArea.FillBitmapBackground()
GeUserArea.DrawSetFont()
GeUserArea.DrawGetTextWidth()
GeUserArea.DrawGetFontHeight()
GeUserArea.DrawGetFontBaseLine()
GeUserArea.DrawSetTextRotation()
GeUserArea.ScrollArea()
GeUserArea.Local2Global()
GeUserArea.Global2Local()
GeUserArea.Local2Screen()
GeUserArea.Screen2Local()
GeUserArea.LayoutChanged()
GeUserArea.GetDragPosition()
GeUserArea.GetDragObject()
GeUserArea.HandleMouseDrag()
NEW
GeUserArea.SetDragDestination()
GeUserArea.CheckDropArea()
GeUserArea.
__init__
(
)
¶
Return type: | c4d.gui.GeUserArea |
---|---|
Returns: | A new user area. |
GeUserArea.
Init
(
self
)
¶
Called once when the user area is initialized by the GUI, before the layout is calculated. Override this function if you need to initialize anything. Return True if successful, or False to signalize an error.
Return type: | bool |
---|---|
Returns: | True if successful, or False to signalize an error. |
GeUserArea.
InitValues
(
self
)
¶
Called after the layout is calculated, before the user area is drawn. Override this function if you need to initialize anything. Return True if successful, or False to signalize an error.
Return type: | bool |
---|---|
Returns: | True if successful, or False to signalize an error. |
GeUserArea.
GetMinSize
(
self
)
¶
Override this function to specify a minimum size for the user area:
def GetMinSize(self): #do a calculation here return self.width, self.height
Return type: | tuple(int, int) |
---|---|
Returns: | A tuple with two elements just like this. |
GeUserArea.
DrawMsg
(
self
,
x1
,
y1
,
x2
,
y2
,
msg
)
¶
Called when Cinema 4D wants you to draw your userarea. Use the drawing functions to update your user area in the region speicified by the rectangle from (x1,y1) to (x2,y2).
Parameters: |
|
---|
GeUserArea.
InputEvent
(
self
,
msg
)
¶
Called when an input event is received. All information about the input event is stored in the msg container.
Parameters: | msg ( c4d.BaseContainer ) – The event container. |
---|---|
Return type: | bool |
Returns: | True if the event was handled, otherwise False . |
GeUserArea.
CoreMessage
(
self
,
id
,
msg
)
¶
Called when a Cinema 4D core messages is received. The message type is given by id and the message information is stored in msg .
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
Currently not used - but you have to return a bool value. |
GeUserArea.
Sized
(
self
,
w
,
h
)
¶
Called when the user area is resized. Override if you need to update anything.
Parameters: |
|
---|
GeUserArea.
Timer
(
self
,
msg
)
¶
If you subscribe to timer events using
SetTimer()
(x), this function is called every
x
th millisecond. The raw timer message is stored in
msg
.
Parameters: | msg ( c4d.BaseContainer ) – The timer message container. |
---|
GeUserArea.
Message
(
self
,
msg
,
result
)
¶
Override this function if you want to react to more messages than covered by the other functions. Normally this is not necessary. Be sure to include a call the parent version of this function,
Message()
:
def Message(self, msg, result): if msg.GetId(): pass #do something return True return GeUserArea.Message(self, msg, result)
Parameters: |
|
---|---|
Return type: |
int |
Returns: |
The return value depends on the message. |
GeUserArea.
Redraw
(
[
thread=False
]
)
¶
Forces the user area to redraw itself.
Parameters: | thread ( bool ) – Must be set to True if the function is called from another thread than the main Cinema 4D thread. |
---|
GeUserArea.
SendParentMessage
(
msg
)
¶
Use this function to send a custom message to the parent dialog.
Parameters: | msg ( c4d.BaseContainer ) – The message container. |
---|
GeUserArea.
GetId
(
)
¶
Returns the ID of the user area.
Return type: | int |
---|---|
Returns: | The ID. |
GeUserArea.
GetWidth
(
)
¶
Returns the width of the user area.
Return type: | int |
---|---|
Returns: | Width in pixels. |
GeUserArea.
GetHeight
(
)
¶
Returns the height of the user area.
Return type: | int |
---|---|
Returns: | Height in pixels. |
GeUserArea.
IsEnabled
(
)
¶
Indicates the enabled state.
Return type: | bool |
---|---|
Returns: | True if the user area is enabled in the dialog, otherwise False . |
GeUserArea.
HasFocus
(
)
¶
Indicates the focus state.
Return type: | bool |
---|---|
Returns: | True if the user area has the focus in the dialog, otherwise False . |
GeUserArea.
SetTimer
(
x
)
¶
Initializes the timer clock, so that
Timer()
is called every timer milliseconds.
Note
Depending on the speed of the computer, the operating system, the complexity of the dialog and the threads running in the background, there is no guarantuee that event messages will occur on a regular basis. Using a value of 500 ms should be no problem but if using a value of 1 ms one might get events with the following time spaces: 3 ms, 76 ms, 15 ms, 19 ms, 67 ms…
Note
Keep in mind that using small timer values results in heavy message traffic in the application which may slow down Cinema 4D (and all other applications running on the computer) to a point where nothing is working any longer besides your dialog.
Parameters: | x ( int ) – The timer interval in milliseconds. |
---|
GeUserArea.
GetInputState
(
askdevice
,
askchannel
,
res
)
¶
Polls a certain channel of a device for the current input state. If the return value is True , the container stored in res is just like an input event message, otherwise no state was available.
See also
Parameters: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||
Returns: |
True if a state could be retrieved, otherwise False . |
GeUserArea.
GetInputEvent
(
askdevice
,
res
)
¶
Gets the next input event for a certain device from the event queue. If the return value is True , the container stored in res is just like an input event message, otherwise no event was available.
See also
Parameters: |
|
||||
---|---|---|---|---|---|
Return type: |
bool |
||||
Returns: |
True if the event could be retrieved, otherwise False . |
GeUserArea.
KillEvents
(
)
¶
Flushes all events from the window message queue. For example if you loop while the mouse is down (polling) you can call this command to flush all keydowns/mouseclicks that are made during the loop.
GeUserArea.
IsHotkeyDown
(
id
)
¶
Checks the standard navigation hotkeys.
Parameters: |
id
(
int
) –
The hotkey:
|
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | bool | ||||||||||||||||||||||||||
Returns: | True if the hotkey is down. |
GeUserArea.
GetColorRGB
(
colorid
)
¶
Gets the RGB values associated with a color code.
Parameters: |
type
(
int
) –
A color constant:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | dict{ r : int, g : int, b : int} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | The color or None . |
GeUserArea.
DrawSetPen
(
color
)
¶
Sets the draw color.
Param: | A color vector. |
---|
GeUserArea.
DrawSetTextCol
(
fg
,
bg
)
¶
Sets the draw color.
Parameters: |
|
---|
GeUserArea.
DrawLine
(
x1
,
y1
,
x2
,
y2
)
¶
Draws a line with the current pen color between ( x1,y1 ) and ( x2,y2 ).
Parameters: |
|
---|
GeUserArea.
DrawRectangle
(
x1
,
y1
,
x2
,
y2
)
¶
Fills a rectangular area with the current pen color between (x1,y1) and (x2,y2).
Parameters: |
|
---|
GeUserArea.
DrawBitmap
(
bmp
,
wx
,
wy
,
ww
,
wh
,
x
,
y
,
w
,
h
,
mode
)
¶
Draws a bitmap into the user area. The region (x,y) to (x+w,y+h) from the bitmap will be scaled and transformed into the region (wx,wy) to (wx+ww,wy+wh) of the destination area.
Note
BMP_ALLOWALPHA can be combined with the other modes.
Parameters: |
|
---|
GeUserArea.
DrawBorder
(
type
,
x1
,
y1
,
x2
,
y2
)
¶
Fills a rectangular area with the current pen color between (x1,y1) and (x2,y2).
Parameters: |
|
---|
GeUserArea.
DrawText
(
text
,
x
,
y
[
,
flags=DRAWTEXT_STD_ALIGN
]
)
¶
Draws the string
txt
with the upper left corner at the position (
x
,
y
). Use
DrawGetTextWidth()
and
DrawGetFontHeight()
to find out where to place the text.
Parameters: |
|
---|
GeUserArea.
DrawBezier
(
sx
,
sy
,
p
,
closed
,
filled
)
¶
New in version R14.014.
Draws concatenated bezier curves.
Note
Due to improve speed performance, the elements of
p
will be modified and might be invalid and all values must be set again if
DrawBezier()
will be called again with the same array.
Parameters: |
|
---|
GeUserArea.
FillBitmapBackground
(
bmp
,
offsetx
,
offsety
)
¶
Fills the bitmap bmp with the current pen color. The offsetx and offsety parameters are used when the background is a pattern and are given in local coordinates of the user area. This can be used to make semi-transparent bitmap blits.
Parameters: |
|
---|
GeUserArea.
DrawSetFont
(
fontid
)
¶
Sets the text font.
Parameters: |
fontid
(
int
) –
The font to use:
|
---|
GeUserArea.
DrawGetTextWidth
(
text
)
¶
Returns the width in pixels of the string text , if it were drawn in the current font.
Parameters: | text ( str ) – The string to measure. |
---|---|
Return type: | int |
Returns: | The width in pixels. |
GeUserArea.
DrawGetFontHeight
(
)
¶
Returns the height in pixels of a line of text in the current font.
Return type: | int |
---|---|
Returns: | Height in pixels. |
GeUserArea.
DrawGetFontBaseLine
(
)
¶
Returns the base line of the set font.
Return type: | int |
---|---|
Returns: | The base line of the set font. |
GeUserArea.
DrawSetTextRotation
(
textrotation
)
¶
Rotates the font for drawing.
Note
Rotation is clockwise and must be set to 0 after drawing.
Parameters: | textrotation ( float ) – The text rotation in degree. |
---|
GeUserArea.
SetClippingRegion
(
x
,
y
,
w
,
h
)
¶
Should be used at the top of the
DrawMsg()
function to specify the clipping region. Without specifying a dedicated clipping region everything will be painted, even if it is outside the user area!
Note
The method
OffScreenOn()
automatically sets the clipping region to the whole user area, so normally this function is not necessary.
Parameters: |
|
---|
GeUserArea.
ClearClippingRegion
(
)
¶
Clears any clipping region set with
SetClippingRegion()
.
GeUserArea.
OffScreenOn
(
[
x
,
y
,
w
,
h
]
)
¶
Enables double buffering to avoid blinking and flickering effects. The GUI will automatically switch planes. Just call this function before drawing things. Sets the clipping area to the rectangular area determined by x , y , w and h .
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if double buffering could be enabled, otherwise False . |
GeUserArea.
ScrollArea
(
xdiff
,
ydiff
,
x
,
y
,
w
,
h
)
¶
Scrolls the area from (x,y) to (x+w,y+h) in the direction specified by xdiff and ydiff .
Parameters: |
|
---|
GeUserArea.
ActivateFading
(
milliseconds
)
¶
New in version R14.014.
Activates the fading.
Parameters: | milliseconds ( int ) – Time for the fading. |
---|
GeUserArea.
AdjustColor
(
colorid
,
highlightid
,
percent
)
¶
New in version R14.014.
Sets the blend colors for user area fading.
Parameters: |
|
---|
GeUserArea.
Local2Global
(
)
¶
Transforms local coordinates (relative to the top left corner of the dialog) to global coordinates (relative to the top left corner of the physical window). Result is a dict with member keys x and y of type int .
Return type: | dict{ x : int, y : int} |
---|---|
Returns: | The converted coordinates or None . |
GeUserArea.
Global2Local
(
)
¶
Transforms global coordinates (relative to the top left corner of the physical window) to local coordinates (relative to the top left corner of the dialog). Result is a dict with member keys x and y of type int .
Return type: | dict{ x : int, y : int} |
---|---|
Returns: | The converted coordinates or None . |
GeUserArea.
Local2Screen
(
)
¶
Transforms local coordinates (relative to the top left corner of the dialog) to screen coordinates (relative to the top left corner of the system screen). Result is a dict with member keys x and y of type int .
Return type: | dict{ x : int, y : int} |
---|---|
Returns: | The converted coordinates or None . |
GeUserArea.
Screen2Local
(
)
¶
Transforms screen coordinates (relative to the top left corner of the system screen) to local coordinates (relative to the top left corner of the dialog). Result is a dict with member keys x and y of type int .
Return type: | dict{ x : int, y : int} |
---|---|
Returns: | The converted coordinates or None . |
GeUserArea.
LayoutChanged
(
)
¶
Tells Cinema 4D that the user area now has new dimensions. That causes c4d to call:
GeUserArea.
GetDragPosition
(
msg
)
¶
Extracts local drag coordinates from a drag and drop event.
Parameters: | msg ( c4d.BaseContainer ) – The original message. |
---|---|
Return type: | dict{‘x’: int, ‘y’: int} |
Returns: | The local X and Y position. |
GeUserArea.
GetDragObject
(
msg
)
¶
Extracts the object from a drag and drop message.
Parameters: | msg ( c4d.BaseContainer ) – The original message. | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | dict{‘type’: int, ‘object’: any} | ||||||||||||||||||||||||
Returns: |
The type of drag and the object itself. The types are:
|
GeUserArea.
HandleMouseDrag
(
msg
,
type
,
data
,
dragflags
)
¶
New in version R19.024.
Starts a drag and drop operation.
Parameters: |
|
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||
Returns: |
True if the user moved the mouse and a drag and drop operation was initiated. False if the user did not move the mouse, so that the original event is a normal mouse click event. |
GeUserArea.
SetDragDestination
(
)
¶
Sets the correct cursor during drag and drop handling.
Parameters: |
cursor
(
int
) –
A mouse cursor:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | True if the cursor could be set, otherwise False . |
GeUserArea.
CheckDropArea
(
msg
,
horiz
,
vert
)
¶
Checks the drag position in a drag event message against the user area’s position in the layout. The check can be limited to only X or Y coordinates.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the drag message is within the bounds specified, otherwise False . |
GeUserArea.
MouseDragStart
(
button
,
mx
,
my
,
flag
)
¶
Starts a mouse drag. Only call this when a mouse down message is received. Then repeatedly poll with
MouseDrag()
during the drag.
Parameters: |
|
---|
GeUserArea.
MouseDrag
(
)
¶
Polls the mouse during a drag started with
MouseDragStart()
.
The best way to use this function is:
while True: result, mx, mx, channels = ua.MouseDrag() if result != c4d.MOUSEDRAGRESULT_CONTINUE: break
To check for qualifiers see the channels container:
if channels[c4d.BFM_INPUT_QUALIFIER] & QSHIFT: ... if channels[c4d.BFM_INPUT_QUALIFIER] & QCTRL: ...
Return type: |
tuple(int, float, float,
c4d.BaseContainer
)
|
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns: |
A tuple with the following information:
int: The mouse drag result: float: The X delta-coordinate of the mouse (the amount the mouse has moved). float: The Y delta-coordinate of the mouse (the amount the mouse has moved).
c4d.BaseContainer
: The channels values. Also contains these pen values:
|
GeUserArea.
MouseDragEnd
(
)
¶
Checks why the mouse drag ended. Allows to perform any undo operations needed if the user canceled the drag.
Return type: | int | ||||||
---|---|---|---|---|---|---|---|
Returns: |
The mouse drag result:
|
GeUserArea.
GetBorderSize
(
type
)
¶
Retrieves the space required to draw a border.
Parameters: |
type
(
int
) –
The border type:
|
||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | dict{ l : int, t : int, r : int, b : int} | ||||||||||||||||||||||||||||||||||||||||||||||
Returns: | The space. |