First GEM steps!

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Willsy
Atari User
Atari User
Posts: 30
Joined: Tue Oct 20, 2009 4:07 pm

First GEM steps!

Postby Willsy » Mon Nov 08, 2010 10:57 pm

Well, I cut my first GEM code. Nothing impressive at all - just, er, opens a window, and closes it again!

Don't laugh!

Code: Select all

#include <stdio.h>
#include <aes.h>

int main(void);

int main(void)
{
   int winHandle,x,y,w,h,winType,winStatus;
   
   /* get maximum size of window */
   wind_get( 0, WF_WORKXYWH, &x, &y, &w, &h );

   /* set options we want for our window */
   winType=NAME|CLOSER|FULLER|MOVER|SIZER;
   
   /* create the window (allocate the resources) */
   winHandle=wind_create( winType, x, y, w, h );
   
   /* set the title */
   wind_set(winHandle, WF_NAME, "Hello World!");
   
   /* open the window (causing it to be drawn) */
   winStatus=wind_open(winHandle, 50, 50, 200, 200 );
   
   getchar();

   wind_close(winHandle);  /* remove from screen    */
   wind_delete(winHandle); /* de-allocate resources */
   return(0);
}


The next step is to make it respond to moved messages and re-sized messages. Then I'll look at how one refreshes the client window - that looks quite scary actually.

I'm assuming that one enters a loop of some sort, waiting for messages with evnt_mesag() and processing them in a big switch block?

Code: Select all

int messageSink[8];
BOOL programClosing=FALSE;

