Type ImageState Global ImageStateList:TList = CreateList() Field Alpha# Field Blend Field ClsColor_R, ClsColor_G, ClsColor_B Field Color_R, Color_G, Color_B Field Handle_X#, Handle_Y# Field ImageFont:TImageFont Field LineWidth# Field MaskColor_R, MaskColor_G, MaskColor_B Field Origin_X#, Origin_Y# Field Rotation# Field Scale_X#, Scale_Y# Field Viewport_X, Viewport_Y, Viewport_Width, Viewport_Height ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' These methods allow you to save and restore the current image settings ' ' Each time you call the save method, the current state is placed on the stack. ' Each time you call the restore method, the last state placed on the stack is restored and removed from the stack. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Function Save() Local IS:ImageState = New ImageState IS.Alpha# = GetAlpha#() IS.Blend = GetBlend() GetClsColor(IS.ClsColor_R, IS.ClsColor_G, IS.ClsColor_B) GetColor(IS.Color_R, IS.Color_G, IS.Color_B) GetHandle(IS.Handle_X#, IS.Handle_Y#) IS.ImageFont = GetImageFont() IS.LineWidth# = GetLineWidth#() GetMaskColor(IS.MaskColor_R, IS.MaskColor_G, IS.MaskColor_B) GetOrigin(IS.Origin_X#, IS.Origin_Y#) IS.Rotation# = GetRotation#() GetScale(IS.Scale_X#, IS.Scale_Y#) GetViewport(IS.Viewport_X, IS.Viewport_Y, IS.Viewport_Width, IS.Viewport_Height) ImageStateList.AddLast(IS) End Function Function Restore() Local IS:ImageState = ImageState(ImageStateList.RemoveLast()) SetAlpha(IS.Alpha#) SetBlend(IS.Blend) SetClsColor(IS.ClsColor_R, IS.ClsColor_G, IS.ClsColor_B) SetColor(IS.Color_R, IS.Color_G, IS.Color_B) SetHandle(IS.Handle_X#, IS.Handle_Y#) SetImageFont(IS.ImageFont) SetLineWidth(IS.LineWidth#) SetMaskColor(IS.MaskColor_R, IS.MaskColor_G, IS.MaskColor_B) SetOrigin(IS.Origin_X#, IS.Origin_Y#) SetRotation(IS.Rotation#) SetScale(IS.Scale_X#, IS.Scale_Y#) SetViewport(IS.Viewport_X, IS.Viewport_Y, IS.Viewport_Width, IS.Viewport_Height) End Function End Type Graphics(640, 480) ImageState.Save() ImageState.Restore() ImageState.Save() ImageState.Save() ImageState.Restore() ImageState.Restore() ' ImageState.Restore() DrawText("Ok!", 16, 16) Flip WaitKey()
I don't know why Max doesn't have a set of commands like this, since they're really useful to have!
These functions save and restore the current image settings, and it does so in a robust manner which makes use of a stack so you can save the settings at the start of your function, call another function inside your function which also saves the settings and restores them, and then restore them when your function is done playing with them.
They'll be used in the sprite system to ensure the system doesn't end up changing your text to black, or multiply blend or something.
Just one small portion of my new object oriented sprite/sprite animation system for BlitzMax. (which is nearly complete) Use this however you like. :-)
(Now I wait for someone to tell me that all I had to do was save some type somewhere in Max and restore it instead of typing all that crap!)