void
JXColorWheel::SetColor
	(
	const JPoint& pt
	)
{
	if (itsImage == NULL)
		{
		Redraw();
		}

	const JRect bounds       = GetBoundsGlobal();
	const JCoordinate max    = JMin(bounds.height(), bounds.width() - kSliderWidth - kSliderMargin);
	const JCoordinate size   = max - 2*kWheelMargin - 1;
	const JCoordinate center = size/2 + kWheelMargin;

	const JCoordinate dx = - pt.x + center;
	const JCoordinate dy = pt.y - center;

	const JFloat r = JMin(sqrt(dx*dx + dy*dy) / center, 1.0);
	const JFloat a = 0.5 + atan2(dy, dx) / (2.0 * kJPi);

	const JSize b = JRound(itsBrightnessSlider->GetValue());
	SetColor(JHSB(JRound(a * kJMaxHSBValue), JRound(r * kJMaxHSBValue), b));
}
void
JXScrolltab::ScaleValue
	(
	const JFloat scaleFactor
	)
{
	SetValue(JRound(scaleFactor * itsValue));
}
void
JXGC::FillArc
	(
	const Drawable		drawable,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	width,
	const JCoordinate	height,
	const JFloat		startAngle,
	const JFloat		deltaAngle
	)
	const
{
	XFillArc(*itsDisplay, drawable, itsXGC, x,y, width-1,height-1,
			 JRound(startAngle*kDegToXAngle),
			 JRound(deltaAngle*kDegToXAngle));
}
JCoordinate
TestFloatTable::GetPrintFooterHeight
	(
	JPagePrinter& p
	)
	const
{
	return JRound(1.5 * p.GetLineHeight());
}
inline int
BlendComponent
	(
	const int		c1,
	const int		c2,
	const JFloat	alpha
	)
{
	return JRound((1.0 - alpha) * c1 + alpha * c2);
}
void
JX2DPlotPrintEPSDialog::GetPlotSize
	(
	JCoordinate*	w,
	JCoordinate*	h,
	Unit*			unit
	)
{
JFloat v;

	JBoolean ok = itsWidthInput->GetValue(&v);
	assert( ok );
	*w = JRound(v * kUnitToPixel [ itsUnit ]);

	ok = itsHeightInput->GetValue(&v);
	assert( ok );
	*h = JRound(v * kUnitToPixel [ itsUnit ]);

	*unit = itsUnit;
}
void
TestWidget::Print
	(
	JPagePrinter& p
	)
{
	if (!p.OpenDocument())
		{
		return;
		}

	const JCoordinate headerHeight = p.JPainter::GetLineHeight();
	const JCoordinate footerHeight = JRound(1.5 * headerHeight);

	const JString dateStr = JGetTimeStamp();

	JBoolean cancelled = kJFalse;
	for (JIndex i=1; i<=3; i++)
		{
		if (!p.NewPage())
			{
			cancelled = kJTrue;
			break;
			}

		// draw the header

		JRect pageRect = p.GetPageRect();
		p.String(pageRect.left, pageRect.top, "testjx TestWidget");
		p.String(pageRect.left, pageRect.top, dateStr,
				 pageRect.width(), JPainter::kHAlignRight);
		p.LockHeader(headerHeight);

		// draw the footer

		pageRect = p.GetPageRect();
		const JString pageNumberStr = "Page " + JString(i);
		p.String(pageRect.left, pageRect.bottom - footerHeight, pageNumberStr,
				 pageRect.width(), JPainter::kHAlignCenter,
				 footerHeight, JPainter::kVAlignBottom);
		p.LockFooter(footerHeight);

		// draw the page

		DrawStuff(p);
		}

	if (!cancelled)
		{
		p.CloseDocument();
		}
}
Exemple #8
0
void
JXApplication::UpdateCurrentTime()
{
#ifdef WIN32

	itsCurrentTime = GetTickCount();

#else

	itimerval timerInfo;
	getitimer(ITIMER_REAL, &timerInfo);
	itsCurrentTime = JRound(1000 * (kTimerStart -
		 (timerInfo.it_value.tv_sec + timerInfo.it_value.tv_usec/1e6)));

#endif
}
void
JXColorWheel::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (sender == itsBrightnessSlider && message.Is(JSliderBase::kMoved))
		{
		itsColor.brightness = JRound(itsBrightnessSlider->GetValue());
		Broadcast(ColorChanged());
		Refresh();
		}
	else
		{
		JXWidget::Receive(sender, message);
		}
}
void
JXScrolltab::PlaceVert
	(
	const JCoordinate	ymin,
	const JCoordinate	ymax,
	const JFloat		scale
	)
{
	JCoordinate y = ymin + JRound(scale * (itsValue - JXScrollbar::kMinValue));
	if (y > ymax)
		{
		y = ymax;
		}
	if (y < ymin)
		{
		y = ymin;
		}

	Place(itsScrollbar->GetBoundsWidth() - kAcrossSize, y);
	SetSize(kAcrossSize, kAlongSize);
}
void
JXScrolltab::PlaceHoriz
	(
	const JCoordinate	xmin,
	const JCoordinate	xmax,
	const JFloat		scale
	)
{
	JCoordinate x = xmin + JRound(scale * (itsValue - JXScrollbar::kMinValue));
	if (x > xmax)
		{
		x = xmax;
		}
	if (x < xmin)
		{
		x = xmin;
		}

	Place(x, itsScrollbar->GetBoundsHeight() - kAcrossSize);
	SetSize(kAlongSize, kAcrossSize);
}
JBoolean
JDiscreteVarEquality::Evaluate()
	const
{
	JIndex value[2];
	for (long i=0; i<2; i++)
		{
		JFloat x = 1.0;
		if (itsArrayIndex[i] != NULL && !itsArrayIndex[i]->Evaluate(&x))
			{
			return kJFalse;
			}
		JIndex arrayIndex = JRound(x);
		if (!itsVariableList->ArrayIndexValid(itsVarIndex[i], arrayIndex))
			{
			(JGetUserNotification())->ReportError("Array index out of bounds");
			return kJFalse;
			}
		value[i] = itsVariableList->GetDiscreteValue(itsVarIndex[i], arrayIndex);
		}
	return JConvertToBoolean( value[0] == value[1] );
}
JBoolean
JFunctionWithVar::EvaluateArrayIndex
	(
	JIndex* index
	)
	const
{
	JFloat x = 1.0;
	if (itsArrayIndex != NULL && !itsArrayIndex->Evaluate(&x))
		{
		return kJFalse;
		}
	*index = JRound(x);
	if (!itsVariableList->ArrayIndexValid(itsVariableIndex, *index))
		{
		(JGetUserNotification())->ReportError("Array index out of bounds");
		return kJFalse;
		}
	else
		{
		return kJTrue;
		}
}
				JFloat value;
				input >> value;
				AddVariable(name, value);
				}
			else
				{
				const JSize nameLen = name.GetLength();
				JIndex bracketIndex;
				const JBoolean foundBracket = name.LocateSubstring("[", &bracketIndex);
				assert( foundBracket && bracketIndex < nameLen-1 );
				const JString sizeStr = name.GetSubstring(bracketIndex+1, nameLen-1);
				name.RemoveSubstring(bracketIndex, nameLen);
				JFloat x;
				const JBoolean isNumber = sizeStr.ConvertToFloat(&x);
				assert( isNumber );
				const JSize arraySize = JRound(x);
				GNArray values(arraySize);
				for (JIndex i=1; i<= arraySize; i++)
					{
					JFloat value;
					input >> value;
					values.AppendElement(value);
					}
				AddArray(name, values);
				}
			}
		else
			{
			JString errorStr = "Unsupported variable type 'x'";
			errorStr.SetCharacter(errorStr.GetLength()-1, type);
			JGetUserNotification()->ReportError(errorStr);
void
JXColorWheel::Draw
	(
	JXWindowPainter&	p,
	const JRect&		rect
	)
{
	JXColormap* colormap    = GetColormap();
	const JColorIndex black = colormap->GetBlackColor();

	const JRect bounds       = GetBoundsGlobal();
	const JCoordinate max    = JMin(bounds.height(), bounds.width() - kSliderWidth - kSliderMargin);
	const JCoordinate size   = max - 2*kWheelMargin - 1;
	const JCoordinate center = size/2 + kWheelMargin;
	if (itsImage == NULL || itsImage->GetWidth() != max || itsColor.brightness != itsLastDrawBrightness)
		{
		p.SetFilling(kJTrue);
		p.SetPenColor(black);
		p.Ellipse(kWheelMargin, kWheelMargin, size, size);
		p.SetFilling(kJFalse);

		JRect r  = bounds;
		r.bottom = r.top  + max;
		r.right  = r.left + max;

		jdelete itsImage;
		itsImage = jnew JXImage(GetDisplay(), p.GetDrawable(), r);
		assert( itsImage != NULL );

		itsLastDrawBrightness = itsColor.brightness;
		for (JCoordinate x=0; x<max; x++)
			{
			const JCoordinate dx = - x + center;

			for (JCoordinate y=0; y<max; y++)
				{
				if (itsImage->GetColor(x,y) == black)
					{
					const JCoordinate dy = y - center;
					const JFloat r = sqrt(dx*dx + dy*dy) / center;
					const JFloat a = 0.5 + atan2(dy, dx) / (2.0 * kJPi);

					JHSB color(JRound(a * kJMaxHSBValue), JRound(r * kJMaxHSBValue), itsLastDrawBrightness);
					itsImage->SetColor(x,y, colormap->JColormap::GetColor(color));
					}
				}
			}

		itsImage->ConvertToRemoteStorage();
		}

	p.JPainter::Image(*itsImage, itsImage->GetBounds(), 0,0);

	const JFloat r = (itsColor.saturation / kJMaxHSBValueF) * size/2;
	const JFloat a = ((itsColor.hue / kJMaxHSBValueF) - 0.5) * 2.0 * kJPi;

	const JCoordinate x = center - JRound(r * cos(a));
	const JCoordinate y = center + JRound(r * sin(a));

	JRect mark(y-kWheelMargin, x-kWheelMargin, y+kWheelMargin+1, x+kWheelMargin+1);

	p.SetPenColor(colormap->GetWhiteColor());
	p.SetFilling(kJTrue);
	p.JPainter::Rect(mark);
	p.SetFilling(kJFalse);
	p.SetPenColor(black);
	p.JPainter::Rect(mark);
}