Skip to content

Commit 2e0eebd

Browse files
authored
Adds print(), printcenter() and showdataview() blocks to print text and visualize data (#29)
* add print and dataview blocks, add ger localization * make all blocks english, improve dataview block, translation fixes, add calliope mini in description, remove radio and microphone from dependencies * steamline js function call to screen().showDataView(..), update documentation in readme * Update README.md
1 parent e1d5292 commit 2e0eebd

File tree

8 files changed

+315
-12
lines changed

8 files changed

+315
-12
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Display shield MakeCode extension for BBC micro:bit
1+
# Display shield MakeCode extension for BBC micro:bit and Calliope mini
22

3-
This MakeCode extension allows you to use any of the MakeCode Arcade shields with the MakeCode for BBC micro:bit editor.
3+
This MakeCode extension allows you to use any of the MakeCode Arcade shields with the MakeCode for BBC micro:bit or MakeCode for Calliope editor.
44
The extension provides access to the color display and buttons on the shield, and has
55
a Bitmap abstraction with numerous drawing primitives
66
(draw line, circle, square, etc).
@@ -21,6 +21,12 @@ Five Arcade (display) shields for the micro:bit V2 are available on the market t
2121
![more MakeCode Arcade shields](https://github.com/microbit-apps/display-shield/blob/master/assets/shields2.png?raw=true)
2222

2323

24+
## Arcade shields for the Calliope mini V3
25+
* [TINYSUPERLAB's GameKit Shield](https://shop.tinysuperlab.com/products/gamekit): No assembly required. Battery holder on the back. Jacdac compatible.
26+
27+
![gamekit-calliope-mini-3](https://github.com/user-attachments/assets/8b0a923e-4297-4a91-ac62-8e150d269ed6)
28+
29+
2430
## Simulator support
2531

2632
As shown below, the extension provides a simulator for the display,
@@ -207,6 +213,29 @@ screen().fillCircle(10, 10, 8, 2)
207213
screen().drawCircle(10, 10, 8, 5)
208214
```
209215

216+
### Text
217+
There are three functions for drawing text onto a bitmap (including the screen):
218+
219+
- `print(text, x, y, color?, font?)` — prints text starting at the given (x, y) coordinate.
220+
- `printCenter(text, y, color?, font?)` — prints text horizontally centered at the given y coordinate.
221+
- `showDataView(headline, label1?, value1?, label2?, value2?, label3?, value3?, color?, backgroundColor?, offset?, font?)` — displays a headline and up to three label/value pairs in a two-column layout, useful for showing sensor data or statistics. Labels or headlines without any string will not be printed. Using offset and a transparent background color, several calls of `showDataView(...)` can be combined to show 6 or more parameters in total.
222+
223+
Here are examples in TypeScript using the `screen()` bitmap:
224+
225+
```ts
226+
// 1) print — draw text at a specific position
227+
screen().print("Score: 123", 4, 4, 1) // x=4, y=4, color index 1
228+
229+
// 2) printCenter — draw text centered horizontally
230+
screen().printCenter("Game Over", 50, 2) // centered at y=50, color index 2
231+
232+
// 3) showDataView — display a headline and data pairs
233+
screen().showDataView("Stats", "Temp", 22, "Light", 55, "Sound", 49)
234+
```
235+
236+
These helpers use built-in bitmapped fonts. You can explicitly pass a font (such as `bitmaps.font8` or `bitmaps.font12`) to control text size.
237+
238+
210239
### Bitmap
211240

212241
Let's dig into bitmaps, which you can create yourself (the screen is represented by a bitmap, as we have seen already). A bitmap is some number of rows and columns of color pixels that make up rectangular picture. A _pixel_ is a single point of color inside the bitmap. A bitmap has a fixed height (number of rows) and width (number of columns). When a bitmap is declared, or created, the height and width are specified either by the _layout_ of the bitmap or as parameters to its `create` method.
@@ -485,5 +514,6 @@ screen().drawTransparentBitmap(orangeBox, 32, 32)
485514
# Supported targets
486515

487516
- for PXT/microbit
517+
- for PXT/calliopemini
488518

489519
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"Bitmap.clone": "Gibt eine Kopie der aktuellen Bitmap zurück",
3+
"Bitmap.drawBitmap": "Zeichnet die angegebene Bitmap auf die aktuelle Bitmap",
4+
"Bitmap.drawCircle": "Zeichnet einen leeren Kreis",
5+
"Bitmap.drawCircle|param|c": "Die Farbe zum Zeichnen des Kreises",
6+
"Bitmap.drawCircle|param|cx": "Die Mittelpunkt-X-Koordinate des Kreises",
7+
"Bitmap.drawCircle|param|cy": "Die Mittelpunkt-Y-Koordinate des Kreises",
8+
"Bitmap.drawCircle|param|r": "Der Radius des Kreises",
9+
"Bitmap.drawLine": "Zeichnet eine Linie",
10+
"Bitmap.drawRect": "Zeichnet ein leeres Rechteck",
11+
"Bitmap.drawTransparentBitmap": "Zeichnet die angegebene Bitmap mit transparentem Hintergrund auf die aktuelle Bitmap",
12+
"Bitmap.equals": "Gibt wahr zurück, wenn die angegebene Bitmap mit dieser Bitmap übereinstimmt, ansonsten falsch.",
13+
"Bitmap.fill": "Füllt die gesamte Bitmap mit einer bestimmten Farbe",
14+
"Bitmap.fillCircle": "Füllt einen Kreis",
15+
"Bitmap.fillCircle|param|c": "Die Farbe zum Zeichnen des Kreises",
16+
"Bitmap.fillCircle|param|cx": "Die Mittelpunkt-X-Koordinate des Kreises",
17+
"Bitmap.fillCircle|param|cy": "Die Mittelpunkt-Y-Koordinate des Kreises",
18+
"Bitmap.fillCircle|param|r": "Der Radius des Kreises",
19+
"Bitmap.fillRect": "Füllt ein Rechteck",
20+
"Bitmap.flipX": "Spiegelt die Pixel horizontal in der aktuellen Bitmap",
21+
"Bitmap.flipY": "Spiegelt die Pixel vertikal in der aktuellen Bitmap",
22+
"Bitmap.getPixel": "Liest eine Pixelfarbe aus",
23+
"Bitmap.mapRect": "Ersetzt Farben in einem Rechteck",
24+
"Bitmap.print": "Druckt Text auf die Bitmap an der angegebenen Position",
25+
"Bitmap.print|param|text": "Der zu druckende Text",
26+
"Bitmap.print|param|x": "Die X-Koordinate",
27+
"Bitmap.print|param|y": "Die Y-Koordinate",
28+
"Bitmap.print|param|color": "Die Textfarbe",
29+
"Bitmap.print|param|font": "Die zu verwendende Schriftart",
30+
"Bitmap.printCenter": "Druckt Text mittig auf die Bitmap",
31+
"Bitmap.printCenter|param|text": "Der zu druckende Text",
32+
"Bitmap.printCenter|param|y": "Die Y-Koordinate",
33+
"Bitmap.printCenter|param|color": "Die Textfarbe",
34+
"Bitmap.printCenter|param|font": "Die zu verwendende Schriftart",
35+
"Bitmap.replace": "Ersetzt eine Farbe in einer Bitmap durch eine andere",
36+
"Bitmap.scroll": "Jedes Pixel in der Bitmap wird um (dx,dy) verschoben",
37+
"Bitmap.setPixel": "Setzt eine Pixelfarbe",
38+
"bitmaps": "Bitmap-Manipulationsblöcke",
39+
"bitmaps._bitmap": "Eine Bitmap",
40+
"bitmaps._bitmap|param|bitmap": "die Bitmap",
41+
"bitmaps.create": "Erstellt eine neue leere (transparente) Bitmap",
42+
"bitmaps.height": "Gibt die Höhe einer Bitmap zurück",
43+
"bitmaps.width": "Gibt die Breite einer Bitmap zurück",
44+
"bmp": "Tagged Bitmap-Literal-Konverter",
45+
"context.eventContext": "Ruft den aktuellen Ereigniskontext ab, falls vorhanden",
46+
"context.onIdle": "Registriert eine Funktion, die ausgeführt wird, wenn das Gerät im Leerlauf ist",
47+
"context.popEventContext": "Entfernt den aktuellen Ereigniskontext und stellt Handler wieder her, falls ein vorheriger Kontext vorhanden ist",
48+
"context.pushEventContext": "Fügt einen neuen Ereigniskontext hinzu und löscht alle Handler",
49+
"controller": "Zugriff auf Spielsteuerung",
50+
"controller.Button.addEventListener": "Fügt einen Ereignishandler hinzu, der ausgelöst wird, wenn das angegebene Ereignis für diese Taste ausgelöst wird. Handler, die mit dieser Methode hinzugefügt werden,\nstehen nicht im Konflikt mit Ereignissen, die über onEvent hinzugefügt wurden. Derselbe Handler kann nicht mehrmals für dasselbe Ereignis hinzugefügt werden.",
51+
"controller.Button.addEventListener|param|handler": "Der Code, der ausgeführt werden soll, wenn das Ereignis ausgelöst wird",
52+
"controller.Button.isPressed": "Gibt an, ob die Taste gerade gedrückt ist",
53+
"controller.Button.onEvent": "Führt Code aus, wenn eine Taste gedrückt, losgelassen oder gehalten wird",
54+
"controller.Button.pauseUntil": "Pausiert, bis eine Taste gedrückt oder losgelassen wird",
55+
"controller.Button.removeEventListener": "Entfernt einen mit addEventListener registrierten Ereignishandler",
56+
"controller.Button.removeEventListener|param|handler": "Der zu entfernende Handler",
57+
"controller.onShieldEvent": "Führt Code aus, wenn Shield abwesend/vorhanden ist",
58+
"controller.pauseUntilAnyButtonIsPressed": "Pausiert das Programm, bis eine Taste gedrückt wird",
59+
"controller.setRepeatDefault": "Konfiguriert das Timing des Tastenwiederholungsereignisses für alle Controller-Tasten",
60+
"controller.setRepeatDefault|param|delay": "Anzahl der Millisekunden von dem Drücken der Taste bis zum Start des Wiederholungsereignisses, z.B.: 500",
61+
"controller.setRepeatDefault|param|interval": "Minimale Anzahl von Millisekunden zwischen Aufrufen des Tastenwiederholungsereignisses, z.B.: 30",
62+
"helpers.imageShowDataView": "Zeigt eine Datenansicht mit Überschrift und bis zu drei Namen-Werte-Paaren",
63+
"helpers.imageShowDataView|param|img": "Die Bitmap, auf der gezeichnet werden soll",
64+
"helpers.imageShowDataView|param|headline": "Die Überschrift",
65+
"helpers.imageShowDataView|param|label1": "Das erste Label",
66+
"helpers.imageShowDataView|param|value1": "Der erste Wert",
67+
"helpers.imageShowDataView|param|label2": "Das zweite Label",
68+
"helpers.imageShowDataView|param|value2": "Der zweite Wert",
69+
"helpers.imageShowDataView|param|label3": "Das dritte Label",
70+
"helpers.imageShowDataView|param|value3": "Der dritte Wert",
71+
"helpers.imageShowDataView|param|color": "Die Textfarbe",
72+
"helpers.imageShowDataView|param|backgroundColor": "Die Hintergrundfarbe",
73+
"helpers.imageShowDataView|param|offset": "Vertikaler Versatz in Pixeln",
74+
"helpers.imageShowDataView|param|font": "Die zu verwendende Schriftart",
75+
"screen": "Ruft die Bildschirm-Bitmap ab",
76+
"shieldhelpers.registerSim": "Registriert den Simulator, um Tastendrücke zu empfangen"
77+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"Bitmap.clone|block": "klone $this",
3+
"Bitmap.drawBitmap|block": "zeichne $from in $this bei x $x y $y",
4+
"Bitmap.drawCircle|block": "zeichne Kreis in $this bei cx $cx cy $cy Radius $r in Farbe $c",
5+
"Bitmap.drawLine|block": "zeichne Linie in $this von x $x0 y $y0 bis x $x1 y $y1 in Farbe $c=colorindexpicker",
6+
"Bitmap.drawRect|block": "zeichne Rechteck in $this bei x $x y $y Breite $w Höhe $h in Farbe $c=colorindexpicker",
7+
"Bitmap.drawTransparentBitmap|block": "zeichne $from transparent in $this bei x $x y $y",
8+
"Bitmap.equals|block": "$this ist gleich Bitmap $other",
9+
"Bitmap.fillCircle|block": "fülle Kreis in $this bei cx $cx cy $cy Radius $r in Farbe $c",
10+
"Bitmap.fillRect|block": "fülle Rechteck in $this bei x $x y $y Breite $w Höhe $h in Farbe $c=colorindexpicker",
11+
"Bitmap.fill|block": "fülle $this mit $c=colorindexpicker",
12+
"Bitmap.flipX|block": "spiegele $this horizontal",
13+
"Bitmap.flipY|block": "spiegele $this vertikal",
14+
"Bitmap.getPixel|block": "$this Farbe bei x $x y $y",
15+
"Bitmap.printCenter|block": "schreibe $text in Mitte von $this bei y $y in Farbe $color=colorindexpicker || und Schrift $font",
16+
"Bitmap.print|block": "schreibe $text in $this bei x $x y $y in Farbe $color=colorindexpicker || und Schrift $font",
17+
"Bitmap.replace|block": "ändere Farbe in $this von $from=colorindexpicker zu $to=colorindexpicker",
18+
"Bitmap.scroll|block": "scrolle $this um x $dx y $dy",
19+
"Bitmap.setPixel|block": "setze $this Farbe bei x $x y $y auf $c=colorindexpicker",
20+
"ControllerButton.A|block": "{id:controller}A",
21+
"ControllerButton.B|block": "{id:controller}B",
22+
"ControllerButton.Down|block": "runter",
23+
"ControllerButton.Left|block": "links",
24+
"ControllerButton.Right|block": "rechts",
25+
"ControllerButton.Up|block": "hoch",
26+
"ControllerButtonEvent.Pressed|block": "gedrückt",
27+
"ControllerButtonEvent.Released|block": "losgelassen",
28+
"ControllerButtonEvent.Repeated|block": "wiederholt",
29+
"ControllerShieldEvent.Absent|block": "abgesteckt",
30+
"ControllerShieldEvent.Present|block": "angesteckt",
31+
"bitmaps._bitmap|block": "$bitmap",
32+
"bitmaps._create|block": "erstelle Bitmap Breite $width Höhe $height",
33+
"bitmaps._font12|block": "große Schrift",
34+
"bitmaps._font5|block": "kleine Schrift",
35+
"bitmaps._font8|block": "mittlere Schrift",
36+
"bitmaps.create|block": "erstelle Bitmap Breite $width Höhe $height",
37+
"bitmaps.height|block": "$bitmap Höhe",
38+
"bitmaps.width|block": "$bitmap Breite",
39+
"bitmaps|block": "Bitmaps",
40+
"context|block": "Kontext",
41+
"controller.A|block": "{id:controller}A",
42+
"controller.Button.isPressed|block": "ist $this **Taste** gedrückt",
43+
"controller.Button.onEvent|block": "wenn $this **Taste** $event",
44+
"controller.B|block": "{id:controller}B",
45+
"controller.down|block": "runter",
46+
"controller.left|block": "links",
47+
"controller.menu|block": "Menü",
48+
"controller.onShieldEvent|block": "wenn Shield $event",
49+
"controller.right|block": "rechts",
50+
"controller.up|block": "hoch",
51+
"controller|block": "Tasten",
52+
"drawing|block": "Bildschirm",
53+
"helpers.imageShowDataView|block": "zeige Datenansicht in $img=theScreen Überschrift $headline $label1 $value1 $label2 $value2 $label3 $value3||Farbe $color=colorindexpicker Hintergrund $backgroundColor=colorindexpicker Versatz $offset Schrift $font",
54+
"screen|block": "Bildschirm",
55+
"shieldhelpers.shieldPresent|block": "Shield vorhanden?",
56+
"shieldhelpers|block": "Shield-Helfer",
57+
"{id:category}Bitmap": "Bitmap",
58+
"{id:category}Bitmaps": "Bitmaps",
59+
"{id:category}Config": "Konfiguration",
60+
"{id:category}Context": "Kontext",
61+
"{id:category}Control": "Steuerung",
62+
"{id:category}Controller": "Tasten",
63+
"{id:category}Drawing": "Bildschirm",
64+
"{id:category}Helpers": "Helfer",
65+
"{id:category}Scene": "Szene",
66+
"{id:category}Shieldhelpers": "Shield-Helfer",
67+
"{id:category}Texteffects": "Texteffekte",
68+
"{id:category}__screen_internal": "__screen_internal",
69+
"{id:category}__screenhelpers": "__screenhelpers",
70+
"{id:group}Compare": "Vergleichen",
71+
"{id:group}Create": "Erstellen",
72+
"{id:group}Drawing": "Zeichnen",
73+
"{id:group}Text": "Text",
74+
"{id:group}Transformations": "Transformationen"
75+
}

controllerbutton.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ enum ControllerButton {
3434
}
3535

3636
enum ControllerShieldEvent {
37-
// block="absent"
37+
//% block="absent"
3838
Absent = 3042,
39-
// block="present"
39+
//% block="present"
4040
Present = 3043,
4141
}
4242

43-
4443
namespace controller {
4544
export class Controller {
4645
constructor(no: number, v: any) { }

ns.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
* Access to game controls
33
*/
44
//% weight=5 color="#D54322" icon="\uf11b"
5+
//% block="Controller"
56
//% blockGap=8
67
namespace controller {
78

89
}
910

1011
//% weight=4 icon="\uf03e" color="#007090"
12+
//% block="Drawing"
13+
//% groups=['Drawing', 'Create', 'Transformations', 'Compare', 'Text']
1114
namespace drawing {
1215

1316
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"dependencies": {
33
"makecode": "^1.3.0",
4+
"pxt-calliopemini": "^8.1.9",
45
"pxt-microbit": "^7.1.9"
56
}
67
}

pxt.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"name": "display-shield",
3-
"version": "1.0.9",
4-
"description": "Display shield extension for MakeCode micro:bit",
3+
"version": "1.1.2",
4+
"description": "Display shield extension for MakeCode micro:bit and Calliope mini",
55
"dependencies": {
66
"core": "*",
7-
"radio": "*",
8-
"microphone": "*",
97
"bitmap": "*",
108
"fonts": "*"
119
},
@@ -56,7 +54,9 @@
5654
"docs/is-pressed.md",
5755
"docs/draw-bitmap.md",
5856
"docs/draw-circle.md",
59-
"tutorials/getting-started.md"
57+
"tutorials/getting-started.md",
58+
"_locales/de/display-shield-jsdoc-strings.json",
59+
"_locales/de/display-shield-strings.json"
6060
],
6161
"testFiles": [
6262
"test.ts"

0 commit comments

Comments
 (0)