summaryrefslogtreecommitdiff
path: root/Xbit.h
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2020-05-13 20:25:51 +0000
committerIan C <ianc@noddybox.co.uk>2020-05-13 20:25:51 +0000
commit58b60d1455a6670cbfb1572257460065fe7e6207 (patch)
tree2a5278c4534a16bcf08dad5433b6f8fb60368ede /Xbit.h
parent983bba81d89ba877e8870251d92f64e16cf901c0 (diff)
Builds (just) and runs.
Diffstat (limited to 'Xbit.h')
-rw-r--r--Xbit.h596
1 files changed, 596 insertions, 0 deletions
diff --git a/Xbit.h b/Xbit.h
new file mode 100644
index 0000000..bfb1ab9
--- /dev/null
+++ b/Xbit.h
@@ -0,0 +1,596 @@
+/*
+
+ lunar - Simple X11 Lunar Lander
+
+ Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ -------------------------------------------------------------------------
+
+*/
+
+#ifndef XBIT_H
+#define XBIT_H "$Id: Xbit.h 7 2005-05-13 01:01:08Z ianc $"
+
+
+/*
+ Version 2 of the Bitmap manipulation library for X
+
+ Now supports :
+
+ Multiple windows
+ Pixmaps bigger than the window
+ Mutiple pixmap buffers (upto a maxim of 256 per window)
+ XImage print routines
+ Better XImage support, defaulting to shared memory usage.
+
+ IMPORTANT NOTES ON MIT-SHM SUPPORT :
+
+ 1. Only call CreateXImage() ONCE per window.
+
+ 2. If you wish resources to be freed properly on completion, it
+ is important that DestroyXImage() is called before exiting
+ with the window the XImage was created in relation to set
+ as the current window.
+
+ 3. Allow the user to toggle MIT-SHM from a switch, as if the
+ server supports it, but using it is failing for some other
+ reason, then your program will be unable to run.
+
+*/
+#include <X11/X.h>
+#include <X11/Xlib.h>
+
+
+/* Just as I'm a lazy typer
+*/
+typedef unsigned char uchar;
+typedef unsigned long ulong;
+
+
+/* Maximums for PutPlots()
+*/
+#define MAX_PUTPLOTS 4096
+
+
+/* Types and constants
+*/
+#define MIN_ANG 0
+#define MAX_ANG 23040
+
+typedef enum
+{
+ XFUNCCONT,
+ XFUNCIGNORE,
+ XFUNCSTOP
+} XFuncControl;
+
+typedef struct
+{
+ int x,y;
+ unsigned short w,h;
+ int lx,ly; /* This field is 'private' */
+ Pixmap data; /* This field is 'private' */
+ Pixmap mask; /* This field is 'private' */
+ Pixmap save; /* This field is 'private' */
+} XSprite;
+
+typedef enum
+{
+ XSPRSAVE,
+ XSPRNOSAVE
+} XSpriteControl;
+
+
+typedef struct
+{
+ int r,g,b;
+} Colour;
+
+typedef Colour Color;
+
+
+typedef enum
+{
+ XPRESS,
+ XRELEASE
+} XPressRelease;
+
+
+typedef XFuncControl (*XVoidCallback)(void);
+typedef XFuncControl (*XMoveCallBack)(Window w, int x, int y);
+typedef XFuncControl (*XButtonCallback)(Window w, XPressRelease mode,
+ int button, int x, int y);
+typedef XFuncControl (*XKeyCallback)(Window w, XPressRelease mode,
+ XEvent *event);
+
+typedef struct
+{
+ Window w;
+ XMoveCallBack func;
+} XWindowMoveCallBack;
+
+typedef struct
+{
+ Window w;
+ XButtonCallback func;
+} XWindowButtonCallback;
+
+typedef struct
+{
+ Window w;
+ XKeyCallback func;
+} XWindowKeyCallback;
+
+
+/* XImage font defs
+*/
+typedef enum
+{
+ XI_FONT1,
+ XI_FONT2
+} XImageFont;
+
+
+/* Portable sprite data definitions - allows sprite data and colormap data to
+ be read from a list of files, returning
+ an array of RGB triplets defining the
+ colormap, and array of pixels
+ corresponding to those colours and a
+ series of sprite images with converted
+ pixel values. This means you can use
+ data normally read in just for the
+ XSprite routines on any format of display
+ mechanism.
+*/
+#define SPRD_AT(spr,x,y) (*(spr.data+(x)+((y)*(spr.w))))
+
+typedef struct
+{
+ int w,h; /* Width, height */
+ ulong *data; /* Data */
+} SpriteData;
+
+typedef struct
+{
+ int no_col; /* No of colours used by sprites */
+ ulong pix[256]; /* Array of pixel values */
+ int no_spr;
+ SpriteData *spr; /* Array of sprite data */
+} SpriteDataSet;
+
+
+/* Function Prototypes
+*/
+
+Window OpenWin
+ (
+ int argc,
+ char *argv[],
+ char *title,
+ int Win_X,
+ int Win_Y,
+ int Win_Width,
+ int Win_Height,
+ int Pix_Width,
+ int Pix_Height,
+ unsigned long event_mask,
+ XSizeHints *hints,
+ ulong *black,
+ ulong *white
+ );
+
+Window OpenRootWin
+ (
+ ulong *black, ulong *white,
+ int *w, int *h, int Pix_Width, int Pix_Height
+ );
+
+void SetCurrentWin
+ (
+ Window w
+ );
+
+int GetVisualDepth(void);
+
+XImage *CreateXImage(void);
+
+void ClsXImage
+ (
+ XImage *img
+ );
+
+void DestroyXImage
+ (
+ XImage *img
+ );
+
+XFontStruct
+ *XUseFont
+ (
+ const char *font_name
+ );
+
+void XUseCursor
+ (
+ const char *bitmap_filename,
+ const char *mask_filename,
+ XColor fg,
+ XColor bg
+ );
+
+void SetAsBackdrop(void);
+
+void DisableDoubleBuffer(void);
+
+void DisablePixmap(void);
+
+void DisableShm(void);
+
+void EnableBuffers
+ (
+ int no,
+ ulong clscol
+ );
+
+void LoadBitmap
+ (
+ const char *fn,
+ int x,
+ int y,
+ int resize
+ );
+
+Pixmap GetBitmap
+ (
+ const char *fn,
+ int *width,
+ int *height,
+ int *hot_x,
+ int *hot_y
+ );
+
+/* These 2 are for manipulating your own XImage structures
+*/
+Pixmap GetCurrentPixmap(void);
+GC GetCurrentGC(void);
+
+void Redraw
+ (
+ int off_x,
+ int off_y
+ );
+
+void DrawXImage
+ (
+ XImage *img
+ );
+
+/* Note that if this used with EnableBuffers() on, this will move to the next
+ buffer
+*/
+void Pageflip(void);
+
+void Resize
+ (
+ int pix_w,
+ int pix_h
+ );
+
+void XSetLineStyle
+ (
+ unsigned int line_width,
+ int line_style,
+ int cap_style,
+ int join_style
+ );
+
+void XUseFunction
+ (
+ int GC_function
+ );
+
+void XCls
+ (
+ ulong colour
+ );
+
+void XPlot
+ (
+ int x,
+ int y,
+ ulong colour
+ );
+
+void XLine
+ (
+ int x1,
+ int y1,
+ int x2,
+ int y2,
+ ulong colour
+ );
+
+void SetSplineThresh
+ (
+ int thresh
+ );
+
+void XSpline
+ (
+ int x1,
+ int y1,
+ int x2,
+ int y2,
+ int x3,
+ int y3,
+ ulong colour
+ );
+
+void XPrint
+ (
+ int x,
+ int y,
+ const char *string,
+ ulong colour
+ );
+
+void Xprintf
+ (
+ int x,
+ int y,
+ ulong colour,
+ const char *fmt,
+ ...
+ );
+
+void XISetFont
+ (
+ XImageFont font_no
+ );
+
+void XIprintf
+ (
+ XImage *img,
+ int x,
+ int y,
+ int scale_x,
+ int scale_y,
+ ulong colour,
+ const char *fmt,
+ ...
+ );
+
+void XBox
+ (
+ int x,
+ int y,
+ int w,
+ int h,
+ ulong colour
+ );
+
+void XFillBox
+ (
+ int x,
+ int y,
+ int w,
+ int h,
+ ulong colour
+ );
+
+void XCircle
+ (
+ int x,
+ int y,
+ int rx,
+ int ry,
+ int ang1,
+ int ang2,
+ ulong colour
+ );
+
+void XFillCircle
+ (
+ int x,
+ int y,
+ int rx,
+ int ry,
+ int ang1,
+ int ang2,
+ ulong colour
+ );
+
+void XStartPlots(void);
+
+void XAddPlot
+ (
+ int x,
+ int y
+ );
+
+void XPutPlots
+ (
+ ulong col
+ );
+
+void XPutPlotsAsLines
+ (
+ ulong col
+ );
+
+void XFillPoly
+ (
+ XPoint xp[],
+ int no_points,
+ int shape,
+ ulong col
+ );
+
+void XScroll
+ (
+ int dx,
+ int dy
+ );
+
+void XCopy
+ (
+ int srcx,
+ int srcy,
+ int w,
+ int h,
+ int destx,
+ int desty
+ );
+
+void XPut
+ (
+ Pixmap src,
+ int srcx,
+ int srcy,
+ int w,
+ int h,
+ int destx,
+ int desty
+ );
+
+void XGet
+ (
+ Pixmap dest,
+ int srcx,
+ int srcy,
+ int w,
+ int h,
+ int destx,
+ int desty
+ );
+
+void ScreenCopy(void);
+
+Display *GetDisplay(void);
+
+void XFinished(void);
+
+/* The following event routines expect mouse events to be set in the
+ event mask */
+
+void XDoTillButtonPress
+ (
+ XVoidCallback func
+ );
+
+void XDoMouse
+ (
+ XButtonCallback mouse_button,
+ XMoveCallBack mouse_movement,
+ XVoidCallback process
+ );
+
+void XDoWindows
+ (
+ XWindowButtonCallback mouse_button[],
+ XWindowMoveCallBack mouse_movement[],
+ XWindowKeyCallback key_press[],
+ XFuncControl (*process) ()
+ );
+
+
+/* Sprite routines */
+void LoadSprite
+ (
+ const char *filename,
+ XSprite *sprite,
+ const XColor xc[256]
+ );
+
+
+void XDrawSprites
+ (
+ XSprite *sprites[],
+ int no,
+ XSpriteControl control
+ );
+
+void XEraseSprites
+ (
+ XSprite *sprites[],
+ int no
+ );
+
+void LoadColormap
+ (
+ const char *filename,
+ XColor xc[256]
+ );
+
+#define AllocColors AllocColours
+void AllocColours
+ (
+ int no,
+ ulong pixels[],
+ const char *colname[]
+ );
+
+#define AllocColorsRGB AllocColoursRGB
+void AllocColoursRGB
+ (
+ int no,
+ ulong pixels[],
+ const Colour cols[]
+ );
+
+void LoadSpriteDataSet
+ (
+ const char *cmap_filename,
+ const char *sprite_filenames[],
+ SpriteDataSet *set
+ );
+
+
+/*
+
+ File Formats:
+
+ NB: all ushorts are stored in network format. See ntohs(3).
+
+ Colormap:
+
+ red.ushort - Red component color 0
+ green.ushort - Red component color 0
+ blue.ushort - Red component color 0
+ ...
+ ...
+ red.ushort - Red component color 255
+ green.ushort - Red component color 255
+ blue.ushort - Red component color 255
+
+
+ Sprite:
+
+ "XbitSprite" - Magic string (NULL terminated)
+ width.ushort - width of sprite
+ height.ushort - height of sprite
+ byte.uchar - Pixel value for (0,0)
+ byte.uchar - Pixel value for (1,0)
+ ...
+ ...
+ byte.uchar - Pixel value for (width-1,height-1)
+
+*/
+
+#endif
+
+/* END OF FILE */