Main Page | Data Structures | Directories | File List | Data Fields | Globals

lcsvga.c File Reference

#include "lcconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "lcstring.h"
#include "common.h"
#include "lctypes.h"
#include "lin-city.h"
#include "mouse.h"
#include "engglobs.h"
#include "engine.h"
#include "screen.h"
#include "lcintl.h"
#include "fileutil.h"

Go to the source code of this file.

Functions

void lc_mouse_handler (int button, int dx, int dy, int dz, int drx, int dry, int drz)
void mouse_setup (void)
void mouse_set_range (int width, int height)
void set_vga_mode (void)
int lc_get_keystroke (void)
void parse_args (int argc, char **argv)
void HandleError (char *description, int degree)
void init_mouse (void)
void setcustompalette (void)

Variables

unsigned char mouse_pointer []
unsigned char under_mouse_pointer [8 *8]
int vga_mode = -1


Function Documentation

void HandleError char *  description,
int  degree
 

Definition at line 240 of file lcsvga.c.

00241 {
00242   fprintf (stderr,
00243            _("An error has occurred.  The description is below...\n"));
00244   fprintf (stderr, "%s\n", description);
00245 
00246   if (degree == FATAL) {
00247       fprintf (stderr, _("Program aborting...\n"));
00248       exit (-1);
00249     }
00250 }

void init_mouse void   ) 
 

Definition at line 253 of file lcsvga.c.

00254 {
00255     mouse_setup ();
00256 }

int lc_get_keystroke void   ) 
 

Definition at line 196 of file lcsvga.c.

00197 {
00198     return vga_getkey ();
00199 }

void lc_mouse_handler int  button,
int  dx,
int  dy,
int  dz,
int  drx,
int  dry,
int  drz
 

Definition at line 154 of file lcsvga.c.

00156 {
00157     static int old_mouse_button = 0;
00158     int mouse_button_change = old_mouse_button ^ button;
00159 
00160     if (mouse_button_change & MOUSE_LEFTBUTTON) {
00161         if (button & MOUSE_LEFTBUTTON) {
00162             cs_mouse_handler(LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS, dx, dy);
00163         } else {
00164             cs_mouse_handler(LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE, dx,
00165                              dy);
00166         }
00167         dx = dy = 0;
00168     }
00169     if (mouse_button_change & MOUSE_MIDDLEBUTTON) {
00170         if (button & MOUSE_MIDDLEBUTTON) {
00171             cs_mouse_handler(LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_PRESS, dx,
00172                              dy);
00173         } else {
00174             cs_mouse_handler(LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_RELEASE, dx,
00175                              dy);
00176         }
00177         dx = dy = 0;
00178     }
00179     if (mouse_button_change & MOUSE_RIGHTBUTTON) {
00180         if (button & MOUSE_RIGHTBUTTON) {
00181             cs_mouse_handler(LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS, dx,
00182                              dy);
00183         } else {
00184             cs_mouse_handler(LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE, dx,
00185                              dy);
00186         }
00187         dx = dy = 0;
00188     }
00189     if (dx || dy) {
00190         cs_mouse_handler(0, dx, dy);
00191     }
00192     old_mouse_button = button;
00193 }

void mouse_set_range int  width,
int  height
 

Definition at line 111 of file lcsvga.c.

00112 {
00113     debug_printf ("setting mouse range: %d %d\n", width, height);
00114     mouse_setxrange(0, width - 1);
00115     mouse_setyrange(0, height - 1);
00116     cs_mouse_xmax = width - 1;
00117     cs_mouse_ymax = height - 1;
00118 }

void mouse_setup void   ) 
 

Definition at line 86 of file lcsvga.c.

00087 {
00088     int m;
00089     m = mouse_init("/dev/mouse", vga_getmousetype(), MOUSE_DEFAULTSAMPLERATE);
00090     mouse_setxrange(0, 640 - 1);
00091     mouse_setyrange(0, 480 - 1);
00092     mouse_setwrap(MOUSE_NOWRAP);
00093     if (m != 0) {
00094         do_error("Can't initialise mouse");
00095     }
00096     cs_mouse_x = 0;
00097     cs_mouse_y = 0;
00098     cs_mouse_button = 0;
00099     cs_mouse_xmax = 640 - 1;
00100     cs_mouse_ymax = 480 - 1;
00101 
00102     /* GCS -- This is meant to fix the upper left cursor problem,
00103      *        but doesnt.  May 11, 2003                                 */
00104     mox = 1; moy = 1;
00105     Fgl_getbox(mox, moy, 8, 8, under_mouse_pointer);
00106 
00107     mouse_seteventhandler(lc_mouse_handler);
00108 }

void parse_args int  argc,
char **  argv
 

Definition at line 206 of file lcsvga.c.

