buttonStop.on('clicked', () => { this.actor.removeTransition('rotateTransition'); this.actor.setRotationAngle(Clutter.RotateAxis.Z_AXIS, 0); scale.setSensitive(true); buttonStart.setSensitive(true); buttonStop.setSensitive(false); });
App.prototype.showModal = function() { let label, modal, contentArea, button, actionArea; label = new Gtk.Label({ label: "Hello 'Modal'!", vexpand: true }); modal = new Gtk.Dialog({ defaultHeight: 200, defaultWidth: 200, modal: true, transientFor: this.window, title: 'Modal', useHeaderBar: false }); modal.on('response', modal.destroy); contentArea = modal.getContentArea(); contentArea.add(label); button = Gtk.Button.newWithLabel ('OK'); button.on("clicked", () => { print('OK pressed'); modal.destroy(); }); actionArea = modal.getActionArea(); actionArea.add(button); modal.showAll(); };
App.prototype.getBody = function() { let buttonR, buttonW, grid; buttonR = new Gtk.Button({ hexpand: true, halign: Gtk.Align.CENTER, label: 'Read JSON' }); buttonR.on('clicked', this.read.bind(this)); buttonW = new Gtk.Button({ hexpand: true, halign: Gtk.Align.CENTER, label: 'Write JSON' }); buttonW.on('clicked', this.write.bind(this)); this.label = new Gtk.Label({ label: '' }); grid = new Gtk.Grid({ columnSpacing: 6, margin: 15, rowSpacing: 6 }); grid.attach(buttonR, 0, 0, 1, 1); grid.attach(buttonW, 1, 0, 1, 1); grid.attach(this.label, 0, 1, 2, 1); return grid; };
buttonStart.on('clicked', () => { let tg, pt; pt = new Clutter.PropertyTransition({ propertyName: 'rotation-angle-z' }); pt.setFrom(0); pt.setTo(360); pt.setDuration(2000); pt.setProgressMode(Clutter.AnimationMode.LINEAR); tg = new Clutter.TransitionGroup(); tg.setDuration(2000); tg.setRepeatCount(-1); // Infinite tg.addTransition(pt); // Add more property transitions ... this.actor.addTransition('rotateTransition', tg); scale.setSensitive(false); buttonStart.setSensitive(false); buttonStop.setSensitive(true); });
App.prototype.buildBody = function() { let embed, grid, titleRotate, scale, buttonStart, buttonStop; embed = new GtkClutter.Embed(); embed.setSizeRequest(400, 240); this.position = new Gtk.Label({ label: 'Drag the square' }); this.position.setSizeRequest(300, -1); titleRotate = new Gtk.Label({ label: 'Rotation: ' }); titleRotate.setSizeRequest(150, -1); scale = new Gtk.Scale({ digits: 1, drawValue: true, valuePos: Gtk.PositionType.LEFT }); scale.setRange(-35, 35); scale.setSizeRequest(150, -1); scale.on('change-value', widget => { this.actor.setRotation(Clutter.RotateAxis.Y_AXIS, widget.getValue(), 50, 0, 0); }); buttonStart = new Gtk.Button({ label: 'Play' }); buttonStart.on('clicked', () => { let tg, pt; pt = new Clutter.PropertyTransition({ propertyName: 'rotation-angle-z' }); pt.setFrom(0); pt.setTo(360); pt.setDuration(2000); pt.setProgressMode(Clutter.AnimationMode.LINEAR); tg = new Clutter.TransitionGroup(); tg.setDuration(2000); tg.setRepeatCount(-1); // Infinite tg.addTransition(pt); // Add more property transitions ... this.actor.addTransition('rotateTransition', tg); scale.setSensitive(false); buttonStart.setSensitive(false); buttonStop.setSensitive(true); }); buttonStop = new Gtk.Button({ label: 'Stop', sensitive: false }); buttonStop.on('clicked', () => { this.actor.removeTransition('rotateTransition'); this.actor.setRotationAngle(Clutter.RotateAxis.Z_AXIS, 0); scale.setSensitive(true); buttonStart.setSensitive(true); buttonStop.setSensitive(false); }); grid = new Gtk.Grid({ columnSpacing: 6, margin: 15, rowSpacing: 6 }); grid.attach(embed, 0, 0, 1, 3); grid.attach(this.position, 1, 0, 2, 1); grid.attach(titleRotate, 1, 1, 1, 1); grid.attach(scale, 2, 1, 1, 1); grid.attach(buttonStart, 1, 2, 1, 1); grid.attach(buttonStop, 2, 2, 1, 1); this.stage = embed.getStage(); this.stage.setColor(new Clutter.Color({ red: 255, green: 255, blue: 255, alpha: 255 })); this.stage.addChild(this.getActor()); return grid; };