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>_getviewcoord() translate physical to view coordinates</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _getviewcoord()         Translate physical to view coordinates

 #include   <graph.h>

 struct xycoord far _getviewcoord( x, y );
  short x;     Horizontal physical coordinate
  short y;     Vertical physical coordinate

    _getviewcoord() used to be called _getlogcoord() under Microsoft C 5.1;
    it gets the view coordinates represented by the physical coordinates
    (x,y).

       Returns:     _getviewcoord() returns the logical coordinates of the
                    physical 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 logical coordinates for the physical point
    (110, 50).

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

           char text[80] = {"<-- Logical 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 physical point 110, 50 */
              xy = _getviewcoord( 0, 0 );
              _moveto( xy.xcoord, xy.ycoord );
              xy = _getviewcoord( 110, 50 );
              _lineto( xy.xcoord, xy.ycoord );

              /* reset text position -- image position does not affect it */
              pix_col = config.numxpixels / config.numtextcols;
              pix_row = config.numypixels / config.numtextrows;
              _settextposition( 50/pix_row+1, 110/pix_col+1 );

              /* print logical coordinates of physical point 110, 50  */
              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: _setlogorg() _getphyscoord() _getvideoconfig()

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