Skip to content

Commit

Permalink
Merge pull request #2 from prujohn/master
Browse files Browse the repository at this point in the history
More enhancements/fix to the UI structure.  Custom icons for the asset tree.
  • Loading branch information
donny-dont committed Oct 5, 2012
2 parents 58b6d11 + b747750 commit 1623be1
Show file tree
Hide file tree
Showing 30 changed files with 222 additions and 111 deletions.
47 changes: 32 additions & 15 deletions web/controls/vector3_input.dart
Expand Up @@ -31,42 +31,59 @@ class Vector3Input extends Control
void _initVector3InputProperties()
{
xProperty = new FrameworkProperty(this, 'x',
propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
yProperty = new FrameworkProperty(this, 'y',
propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
zProperty = new FrameworkProperty(this, 'z',
propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
}

void onFirstLoad(){
// Get references to our textboxes and then set the bindings.
final tbX = Template.findByName('__vector3x__', template) as TextBox;
final tbY = Template.findByName('__vector3y__', template) as TextBox;
final tbZ = Template.findByName('__vector3z__', template) as TextBox;

xProperty.propertyChanging + _valueChanged;
yProperty.propertyChanging + _valueChanged;
zProperty.propertyChanging + _valueChanged;
bind(tbX.textProperty, xProperty, bindingMode:BindingMode.TwoWay);
bind(tbY.textProperty, yProperty, bindingMode:BindingMode.TwoWay);
bind(tbZ.textProperty, zProperty, bindingMode:BindingMode.TwoWay);
}

num get x => _validNum(getValue(xProperty));
num get x => validNum(getValue(xProperty));
set x(num value) => setValue(xProperty, '$value');

num get y => _validNum(getValue(yProperty));
num get y => validNum(getValue(yProperty));
set y(num value) => setValue(yProperty, '$value');

num get z => _validNum(getValue(zProperty));
num get z => validNum(getValue(zProperty));
set z(num value) => setValue(zProperty, '$value');

num _validNum(String value){
/**
* From a String [value], returns a valid num. If the string is not
* valid, then the return is 0.
*/
static num validNum(String value){
if (value == null) return 0;
if (value.isEmpty()) return 0;

num numValue;

try{
return parseDouble(value);
numValue = parseDouble(value);
}
on FormatException catch(e){
return 0;
numValue = 0;
}
}

void _valueChanged(sender, args){
changed.invokeAsync(this, new VectorChangedEventArgs(x,y,z));
return numValue;
}

void _onValueChanged() =>
changed.invokeAsync(this, new VectorChangedEventArgs(x,y,z));

String get defaultControlTemplate {
return
'''
Expand All @@ -75,11 +92,11 @@ class Vector3Input extends Control
<stack>
<stack orientation='horizontal'>
<textblock text='X:' />
<textbox width='50' text='{template x, mode=TwoWay}' />
<textbox name='__vector3x__' width='50' />
<textblock text='Y:' />
<textbox width='50' text='{template y, mode=TwoWay}' />
<textbox name='__vector3y__' width='50' />
<textblock text='Z:' />
<textbox width='50' text='{template z, mode=TwoWay}' />
<textbox name='__vector3z__' width='50' />
</stack>
</stack>
</template>
Expand Down
4 changes: 3 additions & 1 deletion web/editor.dart
Expand Up @@ -62,7 +62,6 @@
#source('views/properties/plane_properties.dart');

#source('viewmodels/editor_view_model.dart');
#source('viewmodels/generated_mesh_view_model.dart');
#source('viewmodels/entity_view_model.dart');
#source('viewmodels/properties/transform_properties_view_model.dart');
#source('viewmodels/properties/sphere_properties_view_model.dart');
Expand All @@ -71,6 +70,9 @@
#source('viewmodels/properties/entity_properties_view_model.dart');
#source('viewmodels/properties/properties_view_model_base.dart');
#source('viewmodels/properties/empty_properties_view_model.dart');
#source('viewmodels/box_entity_view_model.dart');
#source('viewmodels/sphere_entity_view_model.dart');
#source('viewmodels/plane_entity_view_model.dart');


void main()
Expand Down
Binary file added web/resources/cube.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/resources/sphere.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions web/viewmodels/box_entity_view_model.dart
@@ -0,0 +1,14 @@

class BoxEntityViewModel extends EntityViewModel
{
BoxEntityViewModel() :
super(new BoxVisualModel(), new BoxPropertiesViewModel()){
entityName = 'Box';
}

Future<String> get fileTemplate =>
Template.getTemplate('web/views/templates/box_icon.xml');

Future<String> get folderTemplate =>
Template.getTemplate('web/views/templates/box_icon.xml');
}
86 changes: 53 additions & 33 deletions web/viewmodels/editor_view_model.dart
Expand Up @@ -27,6 +27,7 @@ class EditorViewModel extends ViewModelBase
// Model events
registerEventHandler('add_box_clicked', _addBoxHandler);
registerEventHandler('add_sphere_clicked', _addSphereHandler);
registerEventHandler('add_plane_clicked', _addPlaneHandler);

// Canvas events
registerEventHandler('canvas_loaded', _canvasLoadedHandler);
Expand Down Expand Up @@ -110,35 +111,52 @@ class EditorViewModel extends ViewModelBase

void _addBoxHandler(_, __)
{
final boxVM =
new EntityViewModel(new BoxVisualModel(), new BoxPropertiesViewModel())
..entityName ='Box';
addEntity(new BoxEntityViewModel());
}

void _addSphereHandler(_, __)
{
addEntity(new SphereEntityViewModel());
}

void _addPlaneHandler(_, __){
addEntity(new PlaneEntityViewModel());
}

/** Adds an [entityVM] to the application and updates the UI. */
void addEntity(EntityViewModel entityVM){
// something should always be selected (_scene is default)
assert(_currentNode != null);

// Using the tag property to hold a reference to the entity view model
// object.
final node = new TreeNode()
..header = boxVM.entityName
..tag = boxVM;

if (_currentNode != _scene){
// setup the relationships
boxVM.parent = _currentNode.tag;
_currentNode.tag.children.add(boxVM);
}
Futures
.wait([entityVM.fileTemplate, entityVM.folderTemplate])
.chain((result){
return Futures.wait(result.map((r) => Template.deserialize(r)));
})
.then((results){
// Using the tag property to hold a reference to the entity view model
// object.
final node = new TreeNode()
..header = entityVM.entityName
..tag = entityVM
..fileIcon = results[0]
..folderIcon = results[1];

if (_currentNode != _scene){
// setup the relationships
entityVM.parent = _currentNode.tag;
_currentNode.tag.children.add(entityVM);
}

_currentNode.childNodes.add(node);
_currentNode.childVisibility = Visibility.visible;
_currentNode = node;

_updateUITo(_currentNode);
});

_currentNode.childNodes.add(node);
_currentNode.childVisibility = Visibility.visible;
_currentNode = node;

_updateUITo(_currentNode);
}

void _addSphereHandler(_, __)
{
print('Adding sphere');
}

//---------------------------------------------------------------------
Expand All @@ -159,18 +177,20 @@ class EditorViewModel extends ViewModelBase
.propertyVM
.setDataContext()
.then((_){
evm
.propertyVM
.propertyViews
.forEach((String name, View view){
view.ready.then((t){
final ai = new AccordionItem()
..header = name
..body = view.rootVisual;

_componentArea.accordionItems.add(ai);
Futures
.wait(evm.propertyVM.propertyViews.getValues().map((v) => v.ready))
.then((_){
evm
.propertyVM
.propertyViews
.forEach((String name, View view){
final ai = new AccordionItem()
..header = name
..body = view.rootVisual;

_componentArea.accordionItems.add(ai);
});
});
});
});
}

Expand Down
14 changes: 12 additions & 2 deletions web/viewmodels/entity_view_model.dart
@@ -1,17 +1,27 @@

/**
* Represents content, properties, and operations for an entity.
* Base class that represents content, properties, and operations for an entity.
*/
class EntityViewModel extends ViewModelBase
abstract class EntityViewModel extends ViewModelBase
{
/** The model to be used by this entity */
final GeneratedMeshModel model;

/** The property view model to be used by this entity */
final EntityPropertiesViewModel propertyVM;

/** FrameworkProperty that represents the entity friendly name */
FrameworkProperty entityNameProperty;

/** Reference to the parent of this EntityViewModel. Null if no parent. */
EntityViewModel parent;

/** The icon template to be used when the entity has no children. */
abstract Future<String> get fileTemplate;

/** The icon template to be used when the entity has children. */
abstract Future<String> get folderTemplate;

/**
* Reference to the child EntityViewModel's of this EntityViewModel.
*
Expand Down
45 changes: 0 additions & 45 deletions web/viewmodels/generated_mesh_view_model.dart

This file was deleted.

14 changes: 14 additions & 0 deletions web/viewmodels/plane_entity_view_model.dart
@@ -0,0 +1,14 @@

class PlaneEntityViewModel extends EntityViewModel
{
PlaneEntityViewModel() :
super(new PlaneVisualModel(), new PlanePropertiesViewModel()){
entityName = 'Plane';
}

Future<String> get fileTemplate =>
Template.getTemplate('web/views/templates/plane_icon.xml');

Future<String> get folderTemplate =>
Template.getTemplate('web/views/templates/plane_icon.xml');
}
6 changes: 6 additions & 0 deletions web/viewmodels/properties/box_properties_view_model.dart
Expand Up @@ -3,5 +3,11 @@ class BoxPropertiesViewModel extends TransformPropertiesViewModel
{
BoxPropertiesViewModel(){
propertyViews['Box Properties'] = new BoxProperties();

registerEventHandler('extents_changed', extents_changed);
}

void extents_changed(_, args){
print('box extents changed!');
}
}
34 changes: 34 additions & 0 deletions web/viewmodels/properties/entity_properties_view_model.dart
Expand Up @@ -4,5 +4,39 @@ class EntityPropertiesViewModel extends PropertiesViewModelBase

EntityPropertiesViewModel(){
propertyViews['Entity Properties'] = new EntityProperties();

registerEventHandler('texture_coords_changed', _textureCoordsHandler);
registerEventHandler('normal_changed', _normalChangedHandler);
registerEventHandler('tangent_changed', _tangentChangedHandler);
}

void _textureCoordsHandler(CheckBox checkBox, _)
{
if (checkBox.isChecked)
print('Texcoords checked!');
else
print('Texcoords unchecked!');

model.texCoords = checkBox.isChecked;
}

void _normalChangedHandler(CheckBox checkBox, _)
{
if (checkBox.isChecked)
print('Normal checked!');
else
print('Normal unchecked!');

model.normals = checkBox.isChecked;
}

void _tangentChangedHandler(CheckBox checkBox, _)
{
if (checkBox.isChecked)
print('Tangent checked!');
else
print('Tangent unchecked!');

model.tangents = checkBox.isChecked;
}
}

0 comments on commit 1623be1

Please sign in to comment.