Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2004-08-31 17:43:18 +0400
committerTon Roosendaal <ton@blender.org>2004-08-31 17:43:18 +0400
commit0a305446a58c181d2e8f9c1d0af4c7d935117b4c (patch)
tree2a1de251e2360def5f7fef03458a1d08aa3d12c5 /source/blender/src/usiblender.c
parent19a24abcb2584c9c76c14ec32610df11a72bd0c3 (diff)
Three functionalities in one commit, but there's overlap so I can't
separate it... 1) Curve/Surface editmode undo Uses same syntax as mesh undo, so simple to integrate. Edit-curve data is also quite simpler, so no need for any hack at all. It re-uses the undo system from next point, which is nice short & clean local code 2) Framework for global undo The undo calls themselves are commented out. In a next commit I want to enable it for a couple of main features, for further feedback. The speed goes surprisingly well, especially with this new version that 'pushes' undo after a command, ensuring interactivity isnt frustrated 3) framework for texture based icons in Blender Not activated code, but tested here. Part of 2.3 UI project. btw: Johnny Matthews will assist in (and complete) the undo project
Diffstat (limited to 'source/blender/src/usiblender.c')
-rw-r--r--source/blender/src/usiblender.c126
1 files changed, 125 insertions, 1 deletions
diff --git a/source/blender/src/usiblender.c b/source/blender/src/usiblender.c
index 244dcc738fd..ff5b334e480 100644
--- a/source/blender/src/usiblender.c
+++ b/source/blender/src/usiblender.c
@@ -107,6 +107,7 @@
#include "BDR_drawobject.h"
#include "BDR_editobject.h"
+#include "BDR_editcurve.h"
#include "BDR_vpaint.h"
#include "BPY_extern.h"
@@ -126,7 +127,10 @@
void BIF_read_file(char *name)
{
extern short winqueue_break; /* editscreen.c */
+ void BIF_reset_undo(void);
+ void BIF_write_undo(char *);
+ BIF_reset_undo();
//here?
//sound_end_all_sounds();
@@ -145,6 +149,7 @@ void BIF_read_file(char *name)
winqueue_break= 1; /* leave queues everywhere */
+ BIF_write_undo("original"); /* save current state */
}
int BIF_read_homefile(void)
@@ -461,6 +466,123 @@ static void delete_autosave(void)
/***/
+#define MAXUNDONAME 64
+typedef struct UndoElem {
+ struct UndoElem *next, *prev;
+ char str[FILE_MAXDIR+FILE_MAXFILE];
+ char name[MAXUNDONAME];
+} UndoElem;
+
+#define MAXUNDO 32
+static ListBase undobase={NULL, NULL};
+static UndoElem *curundo= NULL;
+
+static void get_undosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE], int num)
+{
+ char numstr[32];
+
+ sprintf(numstr, "%d.blend", num);
+ BLI_make_file_string("/", buf, U.tempdir, numstr);
+
+}
+
+static int read_undosave(char *tstr)
+{
+ char scestr[FILE_MAXDIR+FILE_MAXFILE];
+ int success;
+
+ strcpy(scestr, G.sce); /* temporal store */
+
+ success= BKE_read_file(tstr, NULL);
+ strcpy(G.sce, scestr);
+
+ return success;
+}
+
+/* name can be a dynamic string */
+void BIF_write_undo(char *name)
+{
+ static int counter= 0;
+ int nr;
+ char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
+ UndoElem *uel;
+
+ /* calculate current filename */
+
+ counter++;
+ counter= counter % MAXUNDO;
+ get_undosave_location(tstr, counter);
+
+ if(BLO_write_file(tstr, G.fileflags, &err)) {
+
+ /* remove all undos after (also when curundo==NULL) */
+ while(undobase.last != curundo) {
+ uel= undobase.last;
+ BLI_remlink(&undobase, uel);
+ MEM_freeN(uel);
+ }
+
+ /* make new */
+ curundo= uel= MEM_mallocN(sizeof(UndoElem), "undo file");
+ strcpy(uel->str, tstr);
+ strncpy(uel->name, name, MAXUNDONAME-1);
+ BLI_addtail(&undobase, uel);
+
+ /* and limit amount to the maximum */
+ nr= 0;
+ uel= undobase.last;
+ while(uel) {
+ nr++;
+ if(nr==MAXUNDO) break;
+ uel= uel->prev;
+ }
+ if(uel) {
+ while(undobase.first!=uel) {
+ UndoElem *first= undobase.first;
+ BLI_remlink(&undobase, first);
+ MEM_freeN(first);
+ }
+ }
+ }
+
+}
+
+/* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
+void BIF_undo_step(int step)
+{
+
+ if(step==1) {
+ /* curundo should never be NULL, after restart or load file it should call undo_save */
+ if(curundo==NULL || curundo->prev==NULL) error("No undo available");
+ else {
+ printf("undo %s\n", curundo->name);
+ curundo= curundo->prev;
+ read_undosave(curundo->str);
+ }
+ }
+ else {
+
+ /* curundo has to remain current situation! */
+
+ if(curundo==NULL || curundo->next==NULL) error("No redo available");
+ else {
+ read_undosave(curundo->next->str);
+ curundo= curundo->next;
+ printf("redo %s\n", curundo->name);
+ }
+ }
+}
+
+void BIF_reset_undo(void)
+{
+
+ BLI_freelistN(&undobase);
+ curundo= NULL;
+}
+
+
+/***/
+
static void initbuttons(void)
{
uiDefFont(UI_HELVB,
@@ -576,7 +698,9 @@ void exit_usiblender(void)
#endif
if (G.undo_clear) G.undo_clear();
-
+ undo_clear_curve();
+ BIF_reset_undo();
+
BLI_freelistN(&U.themes);
if(totblock!=0) {