From b2768b1099725195fbd84f5844b088c74ddbd894 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 16 Nov 2017 22:46:51 -0800 Subject: [PATCH] added showimage --- libs/core/_locales/core-jsdoc-strings.json | 4 ++++ libs/core/_locales/core-strings.json | 2 ++ libs/core/screen.ts | 26 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index c4a7c088..3a657732 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -20,6 +20,8 @@ "brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.", "brick.Button.onEvent|param|body": "code to run when the event is raised", "brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.", + "brick._imagePicker": "An image", + "brick._imagePicker|param|image": "the image", "brick.buttonDown": "Down button on the EV3 Brick.", "brick.buttonEnter": "Enter button on the EV3 Brick.", "brick.buttonLeft": "Left button on the EV3 Brick.", @@ -37,6 +39,8 @@ "brick.setPixel|param|y": "the starting position's x coordinate, eg: 0", "brick.setStatusLight": "Set lights.", "brick.setStatusLight|param|pattern": "the lights pattern to use.", + "brick.showImage": "Shows an image on screen", + "brick.showImage|param|image": "image to draw", "control": "Program controls and events.", "control.allocateNotifyEvent": "Allocates the next user notification event", "control.deviceFirmwareVersion": "Determine the version of system software currently running.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 5292ec55..944a0885 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -35,6 +35,7 @@ "brick.Button.isPressed|block": "%button|is pressed", "brick.Button.onEvent|block": "on %button|%event", "brick.Button.wasPressed|block": "%button|was pressed", + "brick._imagePicker|block": "%image", "brick.buttonDown|block": "button down", "brick.buttonEnter|block": "button enter", "brick.buttonLeft|block": "button left", @@ -44,6 +45,7 @@ "brick.print|block": "print %text| at x: %x| y: %y", "brick.setPixel|block": "set pixel %on| at x: %x| y: %y", "brick.setStatusLight|block": "set status light %pattern=led_pattern", + "brick.showImage|block": "show image %image=scren_image_picker", "brick|block": "brick", "control.raiseEvent|block": "raise event|from %src|with value %value", "control|block": "control", diff --git a/libs/core/screen.ts b/libs/core/screen.ts index 70ca003f..2ee647a2 100644 --- a/libs/core/screen.ts +++ b/libs/core/screen.ts @@ -133,6 +133,32 @@ namespace brick { } } + /** + * Shows an image on screen + * @param image image to draw + */ + //% blockId=screen_show_image block="show image %image=scren_image_picker" + //% weight=95 group="Screen" blockGap=8 + export function showImage(image: Image, delay: number = 400) { + if (!image) return; + image.draw(0, 0, Draw.Normal); + delay = Math.max(0, delay); + loops.pause(delay); + } + + /** + * An image + * @param image the image + */ + //% blockId=scren_image_picker block="%image" shim=TD_ID + //% image.fieldEditor="imagedropdown" + //% image.fieldOptions.columns=8 + //% block.fieldOptions.hasSearchBar=true + //% group="Screen" weight=0 blockHidden=1 + export function _imagePicker(image: Image): Image { + return image; + } + export function drawRect(x: number, y: number, w: number, h: number, mode = Draw.Normal) { x |= 0; y |= 0;