[cairo] looking for critic/advice

Jonas Kulla nyocurio at gmail.com
Wed May 22 19:07:24 PDT 2013


2013/5/23 First Last <begre1929 at yahoo.com>

> Hi guys,
>

Hi,


> I try to writte a small clock application in C. I have 3 files yet,
> functions.h, functions.c, main.c. I'm using a structure wich contains a
> cairo_t and a cairo_surface_t that I need to update during the running of
> the application. For having this I'm using a structure defined in
> function.h, I'm a little suspicious about how I use this structure, I do
> some cast ( (*_mc) ) but I'm not sure that's well written, (I never
> written something so funky...), could you just take a look and told me if
> it's correct. gcc doesn't complains, and I don't get any runtime error, so
> I'm just looking for a critic or an advice.
>

Um... gcc doesn't complain, but I assume your program is not doing what you
want it to do?
Did you very recently start learning C? If so, maybe you should start by
writing something
simpler as an exercise (that doesn't require an event loop).

Judging from the little code you provided, it seems as if you create a
surface + context and
do one paint operation all in one function, which is most likely not what
you want to do.
Why aren't you using something more high level like GTK in the first place?
Going with raw Xlib for a simple clock seems a bit overkill to me.


> functions.h has :
>
> <...>
> typedef struct clockStruc{
>         cairo_t                 *c;
>         cairo_surface_t         *s;
>
> }CLOCKSTRUC;
> <...>
>
> functions.c has :
>
> <...>
> #include<cairo.h>
> #include<cairo-xlib.h>
> #include<time.h>
> #include"functions.h"
> <...>
>
> void cairoClock(CLOCKSTRUC *_mc, <...> , int _x, int _y, int _sizex, int
> _sizey){
>         <...>
>         (* _mc).s=cairo_xlib_surface_create(_dpy, wpnl,
> DefaultVisual(_dpy, 0), _sizex, _sizey);
>         (* _mc).c=cairo_create((*_mc).s);
>
>         cairo_rectangle((*_mc).c,0,0,_sizex,_sizey);
>         cairo_set_source_rgba((*_mc).c, 0.5, 0., 0., 1.); // nicoo :
> rouge, temporaire....
>         cairo_fill((*_mc).c);
> }
>
> <...>
>
> main.c has :
>
> <...>
> #include"functions.h"
> <...>
>
> int main(int argc, char *argv[]){
>         <...>
>         CLOCKSTRUC myClock;
>         <...>
>         cairoClock(&myClock, dpy,scr,panelv,5,5,BAR2X-10,34);
>         <...>
> }
>

Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130523/efaa0291/attachment.html>


More information about the cairo mailing list