Bryan Bui-Tuong wrote:
> Never mind,
> 
> Did some more research and found it on the wiki:
> 
> Fill LiteBox with a Specific Color:
> 
> static DFBResult FillBox(LiteBox *box, DFBColor *color)
> {
>     DFBResult res = DFB_OK;
>     IDirectFBSurface *s = box->surface;
> 
>     res = s->SetColor(s, color->r, color->g, color->b, color->a);
>     res = s->FillRectangle(s, box->rect.x, box->rect.y, box->rect.w,
> box->rect.h);
>     res = s->Flip(s, NULL, 0);
>     
>     return res;
> }
> 
> Note that this will immediately call Flip and thus force the update. In case
> you want to collect all changes, do not call Flip at this instance. It's
> generally better to put code like this into your Draw callback for a LiTEBox
> and wait until it's called by a window update.
> 
> 
> One thing I'm not sure how to do is to set a Draw callback for a LiteBox, I
> will have to do some further reading on that.

Have a look at the various widgets in LiTE/lite, e.g. slider.c:


static DFBResult
draw_slider(LiteBox           *box,
               const DFBRegion *region,
               DFBBoolean       clear)
{
      IDirectFBSurface *surface = box->surface;
      LiteSlider       *slider = LITE_SLIDER(box);
      int               h2 = box->rect.h / 2;
      int               w2 = box->rect.w / 2;
      int               pos = (int) (slider->pos * (box->rect.w-5)) + 2;
      int               posw = (int) (slider->pos * (box->rect.h));

      D_ASSERT(box != NULL);

/**** USUAL CLIP *****/
      surface->SetClip(surface, region);

/**** USUAL CLEAR *****/
      /* Fill the background */
      if (clear)
           lite_clear_box(box, region);

/**** CUSTOM DRAWING CODE ****/
      surface->SetDrawingFlags (surface, DSDRAW_NOFX);

      if(slider->vertical) {
           /* Draw vertical line */
           surface->SetColor (surface, 0xe0, 0xe0, 0xe0, 0xff);
           surface->DrawRectangle (surface, w2 - 3, 0, 8, box->rect.h);

           surface->SetColor (surface, 0xb0, 0xb0, 0xb0, 0xff);
           surface->DrawRectangle (surface, w2 - 2, 1, 6 , box->rect.h - 2);

           if (box->is_focused)
                surface->SetColor (surface, 0xc0, 0xc0, 0xff, 0xf0);
           else
                surface->SetColor (surface, 0xf0, 0xf0, 0xf0, 0xd0);
           surface->FillRectangle (surface, w2 - 1, 2, 4, box->rect.h - 4);

           /* Draw the position indicator */
           surface->SetDrawingFlags (surface, DSDRAW_BLEND);
           surface->SetColor (surface, 0x80, 0x80, 0xa0, 0xe0);
           surface->FillRectangle (surface, 0, posw-1, box->rect.w, 1);
           surface->FillRectangle (surface, 0, posw+1, box->rect.w,1);

           surface->SetColor (surface, 0xb0, 0xb0, 0xc0, 0xff);
           surface->FillRectangle (surface, 0, posw, box->rect.w, 1);
      }
      else {
           /* Draw horizontal line */
           surface->SetColor (surface, 0xe0, 0xe0, 0xe0, 0xff);
           surface->DrawRectangle (surface, 0, h2 - 3, box->rect.w, 8);

           surface->SetColor (surface, 0xb0, 0xb0, 0xb0, 0xff);
           surface->DrawRectangle (surface, 1, h2 - 2, box->rect.w - 2, 6);

           if (box->is_focused)
                surface->SetColor (surface, 0xc0, 0xc0, 0xff, 0xf0);
           else
                surface->SetColor (surface, 0xf0, 0xf0, 0xf0, 0xd0);
           surface->FillRectangle (surface, 2, h2 - 1, box->rect.w - 4, 4);

           /* Draw the position indicator */
           surface->SetDrawingFlags (surface, DSDRAW_BLEND);
           surface->SetColor (surface, 0x80, 0x80, 0xa0, 0xe0);
           surface->FillRectangle (surface, pos-1, 0, 1, box->rect.h);
           surface->FillRectangle (surface, pos+1, 0, 1, box->rect.h);

           surface->SetColor (surface, 0xb0, 0xb0, 0xc0, 0xff);
           surface->FillRectangle (surface, pos, 0, 1, box->rect.h);
      }

      return DFB_OK;
}


Such a callback is registered at widget's creation time:


DFBResult
lite_new_slider(LiteBox         *parent,
                 DFBRectangle    *rect,
                 LiteSliderTheme *theme,
                 LiteSlider     **ret_slider)
{
      DFBResult   res;
      LiteSlider *slider = NULL;

      slider = D_CALLOC(1, sizeof(LiteSlider));

      slider->box.parent = parent;
      slider->theme = theme;
      slider->box.rect = *rect;

      res = lite_init_box(LITE_BOX(slider));
      if (res != DFB_OK) {
           D_FREE(slider);
           return res;
      }

      slider->box.type    = LITE_TYPE_SLIDER;
      slider->box.Draw    = draw_slider;        <============ HERE
      slider->box.Destroy = destroy_slider;

      slider->box.OnEnter      = on_enter;
      slider->box.OnFocusIn    = on_focus_in;
      slider->box.OnFocusOut   = on_focus_out;
      slider->box.OnButtonDown = on_button_down;
      slider->box.OnMotion     = on_motion;

      slider->vertical=(slider->box.rect.h > slider->box.rect.w) ? true : false;

      lite_update_box(LITE_BOX(slider), NULL);

      *ret_slider = slider;

      D_DEBUG_AT(LiteSliderDomain, "Created new slider object: %p\n", slider);

      return DFB_OK;
}


-- 
Best regards,
   Denis Oliver Kropp

.------------------------------------------.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/                 |
'------------------------------------------'

_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to