1 /*
2 PLIB - A Suite of Portable Game Libraries
3 Copyright (C) 1998,2002 Steve Baker
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 For further information visit http://plib.sourceforge.net
20
21 $Id: ssgState.cxx 1810 2003-11-20 14:01:05Z stromberg $
22 */
23
24
25 #include "ssgLocal.h"
26
27 static ssgStateCallback _ssgPendingPostDrawCB = NULL ;
28 static ssgState *_ssgPreviousState = NULL ;
29
preApply()30 void ssgState::preApply ()
31 {
32 if ( _ssgPendingPostDrawCB )
33 (*_ssgPendingPostDrawCB)(_ssgPreviousState) ;
34
35 if ( preApplyCB ) (*preApplyCB)(this) ;
36 }
37
38
preDraw()39 void ssgState::preDraw ()
40 {
41 if ( preDrawCB )
42 {
43 (*preDrawCB)(this) ;
44 _ssgPendingPostDrawCB = postDrawCB ;
45 _ssgPreviousState = this ;
46 }
47 }
48
_ssgStartOfFrameInit()49 void _ssgStartOfFrameInit ()
50 {
51 _ssgPendingPostDrawCB = NULL ;
52 _ssgPreviousState = NULL ;
53 }
54
_ssgEndOfFrameCleanup()55 void _ssgEndOfFrameCleanup ()
56 {
57 if ( _ssgPendingPostDrawCB ) (*_ssgPendingPostDrawCB)(_ssgPreviousState) ;
58
59 _ssgPendingPostDrawCB = NULL ;
60 _ssgPreviousState = NULL ;
61 }
62
copy_from(ssgState * src,int clone_flags)63 void ssgState::copy_from ( ssgState *src, int clone_flags )
64 {
65 ssgBase::copy_from ( src, clone_flags ) ;
66 setExternalPropertyIndex ( src -> getExternalPropertyIndex () ) ;
67
68 if ( src -> isTranslucent () )
69 setTranslucent () ;
70 else
71 setOpaque () ;
72
73 setStateCallback( SSG_CALLBACK_PREDRAW, src->getStateCallback( SSG_CALLBACK_PREDRAW ) );
74 setStateCallback( SSG_CALLBACK_POSTDRAW, src->getStateCallback( SSG_CALLBACK_POSTDRAW ) );
75 setStateCallback( SSG_CALLBACK_PREAPPLY, src->getStateCallback( SSG_CALLBACK_PREAPPLY ) );
76 }
77
78
79
ssgState(void)80 ssgState::ssgState (void)
81 {
82 type = ssgTypeState () ;
83
84 preApplyCB = NULL ;
85 preDrawCB = NULL ;
86 postDrawCB = NULL ;
87
88 setOpaque () ;
89 setExternalPropertyIndex ( 0 ) ;
90 }
91
~ssgState(void)92 ssgState::~ssgState (void)
93 {
94 if ( _ssgPreviousState == this )
95 {
96 _ssgPendingPostDrawCB = NULL ;
97 _ssgPreviousState = NULL ;
98 }
99 }
100
101
print(FILE * fd,char * indent,int how_much)102 void ssgState::print ( FILE *fd, char *indent, int how_much )
103 {
104 ssgBase::print ( fd, indent, how_much ) ;
105
106 if ( how_much < 2 )
107 return;
108
109 fprintf ( fd, "%s Translucent = %s\n", indent, translucent?"True":"False");
110 fprintf ( fd, "%s ExternalProp = %d\n", indent, external_property_index ) ;
111 }
112
113
load(FILE * fd)114 int ssgState::load ( FILE *fd )
115 {
116 _ssgReadInt ( fd, & translucent ) ;
117 _ssgReadInt ( fd, & external_property_index ) ;
118
119 preApplyCB = NULL ;
120 preDrawCB = NULL ;
121 postDrawCB = NULL ;
122
123 return ssgBase::load ( fd ) ;
124 }
125
126
save(FILE * fd)127 int ssgState::save ( FILE *fd )
128 {
129 _ssgWriteInt ( fd, translucent ) ;
130 _ssgWriteInt ( fd, external_property_index ) ;
131 return ssgBase::save ( fd ) ;
132 }
133
134
135
136
137