//
// Label - Appends text at the given position in the text.
//
void EZ_label_AppendText(ez_label_t *label, int position, const char *append_text)
{
	int text_len		= label->text_length;
	int append_text_len	= strlen(append_text);

	clamp(position, 0, text_len);

	if (!label->text)
	{
		return;
	}

	// Reallocate the string to fit the new text.
	label->text = (char *)Q_realloc((void *)label->text, (text_len + append_text_len + 1) * sizeof(char));

	// Move the part of the string after the specified position.
	memmove(
		label->text + position + append_text_len,		// Destination, make room for the append text.
		label->text + position,							// Move everything after the specified position.
		(text_len + 1 - position) * sizeof(char));

	// Copy the append text into the newly created space in the string.
	memcpy(label->text + position, append_text, append_text_len * sizeof(char));

	CONTROL_RAISE_EVENT(NULL, label, ez_label_t, OnTextChanged, NULL);
}
Exemple #2
0
/*
* Con_Print
*
* Handles cursor positioning, line wrapping, etc
* All console printing must go through this in order to be logged to disk
* If no console is visible, the text will appear at the top of the game window
*/
static void addchartostr( char **s, int c ) {
    int len = *s ? strlen( *s ) : 0;
    char *newstr = Q_realloc( *s, len + 2 );
    newstr[len] = c;
    newstr[len+1] = '\0';
    *s = newstr;
}
Exemple #3
0
/*
* IN_IME_GetCandidates
*/
unsigned int IN_IME_GetCandidates( char * const *cands, size_t candSize, unsigned int maxCands, int *selected, int *firstKey ) {
	size_t candListSize;
	CANDIDATELIST *candList = in_winime_candList;
	unsigned int i;

	if( selected ) {
		*selected = -1;
	}
	if( firstKey ) {
		*firstKey = 1;
	}

	if( !in_winime_enabled ) {
		return 0;
	}

	candListSize = qimmGetCandidateList( in_winime_context, 0, NULL, 0 );
	if( !candListSize ) {
		return 0;
	}

	if( candListSize > in_winime_candListSize ) {
		candList = Q_realloc( candList, candListSize );
		if( !candList ) {
			return 0;
		}
		in_winime_candList = candList;
		in_winime_candListSize = candListSize;
	}

	if( qimmGetCandidateList( in_winime_context, 0, candList, candListSize ) != candListSize ) {
		return 0;
	}

	clamp_high( maxCands, candList->dwPageSize );
	if( ( candList->dwPageStart + maxCands ) > candList->dwCount ) {
		maxCands = candList->dwCount - candList->dwPageStart;
	}

	if( cands && candSize ) {
		for( i = 0; i < maxCands; i++ )
			Q_WCharToUtf8String( ( const WCHAR * )( ( const char * )candList + candList->dwOffset[candList->dwPageStart + i] ), cands[i], candSize );
	}

	if( selected && ( candList->dwSelection >= candList->dwPageStart ) && ( candList->dwSelection < ( candList->dwPageStart + maxCands ) ) ) {
		*selected = ( int )candList->dwSelection - ( int )candList->dwPageStart;
	}

	if( firstKey ) {
		if( !( qimmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY ) & IME_PROP_CANDLIST_START_FROM_1 ) ) {
			*firstKey = 0;
		}
	}

	return maxCands;
}
//
// Label - Removes text between two given indexes.
//
void EZ_label_RemoveText(ez_label_t *label, int start_index, int end_index)
{
	clamp(start_index, 0, label->text_length);
	clamp(end_index, start_index, label->text_length);

	if (!label->text)
	{
		return;
	}

	memmove(
		label->text + start_index,								// Destination.
		label->text + end_index,								// Source.
		(label->text_length - end_index + 1) * sizeof(char));	// Size.
	
	label->text = Q_realloc(label->text, (strlen(label->text) + 1) * sizeof(char));

	CONTROL_RAISE_EVENT(NULL, label, ez_label_t, OnTextChanged, NULL);
}
Exemple #5
0
// CopyString returns an offset from the string heap
int CopyString (char *str)
{
	int old;
#ifdef FAST_STRING_LOOKUP
	int l,h,m,i;
	
	l=0;
	if (cs_num_strings)
	{
		for (h=cs_num_strings-1;l<h;)
		{
			m=(l+h)/2;
			i=strcmp(cs_strings[m],str);
			if (i==0)
				return cs_strings[m]-strings;
			if (i<0)
				l=m+1;
			else
				h=m-1;
			if (l==h) break;
		}
		i=strcmp(cs_strings[l],str);
		if (!i)
			return cs_strings[l]-strings;
		if (i<0) l++;
	}
#endif

	old = strofs;
	strcpy (strings+strofs, str);
	strofs += strlen(str)+1;

#ifdef FAST_STRING_LOOKUP
	cs_strings=Q_realloc(cs_strings,sizeof(char *)*(cs_num_strings+1));
	for (h=cs_num_strings;h>l;h--)
		cs_strings[h]=cs_strings[h-1];
	cs_strings[h]=strings+old;
	cs_num_strings++;
#endif
	return old;
}
Exemple #6
0
void IN_RawInput_MouseRead(HANDLE in_device_handle)
{
	int i = 0, tbuttons, j;
	int dwSize;

	if ( !raw || !rawmice || rawmicecount < 1 )
		return; // no thx

	// get raw input
	if ((*_GRID)((HRAWINPUT)in_device_handle, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) 
	{
		Com_Printf("Raw input: unable to add to get size of raw input header.\n");
		return;
	}

	if (dwSize > ribuffersize)
	{
		ribuffersize = dwSize;
		raw = Q_realloc(raw, dwSize);
	}
		
	if ((*_GRID)((HRAWINPUT)in_device_handle, RID_INPUT, raw, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize ) {
		Com_Printf("Raw input: unable to add to get raw input header.\n");
		return;
	} 

	// find mouse in our mouse list
	for (; i < rawmicecount; i++)
	{
		if (rawmice[i].rawinputhandle == raw->header.hDevice)
			break;
	}

	if (i == rawmicecount) {
		// we're not tracking this mouse
		if (in_raw_allbuttons.integer) {
			// user wants to get button events from all the devices, so be it
			IN_RawInput_Buttons(raw->data.mouse.usButtonFlags);
		}
		return;
	}

	// movement
	if (raw->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
	{
		if (rawmice[i].pos[0] != RI_INVALID_POS)
		{
			rawmice[i].delta[0] += raw->data.mouse.lLastX - rawmice[i].pos[0];
			rawmice[i].delta[1] += raw->data.mouse.lLastY - rawmice[i].pos[1];
		}
		rawmice[i].pos[0] = raw->data.mouse.lLastX;
		rawmice[i].pos[1] = raw->data.mouse.lLastY;
	}
	else // RELATIVE
	{
		rawmice[i].delta[0] += raw->data.mouse.lLastX;
		rawmice[i].delta[1] += raw->data.mouse.lLastY;
		rawmice[i].pos[0] = RI_INVALID_POS;
	}

	// buttons
	IN_RawInput_Buttons(raw->data.mouse.usButtonFlags);

	// mouse wheel
	if (raw->data.mouse.usButtonFlags & RI_MOUSE_WHEEL)
	{      // If the current message has a mouse_wheel message
		if ((SHORT)raw->data.mouse.usButtonData > 0) 
		{
			Key_Event(K_MWHEELUP, true);
			Key_Event(K_MWHEELUP, false);
		}
		if ((SHORT)raw->data.mouse.usButtonData < 0)
		{
			Key_Event(K_MWHEELDOWN, true);
			Key_Event(K_MWHEELDOWN, false);
		}
	}

	// extra buttons
	tbuttons = raw->data.mouse.ulRawButtons & RI_RAWBUTTON_MASK;
	for (j=6 ; j<rawmice[i].numbuttons ; j++)
	{
		if ( (tbuttons & (1<<j)) && !(rawmice[i].buttons & (1<<j)) )
		{
			Key_Event (K_MOUSE1 + j, true);
		}

		if ( !(tbuttons & (1<<j)) && (rawmice[i].buttons & (1<<j)) )
		{
			Key_Event (K_MOUSE1 + j, false);
		}

	}

	rawmice[i].buttons &= ~RI_RAWBUTTON_MASK;
	rawmice[i].buttons |= tbuttons;
}
Exemple #7
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	char    *src2;
	int      p, crc;
	double   start, stop;
	int	   i;
	FILE    *input;

	start = I_FloatTime ();

	myargc = argc;
	myargv = argv;

	for (i=1;i<argc;i++)
	{
		if (!strcmp(argv[i],"-h"))
   	{
   		printf ("%s [-o destfile] file\n",argv[0]);
   		return 0;
   	}
		if (!strcmp(argv[i],"-o"))
		{
			strcpy(destfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-p"))
		{
			strcpy(defsfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-asm"))
		{
			i++;
			continue;
		}
		break;
	}

	InitData ();

	if (!destfile[0])
		strcpy(destfile,"progs.dat");
	if (!defsfile[0])
		strcpy(defsfile,"progdefs.h");
		
	printf ("outputfile: %s\n", destfile);
	
	pr_dumpasm = false;

	PR_BeginCompilation (malloc (0x100000), 0x100000);


// compile all the files
	if (i==argc || !strcmp(argv[i],"-"))
		input=stdin;
	else
	{
		char buf[1024];
		char *cc;

		cc=getenv("CC");
		if (!cc) cc="gcc";
		sprintf(buf,"%s -x c -E %s",cc,argv[i]);
		input=popen(buf,"r");
		if (!input)
			Error("failed to open pipe to cpp ('%s')",buf);
	}
	
	{
		int size=0;
		src2=NULL;
		while (!feof(input))
		{
			src2=Q_realloc(src2,size+1024);
			size+=fread(&src2[size],1,1024,input);
		}
		src2=Q_realloc(src2,size+1);
		src2[size]=0;
	}

	if (input!=stdin)
		pclose(input);

	if (!PR_CompileFile (src2))
		return 1;

	if (!PR_FinishCompilation ())
		Error ("compilation errors");

	p = CheckParm ("-asm");
	if (p)
		PrintFunction (argv[++p]);

// write progdefs.h
	crc = PR_WriteProgdefs (defsfile);

// write data file
	WriteData (crc);

// write files.dat
#ifdef FILES_DAT
	WriteFiles ();
#endif

	stop = I_FloatTime ();
	printf ("%i seconds elapsed.\n", (int)(stop-start));
	return 0;
}