00207 {
00208   int option;
00209   extern char *optarg;
00210 
00211   /* GCS FIX:  Need to print usage and exit when illegal option spec'd */
00212   while ((option = getopt (argc, argv, "wR:G:B:m:")) != EOF)
00213     {
00214       switch (option)
00215         {
00216         case 'm':
00217           sscanf (optarg, "%d", &vga_mode);
00218           if (vga_mode > 13 || vga_mode < 10)
00219             vga_mode = -1;
00220           break;
00221         case 'w':
00222           gamma_correct_red = GAMMA_CORRECT_RED;
00223           gamma_correct_green = GAMMA_CORRECT_GREEN;
00224           gamma_correct_blue = GAMMA_CORRECT_BLUE;
00225           break;
00226         case 'R':
00227           sscanf (optarg, "%f", &gamma_correct_red);
00228           break;
00229         case 'G':
00230           sscanf (optarg, "%f", &gamma_correct_green);
00231           break;
00232         case 'B':
00233           sscanf (optarg, "%f", &gamma_correct_blue);
00234           break;
00235         }
00236     }
00237 }

void set_vga_mode void   ) 
 

Definition at line 121 of file lcsvga.c.

00122 {
00123   /* If vga_mode is not set by command line, use vga_getdefaultmode() 
00124      to get mode.  Supported modes are 10, 11, 12 or 13.
00125    */
00126   if (vga_mode == -1) {
00127     vga_mode = vga_getdefaultmode();
00128     if (vga_mode > 13 || vga_mode < 10)
00129       vga_mode = 10;
00130   }
00131   vga_setmode (vga_mode);
00132   gl_setcontextvga (vga_mode);
00133   init_mouse();
00134   switch (vga_mode) 
00135     {
00136     case 10:
00137       resize_geometry (640,480);
00138       break;
00139     case 11:
00140       resize_geometry (800,600);
00141       break;
00142     case 12:
00143       resize_geometry (1024,768);
00144       break;
00145     case 13:
00146       resize_geometry (1280,1024);
00147       break;
00148     default:
00149       do_error ("illegal vga mode");
00150     }
00151 }

void setcustompalette void   ) 
 

Definition at line 259 of file lcsvga.c.

00260 {
00261     char s[100];
00262     int i, n, r, g, b, flag[256];
00263     FILE *inf;
00264     Palette pal;
00265     for (i = 0; i < 256; i++)
00266         flag[i] = 0;
00267     if ((inf = fopen (colour_pal_file, "r")) == 0)
00268     {
00269         printf ("The colour palette file <%s>... ", colour_pal_file);
00270         do_error ("Can't find it.");
00271     }
00272     while (feof (inf) == 0)
00273     {
00274         fgets (s, 99, inf);
00275         if (sscanf (s, "%d %d %d %d", &n, &r, &g, &b) == 4)
00276         {
00277             pal.color[n].red = r;
00278             pal.color[n].green = g;
00279             pal.color[n].blue = b;
00280             flag[n] = 1;
00281         }
00282     }
00283     fclose (inf);
00284     for (i = 0; i < 256; i++)
00285     {
00286         if (flag[i] == 0)
00287         {
00288             printf ("Colour %d not loaded\n", i);
00289             do_error ("Can't continue");
00290         }
00291         pal.color[i].red = (unsigned char) ((pal.color[i].red
00292                                              * (1 - gamma_correct_red)) + (64 * sin ((float) pal.color[i].red
00293                                                                                      * M_PI / 128)) * gamma_correct_red);
00294 
00295         pal.color[i].green = (unsigned char) ((pal.color[i].green
00296                                                * (1 - gamma_correct_green)) + (64 * sin ((float) pal.color[i].green
00297                                                                                          * M_PI / 128)) * gamma_correct_green);
00298 
00299         pal.color[i].blue = (unsigned char) ((pal.color[i].blue
00300                                               * (1 - gamma_correct_blue)) + (64 * sin ((float) pal.color[i].blue
00301                                                                                        * M_PI / 128)) * gamma_correct_blue);
00302     }
00303     gl_setpalette (&pal);
00304 }


Variable Documentation

unsigned char mouse_pointer[]
 

Initial value:

 {
    255, 255, 255, 255, 1, 1, 1, 1,
    255, 1, 1, 1, 255, 255, 1, 1,
    255, 1, 255, 255, 255, 1, 255, 1,
    255, 1, 255, 1, 1, 255, 1, 1,
    1, 255, 255, 1, 1, 1, 255, 1,
    1, 255, 1, 255, 1, 1, 1, 1,
    1, 1, 255, 1, 255, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1
}

Definition at line 21 of file lcsvga.c.

unsigned char under_mouse_pointer[8 *8]
 

Definition at line 31 of file lcsvga.c.

int vga_mode = -1 [static]
 

Definition at line 33 of file lcsvga.c.


Generated on Sun Dec 26 11:23:30 2004 for lincity by  doxygen 1.3.9.1