コード例 #1
0
ファイル: ez_slider.c プロジェクト: AAS/ezquake-source
//
// Slider - Key event.
//
int EZ_slider_OnKeyDown(ez_control_t *self, int key, int unichar)
{
	qbool key_handled	= false;
	ez_slider_t *slider = (ez_slider_t *)self;
	int big_step		= max(1, slider->max_value / 10);
	int step			= isCtrlDown() ? big_step : 1;

	switch(key)
	{
		case K_RIGHTARROW :
		{
			EZ_slider_SetPosition(slider, slider->slider_pos + step);
			key_handled = true;
			break;
		}
		case K_LEFTARROW :
		{
			EZ_slider_SetPosition(slider, slider->slider_pos - step);
			key_handled = true;
			break;
		}
		default :
		{
			break;
		}
	}

	return key_handled;
}
コード例 #2
0
ファイル: tool_create_entity.cpp プロジェクト: mixxit/solinia
//***************************************************************
void CToolCreateEntity::updateBeforeRender()
{
	//H_AUTO(R2_CToolCreateEntity_updateBeforeRender)
	if (_CreateState != DrawArray)
	{
		CToolChoosePos::updateBeforeRender();
		_AutoGroup.update(_CreatePosition, _PaletteId, _Valid && !isCtrlDown());
		setContextHelp(CI18N::get(_AutoGroup.getGroupingCandidate() ? "uiR2EDToolCreateEntityAutoGroup" : "uiR2EDToolCreateEntity"));
		return;
	}
	setContextHelp(CI18N::get("uiR2EDDrawArrayContextHelp"));
	// update for array mode
	bool valid = true;
	sint32 mouseX,  mouseY;
	getMousePos(mouseX,  mouseY);
	if (!isInScreen(mouseX,  mouseY) || (isMouseOnUI() && !isMouseOnWorldMap()))
	{
		valid = false;
		_ArrayEnd = _ArrayOrigin;
	}
	//
	CTool::CWorldViewRay worldViewRay;
	computeWorldViewRay(mouseX,  mouseY,  worldViewRay);
	//
	CVector entityPos; // the pos where the ghost will be shown
	CVector inter;     // intersection of view ray with landscape
	_ValidArray = true;
	TRayIntersectionType rayIntersectionType = computeLandscapeRayIntersection(worldViewRay,  inter);
	switch(rayIntersectionType)
	{
		case NoIntersection:
			_ValidArray  = false;
			_ArrayEnd = _ArrayOrigin;
		break;
		case ValidPacsPos:
		case InvalidPacsPos:
			_ArrayEnd = inter;
		break;
	}
	for (uint k = 0; valid && k < _ArrayElements.size(); ++k)
	{
		if (_ArrayElements[k])
		{
			if (_ArrayElements[k]->getDisplayFlag(CDisplayerVisual::FlagBadPos))
			{
				_ValidArray  = false;
			}
		}
	}
	CGroupMap *worldMap = getWorldMap();
	if (worldMap) worldMap->setSelectionAxis(_ValidArray);
	setMouseCursor(_ValidArray ? _CursValid.c_str() : _CursInvalid.c_str());
}
コード例 #3
0
ファイル: Ctrl_EditBox.c プロジェクト: jogi1/camquake
void CEditBox_Key(CEditBox *e, int key)
{
	char c;

	switch (key) {
			case K_LEFTARROW:
				e->pos--;
				break;
			case K_RIGHTARROW:
				e->pos++;
				break;
			case K_HOME:
				e->pos = 0;
				break;
			case K_END:
				e->pos = strlen(e->text);
				break;
			case K_DEL:
				if (e->pos < strlen(e->text))
					memmove(e->text + e->pos,
						e->text + e->pos + 1,
						strlen(e->text + e->pos + 1) + 1);
				break;
			case K_BACKSPACE:
				if (e->pos > 0) {
					memmove(e->text + e->pos - 1,
						e->text + e->pos,
						strlen(e->text + e->pos) + 1);
					e->pos --;
				}
			break;
			case 'v':
			case 'V':
				if (isCtrlDown()) {
					int len;
					char *clip = ReadFromClipboard();
					len = min(strlen(clip), e->max - strlen(e->text));
	
					if (len > 0) {
						memmove(e->text + e->pos + len,
							e->text + e->pos,
							strlen(e->text + e->pos) + 1);
						memcpy(e->text + e->pos, clip, len);
						e->pos += len;
					}
				}
			break;
	}

	e->pos = max(e->pos, 0);
	e->pos = min(e->pos, strlen(e->text));

	if (!isCtrlDown() &&
		key >= ' '  &&  key <= '}' &&
		strlen(e->text) < e->max)
	{
		memmove(e->text + e->pos + 1,
			e->text + e->pos,
			strlen(e->text + e->pos) + 1);
		
		c = key;
		if (isShiftDown() && c >= 'a' && c <= 'z')
			c = toupper(c);

		e->text[e->pos] = c;

		e->pos++;
	}
}
コード例 #4
0
ファイル: EX_FileList.c プロジェクト: AAS/ezquake-source
//
// keys handling
// returns: true if processed, false if ignored
//
 qbool FL_Key(filelist_t *fl, int key)
{
	if (fl->mode != FL_MODE_NORMAL)
	{
		switch(key) 
		{
			case 'y':
			case 'Y':
			case K_ENTER:
				if (!FL_IsCurrentDir(fl))
				{
					if (fl->mode == FL_MODE_DELETE)
					{
						FL_DeleteFile(fl);
					}
					#ifdef WITH_ZIP
					else if (fl->mode == FL_MODE_COMPRESS)
					{
						FL_CompressFile(fl); // Compress file.
					}
					else if (fl->mode == FL_MODE_DECOMPRESS)
					{
						FL_DecompressFile(fl); // Decompress file.
					}
					#endif // WITH_ZIP
				}

				fl->mode = FL_MODE_NORMAL;
				return true;
			case 'n':
			case 'N':
			case K_ESCAPE:
				fl->mode = FL_MODE_NORMAL;
				return true;
		}

		return false;
	}

    // Check for search
    if ((key >= ' ' && key <= '~') && (fl->search_valid || (!isAltDown() && !isCtrlDown() && !isShiftDown())))
    {
        int len;

        if (!fl->search_valid)
        {
            // Start searching
            fl->search_valid = true;
            fl->search_error = false;
            fl->search_string[0] = 0;
        }

        len = strlen(fl->search_string);

        if (len < MAX_SEARCH_STRING && !fl->search_error)
        {
            fl->search_string[len] = key;
            fl->search_string[len+1] = 0;
			fl->search_dirty = true;

			// Save the last time the user entered a char in the
			// search term, so that we know when to timeout the search prompt.
			// (See beginning of FL_Draw)
			last_search_enter_time = Sys_DoubleTime();
        }

        return true;    // handled
    }
    else
    {
        fl->search_valid = false;   // finish search mode
    }

    // sorting mode / displaying columns
	if (key >= '1' && key <= '4') {
		if (isCtrlDown() && !isAltDown() && !isShiftDown())
		{
			switch (key)
			{
			case '2':
				Cvar_Toggle(&file_browser_show_size); break;
			case '3':
				Cvar_Toggle(&file_browser_show_date); break;
			case '4':
				Cvar_Toggle(&file_browser_show_time); break;
			default:
				break;
			}
			return true;
		}
		else if (!isCtrlDown() && isAltDown() && !isShiftDown())
		{
			char buf[128];

			strlcpy(buf, file_browser_sort_mode.string, 32); // WTF?
			if (key  ==  buf[0])
			{
				// reverse order
				buf[0] ^= 128;
			}
			else
			{
				// add new
				memmove(buf+1, buf, strlen(buf)+1);
				buf[0] = key;
			}
			buf[8] = 0;
			Cvar_Set(&file_browser_sort_mode, buf);

			fl->need_resort = true;
			return true;
		}
	}

    // change drive
#ifdef _WIN32
    if (isAltDown()  &&  isCtrlDown()  &&
        tolower(key) >= 'a'  &&  tolower(key) <= 'z')
    {
        char newdir[MAX_PATH+1];
        char olddir[MAX_PATH+1];

        snprintf(newdir, sizeof (newdir), "%c:\\", tolower(key));

        // validate
        if (Sys_getcwd(olddir, MAX_PATH+1) == 0)
            return true;
        if (Sys_chdir(newdir) == 0)
            return true;
        Sys_chdir(olddir);

        // and set
        FL_SetCurrentDir(fl, newdir);
        fl->need_refresh = true;

        return true;
    }
#endif

    if (key == '\\'  ||  key == '/')
    {
        FL_ChangeDir(fl, va("%c", PATH_SEPARATOR));
        return true;
    }

	if (key == K_ENTER || key == K_MOUSE1)
    {
        if (FL_IsCurrentDir(fl))
        {
            FL_ChangeDir(fl, FL_GetCurrentPath(fl));
            return true;
        }
		#ifdef WITH_ZIP
		else if (FL_IsCurrentArchive(fl))
		{
			FL_ChangeArchive(fl, FL_GetCurrentPath(fl));
			return true;
		}
		#endif //WITH_ZIP
        else
        {
			return false;
        }
    }

    if (key == K_BACKSPACE)
    {
		if (fl->show_dirup)
			FL_ChangeDir(fl, "..");
        return true;
    }

    if (key == K_UPARROW || key == K_MWHEELUP)
    {
        fl->current_entry--;
        FL_CheckDisplayPosition(fl);
        return true;
    }

    if (key == K_DOWNARROW || key == K_MWHEELDOWN)
    {
        fl->current_entry++;
        FL_CheckDisplayPosition(fl);
        return true;
    }

    if (key == K_PGUP)
    {
        fl->current_entry -= fl->last_page_size;
        FL_CheckDisplayPosition(fl);
        return true;
    }

    if (key == K_PGDN)
    {
        fl->current_entry += fl->last_page_size;
        FL_CheckDisplayPosition(fl);
        return true;
    }

    if (key == K_HOME)
    {
        fl->current_entry = 0;
        FL_CheckDisplayPosition(fl);
        return true;
    }

    if (key == K_END)
    {
        fl->current_entry = fl->num_entries - 1;
        FL_CheckDisplayPosition(fl);
        return true;
    }

	#ifdef WITH_ZIP
	//
	// Compress the current file.
	//
	if ((key == 'c' || key == 'C') && isAltDown())
	{
		if (!FL_IsCurrentDir(fl))
		{
			if (isShiftDown())
			{
				// Alt + shift + c == Compress without confirming.
				FL_CompressFile(fl);
			}
			else
			{
				// Alt + c == Confirm before compressing.
				fl->mode = FL_MODE_COMPRESS;
			}
		}
		return true;
	}

	//
	// Decompress the current file.
	//
	if ((key == 'd' || key == 'D') && isAltDown())
	{
		if (!strcmp(COM_FileExtension(FL_GetCurrentPath(fl)), "gz"))
		{
			FL_DecompressFile(fl);
		}
	}
	#endif // WITH_ZIP

	//
	// Delete the current file.
	//
	if (key == K_DEL)
	{
		if (!FL_IsCurrentDir(fl)) 
		{
			if (isShiftDown())
			{
				// Shift + del == Delete without confirming.
				FL_DeleteFile(fl);
			}
			else
			{
				// Del == Confirm before deleting.
				fl->mode = FL_MODE_DELETE;
			}
		}
		return true;
	}

    return false;
}