Diagram / Diagram DOM / Drawings / Themes / Theme Based Shapes
Theme Based Shapes

NOV Diagram makes it easy to use theme-based colors for the fill and stroke of shapes. Thus when the user changes the drawing theme of the page, the appearance of the custom shapes will change, too. This is very useful when creating custom shapes in a drawing or in a library.

 Theme Based Shapes in a Drawing

To create a shape whose appearance depends on the currently selected page drawing theme, assign a theme based color to the Tag property of the colors you use for the shape geometry's fill and/or stroke style. NOV Diagram supports the following theme based colors:

  • Theme variant color info (NThemeVariantColorInfo) - represents a theme variant color. Pass a value from 0 to 6 to the constructor of the class to select one of the 7 variant colors of the drawing theme. The variant colors are usually shown on the second or third row of colors in the shape style matrix of the currently selected theme:
  • Theme palette color info (NThemePaletteColorInfo) - represents a theme palette color. Pass an ENThemeColorName enum value and a brightness modifier to the constructor. Must be between -1 and 1. Negative values produce darker colors. 0 means unmodified color.

The following code example demonstrates how to create a shape filled with a hatch that depends on the currently selected page theme:

Create a theme based shape
Copy Code
// Create a rectangle shape
NShape shape = new NShape();
shape.Text = "Shape";
shape.Geometry.AddRelative(new NDrawRectangle(0, 0, 1, 1));
shape.SetBounds(100, 100, 200, 150);

// Make color1 a theme variant color
NDrawingTheme theme = NDrawingTheme.MyDrawNature;
NColor color1 = theme.ColorPalette.Variants[0][0];
color1.Tag = new NThemeVariantColorInfo(0);

// Make color2 a theme palette color
NColor color2 = theme.ColorPalette.Light1;
color2.Tag = new NThemePaletteColorInfo(ENThemeColorName.Light1, 0);

// Set the fill of the geometry to a hatch that depends on the theme
shape.Geometry.Fill = new NHatchFill(ENHatchStyle.DiagonalCross, color1, color2);

// Add the theme based shape to the active page of the drawing
NPage activePage = drawingView.ActivePage;
activePage.Items.Add(shape);
 Theme Based Shapes in a Library

To place a theme based shape in a library use the "Create theme based shape code" above to create a theme based shape, then create a library item with that shape and add it to the library.

We should also set the DrawingView property of the library view (NLibraryView) to a drawing view in order to update the styles of the shapes in the library when the drawing theme of drawing view's active page is changed.

Add a theme based shape to a library
Copy Code
// 1. Create a theme based shape
NShape shape = new NShape();
shape.Text = "Shape";
shape.Geometry.AddRelative(new NDrawRectangle(0, 0, 1, 1));
shape.SetBounds(0, 0, 200, 150);

// Make color1 a theme variant color
NDrawingTheme theme = NDrawingTheme.MyDrawNature;
NColor color1 = theme.ColorPalette.Variants[0][0];
color1.Tag = new NThemeVariantColorInfo(0);

// Make color2 a theme palette color
NColor color2 = theme.ColorPalette.Light1;
color2.Tag = new NThemePaletteColorInfo(ENThemeColorName.Light1, 0);

// Set the fill of the geometry to a hatch that depends on the theme
shape.Geometry.Fill = new NHatchFill(ENHatchStyle.DiagonalCross, color1, color2);

// 2. Create a library view and associate it with a drawing view
NLibraryView libraryView = new NLibraryView();
libraryView.DrawingView = drawingView;

// 3. Add the shape to the library
NLibrary library = libraryView.Library;
library.Items.Add(new NLibraryItem(themeShape, "Theme Based Shape", "Shape filled with a theme dependent hatch"));