Re: Actor signals




On Tue, October 30, 2012 12:47 pm, Lionel Landwerlin wrote:
On 30/10/12 01:37, Patrick Shirkey wrote:
On Tue, October 30, 2012 12:27 pm, Lionel Landwerlin wrote:

On 30/10/12 01:19, Patrick Shirkey wrote:
Thanks for your advice.

This is the pick method:

      def do_pick (self, pick_color):
          if self.should_pick_paint() == False:
              return

          box = self.get_allocation_box()
          self.__draw_shape(box.x2 - box.x1, box.y2 - box.y1,
pick_color)



There's not much to it so I am not sure why it is doing something
weird
or
how to fix it.


Are you sure the __draw_shape() method doesn't alterate the picking
color when drawing? (opacity? mask?)

The opacity is being explicitly set in the button-press-event handler.

     if(status == 0): # button-press-event
         opacity = 200
     else: # button-release-event/button-leave-event
         opacity = 255

     set_opacity(opacity)


The __draw_shape function doesn't appear to have anything that would
cause
trouble. Also the code works for the top layer but not the bottom layer.
The issue appears to be that the id of the actor is not found for the
bottom layer but I am not sure why it would be unable to find it's own
id
especially when the top layer doesn't have this problem.


Here's the __draw_shape methods:

     def do_draw_shape(self, width, height):
         pass

     def __draw_shape(self, width, height, color=None, texture=None):
         tmp_alpha = self.get_paint_opacity() * color.alpha / 255
         if texture:
             Cogl.set_source_texture(texture)
         else:
             Cogl.set_source_color4ub(color.red, color.green,
color.blue,
tmp_alpha)
         self.do_draw_shape(width, height)
         Cogl.path_fill()



Well that's the problem.
When the pick function is called, it should ONLY draw with given color.
Nothing else.
No opacity.

Clutter does picking (aka finding the actor underneath you pointer) by
rendering each object of the scene with a different color.
Then reading the value of the color at a given position in the rendered
scene.

If you change the opacity when doing the picking you're using a color
that isn't known by Clutter, therefore leading to the warning you've seen.

You should add an opacity argument to __draw_shape() and pass :

self.get_paint_opacity() * color.alpha / 255

when called from do_draw_shape() and pass

color.alpha

when called from do_pick()

-Lionel


Thanks for that insight.


For reference this code is working for me now:

----

    def do_draw_shape(self, width, height):
        pass

    def __draw_shape(self, width, height, color=None, opacity=None,
texture=None):
        if texture:
            Cogl.set_source_texture(texture)
        else:
            Cogl.set_source_color4ub(color.red, color.green, color.blue,
opacity)
        self.do_draw_shape(width, height)
        Cogl.path_fill()

    def do_paint (self):
        box = self.get_allocation_box()
        if self._texture:
            self.__draw_shape(box.x2 - box.x1, box.y2 - box.y1,
self._color, texture = self._texture.get_cogl_texture())
        else:
            self._color.alpha = self.get_paint_opacity()
            self.__draw_shape(box.x2 - box.x1, box.y2 - box.y1, color =
self._color, opacity = self._color.alpha)

    def do_pick (self, pick_color):
        if self.should_pick_paint() == False:
            return

        box = self.get_allocation_box()
        self.__draw_shape(box.x2 - box.x1, box.y2 - box.y1, pick_color,
pick_color.alpha)

----


--
Patrick Shirkey
Boost Hardware Ltd



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]