home *** CD-ROM | disk | FTP | other *** search
- /*comment utiliser le driver vga256.bgi */
- /* voila en image la reponse */
- /* on peut virer pas mal d'include */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdarg.h>
- #include <ctype.h>
- #include <graphics.h>
- #include <alloc.h>
- #include <math.h>
- #include <dos.h>
- #include <conio.h>
- #define TRUE 1
- #define FALSE 0
- typedef int Bool; /* Boolean data: true or false */
- /* the global variables */
- int GfxMode = 1; /* graphics mode number, or 0 for text */
- /* 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1024x768 */
- /* positive = 16 colors, negative = 256 colors */
- int OrigX; /* the X origin */
- int OrigY; /* the Y origin */
- int Scale; /* the scale value */
- int PointerX; /* X position of pointer */
- int PointerY; /* Y position of pointer */
- int ScrMaxX; /* maximum X screen coord */
- int ScrMaxY; /* maximum Y screen coord */
- int ScrCenterX; /* X coord of screen center */
- int ScrCenterY; /* Y coord of screen center */
- /****************************/
- // mouse function
- /****************************/
- void MontrePointeur()
- { _AX = 0x1;geninterrupt(0x33);}
- void CachePointeur()
- {_AX = 0x2;geninterrupt(0x33);}
- int MouseStat(int *Nbbouton)
- { int Status;
- _AX = 0x0;
- geninterrupt(0x33);
- Status = _AX;
- *Nbbouton = _BX;
- return Status;
- }
- void modif_pos_souris(int colonne,int ligne)
- {
- _AX = 0x4;
- _CX = colonne;
- _DX = ligne;
- geninterrupt(0x33);
- }
- void LectureMouse(int *x,int *y,int *bouton)
- {
- /**** y ligne *****/
- /**** x colonne ***/
- union REGS ri,ro;
- ri.x.ax= 0x3;
- int86(0x33,&ri,&ro);
- *x=ro.x.cx/2;
- *y=ro.x.dx;
- *bouton=ro.x.bx;
- }
-
- /*terminate the graphics display*/
- void TermGfx()
- {
- if (GfxMode)
- {
- closegraph();
- GfxMode = 0;
- }
- }
- /*
- switch from VGA 16 colours to VGA 256 colours
- */
- Bool SwitchToVGA256()
- {
- static int gdriver = -1;
- int gmode, errorcode;
-
- if (GfxMode > 0 && gdriver != VGA) /* if 16 colors and not failed before */
- {
- if (gdriver == -1)
- {
- gdriver = installuserdriver( "VGA256", NULL);
- errorcode = graphresult();
- }
- closegraph();
- gmode = 0;
- initgraph( &gdriver, &gmode, NULL);
- errorcode = graphresult();
- if (errorcode != grOk)
- {
- /* failed for 256 colors - back to 16 colors */
- gdriver = VGA;
- gmode = VGAHI;
- initgraph( &gdriver, &gmode, NULL);
- errorcode = graphresult();
- }
- if (errorcode != grOk) /* shouldn't happen */
- perror(grapherrormsg( errorcode));
- GfxMode = -1 /* 320x200x256 */;
- ScrMaxX = getmaxx();
- ScrMaxY = getmaxy();
- ScrCenterX = ScrMaxX / 2;
- ScrCenterY = ScrMaxY / 2;
- return TRUE;
- }
- return FALSE;
- }
- /*switch from VGA 256 colours to VGA 16 colours*/
- BoolSwitchToVGA16()
- {
- int gdriver, gmode, errorcode;
-
- if (GfxMode == -1) /* switch only if we are in 320x200x256 colors */
- {
- closegraph();
- gdriver = VGA;
- gmode = VGAHI;
- initgraph( &gdriver, &gmode, NULL);
- errorcode = graphresult();
- if (errorcode != grOk) /* shouldn't happen */
- perror(grapherrormsg( errorcode));
- GfxMode = 2; /* 640x480x16 */
- ScrMaxX = getmaxx();
- ScrMaxY = getmaxy();
- ScrCenterX = ScrMaxX / 2;
- ScrCenterY = ScrMaxY / 2;
- return TRUE;
- }
- return FALSE;
- }
- /*
- draw a filled-in 3D-box on the screen from screen coords
- */
-
- void DrawScreenBox3D( int Xstart, int Ystart, int Xend, int Yend)
- {
- setfillstyle( 1, LIGHTGRAY);
- bar( Xstart + 1, Ystart + 1, Xend - 1, Yend - 1);
- setcolor( DARKGRAY);
- line( Xstart, Yend, Xend, Yend);
- line( Xend, Ystart, Xend, Yend);
- if (Xend - Xstart > 20 && Yend - Ystart > 20)
- {
- line( Xstart + 1, Yend - 1, Xend - 1, Yend - 1);
- line( Xend - 1, Ystart + 1, Xend - 1, Yend - 1);
- setcolor( WHITE);
- line( Xstart + 1, Ystart + 1, Xstart + 1, Yend - 1);
- line( Xstart + 1, Ystart + 1, Xend - 1, Ystart + 1);
- }
- setcolor( WHITE);
- line( Xstart, Ystart, Xend, Ystart);
- line( Xstart, Ystart, Xstart, Yend);
- setcolor( BLACK);
- }
- main()
- {int NbBouton;
- SwitchToVGA256();
- if (MouseStat(&NbBouton))
- {
- MontrePointeur();
- DrawScreenBox3D(10,10,20,20);
- getch();
- CachePointeur();
- BoolSwitchToVGA16();
- MontrePointeur();
- DrawScreenBox3D(10,10,20,20);
- getch();
- CachePointeur();
- }
- else {fprintf(stderr,"souris non presente\n");}
- TermGfx();
- }
- /* end of file */
-