示例#1
0
static void createGUI(lua_State *L)
{
	window *w = malloc(sizeof(window));
	windowInit(w, "main", 300, 400);
	widgetReposition(WIDGET(w), 50, 50);
	widgetShow(WIDGET(w));

	// GL stuff
	widgetEnableGL(WIDGET(w));
	WIDGET(w)->vtbl->doDraw = paintWithGL;
	widgetAddTimerEventHandler(WIDGET(w), EVT_TIMER_SINGLE_SHOT, 3000,
	                           timer, NULL, NULL);
}
示例#2
0
static bool widgetToolTipMouseEnterCallback(widget *self, const event *evt,
                                            int handlerId, void *userData)
{
	// Only relevant if we have a tool-tip
	if (self->toolTip)
	{
		// Install a single-shot event handler to show the tip
		widgetAddTimerEventHandler(self, EVT_TIMER_SINGLE_SHOT, 2000,
		                           widgetToolTipTimerCallback, NULL, NULL);
	}

	return true;
}
示例#3
0
int widgetAddAnimation(widget *self, int nframes,
                       const animationFrame *frames)
{
	int i;
	int lastTime = 0;
	int translateCount = 0, rotateCount = 0, scaleCount = 0, alphaCount = 0;
	vector *ourFrames;
	animationFrame *currFrame;

	/*
	 * We need to make sure that the frames are in order and that there is
	 * enough information to do the required interpolation.
	 */
	for (i = 0; i < nframes; i++)
	{
		// Make sure the frame N+1 follows after N
		assert(frames[i].time >= lastTime);

		// Update the time
		lastTime = frames[i].time;

		// Update the animation frame count
		switch (frames[i].type)
		{
			case ANI_TYPE_TRANSLATE:
				translateCount++;
				break;
			case ANI_TYPE_ROTATE:
				rotateCount++;
				break;
			case ANI_TYPE_SCALE:
				scaleCount++;
				break;
			case ANI_TYPE_ALPHA:
				alphaCount++;
				break;
			default:
				assert(!"Invalid animation type");
				break;
		}
	}

	// Ensure the frame counts are valid
	assert(translateCount != 1);
	assert(rotateCount != 1);
	assert(scaleCount != 1);
	assert(alphaCount != 1);

	// Copy the frames over to our own vector
	ourFrames = vectorCreate();

	for (i = 0; i < nframes; i++)
	{
		// Allocate space for the frame
		currFrame = malloc(sizeof(animationFrame));

		// Copy the frame
		*currFrame = frames[i];

		// De-normalise the frames time (so that it is absolute)
		currFrame->time += widgetGetTime();

		// Add the frame to the vector
		vectorAdd(ourFrames, currFrame);
	}

	// Install the animation timer event handler
	return widgetAddTimerEventHandler(self, EVT_TIMER_PERSISTENT, 10,
	                                  widgetAnimationTimerCallback,
	                                  widgetAnimationTimerCallback, ourFrames);
}