home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
commodities
/
superdark
/
programmer.lha
/
prog
/
example_gadgs.dark.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-21
|
6KB
|
217 lines
/*********************************************/
/* File example_gadgs.dark.c */
/* */
/* This exampleshow you how to use different */
/* kind of 'gadgets' available with superdark*/
/*********************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <dos/dos.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/displayinfo.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
#include <clib/diskfont_protos.h>
#include "/includes/struct.h"
#include "/includes/tom_gadget.h"
#include "image.h"
struct Library *DiskfontBase;
extern struct GfxBase *GfxBase;
extern struct appel_proc *p_data_proc;
#define VOID_ARG void __regargs
char *p_text_info=
"This is a part of programmers.doc\n"
"You can see here the different \n"
"kind of gadgets available\n"
"including 'high level' gadg like\n"
"screen and font\n"
"Note that all corresponding param.\n"
"are saved in the .info file....\n"
"\n"
" @ Thomas Landspurg\n";
struct RastPort *rp;
struct Screen *s;
#define WIDTH 640
#define HEIGHT 256
UWORD ScreenColors[] = {
0x000,
0xFFF,
0xFE2,
0x68B,
0xF90,
0x0F0,
0x00F,
0xF0F,
0x000 };
struct NewScreen Screen= {
0, 0, WIDTH, HEIGHT, 1,0,1,HIRES,CUSTOMSCREEN,NULL,NULL,NULL,NULL};
/* Note that you should put a string with enough place to put the */
/* larger font name */
struct TextAttr myta={"topaz ",0,0,0};
#define TAILLE_BUF 100
char buffer_text[TAILLE_BUF]="";
char *CyclesNames[] = {"This","is","a","list","of","items",NULL};
char *MxNames[] = {"Item 1","Item 2","Item 3",NULL};
int __saveds press_button();
struct tom_gadget my_gadg[]={
{"_Button", BUTTON, 100,10,100, 11,0,0,0,0,(char *)press_button},
{"Checkbo_x", CHECKBOX,280,10, 10, 10,0,0,0,0,0},
{"C_ycle", CYCLE, 100,25,100, 12, 0,1,0,0,(char *)CyclesNames},
{"_String", STRING, 100, 45,250,14,0,TAILLE_BUF,0,0,buffer_text},
{"_Fonts", FONT, 100,60,100,12,0, 0,0,0,(char *)&myta},
{"Scr_een", SCREEN, 220,60,100,12,0, 0,0,0,0},
{"Sli_der", SLIDER, 100,75,200,10,1,0,10,0,0},
{"_Mx", MX, 150,90,100,30,0,0, 0,0,(char *)MxNames},
{"image...", IMAGE, 250,87, 80,30,0,0,0 ,0,(char *)&image_iffImage},
{0, END_LISTE, 0, 0, 0, 0, 0,0,0,0,0}};
/********** a little proc to print text on screen ************/
void my_print(rp,x,y,pc)
struct RastPort *rp;
int x,y;
char *pc;
{
Move(rp,x,y);
Text(rp,pc,strlen(pc));
}
/* The callback procedure, called when the button is pressed, */
/* Note that this function use the keyword __saved. If you */
/* don't have this one, try geta4() function */
int __saveds press_button(pg,p_t,ctx)
struct Gadget *pg;
struct tom_gadget *p_t;
struct contexe *ctx;
{
static struct EasyStruct ES={
sizeof(struct EasyStruct),
0,"Example",
"You've pressed the button gadget","I know,thanks",};
EasyRequest(ctx->Wnd, &ES, NULL);
/* If you return TRUE, this mean that you want to close the */
/* config window. */
return FALSE;
}
/********************* Just to show you something on your screen *****/
void aff_texte(rp)
struct RastPort *rp;
{
struct TextFont *myfont;
int len,tx,ty,x,y;
struct TextExtent result;
char buffer[100];
/* Note that there is SPrintF equivalent in proc_main, */
/* so it's better to use this one: SPrintF */
SetAPen(rp,1);
SPrintF(buffer,"Cycle value: number %ld",my_gadg[2].value);
my_print(rp,10,20,buffer);
SPrintF(buffer,"String value: number %s",my_gadg[3].value);
my_print(rp,10,30,buffer);
SPrintF(buffer,"Slider value: number %ld",my_gadg[6].value);
my_print(rp,10,40,buffer);
SetAPen(rp,1);
if(DiskfontBase){
if (myfont = OpenDiskFont(&myta))
{
SetFont(rp, myfont);
SetSoftStyle(rp, myta.ta_Style ^ myfont->tf_Style,
(FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC));
}
}
len=strlen(my_gadg[3].p_data);
ty=myta.ta_YSize;
tx=TextLength(rp,my_gadg[3].p_data,len);
if(tx+10>s->Width){
tx=s->Width-10;
len=TextFit(rp,my_gadg[3].p_data,len,&result,NULL,1,s->Width-10,ty);
}
x=(s->Width-tx)/2;
y=(s->Height-ty)/2;
Move(rp,x,y+ty);
ty+=8;
Text(rp,my_gadg[3].p_data,len);
}
/***************************************************/
/* This is the main entry point of this blanker....*/
/***************************************************/
void dark()
{
struct tom_gadget *pg;
pg=&my_gadg[5];
/* First we try to open a screen of the type asked by the user */
if((GfxBase->LibNode.lib_Version>=37)&&(pg->d3!=0)){
s=OpenScreenTags( NULL,
SA_Width,(ULONG)pg->d1,
SA_Height,(ULONG)pg->d2,
SA_Depth,(ULONG)pg->d3,
SA_Overscan,(ULONG)pg->value,
SA_DisplayID,(ULONG)pg->p_data,
SA_Quiet,TRUE,TAG_DONE);
}else{
s=OpenScreen(&Screen);
}
if (s){
rp = &(s->RastPort);
SetRast(rp,0);
FreeSprite (0);
GfxBase->SpriteReserved|=1;
LoadRGB4(&s->ViewPort,ScreenColors,1<<3);
aff_texte(rp);
while(tst_end()==FALSE){
WaitTOF();
}
CloseScreen(s);
}
}
void proc_init()
{
DiskfontBase = OpenLibrary("diskfont.library", 37L);
p_data_proc->code_ret=DARK_WB_20;
}
void proc_save()
{
}
void proc_end()
{
if(DiskfontBase)CloseLibrary(DiskfontBase);
}