Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Bitmap in UserArea

    PYTHON Development
    0
    22
    36.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 12/05/2013 at 13:34, xxxxxxxx wrote:

      Ok so first of all: You should always draw a background color if what you can not assume what
      you are drawing fills the complete rectangle. The buffer is not simply all set to zero (black) but
      is left the way it is. You must fill it with the desired background color yourself.

      Second is: You can actually draw outside of the area because the dialog itself is drawn on the same
      buffer. You can clip the drawing by using SetClippingRegion(x1, y1, x2, y2)

          def DrawMsg(self, x1, y1, x2, y2, msg) :
              self.DrawSetPen(c4d.COLOR_BG)
              self.DrawRectangle(x1, y1, x2, y2)
              self.SetClippingRegion(x1, y1, x2, y2)
              w = self.bmp.GetBw()
              h = self.bmp.GetBh()
              self.DrawBitmap(self.bmp, self.xValue, self.yValue, w, h, 0, 0, w, h, c4d.BMP_ALLOWALPHA)
              self.DrawBorder(c4d.BORDER_OUT, x1, y1, x2, y2)
      

      -Niklas

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 12/05/2013 at 14:24, xxxxxxxx wrote:

        No worries. I've got it all worked out now.
        It just didn't like the way I was using the class member variables.

        Here's the working version. Just in case anyone needs it. Or is curious about it.
        When the GeDialog button is clicked. The image moves to a new position properly now.
        I also threw in some mouse position checking code.

        import  c4d,os  
        from c4d import gui, plugins  
          
        class MyUA(c4d.gui.GeUserArea) :  
          
          xValue = 0           #These variables will set the position of the image  
          yValue = 0  
            
          def __init__(self) :      
              dir, file = os.path.split(__file__)   #Gets the plugin's directory   
              path = os.path.join(dir, "res")       #Adds the res folder to the directory to target the res folder      
              image = path + "\myimage.png"         #Adds the image to the path  
                
              self.bmp = c4d.bitmaps.BaseBitmap()   #Create an instance of the BaseBitmap class  
              self.bmp.InitWith(image)              #Initialize it with the image  
          
              self.xValue = 5  
              self.yValue = 5  
          
          def DrawMsg(self, x1, y1, x2, y2, msg) :   
                
              self.DrawSetPen(c4d.COLOR_BG)         #COLOR_BG is the image we load with DrawBitmap  
              self.DrawRectangle(x1, y1, x2, y2)    #Draws a rectangle and fills it with the image bitmap  
              self.SetClippingRegion(x1, y1, x2, y2)  
              w, h = self.bmp.GetSize()             #Gets the size values of the image  
              self.DrawBitmap(self.bmp, x1 + self.xValue, y1 + self.yValue, w, h, 0, 0, w, h, c4d.BMP_NORMAL | c4d.BMP_ALLOWALPHA)  
                
          
                
              self.DrawBorder(c4d.BORDER_ROUND, x1+5, y1+5, x2-5, y2-5)  #Draws a border around the UserArea          
          
          
          def InputEvent(self, msg) :  
            
              action = c4d.BaseContainer(c4d.BFM_ACTION)  
              action.SetLong(c4d.BFM_ACTION_ID, self.GetId())  
          
              while self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, msg) :    #While the left mouse button is held down  
                  if msg.GetLong(c4d.BFM_INPUT_VALUE)==0: break  
            
                  if msg[c4d.BFM_INPUT_DEVICE] == c4d.BFM_INPUT_MOUSE:  
                      x, y = msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y]  
                      g2l  = self.Global2Local()  
                      x += g2l['x']  
                      y += g2l['y']  
          
                  if msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSELEFT:  
                      print x, y  #The mouse's X & Y pos inside the user area  
                        
                      action.SetLong(c4d.BFM_ACTION_INDRAG, True)  
                      self.SendParentMessage(action)                    #Sends a message to the parent dialog that the mouse is dragging in the UA  
                      self.Redraw()                                     #Redraw while the left mouse button is held down  
          
              action.SetLong(c4d.BFM_ACTION_INDRAG, False)  
              self.SendParentMessage(action)                            #Sends a message to the parent dialog that the mouse has stopped dragging in the UA                  
          
              return True  
          
        class MyDialog(c4d.gui.GeDialog) :  
          ua = MyUA()                #Create a local class instance of the UserArea  
          
          def CreateLayout(self) :  
              self.AddUserArea(2000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)  
              self.AttachUserArea(self.ua, 2000)  
                
              self.AddButton(1000, c4d.BFH_CENTER, 80, 15, "Click Me")  
              self.AddButton(1001, c4d.BFH_CENTER, 80, 15, "Close")  
              return True  
                
          
          #This method initializes things when the plugin starts           
          def InitValues(self) :    
              return True  
          
          def Command(self, id, msg) :  
              if id==1000:  
                  self.ua.xValue = 100  
                  self.ua.yValue = 100  
                  self.ua.Redraw()  
                    
              elif id==1001:   
                  self.Close()              
              return True          
                
          
                
        ###### This class is only used to register the plugin...Don't change!!!#######  
        class BitmapUaExample(c4d.plugins.CommandData) :  
          
          dlg = None  
          ua = None  
          PLUGIN_ID   = 10000090 # TESTING ID ONLY!!!  
          ICON = None  
          
          def Execute(self, doc) :          
              if not self.dlg: self.dlg = MyDialog()  
              self.dlg.Open(c4d.DLG_TYPE_ASYNC, self.PLUGIN_ID, -1, -1, 400, 300)  
              return True  
          
          def RestoreLayout(self, subid) :  
              if not self.dlg:  
                  self.dlg  = MyDialog()  
              return self.dlg.Restore(self.PLUGIN_ID, subid)  
            
          
          @classmethod  
          def Register(myPlugin) :  
              data = {  
                  "id":     myPlugin.PLUGIN_ID,  
                  "icon":   myPlugin.ICON,  
                  "str":    "Bitmap UA Example",  
                  "help":   "Some text that shows up at the bottom of the C4D UI",  
                  "info":   c4d.PLUGINFLAG_COMMAND_HOTKEY,  
                  "dat":    myPlugin(),  
              }  
              c4d.plugins.RegisterCommandPlugin(**data)  
          
        if __name__ == "__main__":  
          BitmapUaExample.Register()
        

        -ScottA

        1 Reply Last reply Reply Quote 0
        • First post
          Last post