Exemplo n.º 1
0
void
AngleControl::compute_layout(Rollout *ro, layout_data* pos, int& current_y)
{
   setup_layout(ro, pos, current_y);

   const TCHAR*   label_text = caption->eval()->to_string();
   int label_height = (_tcslen(label_text) != 0) ? ro->text_height + SPACING_BEFORE - 2 : 0;

   Value *val;
   if((val = control_param(diameter)) != &unsupplied)
      m_diameter = val->to_int();
   else if((val = control_param(width)) != &unsupplied)
      m_diameter = val->to_int();
   else if((val = control_param(height)) != &unsupplied)
      m_diameter = val->to_int();
   else
      m_diameter = 64;

   pos->width  = m_diameter;
   process_layout_params(ro, pos, current_y);
   pos->height = label_height + m_diameter;
   current_y = pos->top + pos->height;

}
Exemplo n.º 2
0
void
FooControl::add_control(Rollout *ro, HWND parent, HINSTANCE hInstance, int& current_y)
{
	HWND	label, edit_box, spinner;
	int		left, top, width, height;
	SIZE	size;
	const TCHAR*	text = caption->eval()->to_string();	

	/* add 3 controls for a spinner: the label static, value custeditbox, & spinner itself,
	 * label & edit box are given IDs that are the spinner id * control_count & that + 1, to make
	 * sure they are unique and decodable */

	parent_rollout = ro;
	control_ID = next_id();
	WORD label_id = next_id();
	WORD edit_box_id = next_id();	

	// compute bounding box, apply layout params
	layout_data pos;
	setup_layout(ro, &pos, current_y);
	Value* fw = control_param(fieldwidth);
	int spin_width = (fw == &unsupplied) ? ro->current_width / 2 : fw->to_int() + 10;
	GetTextExtentPoint32(ro->rollout_dc, text, static_cast<int>(_tcslen(text)), &size); 	
	int lbl_width = size.cx;
	int orig_width = lbl_width + spin_width;

	pos.width = orig_width + 2;
	pos.left = pos.left + ro->current_width - pos.width; 
	pos.height = ro->text_height + 3;
	process_layout_params(ro, &pos, current_y);

	// place spinner elements
	int cex = (fw == &unsupplied) ? pos.width * lbl_width / orig_width : pos.width - spin_width;
	cex = min(cex, pos.width);
	width = lbl_width; height = ro->text_height;
	left = pos.left + cex - width - 1; top = pos.top; 
	label = CreateWindow(_T("STATIC"),
							text,
							WS_VISIBLE | WS_CHILD | WS_GROUP,
							left, top, width, height,    
							parent, (HMENU)label_id, hInstance, NULL);

	width = pos.width - cex - 13; height = ro->text_height + 3;
	left = pos.left + cex + 1; 
	edit_box = CreateWindowEx(0,
							CUSTEDITWINDOWCLASS,
							_T(""),
							WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_GROUP,
							left, top, width, height,    
							parent, (HMENU)edit_box_id, hInstance, NULL);

	left += width; width = 10; 
	spinner = CreateWindowEx(0,
							SPINNERWINDOWCLASS,
							_T(""),
							WS_VISIBLE | WS_CHILD,
							left, top, width, height,    
							parent, (HMENU)control_ID, hInstance, NULL);

    SendDlgItemMessage(parent, label_id, WM_SETFONT, (WPARAM)ro->font, 0L);
    SendDlgItemMessage(parent, edit_box_id, WM_SETFONT, (WPARAM)ro->font, 0L);

	/* setup the spinner control */

	ISpinnerControl* spin = GetISpinner(spinner);
	Value*			 range = control_param(range);
	Value*			 type = control_param(type);
	Value*			 scaleval = control_param(scale);

	if (type == n_integer)
		spin_type = EDITTYPE_INT;
	else if (type == n_worldUnits)
		spin_type = EDITTYPE_UNIVERSE;
	else if (type == n_float || type == &unsupplied)
		spin_type = EDITTYPE_FLOAT;
	else
		throw TypeError (MaxSDK::GetResourceStringAsMSTR(IDS_SPINNER_TYPE_MUST_BE_INTEGER_OR_FLOAT), type);
	
	if (ro->init_values)
	{
		if (range == &unsupplied)
		{
			min = 0.0f; max = 100.0f; value = 0.0f;
		}
		else if (is_point3(range))
		{
			Point3 p = range->to_point3();
			min = p.x; max = p.y; value = p.z;
		}
		else
			throw TypeError (MaxSDK::GetResourceStringAsMSTR(IDS_SPINNER_RANGE_MUST_BE_A_VECTOR), range);

		if (scaleval == &unsupplied)
		{
				scale = (spin_type == EDITTYPE_INT) ? 1.0f : 0.1f;
		}
		else
			scale = scaleval->to_float();
	}
	
    spin->LinkToEdit(edit_box, spin_type);
	spin->SetScale(scale);
    if (spin_type == EDITTYPE_INT)
	{
		spin->SetLimits((int)min, (int)max, FALSE);
		spin->SetValue((int)value, FALSE);
	}
	else if (spin_type == EDITTYPE_UNIVERSE)
	{
		spin->SetLimits(min, max, FALSE);
		spin->SetValue(value, FALSE);
	}
	else
	{
		spin->SetLimits(min, max, FALSE);
		spin->SetValue(value, FALSE);
	}
	ReleaseISpinner(spin);
}