while(!programClosing) {
   evnt_mesag(&messageSink);
   switch(messageSink[0]) {
      case WM_CLOSED:
          programClosing=TRUE;
          break;
      case WM_MOVED:
          /* do move thing here (set new coordinates from the message sink)
          break;
   }
}

Something like that anyway. Very enjoyable. I'm thinking about doing a new Forth compiler for the ST. One that is still supported ;) We'll see.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: First GEM steps!

Postby charles » Tue Nov 09, 2010 3:13 am

this guy will be good as soon as he starts writing his own code

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

joska
Hardware Guru
Hardware Guru
Posts: 3669
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: First GEM steps!

Postby joska » Tue Nov 09, 2010 9:03 am

Willsy wrote:The next step is to make it respond to moved messages and re-sized messages. Then I'll look at how one refreshes the client window - that looks quite scary actually.

I'm assuming that one enters a loop of some sort, waiting for messages with evnt_mesag() and processing them in a big switch block?


For any realistic GEM-program you will need to use evnt_multi() in your main loop. But the concept is the same - loop around evnt_multi() and process each event. You can use one big switch block but that will soon become difficult to maintain. It's better to use a small switch-block in the main loop to filter out each type of event, and then call a separate function for each kind.

Redrawing windows is not hard once you understand how it works.

You receive a message with the type WM_REDRAW. This message contains the handle of the affected window, and the dirty rectangle. But - and this is important! - this rectangle is not restricted to this window. It's the actual dirty rectangle and might only partially cover the window. So before you can do any redrawing you need to figure out exactly where you're allowed to draw.

You do this by traversing the window's rectangle list. This is a list of all the windows' visible rectangles. You then intersect each of these rectangles with the dirty rectangle, and redraw the contents of the resulting rectangle. Sounds confusing, but it's actually very simple :) Look for the article series "ProGEM" by Tim Ohren. It's really old stuff, but explains this very well.
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: First GEM steps!

Postby charles » Tue Nov 09, 2010 12:17 pm

i think i up;oaded to this site those help files for c by tim orean

good luck , i never stuck with c
i just use
gfa basic
devpac
omikron basic
ldw basic

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: First GEM steps!

Postby wongck » Tue Nov 09, 2010 1:28 pm

joska wrote: Look for the article series "ProGEM" by Tim Ohren. It's really old stuff, but explains this very well.


Yeap already posted to Willsy here viewtopic.php?f=70&t=15854#p176536
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

Willsy
Atari User
Atari User
Posts: 30
Joined: Tue Oct 20, 2009 4:07 pm

Re: First GEM steps!

Postby Willsy » Tue Nov 09, 2010 4:57 pm

Yep, been reading those articles. Thanks for the links chaps.

I'll try and have another look tonight. I want to catch the WM_MOVED message and re-draw the window.

It seems there are two cases involving moves:

1) The window is moved but is still entirely on the screen - GEM will re-draw without posting a re-draw message - since it's essentially a memory copy
2) The window is moved but part of it is off screen - rectangles come into play - still looks very scary to me

The articles cited mentions an RCS 'Resource Construction Set?' - Seems to be a tool that creates the resource files that GEM/AES can load and interpret directly. I like the sound of that, particularly for the menus. Any idea where I can download it?

Thanks

joska
Hardware Guru
Hardware Guru
Posts: 3669
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: First GEM steps!

Postby joska » Tue Nov 09, 2010 11:01 pm

Willsy wrote:I'll try and have another look tonight. I want to catch the WM_MOVED message and re-draw the window.


You don't do any redraw when handling the WM_MOVED event. You just move the window. If anything needs redrawing, you will be sent WM_REDRAWs as well.

Willsy wrote:The articles cited mentions an RCS 'Resource Construction Set?' - Seems to be a tool that creates the resource files that GEM/AES can load and interpret directly. I like the sound of that, particularly for the menus. Any idea where I can download it?


I recommend Interface instead. I know it's pretty outdated, but it's my favourite.
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: First GEM steps!

Postby wongck » Wed Nov 10, 2010 12:46 am

Willsy wrote:1) The window is moved but is still entirely on the screen - GEM will re-draw without posting a re-draw message - since it's essentially a memory copy
2) The window is moved but part of it is off screen - rectangles come into play - still looks very scary to me


You read the text and just understand what's it's doing.
Frankly, you do not need to re-invent the code again. You just re-use someone's code that does it. No scary business... :wink:
The C code from the professional GEM is pretty good to re-use.
However, I would suggest you read the text before using it because it's easy to fall into the trap of using something of which you are not sure what's going on and get into problems.
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: First GEM steps!

Postby wongck » Wed Nov 10, 2010 12:54 am

Willsy wrote:The articles cited mentions an RCS 'Resource Construction Set?' - Seems to be a tool that creates the resource files that GEM/AES can load and interpret directly. I like the sound of that, particularly for the menus. Any idea where I can download it?


There are plenty RSC construction kits out there on the net.
Interface is really nice looking.
When I started I used ORCS - which worked well on the STFM so it's old. Check the FTP sites.
Also now, Resource Master, another good one is freeware viewtopic.php?f=28&t=14588
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

boniface
Atarian
Atarian
Posts: 2
Joined: Wed Nov 23, 2011 3:18 am

Re: First GEM steps!

Postby boniface » Thu Dec 15, 2011 10:10 pm

New question to an old thread.

I'm new to both GEM and C so I've been going through Clayton Walnuts C-manship. I'm in chapter 14 on dialog boxes and have constructed the dialog as described. The program grabs some of the values from FText objects and a button and v_gtext's them to the screen. For the life of me, I can't figure out how to get the text out of the FText objects. It retrieves it fine from the buttons so I'm not sure what's going on. Here's some code:

AGE is a FTEXT object
NUMBERS is a button

Code: Select all

OBSPEC ob_spec;
TEDINFO *ob_tedinfo;
char *string;

OBJECT tree_addr;

rsrc_gaddr(R_TREE, SAMPLE, &tree_addr);

/* string is empty on this one */
ob_spec = tree_addr[AGE].ob_spec;
ob_tedinfo = &ob_spec;
string = ob_tedinfo->te_ptext;

/* string contains the text of the button on this one */
ob_spec = tree_addr[NUMBERS].ob_spec;
ob_tedinfo = &ob_spec;
string = ob_tedinfo->te_ptext;


I should mention that I'm using Pure C and Interface resource construction tool. I've also got a copy of the Atari Compendium.

I've tried other things like:

Code: Select all

rsrc_gaddr(R_TEDINFO, AGE, &ob_tedinfo);

with no luck as well.

Needless to say, I've scoured the Interwebs for examples, etc. with not much luck. Any help would be greatly appreciated.

joska
Hardware Guru
Hardware Guru
Posts: 3669
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: First GEM steps!

Postby joska » Wed Dec 21, 2011 10:12 pm

If the object is a G_BUTTON, ob_spec points to the text. So in this case the code should look something like this:

Code: Select all

char *s = (char *) tree[INDEX].ob_spec;


s will now point to the text.

If the object is an editable text-field (G_FTEXT) it's bit more complicated. In this case ob_spec points to a TEDINFO structure which holds more info on the edit-field, including the text.

Code: Select all

TEDINFO *t = (TEDINFO *) tree[INDEX].ob_spec;
char *s = t->te_ptext;


You say you're using PureC. In PureC there is a union definition of ob_spec, but I can't recall the details right now. I don't have the PureC stuff at hand. But you should be able to access ob_spec in this way (note! struct- and union- member names taken from memory!):

Code: Select all

char *s = tree[INDEX].ob_spec.tedinfo->te_ptext;
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

boniface
Atarian
Atarian
Posts: 2
Joined: Wed Nov 23, 2011 3:18 am

Re: First GEM steps!

Postby boniface » Mon Dec 26, 2011 6:20 pm

joska wrote:You say you're using PureC. In PureC there is a union definition of ob_spec, but I can't recall the details right now. I don't have the PureC stuff at hand. But you should be able to access ob_spec in this way (note! struct- and union- member names taken from memory!):

Code: Select all

char *s = tree[INDEX].ob_spec.tedinfo->te_ptext;



AWESOME! THANKS!

Finally got a chance to sit down at the Mega after Christmas and try this out. Did the trick! Makes complete sense AFTER I see the code but never having looked at unions before.. huge thanks.

So I will eventually be switching to AHCC and seeing that it is Pure C compatible compiler/assembler, will it handle GEM programming, (G_FTEXT and BUTTONS) in this fashion as well?

joska
Hardware Guru
Hardware Guru
Posts: 3669
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: First GEM steps!

Postby joska » Mon Dec 26, 2011 6:58 pm

Yes, the AHCC GEM-bindings are pretty much identical to PureC.
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest