1. Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 02, 2006
- 533 views
I've started wrapping libX11 in hopes that I can use it to write X apps. I've got about 950 lines of code wrapped so far, and I've hit my first road block. The following structure "_XImage" contains a structure "funcs" that seems to point to routines in memory. I'm using c_struct.e by David Cuny (from his GTK library) which works much the same as Win32Lib or tk_mem.e. If someone could help me out, that'd be great, so I can continue to wrap this library.
typedef struct _XImage { int width, height; /* size of image */ int xoffset; /* number of pixels offset in X direction */ int format; /* XYBitmap, XYPixmap, ZPixmap */ char *data; /* pointer to image data */ int byte_order; /* data byte order, LSBFirst, MSBFirst */ int bitmap_unit; /* quant. of scanline 8, 16, 32 */ int bitmap_bit_order; /* LSBFirst, MSBFirst */ int bitmap_pad; /* 8, 16, 32 either XY or ZPixmap */ int depth; /* depth of image */ int bytes_per_line; /* accelarator to next line */ int bits_per_pixel; /* bits per pixel (ZPixmap) */ unsigned long red_mask; /* bits in z arrangment */ unsigned long green_mask; unsigned long blue_mask; XPointer obdata; /* hook for the object routines to hang on */ struct funcs { /* image manipulation routines */ struct _XImage *(*create_image)( struct _XDisplay* /* display */, Visual* /* visual */, unsigned int /* depth */, int /* format */, int /* offset */, char* /* data */, unsigned int /* width */, unsigned int /* height */, int /* bitmap_pad */, int /* bytes_per_line */); int (*destroy_image) (struct _XImage *); unsigned long (*get_pixel) (struct _XImage *, int, int); int (*put_pixel) (struct _XImage *, int, int, unsigned long); struct _XImage *(*sub_image)(struct _XImage *, int, int, unsigned int, unsigned int); int (*add_pixel) (struct _XImage *, long); } f; } XImage;
~Greg
2. Re: Need help wrapping a structure
- Posted by Bernie Ryan <xotron at bluefrog.com> Jun 02, 2006
- 508 views
Greg Haberek wrote: > > I've started wrapping libX11 in hopes that I can use it to write X > apps. Greg: You can already use libX11; plus Motif + XT + Athena with XMOTOR To use any structure all you have to do describe it with record. It also can use nested structures. Down-load XMOTOR and look at the x demos. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
3. Re: Need help wrapping a structure
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Jun 02, 2006
- 520 views
Bernie Ryan wrote: > > Greg Haberek wrote: > > > > I've started wrapping libX11 in hopes that I can use it to write X > > apps. That's awesome, Greg. I wanted to wrap libX, but i didn't really know where to start. I'm not very good at wrapping libraries. I would definitely want to use an X wrapper, if you can get it working. I'm also trying to figure out how to wrap either ALSA or Jack for sound. I started an ALSA wrapper, but it just crashes when i try to use it. The API is rather confusing. > Greg: > > You can already use libX11; plus Motif + XT + Athena with XMOTOR > To use any structure all you have to do describe it with record. > It also can use nested structures. > Down-load XMOTOR and look at the x demos. > > Bernie > > My files in archive: > WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API > > Can be downloaded here: > <a > href="http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan">http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan</a> Bernie, that's really cool that you made those libraries, but unfortunately, I can't use XMOTOR because it's partially shrouded. No offense, but that doesn't do any good for open source software. So, I need to keep searching for another solution. As I develop FluidAE, I'm trying to come up with good cross-platform APIs for graphics, sound, networking, file management, etc. It seems to be difficult to find libraries that don't depend on 3rd-party C or C++ libraries (wxWidgets, BASS, etc.) I was trying to use wxEuphoria, which is really cool, but it seems to be a little to complicated and buggy. Maybe I'm doing something wrong... Anyway, good luck Greg, I wish I could help you. ~Ryan W. Johnson Fluid Application Environment http://www.fluidae.com/ [cool quote here, if i ever think of one...]
4. Re: Need help wrapping a structure
- Posted by jacques deschĂȘnes <desja at globetrotter.net> Jun 03, 2006
- 523 views
Hi Greg, I don't know how win32lib work with structures, but the way I would do it is: <EUCODE> constant -- typedef struct _XImage { width = 0, -- height = 4, xoffset = 8, format = 12, pdata = 16, -- this is a pointer (4 bytes) byte_order = 20, bitmap_unit = 24, bitmap_bit_order = 28, depth = 32, bytes_per_line = 36, bits_per_pixel = 40, red_mask = 44, green_mask = 48, blue_mask = 52, pobdta = 56, -- this is a pointer (4 bytes) -- struc funcs (one pointer per function) pfn_create_image = 60, pfn_destroy_image = 64, pfn_get_pixel = 68, pfn_put_pixel = 72, pfn_sub_image = 76, pfn_add_pixel = 80, XImage_SIZE = 84 -- size of structure in bytes </EUCODE> hoping this may help regards, jacques deschĂȘnes
5. Re: Need help wrapping a structure
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 03, 2006
- 490 views
On Fri, 2 Jun 2006 03:40:00 -0400, Greg Haberek <ghaberek at gmail.com> wrote: >The following structure "_XImage" contains a >structure "funcs" that seems to point to routines in memory. <snip> > struct funcs { /* image manipulation routines */ > struct _XImage *(*create_image)( <snip to ")"> > int (*destroy_image) (struct _XImage *); > unsigned long (*get_pixel) (struct _XImage *, int, int); > int (*put_pixel) (struct _XImage *, int, int, unsigned long); > struct _XImage *(*sub_image)(struct _XImage ...); > int (*add_pixel) (struct _XImage *, long); > } f; >} XImage; ></eucode> {{{ Looks to me like you should treat that as a block of 5 pointers. Calling them at the right time with the right parameters might prove interesting)
6. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 03, 2006
- 491 views
> That's awesome, Greg. I wanted to wrap libX, but i didn't really know where to > start. I'm not very good at wrapping libraries. I would definitely want to use an > X wrapper, if you can get it working. I'm good at wrapping libraries, I've done several now, but this is my first crack at a major Linux programming project. > Bernie, that's really cool that you made those libraries, but unfortunately, I > can't use XMOTOR because it's partially shrouded. No offense, but that doesn't do > any good for open source software. So, I need to keep searching for another > solution. > As I develop FluidAE, I'm trying to come up with good cross-platform APIs for > graphics, sound, networking, file management, etc. It seems to be difficult to > find libraries that don't depend on 3rd-party C or C++ libraries (wxWidgets, > BASS, etc.) > > I was trying to use wxEuphoria, which is really cool, but it seems to be a > little to complicated and buggy. Maybe I'm doing something wrong... This is the same issue I have, but for different reasons. I want to be able to compile my apps into a single executable. On Windows, I have Win32Lib for this. But on Linux, I've found an issue one way or another. wxEuphoria requires a .so, XMOTOR is partially shrouded (and a bit confusing, simply because I'm used to Win32Lib and I like its interface). > Anyway, good luck Greg, I wish I could help you. Thanks! :)
7. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 03, 2006
- 492 views
> Looks to me like you should treat that as a block of 5 pointers. > Calling them at the right time with the right parameters might prove > interesting) Yes, I realize that now, too. The structure seemed complicated because I thought all the functions had to be defined within the structure itself. Then I realized that the 'funcs' structure was just 6 pointers. I'll cross the 'calling' bridge when I get to it. ~Greg
8. Re: Need help wrapping a structure
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 03, 2006
- 510 views
Greg Haberek wrote: > > I've started wrapping libX11 in hopes that I can use it to write X > apps. I've got about 950 lines of code wrapped so far, and I've hit my > first road block. The following structure "_XImage" contains a > structure "funcs" that seems to point to routines in memory. I'm using > c_struct.e by David Cuny (from his GTK library) which works much the > same as Win32Lib or tk_mem.e. If someone could help me out, that'd be > great, so I can continue to wrap this library. Here it is in win32lib 'speak'
-- _XImage XImage_width = allot(Int), --;/* width of image */ XImage_height = allot(Int), --;/* height of image */ XImage_xoffset = allot(Int), --;/* number of pixels offset in X direction */ XImage_format = allot(Int), --;/* XYBitmap, XYPixmap, ZPixmap */ XImage_data = allot(Ptr), --;/* pointer to image data */ XImage_byte_order = allot(Int), --;/* data byte order, LSBFirst, MSBFirst */ XImage_bitmap_unit = allot(Int), --;/* quant. of scanline 8, 16, 32 */ XImage_bitmap_bit_order = allot(Int), --;/* LSBFirst, MSBFirst */ XImage_bitmap_pad = allot(Int), --;/* 8, 16, 32 either XY or ZPixmap */ XImage_depth = allot(Int), --;/* depth of image */ XImage_bytes_per_line = allot(Int), --;/* accelarator to next line */ XImage_bits_per_pixel = allot(Int), --;/* bits per pixel (ZPixmap) */ XImage_red_mask = allot(ULong), --;/* bits in z arrangment */ XImage_green_mask = allot(ULong), --; XImage_blue_mask = allot(ULong), --; XImage_obdata = allot(Ptr), --;/* hook for the object routines to hang on */ --/* image manipulation routines */ XImage_f_create_image = allot(Ptr), XImage_f_destroy_image = allot(Ptr), XImage_f_get_pixel = allot(Ptr), XImage_f_put_pixel = allot(Ptr), XImage_f_sub_image = allot(Ptr), XImage_f_add_pixel = allot(Ptr), SIZEOF_XImage = w32allotted_size()
-- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
9. Re: Need help wrapping a structure
- Posted by Bernie Ryan <xotron at bluefrog.com> Jun 03, 2006
- 503 views
Greg Haberek wrote: > This is the same issue I have, but for different reasons. I want to be > able to compile my apps into a single executable. On Windows, I have > Win32Lib for this. But on Linux, I've found an issue one way or > another. wxEuphoria requires a .so, XMOTOR is partially shrouded (and > a bit confusing, simply because I'm used to Win32Lib and I like its > interface). > Greg: If you are going to use Euphoria and not a compiler then you will have to use SO's. To use the X-libraries you would have to compile and link. It took me 6-months to figure out how to use the widgets and SO's without getting exception errors. Also using resources took me some time to figure out. Wrapping the SO's is the easy part. Creating running programs is the difficult part. You will find that it is not easy as using window's DLL's If you want to use apps in a single executable then you can bind a program to XMOTOR. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
10. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 03, 2006
- 488 views
- Last edited Jun 04, 2006
> If you are going to use Euphoria and not a compiler then > you will have to use SO's. Yes, but libX11.so comes with every linux distribution with X-Windows. Things like Motif, etc. may not be. > To use the X-libraries you would have to compile and link. I'm fine with dynamicly linking an already distributed library, like libX11. What I'm not fine with is having to distribute another library, like wxEuphoria.so. > It took me 6-months to figure out how to use the widgets and > SO's without getting exception errors. Also using resources > took me some time to figure out. Wrapping the SO's is the > easy part. Creating running programs is the difficult part. > You will find that it is not easy as using window's DLL's Doesn't XMOTOR use 3rd party windowing libraries, like Motif, Athena, XT, etc? And no offense, but I don't like your approach in XMOTOR. Its too abstracted, too many strings. I'm taking this a step at a time. I'll let everyone know how I progress. ~Greg
11. Re: Need help wrapping a structure
- Posted by irv mullins <irvm at ellijay.com> Jun 03, 2006
- 495 views
- Last edited Jun 04, 2006
Greg Haberek wrote: > I'm fine with dynamicly linking an already distributed library, like > libX11. What I'm not fine with is having to distribute another > library, like wxEuphoria.so. ... > I'm taking this a step at a time. I'll let everyone know how I progress. > One thing you need to be aware of: there's a reason for libraries like wxWindows, Motif, GTK. xlib doesn't know anything about buttons, menus, scrollbars, etc. You have to create those yourself. I quote: "Because of its low-level interface, like the Microsoft Windows SDK, it can make for some very complex programs that apparently achieve very little. One book on the author's shelves contains a version of the 'Hello World' program written for Xlib. It does nothing other than display 'Hello World' in a window, together with a button marked 'Exit', which does the obvious thing when you press it. The program listing runs to five pages!" - Beginning Linux Programming, 2nd Edition, Stones & Matthew
12. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 04, 2006
- 481 views
> One thing you need to be aware of: there's a reason for libraries like > wxWindows, Motif, GTK. xlib doesn't know anything about buttons, menus, > scrollbars, > etc. You have to create those yourself. I quote: Yes I am aware of this. Oddly enough, I like that. I am aware that this is not a simple 'wrap' and go. I want something that is as easy to use as Win32Lib, and I want it done right. I don't like all the other windowing libraries out there. GTK, Motif, etc. They're just not what I want to use. So I'm writing my own. In Euphoria. Step 1: Create full libX11 wrapper. (50% complete) Step 2: Test wrapper by translating various C libX11 demo programs to Euphoria. Step 3: Using C demos as a guide, create a high-level interface similar to Win32Lib. Step 4: Re-create C demos using new interface. Step 5: Release to public. ~Greg
13. Re: Need help wrapping a structure
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 04, 2006
- 480 views
On Sat, 3 Jun 2006 16:34:14 -0400, Greg Haberek <ghaberek at gmail.com> wrote: >And no offense, but I don't like your approach in XMOTOR. Its >too abstracted, too many strings. > >I'm taking this a step at a time. I'll let everyone know how I progress. I don't want to rain on your parade here, but from what I've heard it is common wisdom not to attempt direct 'X' api programming. I hope you've got a book and/or some sample (C) code to go on. If you know of any code samples on the web, I wouldn't mind a link, just out of curiosity Regards, Pete
14. Re: Need help wrapping a structure
- Posted by irv mullins <irvm at ellijay.com> Jun 04, 2006
- 490 views
Pete Lomax wrote: > I don't want to rain on your parade here, but from what I've heard it > is common wisdom not to attempt direct 'X' api programming. I hope > you've got a book and/or some sample (C) code to go on. > > If you know of any code samples on the web, I wouldn't mind a link, > just out of curiosity > > Regards, > Pete > > http://www.sbin.org/doc/Xlib/chapt_03.html http://en.wikipedia.org/wiki/Xlib
15. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 04, 2006
- 515 views
> I don't want to rain on your parade here, but from what I've heard it > is common wisdom not to attempt direct 'X' api programming. I hope > you've got a book and/or some sample (C) code to go on. But I like rain. :) Here's my opinion on it: I am new to Linux GUI programming. Why not start from the bottom? From what I've read, its not that difficult. I'm basicly just writing an X toolkit (like Motif or XT) for Euphoria, in Euphoria. > If you know of any code samples on the web, I wouldn't mind a link, > just out of curiosity Here's the start of my tutorial/example bookmarks: http://tronche.com/gui/x/ http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming.html http://www.xmission.com/~georgeps/documentation/tutorials/tmp.html http://www.ac3.edu.au/SGI_Developer/books/XLib_PG/sgi_html/front.html http://www.everything2.com/index.pl?node=Xlib ~Greg
16. Re: Need help wrapping a structure
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Jun 05, 2006
- 493 views
Greg Haberek wrote: > > > One thing you need to be aware of: there's a reason for libraries like > > wxWindows, Motif, GTK. xlib doesn't know anything about buttons, menus, > > scrollbars, > > etc. You have to create those yourself. I quote: > > Yes I am aware of this. Oddly enough, I like that. I am aware that > this is not a simple 'wrap' and go. I want something that is as easy > to use as Win32Lib, and I want it done right. I don't like all the > other windowing libraries out there. GTK, Motif, etc. They're just not > what I want to use. So I'm writing my own. In Euphoria. > > Step 1: Create full libX11 wrapper. (50% complete) > Step 2: Test wrapper by translating various C libX11 demo programs to > Euphoria. > Step 3: Using C demos as a guide, create a high-level interface > similar to Win32Lib. > Step 4: Re-create C demos using new interface. > Step 5: Release to public. > > ~Greg > > Greg, this sounds like just what i need to get FluidAE working on Linux. It worked ok on windows, using win32lib, but i got sick of windows and switched to linux thinking I would be able to port FluidAE. But, here I am a year later, and still no new release of FluidAE. WxWidgets is too complex for me. I just need a simple library for: 1) creating windows and pixmaps 2) getting events from windows 3) drawing to windows and pixmaps I like the idea of using the lowest layer possible (xlib), it's just more efficient. We have win32api wrappers for euphoria, so why not xlib, right? I don't know if you've looked at FluidAE, but the GUI's widget system is written in 100% euphoria. I'm designing it to be very easy to use. About a year ago when i was running it on Windows, it looked like this: http://www.fluidae.com/images/ss_18-jul-05.jpg. As you can see, it's pretty much complete enough to make basic applications, but I need good graphics libraries to run on any platform. I would be very interesting in testing your library as soon as it's ready. ~Ryan W. Johnson Fluid Application Environment http://www.fluidae.com/ [cool quote here, if i ever think of one...]
17. Re: Need help wrapping a structure
- Posted by "Greg Haberek" <ghaberek at gmail.com> Jun 05, 2006
- 493 views
> WxWidgets is too complex for me. I just need a simple library for: > 1) creating windows and pixmaps > 2) getting events from windows > 3) drawing to windows and pixmaps That's *ALL* Xlib does anyway. :) > I don't know if you've looked at FluidAE, but the GUI's widget system is > written in 100% euphoria. I'm designing it to be very easy to use. About a year > ago when i was running it on Windows, it looked like this: > http://www.fluidae.com/images/ss_18-jul-05.jpg. Yes, I looked at it before. I like the idea. Hopefully my advances of Xlib will help you with FluidAE. ~Greg