AspectTip3.sml

  Download

More scripts: Enhanced Data Tip

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
### AspectTip3.sml
### sample Display Control Script
### Creates a DataTip graphic within a normal DataTip frame and background;
### DataTip information from other layers is permitted.
################ Global Variables ###########################
class RVC_RASTER ASPECT;				# the aspect raster object
class GRE_LAYER aspectLayer;		# the layer containing the aspect raster
class GRDEVICE_MEM_RGBA dev;		# RGB Alpha (opacity) graphics rendering device in memory for drawing in DataTip
class COLOR transparent(0, 0, 0, 0);		# transparent color to clear device
numeric height, width;			# height and width of graphics rendering device
#################################################################
### procedure called when group or layout is initialized
proc OnInitialize () {
	width = 110;				# set width of rendering device in pixels
	height = width * 1.45;	# set height of rendering device in pixels
	dev.Create(height, width);		# create graphics rendering device
	}
##################################################################
### procedure called when view is created for layout
proc OnLayoutCreateView (
   class GRE_LAYOUT layout,
   class GRE_VIEW view
   ) {
	local class GRE_GROUP group;
	local class RVC_RASTER rast;
	local class GRE_LAYER layer;
	local string name$;				# name of the target raster object
	# locate the Group in the layout
	group = layout.FirstGroup;		# start with first group in layout
	while (group.Name != "Group 1")	# iterate through groups until find named group
		group = group.NextGroup;
	# find the aspect raster by its object name "ASPECT"
	layer = group.FirstLayer;
	while (name$ != "ASPECT")
		{
		# check if layer with single raster; if so, get object name
		if (layer.TypeID == "Raster"  && layer.GetNumObjects() == 1)
			{
			DispGetRasterFromLayer(rast, layer);	# get raster object from layer
			name$ = rast.$Info.Name;	# check name of raster object
			if (name$ == "ASPECT")
				{
				aspectLayer = layer;
				DispGetRasterFromLayer(ASPECT, layer);	# assign object to global raster instance
				} # end if
			} # end if
		layer = layer.NextLayer;	# move to next layer in group
		} # end while
	} # end of proc OnLayoutCreateView
##########################################################
### function called when DataTip request is made
func OnViewDataTipShowRequest (
   class GRE_VIEW view,
   class POINT2D point,
   class TOOLTIP datatip
   ) {
	local class TRANSPARM trans;	# coordinate transformation parameters
	local numeric lin, col;			# current line and column position
	local numeric aspect;			# value from the ASPECT raster for cell under cursor
	local string aspect$;			# aspect value string
	local class GC gc;					# graphics context for the graphics rendering device
	local class COLOR color;			# reusable color for drawing
	local class POINT2D center;		# position of center of rotation of aspect arrow
	local class POINT2D arrowEnd;		# position used to draw arrow head for aspect pointer
	local numeric radius;				# radius of aspect circle
	local numeric aspectDrawAngle;	# angle used for drawing aspect arrow
	local numeric arrowLength;			# half-length of aspect pointer in pixels
	local numeric boxtop;				# y position of top of label rectangle
	local numeric start;					# computed start position for centered text
	# get transform from screen to layer coordinates and convert cursor position to layer coordinates
   trans = view.GetTransLayerToScreen(aspectLayer, 1);	# 1 for second parameter gets the inverse transform
	point = trans.ConvertPoint2DFwd(point);
	lin = floor(point.y);				## line and column position of cell under cursor
	col = floor(point.x);
	aspect = ASPECT[lin, col];
	if (aspect <> ASPECT.$Info.NullValue)	# if cursor is not over a null cell
		{
		### clear the graphics rendering device
		dev.Clear(transparent);
		### Draw static GraphTip elements
		gc = dev.CreateGC();		# create graphics context
		# draw background circle for aspect indicator and rectangle for aspect text
		center.x = width * 0.5;
		center.y = center.x;
		radius = width * 0.45;
		boxtop = center.x * 2;
		gc.SetColorRGB(230, 255, 230);
		gc.FillCircle(center.x, center.y, radius);
		gc.FillRect(15, boxtop, width-30, 35);
		# draw black circle outline and black rectangle outline
		gc.SetColorName("black");
		gc.DrawCircle(center.x, center.y, radius);	# circle outline
		gc.DrawRect(15, boxtop, width-30, 35);			# rectangle outline
		# set parameters for drawing Aspect text label in rectangle
		gc.DrawTextSetFont("ARIALBD.TTF");
		gc.DrawTextSetHeightPixels(12);
		color.Name = "black";
		gc.DrawTextSetColors(color);
		# draw centered Aspect label in rectangle
		start = center.x - ( gc.TextGetWidth("Aspect:") * 0.5 );
		gc.DrawTextSimple("Aspect", start, boxtop + 15);
		# set aspect text and pointer parameters
		gc.DrawTextSetFont("ARIAL.TTF");		# font for aspect value string
		if (aspect == -1) { 		# flat area with aspect undefined; only write string
			aspect$ = "Undefined";
			start = center.x - ( gc.TextGetWidth(aspect$) * 0.5 );
			gc.DrawTextSimple(aspect$, start, boxtop + 30);
			}
		else {				# draw aspect value and pointer
			aspect$ = sprintf("%.1f deg", aspect);		# create and draw aspect label string
			start = center.x - ( gc.TextGetWidth(aspect$) * 0.5 );
			gc.DrawTextSimple(aspect$, start, boxtop + 30);
			aspectDrawAngle = (aspect - 90);				# drawing angle for aspect pointer
			arrowLength = 40;
			gc.SetLineWidth(3);	# set line width to 3 pixels for pointer
			### find and store coordinates of end of pointer line
			arrowEnd.x = center.x + arrowLength * cosd(aspectDrawAngle);
			arrowEnd.y = center.y + arrowLength * sind(aspectDrawAngle);
			### move to start of pointer line and draw to end
			gc.MoveTo( center.x - arrowLength * cosd(aspectDrawAngle), center.y - arrowLength * sind(aspectDrawAngle) );
			gc.SetColorName("red");
			gc.DrawTo(arrowEnd.x, arrowEnd.y);
			### draw arrowhead and small black circle at center of rotation of pointer
			gc.DrawArrow(arrowEnd.x, arrowEnd.y, aspectDrawAngle, 9, 30, "Open");
			gc.SetColorName("black");
			gc.FillCircle(center.x, center.y, 3);
			datatip.AppendImage(dev);		# add the graphics device to the DataTip
			datatip.AppendText("{~FARIAL.TTF}\n");
			return 0;		# render image in normal DataTip along with info from other layers
			}
		} # end if not over null cell
	else return -1;	# if outside ASPECT raster or on null cell, don't show any DataTip
	} # end OnViewDataTipShowRequest