/** * @param node The node to draw */ static void UI_MaterialEditorNodeDraw (uiNode_t *node) { int i; vec2_t pos; int cnt = 0; int cntView = 0; const int imagesPerLine = (node->size[0] - node->padding) / (IMAGE_WIDTH + node->padding); if (UI_AbstractScrollableNodeIsSizeChange(node)) UI_MaterialEditorNodeUpdateView(node, qfalse); /* width too small to display anything */ if (imagesPerLine <= 0) return; UI_GetNodeAbsPos(node, pos); /* display images */ for (i = 0; i < r_numImages; i++) { image_t *image = R_GetImageAtIndex(i); vec2_t imagepos; #ifndef ANYIMAGES /* filter */ if (image->type != it_world) continue; if (strstr(image->name, "tex_common")) continue; #endif /* skip images before the scroll position */ if (cnt / imagesPerLine < EXTRADATA(node).scrollY.viewPos) { cnt++; continue; } /** @todo do it incremental. Don't need all this math */ imagepos[0] = pos[0] + node->padding + (cntView % imagesPerLine) * (IMAGE_WIDTH + node->padding); imagepos[1] = pos[1] + node->padding + (cntView / imagesPerLine) * (IMAGE_WIDTH + node->padding); /* vertical overflow */ if (imagepos[1] + IMAGE_WIDTH + node->padding >= pos[1] + node->size[1]) break; if (i == node->num) { #define MARGIN 3 R_DrawRect(imagepos[0] - MARGIN, imagepos[1] - MARGIN, IMAGE_WIDTH + MARGIN * 2, IMAGE_WIDTH + MARGIN * 2, node->selectedColor, 2, 0xFFFF); #undef MARGIN } UI_DrawNormImage(qfalse, imagepos[0], imagepos[1], IMAGE_WIDTH, IMAGE_WIDTH, 0, 0, 0, 0, image); cnt++; cntView++; } }
static void UI_EditorNodeHighlightNode (uiNode_t *node, const vec4_t color, bool displayAnchor) { vec2_t pos; UI_GetNodeAbsPos(node, pos); R_DrawRect(pos[0] - 1, pos[1] - 1, node->box.size[0] + 2, node->box.size[1] + 2, color, 1.0, 0x3333); if (displayAnchor) { UI_DrawFill(pos[0] - anchorSize, pos[1] - anchorSize, anchorSize, anchorSize, color); UI_DrawFill(pos[0] - anchorSize, pos[1] + node->box.size[1], anchorSize, anchorSize, color); UI_DrawFill(pos[0] + node->box.size[0], pos[1] + node->box.size[1], anchorSize, anchorSize, color); UI_DrawFill(pos[0] + node->box.size[0], pos[1] - anchorSize, anchorSize, anchorSize, color); } }
/** * @brief Draws a base. */ static void UI_BaseMapNodeDraw (uiNode_t * node) { int width, height, row, col; const building_t *building; const base_t *base = B_GetCurrentSelectedBase(); qboolean used[MAX_BUILDINGS]; if (!base) { UI_PopWindow(qfalse); return; } /* reset the used flag */ OBJZERO(used); width = node->size[0] / BASE_SIZE; height = node->size[1] / BASE_SIZE + BASE_IMAGE_OVERLAY; for (row = 0; row < BASE_SIZE; row++) { const char *image = NULL; for (col = 0; col < BASE_SIZE; col++) { vec2_t pos; UI_GetNodeAbsPos(node, pos); pos[0] += col * width; pos[1] += row * (height - BASE_IMAGE_OVERLAY); /* base tile */ if (B_IsTileBlocked(base, col, row)) { building = NULL; image = "base/invalid"; } else if (B_GetBuildingAt(base, col, row) == NULL) { building = NULL; image = "base/grid"; } else { building = B_GetBuildingAt(base, col, row); assert(building); if (building->image) image = building->image; /* some buildings are drawn with two tiles - e.g. the hangar is no square map tile. * These buildings have the needs parameter set to the second building part which has * its own image set, too. We are searching for this second building part here. */ if (B_BuildingGetUsed(used, building->idx)) continue; B_BuildingSetUsed(used, building->idx); } /* draw tile */ if (image != NULL) UI_DrawNormImageByName(qfalse, pos[0], pos[1], width * (building ? building->size[0] : 1), height * (building ? building->size[1] : 1), 0, 0, 0, 0, image); if (building) { switch (building->buildingStatus) { case B_STATUS_DOWN: case B_STATUS_CONSTRUCTION_FINISHED: break; case B_STATUS_UNDER_CONSTRUCTION: { const float time = max(0.0, B_GetConstructionTimeRemain(building)); UI_DrawString("f_small", ALIGN_UL, pos[0] + 10, pos[1] + 10, pos[0] + 10, node->size[0], 0, va(ngettext("%3.1f day left", "%3.1f days left", time), time), 0, 0, NULL, qfalse, 0); break; } default: break; } } } } if (!node->state) return; UI_BaseMapGetCellAtPos(node, mousePosX, mousePosY, &col, &row); if (col == -1) return; /* if we are building */ if (ccs.baseAction == BA_NEWBUILDING) { int y, x; int xCoord, yCoord, widthRect, heigthRect; vec2_t pos; assert(base->buildingCurrent); for (y = row; y < row + base->buildingCurrent->size[1]; y++) { for (x = col; x < col + base->buildingCurrent->size[0]; x++) { if (!B_MapIsCellFree(base, x, y)) return; } } UI_GetNodeAbsPos(node, pos); xCoord = pos[0] + col * width; yCoord = pos[1] + row * (height - BASE_IMAGE_OVERLAY); widthRect = base->buildingCurrent->size[0] * width; heigthRect = base->buildingCurrent->size[1] * (height - BASE_IMAGE_OVERLAY); R_DrawRect(xCoord, yCoord, widthRect, heigthRect, white, 3, 1); } }
/** * @brief Renders text and images * @sa SEQ_InitStartup * @param[in] context Sequence context * @param[in] backgroundObjects if true, draw background objects, else display foreground objects */ static void SEQ_Render2D (sequenceContext_t* context, bool backgroundObjects) { int height = 0; /* add texts */ for (int i = 0; i < context->numObj2Ds; i++) { seq2D_t* s2d = &context->obj2Ds[i]; if (!s2d->inuse) continue; if (backgroundObjects != s2d->inBackground) continue; if (s2d->relativePos && height > 0) { s2d->pos[1] += height; s2d->relativePos = false; } /* advance in time */ for (int j = 0; j < 4; j++) { s2d->color[j] += cls.frametime * s2d->fade[j]; if (s2d->color[j] < 0.0) s2d->color[j] = 0.0; else if (s2d->color[j] > 1.0) s2d->color[j] = 1.0; } for (int j = 0; j < 2; j++) { s2d->pos[j] += cls.frametime * s2d->speed[j]; s2d->size[j] += cls.frametime * s2d->enlarge[j]; } /* outside the screen? */ /** @todo We need this check - but this does not work */ /*if (s2d->pos[1] >= VID_NORM_HEIGHT || s2d->pos[0] >= VID_NORM_WIDTH) continue;*/ /* render */ R_Color(s2d->color); /* image can be background */ if (s2d->image[0] != '\0') { const image_t* image = R_FindImage(s2d->image, it_pic); R_DrawImage(s2d->pos[0], s2d->pos[1], image); } /* bgcolor can be overlay */ if (s2d->bgcolor[3] > 0.0) R_DrawFill(s2d->pos[0], s2d->pos[1], s2d->size[0], s2d->size[1], s2d->bgcolor); /* border */ if (s2d->border > 0 && s2d->bordercolor[3] > 0.0) R_DrawRect(s2d->pos[0], s2d->pos[1], s2d->size[0], s2d->size[1], s2d->bordercolor, s2d->border, 0xFFFF); /* render */ R_Color(s2d->color); /* gettext placeholder */ if (s2d->text) { int maxWidth = (int) s2d->size[0]; if (maxWidth <= 0) maxWidth = VID_NORM_WIDTH; height += UI_DrawString(s2d->font, s2d->align, s2d->pos[0], s2d->pos[1], s2d->pos[0], maxWidth, -1 /** @todo use this for some nice line spacing */, CL_Translate(s2d->text)); } } R_Color(nullptr); }
void UI_DrawRect (int x, int y, int w, int h, const vec4_t color, float lineWidth, int pattern) { R_DrawRect(x, y, w, h, color, lineWidth, pattern); }