Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_getphyscoord() convert logical to physical coordinates</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _getphyscoord()         Convert logical to physical coordinates

 #include   <graph.h>

 struct xycoord far _getphyscoord( x, y );
  short x;     Horizontal logical coordinate
  short y;     Vertical logical coordinate

    _getphyscoord() gets the physical coordinates represented by the
    logical coordinates (x,y).

       Returns:     _getphyscoord() returns the physical coordinates of
                    the logical coordinates (x,y) in an xycoord
                    structure, defined in graph.h:

                    struct xycoord {
                       short xcoord;    x coordinate (horizontal)
                       short ycoord;    y coordinate (vertical)
                       };

         Notes:     The graphics functions recognize two sets of
                    coordinates:

                    1. Physical coordinates determined by the hardware
                    and display configuration of the user's environment.

                    2. Logical coordinates defined by the application,
                    which can be reassigned to different physical
                    coordinates.

                    Functions affected by the logical coordinates
                    translate them to the appropriate physical
                    coordinates, and vice versa.

                    The default logical coordinate system is identical to
                    the physical one. The physical origin (0, 0) is
                    always in the upper-left corner of the display.
                    Increasing physical x values move the origin from
                    left to right. Increasing physical y values move the
                    origin from top to bottom. _setlogorg() permits the
                    logical origin to be displaced from default physical
                    origin.

                    The dimensions of the x and y axes depend on the
                    available display hardware and the selected video
                    mode. These values are accessible at run time by
                    examining the numxpixels and numypixels members of
                    the videoconfig structure returned by
                    _getvideoconfig().

                    The physical coordinates of any logical point can be
                    determined using _getphyscoord(), and the logical
                    coordinates of any physical point can be determined
                    with _getviewcoord().

                    The logical and physical coordinate systems affect
                    the location of images only, and have no effect on
                    the location of text.

   Portability:     MS-DOS only, true MDPA, CGA, EGA, MCGA, or VGA video
                    compatibles

 -------------------------------- Example ---------------------------------

    This program gets the physical coordinates for the logical point -49,
    -49

           #include <conio.h>
           #include <string.h>
           #include <stdlib.h>
           #include <graph.h>

           char text[80] = {"<-- Physical point "};
           char xloc[10], yloc[10];

           main()
           {
              struct xycoord xy;
              struct videoconfig config;
              short pix_row, pix_col;

              _setvideomode( _MRES4COLOR );
              _getvideoconfig( &config );

              /* shift logical origin to center of screen  */
              _setlogorg( config.numxpixels/2-1, config.numypixels/2-1);

              /* draw line from physical origin to logical point -49, -49 */
              xy = _getviewcoord( 0, 0 );
              _moveto( xy.xcoord, xy.ycoord );
              _lineto( -49, -49 );

              /* reset text position -- image position does not affect it */
              xy = _getphyscoord( -49, -49 );
              pix_col = config.numxpixels / config.numtextcols;
              pix_row = config.numypixels / config.numtextrows;
              _settextposition( xy.ycoord/pix_row+1, xy.xcoord/pix_col+1 );

              /* print physical coordinates of logical point -49, -49  */
              itoa( xy.xcoord, xloc, 10 );
              itoa( xy.ycoord, yloc, 10 );
              strcat( text, xloc );
              strcat( text, ", " );
              strcat( text, yloc );
              _outtext( text );

              while ( !kbhit() );
              _setvideomode( _DEFAULTMODE );
           }


See Also: _getviewcoord() _getvideoconfig() _settextposition()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson