/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Screen.h
    Author:  Copyright  1992 Jasn Williams
    Version: 1.00 (23 Mar 1992)
    Purpose: Screen functions (read size, eig factors, etc.)
*/

#ifndef __dl_screen_h
#define __dl_screen_h

#ifdef __cplusplus
extern "C" {
#endif


#ifndef __dl_wimp_h
#include "Wimp.h"
#endif

/* EXTRA NOTES:
 * See Handler.c and '!TestApp.c' for examples of mode_change handlers to
 * automatically keep all these mode variables up-to-date, etc.
 */

/* These variables can be accessed globally for maximum efficiency.
 * Note that they are not valid unless screen_mode == the current screen mode
 * This can be guaranteed if you call Screen_CacheModeInfo() every time
 * you get a mode change message, or before you attempt to use these variables
 *
 * Usage should be:
 *   Screen_CacheModeInfo();
 *   ...
 *   screenwidth = screen_size.x;   (or whatever)
 *   ...
 */


typedef struct
{
   // New style mode specifier block
   unsigned int  flags;    // bit 0 = 1; bits 1-7 are format specifier
   unsigned int  xres;
   unsigned int  yres;
   unsigned int  pixdepth; // 0=1, 1=2, 2=4, 3=8, 4=16, 5=24 (and 32 is?)
   unsigned int  framerate;
   struct
   {
      unsigned int index;  // should be -1 to terminate
      unsigned int value;
   } modevar[1];
} screen_modespecifier;

typedef struct
{
   // New style specifier used for sprites
   int spritetype :  1;    // set to 1 to distinguish from mode specifier
   int hdpi       : 13;    // horizontal DPI
   int vdpi       : 13;    // vertical DPI
   int type       :  5;    // 0 = Old format (mode in bits 0-6)
                           // 1 = 1bpp; 2=2bpp; 3=4bpp; 4=8bpp; 5=16bpp (5:5:5 32K cols);
                           // 6=32bpp; 7=32bpp CMYK(CC?); 8=24bpp(CC), 9=JPEG; and
                           // 10=16bpp(5:6:5 64K cols).
} screen_modesprite;

typedef union
{
   unsigned int          oldmode;      // old style mode number
   screen_modespecifier  *specifier;   // pointer to new style specifier block
   screen_modesprite     spritemode;   // new style DPI sprite mode
} screen_modetypes;


extern screen_modetypes screen_mode;   // phew! complicated!
extern wimp_point screen_size;
extern wimp_point screen_eig;		/* Log2( screen_delta)		*/
extern wimp_point screen_delta;	        /* pixel size in os coors	*/
extern int        screen_bpp;		/* Bits per pixel		*/



extern BOOL Screen_CacheModeInfo(void);
 /*
  * This should be called before you try to use any of the above screen
  * variables. It only needs to be called whenever the screen mode changes
  * so call it:
  *   a) When you initialise your program, and whenever a mode change
  *      message is received (see ModeChangeHandler, below)
  *   b) Immediately before you use the variables (i.e. in your redraw
  *      handler, etc.)
  *
  * It checks the screenmode, and if it has not changed, then the variables
  * are not updated, so it is not too bad if you call it more often than
  * you really need to (i.e. every time you redraw, for example).
  */


#ifdef __cplusplus
}
#endif


#endif
