================= Item_SetFocus ================= */ will optionaly set focus to this item
| 9168 | */ |
| 9169 | // will optionaly set focus to this item |
| 9170 | qboolean Item_SetFocus(itemDef_t *item, float x, float y) |
| 9171 | { |
| 9172 | int i; |
| 9173 | itemDef_t *oldFocus; |
| 9174 | sfxHandle_t *sfx = &DC->Assets.itemFocusSound; |
| 9175 | qboolean playSound = qfalse; |
| 9176 | // sanity check, non-null, not a decoration and does not already have the focus |
| 9177 | if (item == NULL || item->window.flags & WINDOW_DECORATION || item->window.flags & WINDOW_HASFOCUS || !(item->window.flags & WINDOW_VISIBLE) || (item->window.flags & WINDOW_INACTIVE)) |
| 9178 | { |
| 9179 | return qfalse; |
| 9180 | } |
| 9181 | menuDef_t *parent = (menuDef_t*)item->parent; |
| 9182 | |
| 9183 | // items can be enabled and disabled |
| 9184 | if (item->disabled) |
| 9185 | { |
| 9186 | return qfalse; |
| 9187 | } |
| 9188 | |
| 9189 | // items can be enabled and disabled based on cvars |
| 9190 | if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) |
| 9191 | { |
| 9192 | return qfalse; |
| 9193 | } |
| 9194 | |
| 9195 | if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) |
| 9196 | { |
| 9197 | return qfalse; |
| 9198 | } |
| 9199 | |
| 9200 | oldFocus = Menu_ClearFocus((menuDef_t *) item->parent); |
| 9201 | |
| 9202 | if (item->type == ITEM_TYPE_TEXT) |
| 9203 | { |
| 9204 | rectDef_t r; |
| 9205 | r = item->textRect; |
| 9206 | //r.y -= r.h; |
| 9207 | //JLFMOUSE |
| 9208 | if (Rect_ContainsPoint(&r, x, y)) |
| 9209 | { |
| 9210 | item->window.flags |= WINDOW_HASFOCUS; |
| 9211 | if (item->focusSound) |
| 9212 | { |
| 9213 | sfx = &item->focusSound; |
| 9214 | } |
| 9215 | playSound = qtrue; |
| 9216 | } |
| 9217 | else |
| 9218 | |
| 9219 | { |
| 9220 | if (oldFocus) |
| 9221 | { |
| 9222 | oldFocus->window.flags |= WINDOW_HASFOCUS; |
| 9223 | if (oldFocus->onFocus) |
| 9224 | { |
| 9225 | Item_RunScript(oldFocus, oldFocus->onFocus); |
| 9226 | } |
| 9227 | } |
no test coverage detected