1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

V22 - New API for Text on Canvas

Discussion in 'Add-on Development' started by simonb65, Sep 19, 2020.

  1. simonb65

    simonb65 Alibre Super User

    @Max is there any documentation or reference available yet on this new feature in v22?
    NateLiqGrav likes this.
  2. NateLiqGrav

    NateLiqGrav Alibre Super User

    There seems to be a lot missing from add-on documentation. Digging into every example add-on yields more info but I feel like I'm looking thru a keyhole.
    simonb65 likes this.
  3. simonb65

    simonb65 Alibre Super User

    Totally agree. The 'limited' functionality examples and digging around in the Visual Stuido Object Browser trying to reverse engineer and figure out function syntax is a right pain. I've written an internal company helper add-on, but it's not been straight forward by any means!
  4. simonb65

    simonb65 Alibre Super User

    resolved, use the IADAddOnCanvasDisplay -> DrawScreenText function for HOOPS rendering ...

    Simple helper function (with fixed font, size and text colour) ...
    #define COLOR_ARGB(a,r,g,b)            (long)((a<<24) | (r<<16) | (g<<8) | b)
    void HOOPS_DrawText(IADAddOnCanvasDisplay* pCanvasDisplay, LPWSTR text, long x, long y)
        BSTR segmentName = SysAllocString(L"text segment");
        BSTR str = SysAllocString(text);
        BSTR fontName = SysAllocString(L"Consolas");
        LONG64 segment;
        pCanvasDisplay->AddSubSegment(NULL, segmentName, &segment);
        LONG64 result;
        pCanvasDisplay->DrawScreenText(segment, str, x, y, TextAlignment::TextAlignment_TopLeft, fontName, 12.0f, COLOR_ARGB(255, 0, 0, 0), VARIANT_TRUE, &result);
    Example usage ...
    HRESULT _stdcall CMyAddOnCommand::On3DRender(void)
        // With the Hoops based rendering engine (V2019 and later), the add-on need not redraw its graphics unless it invalidated it.
        // So, view manipulation operations like pan/rotate/zoom etc do not require a redraw by addon
        if (m_bIsOutOfDate)
            IUnknown* pUnkDisplayContext = NULL;
            IADAddOnCanvasDisplay* pCanvasDisplay = NULL;
            // Call Begin3DDisplay () and get a context to render my graphics primitives
            m_pCmdSite->Begin3DDisplay(m_bClearViewPort, &pUnkDisplayContext);
            // Draw some example text
            HOOPS_DrawText(pCanvasDisplay, L"X = 1.25", 10, 10);
            HOOPS_DrawText(pCanvasDisplay, L"Y = 0.00", 10, 30);
            HOOPS_DrawText(pCanvasDisplay, L"Z = 2.76", 10, 50);
            // End 3D Display.
            m_bIsOutOfDate = false;
        return S_OK;
    Not sure if the font is created and destroyed on every call of DrawScreenText(..) or if the graphics core caches it?? if it's the former then this call will produce a performance hit if called repeatably or with large amounts of text drawn in different positions!
    cadtec and NateLiqGrav like this.

Share This Page