OSDN Git Service

Client is version 0.5.51, Working new balloon!
authoritozyun <itozyun@user.sourceforge.jp>
Sun, 31 Mar 2013 12:42:45 +0000 (21:42 +0900)
committeritozyun <itozyun@user.sourceforge.jp>
Sun, 31 Mar 2013 12:42:45 +0000 (21:42 +0900)
app/assets/javascripts/peta-apps.js
app/assets/javascripts/peta-common.js

index 0175294..89e3be9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * pettanR peta.apps.js
- *   version 0.5.50
+ *   version 0.5.51
  *   
  * author:
  *   itozyun
@@ -93,7 +93,7 @@
                                        case BALLOON_TEMPLETE_ARRAY :
                                                json.type = FILE_TYPE.BALLOON_TEMPLETE;
                                                // register pettanr.balloon
-                                               pettanr.newBalloon.register( json.classname, json.settings );
+                                               pettanr.newBalloon.register( json.id, json.classname, json.settings );
                                                data = createFileData( json, BALLOON_TEMPLETE_ARRAY, 'name,caption,classname,settings' );
                                                addChildData( FILE_DATA_BALLOON_ROOT, data );
                                                break;
                                        case FILE_TYPE.ARTIST :
                                                return [ 'artist id:', data.id, ' Email:', data.email || 'empty' , ', HP:', data.homepage_url || 'empty' ].join( '' );
                                        case FILE_TYPE.BALLOON_TEMPLETE :
-                                               return data.name + ', ' + data.settings;
+                                               return data.name;// + ', ' + data.settings;
                                        case FILE_TYPE.FOLDER :
                                                return 'pettanR folder';
                                };
@@ -2321,7 +2321,48 @@ var Editor = gOS.registerApplication( function(){
                        'toolbox-window', 'Tool box', 0, 215, 110, 290, true
                );
        })();
-       
+
+/* ----------------------------------------
+ * BALLOON_TEMPLETE_EXPROLER
+ *  - window
+ */
+       var BALLOON_EXPLORER_WINDOW = ( function(){
+               var tree, finder;
+               
+               function onFileSelect( file ){
+                       // 他の image ファイルも許可する?
+                       if( Driver.isPettanrFileInstance( file ) === true ){
+                               if( file.getType() === FILE_TYPE.BALLOON_TEMPLETE ){
+                                       PANEL_ELEMENT_CONTROL.onBalloonSelect( FileAPI.getFileData( file ) );
+                               };
+                       };
+               };
+               
+               return WINDOWS_CONTROL.createWindow(
+                       {
+                               onInit: function(){},
+                               onFirstOpen: function( _w, _h, nodeBody ){
+                                       tree = FileAPI.createTree( FILE_DATA_BALLOON_ROOT );
+                                       var     _root  = tree.getRootFile();
+                                       _root.getSeqentialFiles();
+                       
+                                       finder = app.createFinder(
+                                               nodeBody,
+                                               tree,
+                                               onFileSelect
+                                       );
+                                       finder.createPath( BALLOON_EXPLORER_WINDOW.createHeaderItem() );
+                               },
+                               onOpen: function( _w, _h ){
+                                       finder.resize( _w, _h );
+                               },
+                               onResize: function( _w, _h ){
+                                       finder.resize( _w, _h );
+                               }
+                       },
+                       null, 'Balloon', 0, 215, 600, 350, false, true, true, 300, 300
+               );
+       })();   
        
 /* ----------------------------------------
  * IMAGE_EXPROLER
@@ -3801,14 +3842,6 @@ var Editor = gOS.registerApplication( function(){
 /* --------------------------------------------------------------------------------------------
  * TextElementClass
  * 
- * type
- * 0.none
- * 1.speach balloon
- * 2.think
- * 3.bom
- * 4.black-box( dq style)
- * 5.blue-box( ff style)
- * 
  */
        var jqTextElementOrigin;
        var TextElementClass = function( data ){
@@ -3829,7 +3862,8 @@ var Editor = gOS.registerApplication( function(){
                        }
                        return '';
                })();
-               this.balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, this.type );
+               // this.balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, this.type );
+               this.balloon = pettanr.newBalloon.create( data.balloon_classname, data.width, data.height, data.tail )
                this.z       = data.z;
                this.timing  = data.t || PANEL_ELEMENT_ARRAY.length;
                
