float colour::getLumination(void) const { float pMax = ceguimax(ceguimax(d_red, d_green), d_blue); float pMin = ceguimin(ceguimin(d_red, d_green), d_blue); float pLum = (pMax + pMin) / 2; return pLum; }
//----------------------------------------------------------------------------// HSV_Colour ColourPickerConversions::toHSV(RGB_Colour colour) { float r = colour.r / 255.0f; float g = colour.g / 255.0f; float b = colour.b / 255.0f; bool maxCompRed = false; bool maxCompGreen = false; float max_comp = b; if(r > g && r > b) { maxCompRed = true; max_comp = r; } else if(g > b) { maxCompGreen = true; max_comp = g; } float min_comp = ceguimin(ceguimin(r, g), b); float h; float s; float v = max_comp; float diff = max_comp - min_comp; s = (max_comp == 0.0f ? 0.0f : diff / max_comp); if (max_comp == min_comp) { h = 0; // achromatic } else { if (maxCompRed) h = (g - b) / diff + (g < b ? 6.0f : 0.0f); if (maxCompGreen) h = (b - r) / diff + 2.0f; else h = (r - g) / diff + 4.0f; h /= 6.0f; } return HSV_Colour(h, s, v); }
/************************************************************************* Handler called whenever the mouse moves while dragging a segment *************************************************************************/ bool ListHeader::segmentDragHandler(const EventArgs&) { // what we do here is monitor the position and scroll if we can when mouse is outside area. // get mouse position as something local const Vector2f localMousePos(CoordConverter::screenToWindow(*this, getUnprojectedPosition(getGUIContext(). getMouseCursor().getPosition()))); // scroll left? if (localMousePos.d_x < 0.0f) { if (d_segmentOffset > 0.0f) { setSegmentOffset(ceguimax(0.0f, d_segmentOffset - ScrollSpeed)); } } // scroll right? else if (localMousePos.d_x >= d_pixelSize.d_width) { float maxOffset = ceguimax(0.0f, getTotalSegmentsPixelExtent() - d_pixelSize.d_width); // if we have not scrolled to the limit if (d_segmentOffset < maxOffset) { // scroll, but never beyond the limit setSegmentOffset(ceguimin(maxOffset, d_segmentOffset + ScrollSpeed)); } } return true; }
float colour::getSaturation(void) const { float pMax = ceguimax(ceguimax(d_red, d_green), d_blue); float pMin = ceguimin(ceguimin(d_red, d_green), d_blue); float pLum = (pMax + pMin) / 2; float pSat; if( pMax == pMin ) { pSat = 0; } else { if( pLum < 0.5 ) pSat = (pMax - pMin) / (pMax + pMin); else pSat = (pMax - pMin) / (2 - pMax - pMin); } return pSat; }
void Spinner::setCurrentValue(float value) { if (value != d_currentValue) { // limit input value to within valid range for spinner value = ceguimax(ceguimin(value, d_maxValue), d_minValue); d_currentValue = value; WindowEventArgs args(this); onValueChanged(args); } }
float colour::getHue(void) const { float pRed = d_red; float pGreen = d_green; float pBlue = d_blue; float pMax = ceguimax(ceguimax(d_red, d_green), d_blue); float pMin = ceguimin(ceguimin(d_red, d_green), d_blue); float pHue; if( pMax == pMin ) { pHue = 0; } else { if( pMax == pRed ) { pHue = (pGreen - pBlue) / (pMax - pMin); } else if( pMax == pGreen ) { pHue = 2 + (pBlue - pRed) / (pMax - pMin); } else { pHue = 4 + (pRed - pGreen) / (pMax - pMin); } } float Hue = pHue / 6; if( Hue < 0 ) Hue += 1; return Hue; }
void GuiChat::historiqueBas() { CEGUI::Editbox* editbox = static_cast<CEGUI::Editbox*>(chatWindow->getChild("Editbox")); d_historyPos = ceguimin(d_historyPos + 1, static_cast<int>(d_history.size())); if (d_historyPos < static_cast<int>(d_history.size())) { editbox->setText(d_history[d_historyPos]); editbox->setCaretIndex(static_cast<size_t>(-1)); } else { editbox->setText(""); } editbox->activate(); }
/************************************************************************* method to do work of constructor *************************************************************************/ void DirectX9Renderer::constructor_impl(LPDIRECT3DDEVICE9 device, const Size& display_size) { d_device = device; d_queueing = true; d_currTexture = 0; d_buffer = 0; d_bufferPos = 0; // initialise renderer display area d_display_area.d_left = 0; d_display_area.d_top = 0; d_display_area.setSize(display_size); // Create a vertex buffer if (FAILED(d_device->CreateVertexBuffer( (VERTEXBUFFER_CAPACITY * sizeof(QuadVertex)), D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, VERTEX_FVF, D3DPOOL_DEFAULT, &d_buffer, 0))) { // Ideally, this would have been a RendererException, but we can't use that until the System object is created // and that requires a Renderer passed to the constructor, so we throw this instead. throw std::exception("Creation of VertexBuffer for Renderer object failed"); } // get the maximum available texture size. D3DCAPS9 devCaps; if (FAILED(device->GetDeviceCaps(&devCaps))) { // release vertex buffer d_buffer->Release(); throw std::exception("Unable to retrieve device capabilities from Direct3DDevice9."); } // set max texture size the the smaller of max width and max height. d_maxTextureSize = ceguimin(devCaps.MaxTextureWidth, devCaps.MaxTextureHeight); d_device->AddRef(); // set ID string d_identifierString = "CEGUI::DirectX81Renderer - Official Direct3D 9 based renderer module for CEGUI"; }
//----------------------------------------------------------------------------// Direct3D9Renderer::Direct3D9Renderer(LPDIRECT3DDEVICE9 device) : d_device(device), d_displaySize(getViewportSize()), d_displayDPI(96, 96), d_defaultTarget(0) { D3DCAPS9 caps; device->GetDeviceCaps(&caps); if (!caps.RasterCaps && D3DPRASTERCAPS_SCISSORTEST) CEGUI_THROW(RendererException( "Hardware does not support D3DPRASTERCAPS_SCISSORTEST. " "Unable to proceed.")); d_maxTextureSize = ceguimin(caps.MaxTextureHeight, caps.MaxTextureWidth); d_supportNonSquareTex = !(caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY); d_supportNPOTTex = !(caps.TextureCaps & D3DPTEXTURECAPS_POW2) || (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL); d_defaultTarget = new Direct3D9ViewportTarget(*this); }
Rectf ImagerySection::getBoundingRect(const Window& wnd, const Rectf& rect) const { Rectf compRect; Rectf bounds(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::min(), std::numeric_limits<float>::min()); // measure all frame components for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame) { compRect = (*frame).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } // measure all imagery components for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image) { compRect = (*image).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } // measure all text components for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text) { compRect = (*text).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } return bounds; }
/************************************************************************* Render text lines. *************************************************************************/ void MultiLineEditbox::cacheTextLines(const Rect& dest_area) { // text is already formatted, we just grab the lines and render them with the required alignment. Rect drawArea(dest_area); drawArea.offset(Point(-d_horzScrollbar->getScrollPosition(), -d_vertScrollbar->getScrollPosition())); Renderer* renderer = System::getSingleton().getRenderer(); const Font* fnt = getFont(); if (fnt) { // get layers to use for rendering float textZ = renderer->getZLayer(4) - renderer->getCurrentZ(); float selZ = renderer->getZLayer(3) - renderer->getCurrentZ(); // calculate final colours to use. ColourRect colours; float alpha = getEffectiveAlpha(); colour normalTextCol = d_normalTextColour; normalTextCol.setAlpha(normalTextCol.getAlpha() * alpha); colour selectTextCol = d_selectTextColour; selectTextCol.setAlpha(selectTextCol.getAlpha() * alpha); colour selectBrushCol = hasInputFocus() ? d_selectBrushColour : d_inactiveSelectBrushColour; selectBrushCol.setAlpha(selectBrushCol.getAlpha() * alpha); // Cache font info const float fLineSpacing = fnt->getLineSpacing (); // for each formatted line. for (size_t i = 0; i < d_lines.size(); ++i) { Rect lineRect(drawArea); // Check line is within the dest_area if ( lineRect.d_top < dest_area.d_bottom && lineRect.d_top + fLineSpacing > dest_area.d_top ) { const LineInfo& currLine = d_lines[i]; String lineText(d_text.substr(currLine.d_startIdx, currLine.d_length)); // if it is a simple 'no selection area' case if ((currLine.d_startIdx >= d_selectionEnd) || ((currLine.d_startIdx + currLine.d_length) <= d_selectionStart) || (d_selectionBrush == NULL)) { colours.setColours(normalTextCol); // render the complete line. d_renderCache.cacheText(lineText, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); } // we have at least some selection highlighting to do else { // Start of actual rendering section. String sect; size_t sectIdx = 0, sectLen; float selStartOffset = 0.0f, selAreaWidth = 0.0f; // render any text prior to selected region of line. if (currLine.d_startIdx < d_selectionStart) { // calculate length of text section sectLen = d_selectionStart - currLine.d_startIdx; // get text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the pixel offset to the beginning of the selection area highlight. selStartOffset = fnt->getTextExtent(sect); // draw this portion of the text colours.setColours(normalTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); // set position ready for next portion of text lineRect.d_left += selStartOffset; } // calculate the length of the selected section sectLen = ceguimin(d_selectionEnd - currLine.d_startIdx, currLine.d_length) - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the extent to use as the width of the selection area highlight selAreaWidth = fnt->getTextExtent(sect); // draw the text for this section colours.setColours(selectTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); // render any text beyond selected region of line if (sectIdx < currLine.d_length) { // update render position to the end of the selected area. lineRect.d_left += selAreaWidth; // calculate length of this section sectLen = currLine.d_length - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); // render the text for this section. colours.setColours(normalTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); } // calculate area for the selection brush on this line lineRect.d_left = drawArea.d_left + selStartOffset; lineRect.d_right = lineRect.d_left + selAreaWidth; lineRect.d_bottom = lineRect.d_top + fLineSpacing; // render the selection area brush for this line colours.setColours(selectBrushCol); d_renderCache.cacheImage(*d_selectionBrush, lineRect, selZ, colours, &dest_area); } } // update master position for next line in paragraph. drawArea.d_top += fLineSpacing; } } }
void FalagardMultiLineEditbox::cacheTextLines(const Rectf& dest_area) { MultiLineEditbox* w = (MultiLineEditbox*)d_window; // text is already formatted, we just grab the lines and render them with the required alignment. Rectf drawArea(dest_area); float vertScrollPos = w->getVertScrollbar()->getScrollPosition(); drawArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -vertScrollPos)); const Font* fnt = w->getFont(); if (fnt) { // calculate final colours to use. ColourRect colours; const float alpha = w->getEffectiveAlpha(); ColourRect normalTextCol; setColourRectToUnselectedTextColour(normalTextCol); normalTextCol.modulateAlpha(alpha); ColourRect selectTextCol; setColourRectToSelectedTextColour(selectTextCol); selectTextCol.modulateAlpha(alpha); ColourRect selectBrushCol; w->hasInputFocus() ? setColourRectToActiveSelectionColour(selectBrushCol) : setColourRectToInactiveSelectionColour(selectBrushCol); selectBrushCol.modulateAlpha(alpha); const MultiLineEditbox::LineList& d_lines = w->getFormattedLines(); const size_t numLines = d_lines.size(); // calculate the range of visible lines size_t sidx,eidx; sidx = static_cast<size_t>(vertScrollPos / fnt->getLineSpacing()); eidx = 1 + sidx + static_cast<size_t>(dest_area.getHeight() / fnt->getLineSpacing()); eidx = ceguimin(eidx, numLines); drawArea.d_min.d_y += fnt->getLineSpacing()*static_cast<float>(sidx); // for each formatted line. for (size_t i = sidx; i < eidx; ++i) { Rectf lineRect(drawArea); const MultiLineEditbox::LineInfo& currLine = d_lines[i]; String lineText(w->getTextVisual().substr(currLine.d_startIdx, currLine.d_length)); // offset the font little down so that it's centered within its own spacing const float old_top = lineRect.top(); lineRect.d_min.d_y += (fnt->getLineSpacing() - fnt->getFontHeight()) * 0.5f; // if it is a simple 'no selection area' case if ((currLine.d_startIdx >= w->getSelectionEndIndex()) || ((currLine.d_startIdx + currLine.d_length) <= w->getSelectionStartIndex()) || (w->getSelectionBrushImage() == 0)) { colours = normalTextCol; // render the complete line. fnt->drawText(w->getGeometryBuffer(), lineText, lineRect.getPosition(), &dest_area, colours); } // we have at least some selection highlighting to do else { // Start of actual rendering section. String sect; size_t sectIdx = 0, sectLen; float selStartOffset = 0.0f, selAreaWidth = 0.0f; // render any text prior to selected region of line. if (currLine.d_startIdx < w->getSelectionStartIndex()) { // calculate length of text section sectLen = w->getSelectionStartIndex() - currLine.d_startIdx; // get text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the pixel offset to the beginning of the selection area highlight. selStartOffset = fnt->getTextAdvance(sect); // draw this portion of the text colours = normalTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); // set position ready for next portion of text lineRect.d_min.d_x += selStartOffset; } // calculate the length of the selected section sectLen = ceguimin(w->getSelectionEndIndex() - currLine.d_startIdx, currLine.d_length) - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the extent to use as the width of the selection area highlight selAreaWidth = fnt->getTextAdvance(sect); const float text_top = lineRect.top(); lineRect.top(old_top); // calculate area for the selection brush on this line lineRect.left(drawArea.left() + selStartOffset); lineRect.right(lineRect.left() + selAreaWidth); lineRect.bottom(lineRect.top() + fnt->getLineSpacing()); // render the selection area brush for this line colours = selectBrushCol; w->getSelectionBrushImage()->render(w->getGeometryBuffer(), lineRect, &dest_area, colours); // draw the text for this section colours = selectTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); lineRect.top(text_top); // render any text beyond selected region of line if (sectIdx < currLine.d_length) { // update render position to the end of the selected area. lineRect.d_min.d_x += selAreaWidth; // calculate length of this section sectLen = currLine.d_length - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); // render the text for this section. colours = normalTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); } } // update master position for next line in paragraph. drawArea.d_min.d_y += fnt->getLineSpacing(); } } }