Go Back   AC3D Forums > Technical > AC3D Developers
Register FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Display Modes
Old 24th June 2003, 08:58 AM   #1
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,565
Default Re: What are people developing with the SDK?

This sort of thing is easy enough in 3.6 but to make it undoable is a bit of a nightmare (or is quite inefficient).

For the next release (3.7), things are a lot better.

Here's the actual code that changes the surface shading (when 'Flat' or 'Smooth' is pressed).

Code:
class UndoableSurfacesSetShading : public Undoable
{
private:

	List *surfaces;
	List *oldshading;
	int newshading;

public:

	UndoableSurfacesSetShading(int col)
	{
	newshading = col;
	surfaces = ac_selection_get_whole_surfaces_all();
	oldshading = NULL;
	}

	void execute()
	{
	List *last = NULL;
	int numdone = 0;

	display_message("setting shading on surfaces...");

	// save the old colours in a list
	for (List *p = surfaces; p != NULL; p = p->next)
		{
		Surface *s = (Surface *)p->data;

		last = list_add_item_fast(&oldshading, last, (void *)surface_get_shading(s));

		surface_set_shading(s, newshading);
		numdone++;
		}

	redraw_all();
	display_message("new shading set on surfaces: %d", numdone);
	}

	
	void undo()
	{
	// restore the original types
	display_message("restoring surface shading");

	List *cl = oldshading;
	int numdone = 0;
	for (List *p = surfaces; p != NULL; p = p->next, cl = cl->next)
		{
		Surface *s = (Surface *)p->data;
		int oldshadingt = (int)cl->data;

		surface_set_shading(s, oldshadingt);
		numdone++;
		}

	redraw_all();

	display_message("shading set on surfaces: %d", numdone);
	}

	void redo()
	{
	for (List *p = surfaces; p != NULL; p = p->next)
		{
		Surface *s = (Surface *)p->data;

		surface_set_shading(s, newshading);
		}
	redraw_all();
	}

	~UndoableSurfacesSetShading()
	{
		list_free(&surfaces);
		list_free(&oldshading);
	}
};






Prototype void selected_set_surface_shading(int indexc)
{

	add_undoable("set surface shading", new UndoableSurfacesSetShading(indexc));
}
Andy is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 11:35 PM.


AC3D Forum
(C) Inivis Limited 2020