====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
script_shape_background [2017/06/18 04:55] tbog [Script code] |
script_shape_background [2017/06/20 18:20] tbog [Script code] |
||
---|---|---|---|
Line 15: | Line 15: | ||
<sxh javascript> | <sxh javascript> | ||
- | // v1.1.test3 | + | // v1.1.test6 |
function DrawData() | function DrawData() | ||
{ | { | ||
Line 79: | Line 79: | ||
this.validate = function( c ) | this.validate = function( c ) | ||
{ | { | ||
- | // if not all properties found, copy them from "c" | + | // if not all properties found, copy them to "c" |
- | for( var prop in c ) | + | for( var prop in this ) |
{ | { | ||
- | if ( (typeof c[prop] == 'boolean') || (typeof c[prop] == 'number') || (typeof c[prop] == 'string') ) | + | if ( (typeof this[prop] == 'boolean') || (typeof this[prop] == 'number') || (typeof this[prop] == 'string') ) |
{ | { | ||
- | if ( (typeof this[prop] == 'undefined') || (typeof this[prop] == 'object') ) | + | if ( (typeof c[prop] == 'undefined') || (typeof c[prop] == 'object') ) |
- | this[prop] = c[prop]; | + | c[prop] = this[prop]; |
} | } | ||
} | } | ||
- | if ( this.width < 0 ) | + | if ( c.width < 0 ) |
- | this.width = c.width; | + | c.width = this.width; |
- | if ( this.height < 0 ) | + | if ( c.height < 0 ) |
- | this.height = c.height; | + | c.height = this.height; |
}; | }; | ||
} | } | ||
Line 141: | Line 141: | ||
case enumShapeType.RECTANGLE: | case enumShapeType.RECTANGLE: | ||
canvas.drawRect( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, paint ); | canvas.drawRect( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, paint ); | ||
- | break; | + | break; |
case enumShapeType.OVAL: | case enumShapeType.OVAL: | ||
canvas.drawOval( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, paint ); | canvas.drawOval( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, paint ); | ||
- | break; | + | break; |
case enumShapeType.ARC: | case enumShapeType.ARC: | ||
canvas.drawArc( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, shapeInfo.startAngle, shapeInfo.sweepAngle, true, paint ); | canvas.drawArc( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, shapeInfo.startAngle, shapeInfo.sweepAngle, true, paint ); | ||
- | break; | + | break; |
case enumShapeType.ROUND_RECT: | case enumShapeType.ROUND_RECT: | ||
canvas.drawRoundRect( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, shapeInfo.cornerX, shapeInfo.cornerY, paint ); | canvas.drawRoundRect( shapeInfo.offsetX, shapeInfo.offsetY, shapeInfo.offsetX + shapeWidth, shapeInfo.offsetY + shapeHeight, shapeInfo.cornerX, shapeInfo.cornerY, paint ); | ||
- | break; | + | break; |
default: | default: | ||
- | alert('Unknown shape type "' + shapeInfo.type + '"'); | + | Android.makeNewToast( 'Unknown shape type "' + shapeInfo.type + '"', true ).show(); |
} | } | ||
} | } | ||
Line 177: | Line 177: | ||
{ | { | ||
g_cache.data = data; | g_cache.data = data; | ||
- | var defaultShape = new ShapeInfo(); | ||
- | defaultShape.width = item.getWidth(); | ||
- | defaultShape.height = item.getHeight(); | ||
- | // validate shapes | ||
- | for ( var iter in g_cache.data.shapeAdd ) | ||
- | { | ||
- | g_cache.data.shapeAdd[iter].validate( defaultShape ); | ||
- | } | ||
} | } | ||
} | } | ||
g_cache.itemId = item.getId(); | g_cache.itemId = item.getId(); | ||
+ | |||
// hack to initialize with item size | // hack to initialize with item size | ||
if ( g_cache.data.width <= 0 ) | if ( g_cache.data.width <= 0 ) | ||
Line 193: | Line 186: | ||
if ( g_cache.data.height <= 0 ) | if ( g_cache.data.height <= 0 ) | ||
g_cache.data.height = item.getHeight(); | g_cache.data.height = item.getHeight(); | ||
+ | |||
+ | // validate shapes | ||
+ | var defaultShape = new ShapeInfo(); | ||
+ | defaultShape.width = g_cache.data.width; | ||
+ | defaultShape.height = g_cache.data.height; | ||
+ | for ( var i = 0; i < g_cache.data.shapeArr.length; i+= 1 ) | ||
+ | { | ||
+ | defaultShape.validate( g_cache.data.shapeArr[i] ); | ||
+ | } | ||
return g_cache.data; | return g_cache.data; | ||
} | } | ||
Line 482: | Line 484: | ||
editHeight.setInputType( InputType.TYPE_CLASS_NUMBER ); | editHeight.setInputType( InputType.TYPE_CLASS_NUMBER ); | ||
+ | linearView.addView( shapeInfoLayout = new LinearLayout( ctxTheme ) ); | ||
var btn; | var btn; | ||
- | linearView.addView( btn = new Button( ctxTheme ) ); | + | shapeInfoLayout.addView( btn = new Button( ctxTheme ) ); |
btn.setAllCaps( false ); | btn.setAllCaps( false ); | ||
- | btn.setText( 'Save size' ); | + | btn.setText( 'Set size' ); |
btn.setOnClickListener( new View.OnClickListener() | btn.setOnClickListener( new View.OnClickListener() | ||
{ | { | ||
Line 496: | Line 499: | ||
setDrawData( item, drawData ); | setDrawData( item, drawData ); | ||
+ | dialog.dismiss(); | ||
+ | var time = setTimeout(function(){clearTimeout(time); showShapeMenu(item);}, 0); | ||
+ | } | ||
+ | }); | ||
+ | shapeInfoLayout.addView( btn = new Button( ctxTheme ) ); | ||
+ | btn.setAllCaps( false ); | ||
+ | btn.setText( 'Reset size' ); | ||
+ | btn.setOnClickListener( new View.OnClickListener() | ||
+ | { | ||
+ | onClick: function( view ) | ||
+ | { | ||
+ | var drawData = getDrawData( item ); | ||
+ | |||
+ | drawData.width = item.getWidth(); | ||
+ | drawData.height = item.getHeight(); | ||
+ | |||
+ | setDrawData( item, drawData ); | ||
+ | dialog.dismiss(); | ||
var time = setTimeout(function(){clearTimeout(time); showShapeMenu(item);}, 0); | var time = setTimeout(function(){clearTimeout(time); showShapeMenu(item);}, 0); | ||
} | } | ||
Line 570: | Line 591: | ||
img.update(); | img.update(); | ||
item.setBoxBackground( img, 'nsf', true ); | item.setBoxBackground( img, 'nsf', true ); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | linearView.addView( btn = new Button( ctxTheme ) ); | ||
+ | btn.setAllCaps( false ); | ||
+ | btn.setText( 'Export to string' ); | ||
+ | btn.setOnClickListener( new View.OnClickListener() | ||
+ | { | ||
+ | onClick: function( view ) | ||
+ | { | ||
+ | var drawData = getDrawData( item ); | ||
+ | var text = JSON.stringify(drawData); | ||
+ | var ctx = getActiveScreen().getContext(); | ||
+ | //bindClass( 'android.content.Context' ); | ||
+ | bindClass( 'android.content.ClipboardManager' ); | ||
+ | bindClass( 'android.content.ClipData' ); | ||
+ | var clipboard = ctx.getSystemService(Context.CLIPBOARD_SERVICE); | ||
+ | var clip = ClipData.newPlainText('shape export', text); | ||
+ | clipboard.setPrimaryClip(clip); | ||
+ | Android.makeNewToast('Shape data exported to clipboard.', true).show(); | ||
} | } | ||
}); | }); |