@@ -3852,16 +3886,18 @@ var Editor = gOS.registerApplication( function(){
                                this.resize( this.data.x, this.data.y, this.data.width, this.data.height, this.data.tail );
                                this.init = null;
                        },
+                       /*
                        _updateType : function( _type ){
                                if( this.type !== _type ){
                                        this.type = _type || this.type;
                                        this.balloon.type( this.type );
                                };
-                       },
+                       }, */
                        _updateAngle : function( _a ){
                                if( _a !== undefined && a !== _a ){
                                        this.a = _a !== undefined ? _a : this.a;
-                                       this.balloon.angle( this.a );
+                                       //this.balloon.angle( this.a );
+                                       this.balloon.update( this.w, this.h, this.a );
                                };
                        },
                        /* history */
@@ -3870,7 +3906,8 @@ var Editor = gOS.registerApplication( function(){
                                this.elmText.firstChild.data = this.content;
                        },
                        _resizeBalloon : function(){
-                               this.balloon && this.balloon.resize( this.a, this.w, this.h );
+                               //this.balloon && this.balloon.resize( this.a, this.w, this.h );
+                               this.balloon && this.balloon.update( this.w, this.h, this.a );
                        },
                        angle : function( _a ){
                                _a !== undefined && this.resize( this.x, this.y, this.w, this.h, _a );
@@ -4107,19 +4144,27 @@ var Editor = gOS.registerApplication( function(){
                                HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ false, _panelElement ], [ true, _panelElement ], true );
                        },
                        createTextElement: function( data ){
-                               var _panelElement;
                                if( Type.isObject( data ) === false ){
+                                       BALLOON_EXPLORER_WINDOW.open();
+                               } else {
+                                       PANEL_ELEMENT_CONTROL.onBalloonSelect( data );
+                               };
+                       },
+                       onBalloonSelect : function( data ){
+                               var _panelElement;
+                               if( data.classname ){
                                        data = {
-                                               balloon_template_id:1,
-                                               size:               1,
-                                               tail:               90,
-                                               x:                                      Math.floor( panelW / 2 - 100 + Math.random() * 10 ),
-                                               y:                  Math.floor( panelH / 2 - 100 + Math.random() * 10 ),
-                                               z:                  -1,
-                                               t:                  0,
-                                               width:              200,
-                                               height:             200,
-                                               speeches_attributes: {
+                                               balloon_template_id : data.id,
+                                               balloon_classname   : data.classname,
+                                               size                : 1,
+                                               tail                : 90,
+                                               x                   : Math.floor( panelW / 2 - 100 + Math.random() * 10 ),
+                                               y                   : Math.floor( panelH / 2 - 100 + Math.random() * 10 ),
+                                               z                   : -1,
+                                               t                   : 0,
+                                               width               : 200,
+                                               height              : 200,
+                                               speeches_attributes : {
                                                        text1: {
                                                                content:    'Hello'
                                                        }
index d56c6fd..49dc559 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  * pettanR peta.common.js\r
- *   version 0.5.50\r
+ *   version 0.5.51\r
  * \r
  *   author:\r
  *     itozyun\r
@@ -316,9 +316,10 @@ pettanr.balloon = ( function() {
  * \r
  */\r
 pettanr.newBalloon = ( function(){\r
-       var TEMPLETES = {};\r
+       var TEMPLETES = [];\r
        \r
-       var STROKE_WIDTH       = 1.2,\r
+       var PICTURE_PATH       = pettanr.CONST.SYSTEM_PICTURE_PATH,\r
+               STROKE_WIDTH       = 1.2,\r
                IS_VML             = UA.isIE === true && UA.ieVersion < 9,\r
                ELM_BALLOON_ORIGIN = ( function(){\r
                        var ret;\r
@@ -356,7 +357,7 @@ pettanr.newBalloon = ( function(){
                BalloonClass;\r
        \r
        if( vectorEnabled === true ){\r
-               BalloonClass = function( templete ){\r
+               BalloonClass = function( klass ){\r
                        this.elm     = ELM_BALLOON_ORIGIN.cloneNode( true );\r
                        this.path    = this.elm.getElementsByTagName( IS_VML === true ? 'shape' : 'path' )[ 0 ];\r
                        this.klass   = klass;\r
@@ -412,7 +413,7 @@ pettanr.newBalloon = ( function(){
                        update : function( /* w, h [, angle, ,,, ] */ ){\r
                                var id = this.getPictureID.call( this.klass, arguments );\r
                                if( id !== 0 && !id ) return false;\r
-                               this.elm.src = pettanr.CONST.SYSTEM_PICTURE_PATH + id + '.gif';\r
+                               this.elm.src = PICTURE_PATH + id + '.gif';\r
                        },\r
                        destroy : function(){\r
                                this.elm.parentNode && this.elm.parentNode.removeChild( this.elm );\r
@@ -420,7 +421,7 @@ pettanr.newBalloon = ( function(){
                };\r
        };\r
        \r
-       /*\r
+       /* js を持たず ハッシュに格納したデータと 1枚以上の system picture から描画を行う\r
         * http://sourceforge.jp/projects/pettanr/wiki/HowToMakeSpeechBalloon\r
         */\r
        var NonVectorBalloonClass = function( templete ){\r
@@ -431,25 +432,31 @@ pettanr.newBalloon = ( function(){
                //this.defaultW  = templete.default_width;\r
                //this.defaultH  = templete.default_height;\r
                //this.sizeCount = templete.size_count;\r
-               this.wOffset   = templete.width_offset;\r
-               this.hOffset   = templete.height_offset;\r
-               this.wStep     = templete.width_step;\r
-               this.hStep     = templete.height_step;\r
+               this.wOffset   = templete.speech_balloon.width_offset;\r
+               this.hOffset   = templete.speech_balloon.height_offset;\r
+               this.wStep     = templete.speech_balloon.width_step;\r
+               this.hStep     = templete.speech_balloon.height_step;\r
                // r_offset\r
                // r_steps\r
                \r
-               var obj = templete.balloon_template_attributes, v, p;\r
-               \r
-               if( templete.size_count && 1 < templete.size_count ){\r
+               var obj = templete, v, p;\r
+               // 2013.3.31 itozyun's memo\r
+               // 以下の使いやすく加工する処理は pettanr.balloon.register() 内に移動してもよさそう\r
+               // new TempleteClass( templeteJson );\r
+               // NonVectorBalloon.templete.defaultW みたいにアクセス\r
+               if( templete.speech_balloon.size_count && 1 < templete.speech_balloon.size_count ){\r
                        this.picIDs = []; // system picture id list\r
-                       for( p in obj ){\r
-                               v = obj[ v ];\r
-                               this.picIDs[ v.size ] = v.system_picture_id;\r
+                       for( p in templete ){\r
+                               if( p === 'speech_balloon' ) continue;\r
+                               v = obj[ p ];\r
+                               this.picIDs[ this.picIDs.length ] = v.balloon.system_picture_id;\r
                        };                      \r
                } else {\r
                        for( p in obj ){\r
-                               v = obj[ v ];\r
-                               this.picID = v.system_picture_id;\r
+                               if( p === 'speech_balloon' ) continue;\r
+                               v = obj[ p ];\r
+                               this.picID = v.balloon.system_picture_id;\r
+                               break;\r
                        };\r
                };\r
        };\r
@@ -460,7 +467,9 @@ pettanr.newBalloon = ( function(){
                args     : null,\r
                picIDs   : null,\r
                picID    : 0,\r
-               path     : pettanr.CONST.SYSTEM_PICTURE_PATH,\r
+               src      : 0,\r
+               w        : 0,\r
+               h        : 0,\r
                update : function( w, h /* [, angle, ,,, ] */ ){\r
                        var l, id, _w, _h;\r
                        if( this.picIDs ){\r
@@ -469,16 +478,24 @@ pettanr.newBalloon = ( function(){
                                l  = this.picIDs.length - 1;\r
                                _w = _w < 0 ? 0 : ( _w > l ? l : _w );\r
                                _h = _h < 0 ? 0 : ( _h > l ? l : _h );\r
-                               id = this.picIDs[ _w > _h ? _w : _h ];\r
+                               id = this.picIDs[ Math.floor( _w > _h ? _w : _h ) ];\r
                        } else {\r
                                id = this.picID;\r
                        };\r
-                       \r
-                       this.elm.src     = this.path + id + '.gif';\r
-                       this.size.width  = w + 'px';\r
-                       this.size.height = h + 'px';\r
+                       if( this.src !== id ){\r
+                               this.elm.src = PICTURE_PATH + id + '.gif';\r
+                               this.src = id;\r
+                       };\r
+                       if( this.w !== w ){\r
+                               this.size.width = w + 'px';\r
+                               this.w = w;\r
+                       };\r
+                       if( this.h !== h ){\r
+                               this.size.height = h + 'px';\r
+                               this.h = h;\r
+                       };\r
                },\r
-               destory : function(){\r
+               destroy : function(){\r
                        this.elm.parentNode && this.elm.parentNode.removeChild( this.elm );\r
                }\r
        };\r
@@ -488,17 +505,22 @@ pettanr.newBalloon = ( function(){
                 * balloon_templetes.json 取得時に呼ばれる\r
                 * className は存在しない場合もある \r
                 */\r
-               register : function( name, templete ){\r
+               register : function( id, name, templete ){\r
                        templete = $.parseJSON( templete );\r
                        if( !TEMPLETES[ name ] ){\r
-                               TEMPLETES[ name ] = templete.speech_balloon;\r
+                               TEMPLETES[ name ] = templete;\r
+                               TEMPLETES[ id ]   = templete;\r
                        };\r
                },\r
-               create : function( name ){\r
-                       if( Type.isString( name ) === true && name in window ){\r
-                               return new BalloonClass( window[ name ] );\r
+               create : function( idOrName, w, h /* [, angle, ,,, ] */ ){\r
+                       var ret;\r
+                       if( Type.isString( idOrName ) === true && idOrName in window ){\r
+                               ret = new BalloonClass( window[ idOrName ] );\r
+                       } else {\r
+                               ret = new NonVectorBalloonClass( TEMPLETES[ idOrName ] );\r
                        };\r
-                       return new NonVectorBalloonClass( TEMPLETES[ name ] );\r
+                       ret.update( w, h /* [, angle, ,,, ] */ );\r
+                       return ret;\r
                },\r
                isTemplete : function( templete ){\r
                        \r
@@ -984,7 +1006,8 @@ pettanr.bind = ( function(){
                                'z-index:', data.z, ';'\r
                        ].join( '' );\r
 \r
-                       balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail );\r
+                       //balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail );\r
+                       balloon = pettanr.newBalloon.create( data.id, data.width, data.height, data.tail );\r
                        elmBalloonWrap.appendChild( balloon.elm );\r
                        \r
                        elmBalloonWrap.appendChild( elmText );\r