aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llundo.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/llundo.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/llundo.cpp180
1 files changed, 180 insertions, 0 deletions
diff --git a/linden/indra/llui/llundo.cpp b/linden/indra/llui/llundo.cpp
new file mode 100644
index 0000000..b662a1a
--- /dev/null
+++ b/linden/indra/llui/llundo.cpp
@@ -0,0 +1,180 @@
1/**
2 * @file llundo.cpp
3 * @brief LLUndo class
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28// Generic interface for undo/redo circular buffer
29
30#include "linden_common.h"
31
32#include "llundo.h"
33#include "llerror.h"
34
35
36// TODO:
37// implement doubly linked circular list for ring buffer
38// this will allow us to easily change the size of an undo buffer on the fly
39
40//-----------------------------------------------------------------------------
41// LLUndoBuffer()
42//-----------------------------------------------------------------------------
43LLUndoBuffer::LLUndoBuffer( LLUndoAction (*create_func()), S32 initial_count )
44{
45 mNextAction = 0;
46 mLastAction = 0;
47 mFirstAction = 0;
48 mOperationID = 0;
49
50 mNumActions = initial_count;
51
52 mActions = new LLUndoAction *[initial_count];
53
54 //initialize buffer with actions
55 for (S32 i = 0; i < initial_count; i++)
56 {
57 mActions[i] = create_func();
58 if (!mActions[i])
59 {
60 llerrs << "Unable to create action for undo buffer" << llendl;
61 }
62 }
63}
64
65//-----------------------------------------------------------------------------
66// ~LLUndoBuffer()
67//-----------------------------------------------------------------------------
68LLUndoBuffer::~LLUndoBuffer()
69{
70 for (S32 i = 0; i < mNumActions; i++)
71 {
72 delete mActions[i];
73 }
74
75 delete [] mActions;
76}
77
78//-----------------------------------------------------------------------------
79// getNextAction()
80//-----------------------------------------------------------------------------
81LLUndoAction *LLUndoBuffer::getNextAction(BOOL setClusterBegin)
82{
83 LLUndoAction *nextAction = mActions[mNextAction];
84
85 if (setClusterBegin)
86 {
87 mOperationID++;
88 }
89 mActions[mNextAction]->mClusterID = mOperationID;
90
91 mNextAction = (mNextAction + 1) % mNumActions;
92 mLastAction = mNextAction;
93
94 if (mNextAction == mFirstAction)
95 {
96 mActions[mFirstAction]->cleanup();
97 mFirstAction = (mFirstAction + 1) % mNumActions;
98 }
99
100 return nextAction;
101}
102
103//-----------------------------------------------------------------------------
104// undoAction()
105//-----------------------------------------------------------------------------
106BOOL LLUndoBuffer::undoAction()
107{
108 if (!canUndo())
109 {
110 return FALSE;
111 }
112
113 S32 prevAction = (mNextAction + mNumActions - 1) % mNumActions;
114
115 while(mActions[prevAction]->mClusterID == mOperationID)
116 {
117 // go ahead and decrement action index
118 mNextAction = prevAction;
119
120 // undo this action
121 mActions[mNextAction]->undo();
122
123 // we're at the first action, so we don't know if we've actually undid everything
124 if (mNextAction == mFirstAction)
125 {
126 mOperationID--;
127 return FALSE;
128 }
129
130 // do wrap-around of index, but avoid negative numbers for modulo operator
131 prevAction = (mNextAction + mNumActions - 1) % mNumActions;
132 }
133
134 mOperationID--;
135
136 return TRUE;
137}
138
139//-----------------------------------------------------------------------------
140// redoAction()
141//-----------------------------------------------------------------------------
142BOOL LLUndoBuffer::redoAction()
143{
144 if (!canRedo())
145 {
146 return FALSE;
147 }
148
149 mOperationID++;
150
151 while(mActions[mNextAction]->mClusterID == mOperationID)
152 {
153 if (mNextAction == mLastAction)
154 {
155 return FALSE;
156 }
157
158 mActions[mNextAction]->redo();
159
160 // do wrap-around of index
161 mNextAction = (mNextAction + 1) % mNumActions;
162 }
163
164 return TRUE;
165}
166
167//-----------------------------------------------------------------------------
168// flushActions()
169//-----------------------------------------------------------------------------
170void LLUndoBuffer::flushActions()
171{
172 for (S32 i = 0; i < mNumActions; i++)
173 {
174 mActions[i]->cleanup();
175 }
176 mNextAction = 0;
177 mLastAction = 0;
178 mFirstAction = 0;
179 mOperationID = 0;
180}