HTML Canvas for MORFIK
Browser Support:
Internet Explorer 9+, Firefox, Opera, Chrome, and Safari
Save Method
Class THtml5Canvas2D
procedure Save;
The Save method pushes the current canvas state of transformations, clipping regions, and properties into a stack. Use the Restore method to pop the saved state out of the stack in reverse order in wich they were pushed in. Save will store the state of Scale, Rotate, Translate, Transform, SetTransform, Clip, and the following properties: FillStyle, StrokeStyle, ShadowColor, ShadowBlur, ShadowOffsetX, ShadowOffsetY, CreateLinearGradient, CreateRadialGradient, CreatePattern, LineCap, LineJoin, LineWidth, MiterLimit, Font, TextAlign, TextBaseline, GlobalAlpha, and GlobalCompositeOperation.
Example:
Draw 4 rectangles on a canvas (150px * 90px). Use Save and Restore methods to control the canvas state:
// fill a black rect Canvas.FillRect(0,0,100,50); // set global alpha and save state Canvas.FillStyle := clBlue; Canvas.Save; // set fillstyle red, set global alpha // and save state Canvas.FillStyle := clRed; Canvas.GlobalAlpha := 0.4; Canvas.Save; // rotate canvas 45 degress, // disable global alpha Canvas.Rotate(45*Math.PI/180); Canvas.GlobalAlpha := 1; Canvas.FillStyle := clGreen; Canvas.FillRect(0,0,100,36); // restore state with fillstyle red, // global alpha 0.4 Canvas.Restore; Canvas.FillRect(20,20,100,50); // restore state with fillstyle blue Canvas.Restore; Canvas.FillRect(40,40,100,50);
|