doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaterialDoc.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #pragma once
29 
30 #include "MaterialEditor.h"
31 #include "MaterialModifier.h"
32 #include "MaterialDef.h"
33 
37 typedef struct {
39  bool enabled;
40 } MEStage_t;
41 
45 typedef struct {
48 } MEMaterial_t;
49 
54 
55 public:
57  virtual ~SourceModifyOwner() {};
58 
59  virtual idStr GetSourceText() { return ""; };
60 };
61 
62 class MaterialDocManager;
63 
67 class MaterialDoc {
68 
69 public:
74 
75  bool modified;
77  bool deleted;
78 
81 
82 public:
83  MaterialDoc(void);
84  ~MaterialDoc(void);
85 
89  enum {
92  };
93 
94  //Initialization Methods
95  void SetRenderMaterial(idMaterial* material, bool parseMaterial = true, bool parseRenderMatierial = false);
96 
97  //Stage Info Methods
98  int GetStageCount();
99  int FindStage(int stageType, const char* name);
100  MEStage_t GetStage(int stage);
101  void EnableStage(int stage, bool enabled);
102  void EnableAllStages(bool enabled);
103  bool IsStageEnabled(int stage);
104 
105  //Get Attributes
106  const char* GetAttribute(int stage, const char* attribName, const char* defaultString = "");
107  int GetAttributeInt(int stage, const char* attribName, const char* defaultString = "0");
108  float GetAttributeFloat(int stage, const char* attribName, const char* defaultString = "0");
109  bool GetAttributeBool(int stage, const char* attribName, const char* defaultString = "0");
110 
111  //Set Attribute Methods
112  void SetAttribute(int stage, const char* attribName, const char* value, bool addUndo = true);
113  void SetAttributeInt(int stage, const char* attribName, int value, bool addUndo = true);
114  void SetAttributeFloat(int stage, const char* attribName, float value, bool addUndo = true);
115  void SetAttributeBool(int stage, const char* attribName, bool value, bool addUndo = true);
116  void SetMaterialName(const char* materialName, bool addUndo = true);
117  void SetData(int stage, idDict* data);
118 
119  //Source Editing Methods
120  void SourceModify(SourceModifyOwner* owner);
121  bool IsSourceModified();
122  void ApplySourceModify(idStr& text);
123  const char* GetEditSourceText();
124 
125  //Stage Modification Methods
126  void AddStage(int stageType, const char* stageName, bool addUndo = true);
127  void InsertStage(int stage, int stageType, const char* stageName, bool addUndo = true);
128  void RemoveStage(int stage, bool addUndo = true);
129  void ClearStages();
130  void MoveStage(int from, int to, bool addUndo = true);
131 
132  void ApplyMaterialChanges(bool force = false);
133  void Save();
134  void Delete();
135 
136 protected:
137 
138  //Internal Notifications
139  void OnMaterialChanged();
140 
141  //Load Material Methods
142  void ParseMaterialText(const char* source);
143  void ParseMaterial(idLexer* src);
144  void ParseStage(idLexer* src);
145  void AddSpecialMapStage(const char* stageName, const char* map);
146  bool ParseMaterialDef(idToken* token, idLexer* src, int type, idDict* dict);
147  void ClearEditMaterial();
148 
149  //Save/Apply Material Methods
150  const char* GenerateSourceText();
151  void ReplaceSourceText();
152  void WriteStage(int stage, idFile_Memory* file);
153  void WriteSpecialMapStage(int stage, idFile_Memory* file);
154  void WriteMaterialDef(int stage, idFile_Memory* file, int type, int indent);
155 };
156 
void EnableStage(int stage, bool enabled)
Specifies the enabled state of a single stage.
void ClearEditMaterial()
Cleans up the edit material by deleting the stage data structures.
GLsizei const GLfloat * value
Definition: glext.h:3614
void Delete()
Deletes the material.
void Save()
Saves the material.
int FindStage(int stageType, const char *name)
Returns the index of the stage with the specified type and name or -1 if the stage does not exist...
bool modified
Definition: MaterialDoc.h:75
idMaterial * renderMaterial
Definition: MaterialDoc.h:72
void WriteMaterialDef(int stage, idFile_Memory *file, int type, int indent)
Writes a set of material attributes to a file.
void SourceModify(SourceModifyOwner *owner)
Called when the editor modifies the source of the material.
bool ParseMaterialDef(idToken *token, idLexer *src, int type, idDict *dict)
Finds the appropriate material definition for the supplied token and initializes the internal diction...
void SetAttributeFloat(int stage, const char *attribName, float value, bool addUndo=true)
Sets an attribute float in the material or a stage.
void SetAttributeInt(int stage, const char *attribName, int value, bool addUndo=true)
Sets an attribute int in the material or a stage.
void OnMaterialChanged()
Sets the proper internal states and notifies the MaterialDocManager once a material has been changed...
void ReplaceSourceText()
Writes the internal dictionary data to the standard format and replaces the idMaterial source text wi...
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
Definition: Token.h:71
const char * GenerateSourceText()
Writes the internal dictionary data to the standard format.
GLuint src
Definition: glext.h:5390
bool applyWaiting
Definition: MaterialDoc.h:76
void MoveStage(int from, int to, bool addUndo=true)
Moves a stage from one location to another.
Dictionary representation of a material.
Definition: MaterialDoc.h:45
void ApplyMaterialChanges(bool force=false)
Applies any changes to the material.
SourceModifyOwner * sourceModifyOwner
Definition: MaterialDoc.h:80
bool deleted
Definition: MaterialDoc.h:77
void RemoveStage(int stage, bool addUndo=true)
Removes a stage from the material.
void WriteSpecialMapStage(int stage, idFile_Memory *file)
Writes a single special stage.
void ParseMaterial(idLexer *src)
Parses the source text from an idMaterial and initializes the editor dictionary representation of the...
void InsertStage(int stage, int stageType, const char *stageName, bool addUndo=true)
Inserts a new stage to the material at a specified location.
const char * GetEditSourceText()
Returns the appropriate source for the editing.
GLsizei GLsizei GLcharARB * source
Definition: glext.h:3633
void WriteStage(int stage, idFile_Memory *file)
Writes a single stage.
Definition: Lexer.h:137
void SetAttribute(int stage, const char *attribName, const char *value, bool addUndo=true)
Sets an attribute string in the material or a stage.
void AddSpecialMapStage(const char *stageName, const char *map)
Adds a special stage to the material.
Responsible for managing a single material that is being viewed and/or edited.
Definition: MaterialDoc.h:67
Definition: Dict.h:65
idStr name
Definition: MaterialDoc.h:71
void AddStage(int stageType, const char *stageName, bool addUndo=true)
Adds a stage to the material.
bool IsSourceModified()
Returns true if the source text of this material has been edited.
void SetMaterialName(const char *materialName, bool addUndo=true)
Sets the material name.
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
bool sourceModify
Definition: MaterialDoc.h:79
int GetStageCount()
Returns the number of stages in this material.
Definition: MaterialDoc.cpp:93
int GetAttributeInt(int stage, const char *attribName, const char *defaultString="0")
Returns an attribute int from the material or a stage.
void ParseStage(idLexer *src)
Parses a single stage from the source text from an idMaterial and initializes the editor dictionary r...
void SetAttributeBool(int stage, const char *attribName, bool value, bool addUndo=true)
Sets an attribute bool in the material or a stage.
const char * GetAttribute(int stage, const char *attribName, const char *defaultString="")
Returns an attribute string from the material or a stage.
MaterialDocManager * manager
Definition: MaterialDoc.h:70
void ParseMaterialText(const char *source)
Passes text to a render material for parsing.
void SetData(int stage, idDict *data)
Sets the entire dictionary for a material or stage.
idDict materialData
Definition: MaterialDoc.h:46
bool GetAttributeBool(int stage, const char *attribName, const char *defaultString="0")
Returns an attribute bool from the material or a stage.
void EnableAllStages(bool enabled)
Sets the enabled state of all stages.
const GLcharARB * name
Definition: glext.h:3629
Implemented by the edit window that is responsible for modifying the material source text...
Definition: MaterialDoc.h:53
idDict stageData
Definition: MaterialDoc.h:38
Definition: Str.h:116
~MaterialDoc(void)
Destructor for MaterialDoc.
Definition: MaterialDoc.cpp:46
virtual ~SourceModifyOwner()
Definition: MaterialDoc.h:57
Responsible for managing the materials that are being viewed and/or edited.
void SetRenderMaterial(idMaterial *material, bool parseMaterial=true, bool parseRenderMatierial=false)
Initializes the MaterialDoc instance with a specific idMaterial.
Definition: MaterialDoc.cpp:58
void ApplySourceModify(idStr &text)
Applies any source changes to the edit representation of the material.
float GetAttributeFloat(int stage, const char *attribName, const char *defaultString="0")
Returns an attribute float from the material or a stage.
MEMaterial_t editMaterial
Definition: MaterialDoc.h:73
MEStage_t GetStage(int stage)
Returns a copy of the specified stage.
virtual idStr GetSourceText()
Definition: MaterialDoc.h:59
bool IsStageEnabled(int stage)
Returns the enabled state of a stage.
Dictionary representation of a Material Stage.
Definition: MaterialDoc.h:37
void ClearStages()
Removes all stages from the material.
idList< MEStage_t * > stages
Definition: MaterialDoc.h:47
bool enabled
Definition: MaterialDoc.h:39
MaterialDoc(void)
Constructor for MaterialDoc.
Definition: MaterialDoc.cpp:37