/** * @brief Update the scrollable view */ void uiMaterialEditorNode::updateView (uiNode_t* node, bool reset) { const int imageCount = UI_MaterialEditorNodeGetImageCount(node); const int imagesPerLine = (node->box.size[0] - node->padding) / (IMAGE_WIDTH + node->padding); const int imagesPerColumn = (node->box.size[1] - node->padding) / (IMAGE_WIDTH + node->padding); /* update view */ if (imagesPerLine > 0 && imagesPerColumn > 0) { const int pos = reset ? 0 : -1; setScrollY(node, pos, imagesPerColumn, imageCount / imagesPerLine); } else setScrollY(node, 0, 0, 0); }
void AdvScrollArea::ensureVisibleY(int y) { int ch = getScrollAreaHeight(); int cy = getScrollY(); scrollV->setValue(y); if (y < cy) {setScrollX(y - ch);} if (y > cy + ch) {setScrollY(y);} }
void LevelEditor::selectObjectAtIndex(int index) { previewScene_.selectObjectAtIndex(index); // if ((toolManager_.objectEditorSingleGroupIt()->xPos()) // > (scrollX_ + 50)) { setScrollX(toolManager_.objectEditorSingleGroupIt() ->xPos() - (300 / scale())); if (scrollX() < 0) { setScrollX(0); } setScrollY(toolManager_.objectEditorSingleGroupIt() ->yPos() - (300 / scale())); if (scrollY() < 0) { setScrollY(0); } // } }
bool LevelEditor::editAndAppendObject() { bool result = previewScene_.editAndAppendObject(); if (result) { setScrollX(toolManager_.objectEditorSingleGroupIt() ->xPos() - (300 / scale())); if (scrollX() < 0) { setScrollX(0); } setScrollY(toolManager_.objectEditorSingleGroupIt() ->yPos() - (300 / scale())); if (scrollY() < 0) { setScrollY(0); } } return result; }
void UISelector::updateScroll() { if(mSelectedIndex < 0) return; int scroll = mSelectedIndex - getMaxHeight() + 2; if (scroll < 0) scroll = 0; setScrollY(-scroll); }
/** * @brief Handles line breaks and drawing for shared data id * @param[in] node The context node * @param[in] text The test to draw else nullptr * @param[in] list The test to draw else nullptr * @param[in] noDraw If true, calling of this function only update the cache (real number of lines) * @note text or list but be used, not both */ void uiTextNode::drawText (uiNode_t* node, const char* text, const linkedList_t* list, bool noDraw) { static char textCopy[UI_TEXTNODE_BUFFERSIZE]; char newFont[MAX_VAR]; const char* oldFont = nullptr; vec4_t colorHover; vec4_t colorSelectedHover; char* cur, *tab, *end; int fullSizeY; const char* font = UI_GetFontFromNode(node); vec2_t pos; int x, y, width; int viewSizeY; UI_GetNodeAbsPos(node, pos); if (isSizeChange(node)) { int lineHeight = EXTRADATA(node).lineHeight; if (lineHeight == 0) { const char* font = UI_GetFontFromNode(node); lineHeight = UI_FontGetHeight(font); } viewSizeY = node->box.size[1] / lineHeight; } else { viewSizeY = EXTRADATA(node).super.scrollY.viewSize; } /* text box */ x = pos[0] + node->padding; y = pos[1] + node->padding; width = node->box.size[0] - node->padding - node->padding; if (text) { Q_strncpyz(textCopy, text, sizeof(textCopy)); } else if (list) { Q_strncpyz(textCopy, CL_Translate((const char*)list->data), sizeof(textCopy)); } else return; /**< Nothing to draw */ cur = textCopy; /* Hover darkening effect for normal text lines. */ VectorScale(node->color, 0.8, colorHover); colorHover[3] = node->color[3]; /* Hover darkening effect for selected text lines. */ VectorScale(node->selectedColor, 0.8, colorSelectedHover); colorSelectedHover[3] = node->selectedColor[3]; /* fix position of the start of the draw according to the align */ switch (node->contentAlign % 3) { case 0: /* left */ break; case 1: /* middle */ x += width / 2; break; case 2: /* right */ x += width; break; } R_Color(node->color); fullSizeY = 0; do { bool haveTab; int x1; /* variable x position */ /* new line starts from node x position */ x1 = x; if (oldFont) { font = oldFont; oldFont = nullptr; } /* text styles and inline images */ if (cur[0] == '^') { switch (toupper(cur[1])) { case 'B': Com_sprintf(newFont, sizeof(newFont), "%s_bold", font); oldFont = font; font = newFont; cur += 2; /* don't print the format string */ break; } } /* get the position of the next newline - otherwise end will be null */ end = strchr(cur, '\n'); if (end) /* set the \n to \0 to draw only this part (before the \n) with our font renderer */ /* let end point to the next char after the \n (or \0 now) */ *end++ = '\0'; /* highlighting */ if (fullSizeY == EXTRADATA(node).textLineSelected && EXTRADATA(node).textLineSelected >= 0) { /* Draw current line in "selected" color (if the linenumber is stored). */ R_Color(node->selectedColor); } else { R_Color(node->color); } if (node->state && EXTRADATA(node).mousefx && fullSizeY == EXTRADATA(node).lineUnderMouse) { /* Highlight line if mousefx is true. */ /** @todo what about multiline text that should be highlighted completely? */ if (fullSizeY == EXTRADATA(node).textLineSelected && EXTRADATA(node).textLineSelected >= 0) { R_Color(colorSelectedHover); } else { R_Color(colorHover); } } /* tabulation, we assume all the tabs fit on a single line */ haveTab = strchr(cur, '\t') != nullptr; if (haveTab) { while (cur && *cur) { int tabwidth; tab = strchr(cur, '\t'); /* use tab stop as given via property definition * or use 1/3 of the node size (width) */ if (!EXTRADATA(node).tabWidth) tabwidth = width / 3; else tabwidth = EXTRADATA(node).tabWidth; if (tab) { int numtabs = strspn(tab, "\t"); tabwidth *= numtabs; while (*tab == '\t') *tab++ = '\0'; } else { /* maximize width for the last element */ tabwidth = width - (x1 - x); if (tabwidth < 0) tabwidth = 0; } /* minimize width for element outside node */ if ((x1 - x) + tabwidth > width) tabwidth = width - (x1 - x); /* make sure it is positive */ if (tabwidth < 0) tabwidth = 0; if (tabwidth != 0) UI_DrawString(font, (align_t)node->contentAlign, x1, y, x1, tabwidth - 1, EXTRADATA(node).lineHeight, cur, viewSizeY, EXTRADATA(node).super.scrollY.viewPos, &fullSizeY, false, LONGLINES_PRETTYCHOP); /* next */ x1 += tabwidth; cur = tab; } fullSizeY++; } /*Com_Printf("until newline - lines: %i\n", lines);*/ /* the conditional expression at the end is a hack to draw "/n/n" as a blank line */ /* prevent line from being drawn if there is nothing that should be drawn after it */ if (cur && (cur[0] || end || list)) { /* is it a white line? */ if (!cur) { fullSizeY++; } else { if (noDraw) { int lines = 0; R_FontTextSize(font, cur, width, (longlines_t)EXTRADATA(node).longlines, nullptr, nullptr, &lines, nullptr); fullSizeY += lines; } else UI_DrawString(font, (align_t)node->contentAlign, x1, y, x, width, EXTRADATA(node).lineHeight, cur, viewSizeY, EXTRADATA(node).super.scrollY.viewPos, &fullSizeY, true, (longlines_t)EXTRADATA(node).longlines); } } if (EXTRADATA(node).mousefx) R_Color(node->color); /* restore original color */ /* now set cur to the next char after the \n (see above) */ cur = end; if (!cur && list) { list = list->next; if (list) { Q_strncpyz(textCopy, CL_Translate((const char*)list->data), sizeof(textCopy)); cur = textCopy; } } } while (cur); /* update scroll status */ setScrollY(node, -1, viewSizeY, fullSizeY); R_Color(nullptr); }
/** * @brief Scroll the Y scroll with a relative position, and call event if need * @return true, if something have change */ bool uiAbstractScrollableNode::scrollY (uiNode_t *node, int offset) { assert(UI_Node_IsScrollableContainer(node)); return setScrollY(node, EXTRADATA(node).scrollY.viewPos + offset, -1, -1); }