home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
dev
/
rkrm.lha
/
RKRM
/
GadTools
/
gadtoolsgadgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-03
|
14KB
|
431 lines
;/* gadtoolsgadgets.c - Compiled with SAS C v5.10b
lc -b1 -cfistq -v -y -j73 gadtoolsgadgets
blink FROM LIB:c.o gadtoolsgadgets.o TO gadtoolsgadgets LIB LIB:lc.lib LIB:amiga.lib
quit
*/
/*
Copyright (c) 1992 Commodore-Amiga, Inc.
This example is provided in electronic form by Commodore-Amiga, Inc. for
use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
published by Addison-Wesley (ISBN 0-201-56774-1).
The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
information on the correct usage of the techniques and operating system
functions presented in these examples. The source and executable code
of these examples may only be distributed in free electronic form, via
bulletin board or as part of a fully non-commercial and freely
redistributable diskette. Both the source and executable code (including
comments) must be included, without modification, in any copy. This
example may not be published in printed form or distributed with any
commercial product. However, the programming techniques and support
routines set forth in these examples may be used in the development
of original executable software products for Commodore Amiga computers.
All other rights reserved.
This example is provided "as-is" and is subject to change; no
warranties are made. All use is at your own risk. No liability or
responsibility is assumed.
*/
/* gadtoolsgadgets.c
** Simple example of using a number of gadtools gadgets.
*/
#define INTUI_V36_NAMES_ONLY
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <stdio.h>
#ifdef LATTICE
int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
int chkabort(void) { return(0); } /* really */
#endif
/* Gadget defines of our choosing, to be used as GadgetID's,
** also used as the index into the gadget array my_gads[].
*/
#define MYGAD_SLIDER (0)
#define MYGAD_STRING1 (1)
#define MYGAD_STRING2 (2)
#define MYGAD_STRING3 (3)
#define MYGAD_BUTTON (4)
/* Range for the slider: */
#define SLIDER_MIN (1)
#define SLIDER_MAX (20)
struct TextAttr Topaz80 = { "topaz.font", 8, 0, 0, };
struct Library *IntuitionBase;
struct Library *GfxBase;
struct Library *GadToolsBase;
/* Print any error message. We could do more fancy handling (like
** an EasyRequest()), but this is only a demo.
*/
void errorMessage(STRPTR error)
{
if (error)
printf("Error: %s\n", error);
}
/*
** Function to handle a GADGETUP or GADGETDOWN event. For GadTools gadgets,
** it is possible to use this function to handle MOUSEMOVEs as well, with
** little or no work.
*/
VOID handleGadgetEvent(struct Window *win, struct Gadget *gad, UWORD code,
WORD *slider_level, struct Gadget *my_gads[])
{
switch (gad->GadgetID)
{
case MYGAD_SLIDER:
/* Sliders report their level in the IntuiMessage Code field: */
printf("Slider at level %ld\n", code);
*slider_level = code;
break;
case MYGAD_STRING1:
/* String gadgets report GADGETUP's */
printf("String gadget 1: '%s'.\n",
((struct StringInfo *)gad->SpecialInfo)->Buffer);
break;
case MYGAD_STRING2:
/* String gadgets report GADGETUP's */
printf("String gadget 2: '%s'.\n",
((struct StringInfo *)gad->SpecialInfo)->Buffer);
break;
case MYGAD_STRING3:
/* String gadgets report GADGETUP's */
printf("String gadget 3: '%s'.\n",
((struct StringInfo *)gad->SpecialInfo)->Buffer);
break;
case MYGAD_BUTTON:
/* Buttons report GADGETUP's (button resets slider to 10) */
printf("Button was pressed, slider reset to 10.\n");
*slider_level = 10;
GT_SetGadgetAttrs(my_gads[MYGAD_SLIDER], win, NULL,
GTSL_Level, *slider_level,
TAG_END);
break;
}
}
/*
** Function to handle vanilla keys.
*/
VOID handleVanillaKey(struct Window *win, UWORD code,
WORD *slider_level, struct Gadget *my_gads[])
{
switch (code)
{
case 'v':
/* increase slider level, but not past maximum */
if (++*slider_level > SLIDER_MAX)
*slider_level = SLIDER_MAX;
GT_SetGadgetAttrs(my_gads[MYGAD_SLIDER], win, NULL,
GTSL_Level, *slider_level,
TAG_END);
break;
case 'V':
/* decrease slider level, but not past minimum */
if (--*slider_level < SLIDER_MIN)
*slider_level = SLIDER_MIN;
GT_SetGadgetAttrs(my_gads[MYGAD_SLIDER], win, NULL,
GTSL_Level, *slider_level,
TAG_END);
break;
case 'c':
case 'C':
/* button resets slider to 10 */
*slider_level = 10;
GT_SetGadgetAttrs(my_gads[MYGAD_SLIDER], win, NULL,
GTSL_Level, *slider_level,
TAG_END);
break;
case 'f':
case 'F':
ActivateGadget(my_gads[MYGAD_STRING1], win, NULL);
break;
case 's':
case 'S':
ActivateGadget(my_gads[MYGAD_STRING2], win, NULL);
break;
case 't':
case 'T':
ActivateGadget(my_gads[MYGAD_STRING3], win, NULL);
break;
}
}
/*
** Here is where all the initialization and creation of GadTools gadgets
** take place. This function requires a pointer to a NULL-initialized
** gadget list pointer. It returns a pointer to the last created gadget,
** which can be checked for success/failure.
*/
struct Gadget *createAllGadgets(struct Gadget **glistptr, void *vi,
UWORD topborder, WORD slider_level, struct Gadget *my_gads[])
{
struct NewGadget ng;
struct Gadget *gad;
/* All the gadget creation calls accept a pointer to the previous gadget, and
** link the new gadget to that gadget's NextGadget field. Also, they exit
** gracefully, returning NULL, if any previous gadget was NULL. This limits
** the amount of checking for failure that is needed. You only need to check
** before you tweak any gadget structure or use any of its fields, and finally
** once at the end, before you add the gadgets.
*/
/* The following operation is required of any program that uses GadTools.
** It gives the toolkit a place to stuff context data.
*/
gad = CreateContext(glistptr);
/* Since the NewGadget structure is unmodified by any of the CreateGadget()
** calls, we need only change those fields which are different.
*/
ng.ng_LeftEdge = 140;
ng.ng_TopEdge = 20+topborder;
ng.ng_Width = 200;
ng.ng_Height = 12;
ng.ng_GadgetText = "_Volume: ";
ng.ng_TextAttr = &Topaz80;
ng.ng_VisualInfo = vi;
ng.ng_GadgetID = MYGAD_SLIDER;
ng.ng_Flags = NG_HIGHLABEL;
my_gads[MYGAD_SLIDER] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
GTSL_Min, SLIDER_MIN,
GTSL_Max, SLIDER_MAX,
GTSL_Level, slider_level,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 20;
ng.ng_Height = 14;
ng.ng_GadgetText = "_First:";
ng.ng_GadgetID = MYGAD_STRING1;
my_gads[MYGAD_STRING1] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, "Try pressing",
GTST_MaxChars, 50,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 20;
ng.ng_GadgetText = "_Second:";
ng.ng_GadgetID = MYGAD_STRING2;
my_gads[MYGAD_STRING2] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, "TAB or Shift-TAB",
GTST_MaxChars, 50,
GT_Underscore, '_',
TAG_END);
ng.ng_TopEdge += 20;
ng.ng_GadgetText = "_Third:";
ng.ng_GadgetID = MYGAD_STRING3;
my_gads[MYGAD_STRING3] = gad = CreateGadget(STRING_KIND, gad, &ng,
GTST_String, "To see what happens!",