Ejemplo n.º 1
0
//
// Set the range of the meter and updates the display.
//
void CMeterCtrl::SetRange(int range1, int range2, BOOL range_auto)
{
	auto_range = range_auto;
	// Disallow setting the ranges to the same value.
	if (range1 == range2)
		return;

	min_range = ((range1 < range2) ? range1 : range2);
	max_range = ((range1 > range2) ? range1 : range2);

	// Make sure that the needle value is within the new range and update
	// the actual angle that the needle should be.
	if (value < min_range)
		actual_angle = 0;
	else if (value > max_range)
		actual_angle = NEEDLE_SWEEP;
	else
		actual_angle = (int)(value / (max_range - min_range) * NEEDLE_SWEEP);

	// Update the displayed scale and marker labels.
	UpdateScaleInfo();
	UpdateLabelInfo();

	RedrawWindow();
}
Ejemplo n.º 2
0
//
// Handles WM_CREATE message (Window is being created)
//
int CMeterCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	CRect control_box;
	POINT temp_point;

	// Allow the framework to create the window
	VERIFY(CWnd::OnCreate(lpCreateStruct) == 0);

	// Store the control's client area rectangle
	GetClientRect(&control_box);

	// Determine where the pivot point should be located.
	// Get the length of the longest radius that will fit inside the box.
	outer_radius = (int)min(control_box.Width() / 2, control_box.Height()
				/ (1 + cos(PIVOT_ARC_ANGLE * PI / 180)));
	inner_radius = (int)(outer_radius * .70);
	pivot_point.x = (int)(control_box.Width() / 2);
	pivot_point.y = outer_radius;

	// Set the size of the rectangle containing the dial.
	meter_box.left = pivot_point.x - outer_radius;
	meter_box.top = pivot_point.y - outer_radius;
	meter_box.right = pivot_point.x + outer_radius;
	meter_box.bottom = pivot_point.y + outer_radius;

	// Initialize the needle's center pivot circle.
	pivot_radius = inner_radius / 12;
	needle_pivot.SetRect(pivot_point.x - pivot_radius,
			     pivot_point.y - pivot_radius, pivot_point.x + pivot_radius, pivot_point.y + pivot_radius);

	// Set the points for the bounding pie wedge.
	CalculatePoint(0, inner_radius, &(min_point.x), &(min_point.y));
	max_point.x = pivot_point.x + (pivot_point.x - min_point.x);
	max_point.y = min_point.y;

	// Now set the needle to the resting position.
	shown_angle = 0;
	actual_angle = 0;
	SetNeedlePoints();

	// Create the text box for the scale display.
	CalculatePoint(0, inner_radius, &scale_box.right, &temp_point.y);
	CalculatePoint(0, outer_radius, &temp_point.x, &scale_box.bottom);
	CalculatePoint(NEEDLE_SWEEP, inner_radius, &scale_box.left, &scale_box.top);

	// Initialize information needed to display the scale and labels.
	scale_font.CreateFont((int)(outer_radius * .2), 0, 0, 0, FW_NORMAL, FALSE,
			      FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
			      DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");
	label_font.CreateFont((int)(outer_radius * .18), 0, 0, 0, FW_NORMAL, FALSE,
			      FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
			      DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");
	marker_pen.CreatePen(PS_SOLID, 2, 0x00FFFFFF);
	label_box_size = (int)(outer_radius * .1);
	label_radius = (int)(outer_radius * .8275);
	tick_mark_radius = (int)(outer_radius * .96);
	UpdateScaleInfo();
	UpdateLabelInfo();

	// Set the points for the rectangle surrounding the watermark arc.
	watermark_box.left = pivot_point.x - inner_radius - 2;
	watermark_box.top = pivot_point.y - inner_radius - 2;
	watermark_box.right = pivot_point.x + inner_radius + 2;
	watermark_box.bottom = pivot_point.y + inner_radius + 2;

	return 0;
}