static void MissionDrawDoorEnabled( UIObject *o, GraphicsDevice *g, struct vec2i pos, void *data) { UNUSED(o); UNUSED(g); CampaignOptions *co = data; if (!CampaignGetCurrentMission(co)) return; DisplayFlag( svec2i_add(pos, o->Pos), "Doors", CampaignGetCurrentMission(co)->u.Cave.DoorsEnabled, UIObjectIsHighlighted(o)); }
static void MissionDrawRoomsOverlap( UIObject *o, GraphicsDevice *g, struct vec2i pos, void *data) { UNUSED(o); UNUSED(g); UNUSED(pos); CampaignOptions *co = data; if (!CampaignGetCurrentMission(co)) return; DisplayFlag( svec2i_add(pos, o->Pos), "Room overlap", CampaignGetCurrentMission(co)->u.Cave.Rooms.Overlap, UIObjectIsHighlighted(o)); }
bool UITryGetObject(UIObject *o, Vec2i pos, UIObject **out) { if (!o->IsVisible) { return false; } bool isHighlighted = UIObjectIsHighlighted(o); if (o->Type == UITYPE_TAB) { // only recurse to the chosen child if (o->Children.size > 0) { UIObject **objp = CArrayGet(&o->Children, o->u.Tab.Index); if ((!((*objp)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) && (*objp)->IsVisible && UITryGetObject(*objp, Vec2iMinus(pos, o->Pos), out)) { return true; } } } else { size_t i; UIObject **objs = o->Children.data; for (i = 0; i < o->Children.size; i++, objs++) { if ((!((*objs)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) && (*objs)->IsVisible && UITryGetObject(*objs, Vec2iMinus(pos, o->Pos), out)) { return true; } } } if (IsInside(pos, o->Pos, o->Size) && o->Type != UITYPE_CONTEXT_MENU) { *out = o; return true; } return false; }
static void UIObjectDrawAndAddChildren( UIObject *o, GraphicsDevice *g, Vec2i pos, Vec2i mouse, CArray *objs) { if (!o) { return; } if (o->CheckVisible) { o->CheckVisible(o, o->Data); } if (!o->IsVisible) { return; } int isHighlighted = UIObjectIsHighlighted(o); Vec2i oPos = Vec2iAdd(pos, o->Pos); switch (o->Type) { case UITYPE_LABEL: { const char *text = LabelGetText(o); if (!text) { break; } color_t textMask = isHighlighted ? colorRed : colorWhite; FontStrMaskWrap(text, oPos, textMask, o->Size.x); } break; case UITYPE_TEXTBOX: { int isText = !!o->u.Textbox.TextLinkFunc; const char *text = isText ? o->u.Textbox.TextLinkFunc(o, o->Data) : NULL; int isEmptyText = !isText || !text || strlen(text) == 0; color_t bracketMask = isHighlighted ? colorRed : colorWhite; color_t textMask = isEmptyText ? colorGray : colorWhite; int oPosX = oPos.x; if (isEmptyText) { text = o->u.Textbox.Hint; } if (!o->u.Textbox.IsEditable) { textMask = bracketMask; } if (o->u.Textbox.IsEditable) { oPos = FontChMask('>', oPos, bracketMask); } oPos = FontStrMaskWrap( text, oPos, textMask, o->Pos.x + o->Size.x - oPosX); if (o->u.Textbox.IsEditable) { oPos = FontChMask('<', oPos, bracketMask); } oPos.x = oPosX; } break; case UITYPE_TAB: if (o->Children.size > 0) { color_t textMask = isHighlighted ? colorRed : colorWhite; char **labelp = CArrayGet(&o->u.Tab.Labels, o->u.Tab.Index); UIObject **objp = CArrayGet(&o->Children, o->u.Tab.Index); FontStrMaskWrap( *labelp, Vec2iAdd(pos, o->Pos), textMask, o->Size.x); if (!((*objp)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawAndAddChildren(*objp, g, oPos, mouse, objs); } } break; case UITYPE_BUTTON: { int isDown = o->u.Button.IsDownFunc && o->u.Button.IsDownFunc(o->Data); BlitMasked( g, o->u.Button.Pic, oPos, isDown ? colorGray : colorWhite, 1); } break; case UITYPE_CONTEXT_MENU: { // Draw background DrawRectangle( g, Vec2iAdd(oPos, Vec2iScale(Vec2iUnit(), -TOOLTIP_PADDING)), Vec2iAdd(o->Size, Vec2iScale(Vec2iUnit(), 2 * TOOLTIP_PADDING)), menuBGColor, 0); // Find if mouse over any children, and draw highlight for (int i = 0; i < (int)o->Children.size; i++) { UIObject *child = *(UIObject **)CArrayGet(&o->Children, i); if (IsInside(mouse, Vec2iAdd(oPos, child->Pos), child->Size)) { DrawRectangle( g, Vec2iAdd(oPos, child->Pos), child->Size, hiliteColor, 0); } } } break; case UITYPE_CUSTOM: o->u.CustomDrawFunc(o, g, pos, o->Data); break; default: // do nothing break; } // add children // Note: tab type draws its own children (one) if (o->Type != UITYPE_TAB && objs != NULL) { size_t i; UIObject **childPtr = o->Children.data; for (i = 0; i < o->Children.size; i++, childPtr++) { if (!((*childPtr)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawContext c; c.obj = *childPtr; c.pos = oPos; CArrayPushBack(objs, &c); } } } }