📄 ui_shared.c
字号:
value = DC->getCVarValue(item->cvar);
if (value < editDef->minVal) {
value = editDef->minVal;
} else if (value > editDef->maxVal) {
value = editDef->maxVal;
}
range = editDef->maxVal - editDef->minVal;
value -= editDef->minVal;
value /= range;
//value /= (editDef->maxVal - editDef->minVal);
value *= SLIDER_WIDTH;
x += value;
// vm fuckage
//x = x + (((float)value / editDef->maxVal) * SLIDER_WIDTH);
return x;
}
int Item_Slider_OverSlider(itemDef_t *item, float x, float y) {
rectDef_t r;
r.x = Item_Slider_ThumbPosition(item) - (SLIDER_THUMB_WIDTH / 2);
r.y = item->window.rect.y - 2;
r.w = SLIDER_THUMB_WIDTH;
r.h = SLIDER_THUMB_HEIGHT;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_THUMB;
}
return 0;
}
int Item_ListBox_OverLB(itemDef_t *item, float x, float y) {
rectDef_t r;
listBoxDef_t *listPtr;
int thumbstart;
int count;
count = DC->feederCount(item->special);
listPtr = (listBoxDef_t*)item->typeData;
if (item->window.flags & WINDOW_HORIZONTAL) {
// check if on left arrow
r.x = item->window.rect.x;
r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
r.h = r.w = SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_LEFTARROW;
}
// check if on right arrow
r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_RIGHTARROW;
}
// check if on thumb
thumbstart = Item_ListBox_ThumbPosition(item);
r.x = thumbstart;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_THUMB;
}
r.x = item->window.rect.x + SCROLLBAR_SIZE;
r.w = thumbstart - r.x;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_PGUP;
}
r.x = thumbstart + SCROLLBAR_SIZE;
r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_PGDN;
}
} else {
r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
r.y = item->window.rect.y;
r.h = r.w = SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_LEFTARROW;
}
r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_RIGHTARROW;
}
thumbstart = Item_ListBox_ThumbPosition(item);
r.y = thumbstart;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_THUMB;
}
r.y = item->window.rect.y + SCROLLBAR_SIZE;
r.h = thumbstart - r.y;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_PGUP;
}
r.y = thumbstart + SCROLLBAR_SIZE;
r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
if (Rect_ContainsPoint(&r, x, y)) {
return WINDOW_LB_PGDN;
}
}
return 0;
}
void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y)
{
rectDef_t r;
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
item->window.flags &= ~(WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN);
item->window.flags |= Item_ListBox_OverLB(item, x, y);
if (item->window.flags & WINDOW_HORIZONTAL) {
if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) {
// check for selection hit as we have exausted buttons and thumb
if (listPtr->elementStyle == LISTBOX_IMAGE) {
r.x = item->window.rect.x;
r.y = item->window.rect.y;
r.h = item->window.rect.h - SCROLLBAR_SIZE;
r.w = item->window.rect.w - listPtr->drawPadding;
if (Rect_ContainsPoint(&r, x, y)) {
listPtr->cursorPos = (int)((x - r.x) / listPtr->elementWidth) + listPtr->startPos;
if (listPtr->cursorPos >= listPtr->endPos) {
listPtr->cursorPos = listPtr->endPos;
}
}
} else {
// text hit..
}
}
} else if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) {
r.x = item->window.rect.x;
r.y = item->window.rect.y;
r.w = item->window.rect.w - SCROLLBAR_SIZE;
r.h = item->window.rect.h - listPtr->drawPadding;
if (Rect_ContainsPoint(&r, x, y)) {
listPtr->cursorPos = (int)((y - 2 - r.y) / listPtr->elementHeight) + listPtr->startPos;
if (listPtr->cursorPos > listPtr->endPos) {
listPtr->cursorPos = listPtr->endPos;
}
}
}
}
void Item_MouseEnter(itemDef_t *item, float x, float y) {
rectDef_t r;
if (item) {
r = item->textRect;
r.y -= r.h;
// in the text rect?
// items can be enabled and disabled based on cvars
if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) {
return;
}
if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) {
return;
}
if (Rect_ContainsPoint(&r, x, y)) {
if (!(item->window.flags & WINDOW_MOUSEOVERTEXT)) {
Item_RunScript(item, item->mouseEnterText);
item->window.flags |= WINDOW_MOUSEOVERTEXT;
}
if (!(item->window.flags & WINDOW_MOUSEOVER)) {
Item_RunScript(item, item->mouseEnter);
item->window.flags |= WINDOW_MOUSEOVER;
}
} else {
// not in the text rect
if (item->window.flags & WINDOW_MOUSEOVERTEXT) {
// if we were
Item_RunScript(item, item->mouseExitText);
item->window.flags &= ~WINDOW_MOUSEOVERTEXT;
}
if (!(item->window.flags & WINDOW_MOUSEOVER)) {
Item_RunScript(item, item->mouseEnter);
item->window.flags |= WINDOW_MOUSEOVER;
}
if (item->type == ITEM_TYPE_LISTBOX) {
Item_ListBox_MouseEnter(item, x, y);
}
}
}
}
void Item_MouseLeave(itemDef_t *item) {
if (item) {
if (item->window.flags & WINDOW_MOUSEOVERTEXT) {
Item_RunScript(item, item->mouseExitText);
item->window.flags &= ~WINDOW_MOUSEOVERTEXT;
}
Item_RunScript(item, item->mouseExit);
item->window.flags &= ~(WINDOW_LB_RIGHTARROW | WINDOW_LB_LEFTARROW);
}
}
itemDef_t *Menu_HitTest(menuDef_t *menu, float x, float y) {
int i;
for (i = 0; i < menu->itemCount; i++) {
if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) {
return menu->items[i];
}
}
return NULL;
}
void Item_SetMouseOver(itemDef_t *item, qboolean focus) {
if (item) {
if (focus) {
item->window.flags |= WINDOW_MOUSEOVER;
} else {
item->window.flags &= ~WINDOW_MOUSEOVER;
}
}
}
qboolean Item_OwnerDraw_HandleKey(itemDef_t *item, int key) {
if (item && DC->ownerDrawHandleKey) {
return DC->ownerDrawHandleKey(item->window.ownerDraw, item->window.ownerDrawFlags, &item->special, key);
}
return qfalse;
}
qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolean force) {
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
int count = DC->feederCount(item->special);
int max, viewmax;
if (force || (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS)) {
max = Item_ListBox_MaxScroll(item);
if (item->window.flags & WINDOW_HORIZONTAL) {
viewmax = (item->window.rect.w / listPtr->elementWidth);
if ( key == K_LEFTARROW || key == K_KP_LEFTARROW )
{
if (!listPtr->notselectable) {
listPtr->cursorPos--;
if (listPtr->cursorPos < 0) {
listPtr->cursorPos = 0;
}
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos--;
if (listPtr->startPos < 0)
listPtr->startPos = 0;
}
return qtrue;
}
if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW )
{
if (!listPtr->notselectable) {
listPtr->cursorPos++;
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= count) {
listPtr->cursorPos = count-1;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos++;
if (listPtr->startPos >= count)
listPtr->startPos = count-1;
}
return qtrue;
}
}
else {
viewmax = (item->window.rect.h / listPtr->elementHeight);
if ( key == K_UPARROW || key == K_KP_UPARROW )
{
if (!listPtr->notselectable) {
listPtr->cursorPos--;
if (listPtr->cursorPos < 0) {
listPtr->cursorPos = 0;
}
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos--;
if (listPtr->startPos < 0)
listPtr->startPos = 0;
}
return qtrue;
}
if ( key == K_DOWNARROW || key == K_KP_DOWNARROW )
{
if (!listPtr->notselectable) {
listPtr->cursorPos++;
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= count) {
listPtr->cursorPos = count-1;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos++;
if (listPtr->startPos > max)
listPtr->startPos = max;
}
return qtrue;
}
}
// mouse hit
if (key == K_MOUSE1 || key == K_MOUSE2) {
if (item->window.flags & WINDOW_LB_LEFTARROW) {
listPtr->startPos--;
if (listPtr->startPos < 0) {
listPtr->startPos = 0;
}
} else if (item->window.flags & WINDOW_LB_RIGHTARROW) {
// one down
listPtr->startPos++;
if (listPtr->startPos > max) {
listPtr->startPos = max;
}
} else if (item->window.flags & WINDOW_LB_PGUP) {
// page up
listPtr->startPos -= viewmax;
if (listPtr->startPos < 0) {
listPtr->startPos = 0;
}
} else if (item->window.flags & WINDOW_LB_PGDN) {
// page down
listPtr->startPos += viewmax;
if (listPtr->startPos > max) {
listPtr->startPos = max;
}
} else if (item->window.flags & WINDOW_LB_THUMB) {
// Display_SetCaptureItem(item);
} else {
// select an item
if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick) {
Item_RunScript(item, listPtr->doubleClick);
}
lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY;
if (item->cursorPos != listPtr->cursorPos) {
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
}
return qtrue;
}
if ( key == K_HOME || key == K_KP_HOME) {
// home
listPtr->startPos = 0;
return qtrue;
}
if ( key == K_END || key == K_KP_END) {
// end
listPtr->startPos = max;
return qtrue;
}
if (key == K_PGUP || key == K_KP_PGUP ) {
// page up
if (!listPtr->notselectable) {
listPtr->cursorPos -= viewmax;
if (listPtr->cursorPos < 0) {
listPtr->cursorPos = 0;
}
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos -= viewmax;
if (listPtr->startPos < 0) {
listPtr->startPos = 0;
}
}
return qtrue;
}
if ( key == K_PGDN || key == K_KP_PGDN ) {
// page down
if (!listPtr->notselectable) {
listPtr->cursorPos += viewmax;
if (listPtr->cursorPos < listPtr->startPos) {
listPtr->startPos = listPtr->cursorPos;
}
if (listPtr->cursorPos >= count) {
listPtr->cursorPos = count-1;
}
if (listPtr->cursorPos >= listPtr->startPos + viewmax) {
listPtr->startPos = listPtr->cursorPos - viewmax + 1;
}
item->cursorPos = listPtr->cursorPos;
DC->feederSelection(item->special, item->cursorPos);
}
else {
listPtr->startPos += viewmax;
if (listPtr->startPos > max) {
listPtr->startPos = max;
}
}
return qtrue;
}
}
return qfalse;
}
qboolean Item_YesNo_HandleKey(itemDef_t *item, int key) {
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar) {
if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) {
DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar)));
return qtrue;
}
}
return qfalse;
}
int Item_Multi_CountSettings(itemDef_t *item) {
multiDef_t *multiPtr = (multiDef_t*)item->typeData;
if (multiPtr == NULL) {
return 0;
}
return multiPtr->count;
}
int Item_Multi_FindCvarByValue(itemDef_t *item) {
char buff[1024];
float value = 0;
int i;
multiDef_t *multiPtr = (multiDef_t*)item->typeData;
if (multiPtr) {
if (multiPtr->strDef) {
DC->getCVarString(item->cvar, buff, sizeof(buff));
} else {
value = DC->getCVarValue(item->cvar);
}
for (i = 0; i < multiPtr->count; i++) {
if (multiPtr->strDef) {
if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) {
return i;
}
} else {
if (multiPtr->cvarValue[i] == value) {
return i;
}
}
}
}
return 0;
}
const char *Item_Multi_Setting(itemDef_t *item) {
char buff[1024];
float value = 0;
int i;
multiDef_t *multiPtr = (multiDef_t*)item->typeData;
if (multiPtr) {
if (multiPtr->strDef) {
DC->getCVarString(item->cvar, buff, sizeof(buff));
} else {
value = DC->getCVarValue(item->cvar);
}
for (i = 0; i < multiPtr->count; i++) {
if (multiPtr->strDef) {
if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) {
return multiPtr->cvarList[i];
}
} else {
if (multiPtr->cvarValue[i] == value) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -