Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


Hint:  You can achieve similar results with commands like ZOOM or PAN.

DWG Viewer - Change layout background color

Status
titleOBJ-C
Status
colourYellow
titleC++

The DWG Viewer uses a native method -(void)SetBackgroundColor:(Colors) color to change the background color of the active model or sheet.  The offered color indexes are linked to a button. The native method is called when the button is tapped.  The native method -(void)SetBackgroundColor:(Colors) color manipulates the C++ part of the application.

File: CFxNativeConnection.mm

Code Block
-(void)SetBackgroundColor:(Colors)color
{
    ODCOLORREF background = 0;
    switch ( color )
    {
        case BLACK:
            background = 0;
            break;
        case WHITE:
            background = ODRGB( 255, 255, 255 );
            break;
        case MAGENTA:
            background = ODRGB( 255, 0, 255 );
            break;
    }

    OdEditorImplPtr pEditor = odedEditor();
    pEditor->fire_modelessOperationWillStart( L"BACKGROUND_COLOR" );
    ACTIVE_DOCUMENT()->GetFxDisplayDevice()->SetBackground( background );
    CFxDisplayDevicePtr pDevice = ACTIVE_DOCUMENT()->GetFxDisplayDevice();
    for ( int i = 0; i < pDevice->numViews(); i++ )
    {
        OdGsView *pView = pDevice->viewAt(i );
        if ( pView->isVisible() )
            pView->invalidate();
    }
    pEditor->fire_modelessOperationEnded( L"BACKGROUND_COLOR" );
}

 

File: ViewController.m

Code Block
- (IBAction)onBlackBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:BLACK];
}

- (IBAction)onWhiteBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:WHITE];
}

- (IBAction)onMagentaBackgroundPressed:(id)sender
{
    [[CFxNativeConnection GetNativeConnection] SetBackgroundColor:MAGENTA];
}