Tscope5
Main Page
Related Pages
Files
Examples
graphics03.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// graphics03.c
// - Illustration of the display coordinate system.
// - Set/get the display size and position.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
int
main()
{
ts5_set_coordinate_system
(TS5_DISPLAY_COORDINATES);
// get the size of the first display adapter
double
aw, ah;
ts5_get_display_adapter_size
(1, &aw, &ah);
// open a display half the size of the display adapter
ts5_set_display_size
(aw/2.0, ah/2.0);
ts5_set_display_position
(aw/4.0, ah/4.0);
ts5_install_display
();
// make a bitmap half that size
TS5_BITMAP *map =
ts5_alloc_bitmap
(aw/4.0, ah/4.0);
// use the query functions to get
// - the display size
// - the display position
// - the bitmap size
double
dw, dh;
double
dx, dy;
double
bw, bh;
ts5_get_display_size
(1, &dw, &dh);
ts5_get_display_position
(1, &dx, &dy);
ts5_get_bitmap_size
(map, &bw, &bh);
// clear the bitmap to white
ts5_set_background_color
(
ts5_make_named_color
(
"white"
, 1.0));
ts5_set_drawing_target
(map);
ts5_clear_display
();
// print the display size, position etc. on the bitmap
ts5_set_foreground_color
(
ts5_make_named_color
(
"black"
, 1.0));
ts5_printf
(bw/2.0, bh/2.0 - 60,
"display adapter size: %5.2f x %5.2f"
, aw, ah);
ts5_printf
(bw/2.0, bh/2.0 - 20.0,
"display size: %5.2f x %5.2f"
, dw, dh);
ts5_printf
(bw/2.0, bh/2.0 + 20.0,
"display position: %5.2f x %5.2f"
, dx, dy);
ts5_printf
(bw/2.0, bh/2.0 + 60.0,
"bitmap size: %5.2f x %5.2f"
, bw, bh);
// draw the bitmap on the display
ts5_set_active_display
(1);
ts5_draw_bitmap
(map, dw/4.0, dh/4.0);
// draw instructions to move the display
ts5_set_foreground_color
(
ts5_make_named_color
(
"red"
, 1.0));
ts5_printf
(dw/2.0, dh-80.0,
"please drag the display to a new position"
);
ts5_flip_display
();
// wait for a click
ts5_draw_mouse_button
(dw-50.0, dh-50.0);
// print the new display position
// draw a dot on the centre of the display adapter
ts5_get_display_position
(1, &dx, &dy);
ts5_printf
(dw/2.0, dh-40.0,
"new display position: %5.2f x %5.2f"
, dx, dy);
ts5_set_fill_mode
(TS5_FILL_ON);
ts5_draw_circle
(dw-dx, dh-dy, 5);
ts5_flip_display
();
// wait for a click
ts5_draw_mouse_button
(dw-50.0,dh-50.0);
// free the bitmap
ts5_free_bitmap
(map);
return
0;
}