mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Display a fraction
This commit is contained in:
2
Makefile
2
Makefile
@@ -46,7 +46,7 @@ CXXFLAGS = -std=c++11 -fno-exceptions -fno-unwind-tables -fno-rtti -nostdlib
|
||||
products := boot.elf boot.hex boot.bin
|
||||
|
||||
objs += external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o
|
||||
objs += external/newlib/libc/string/memset.o external/newlib/libc/string/memcpy.o
|
||||
objs += $(addprefix external/newlib/libc/, string/memset.o string/memcpy.o string/strlen.o)
|
||||
|
||||
objs += lib/assert.o
|
||||
|
||||
|
||||
1
external/NEWLIB.txt
vendored
1
external/NEWLIB.txt
vendored
@@ -1,3 +1,4 @@
|
||||
- Using memcpy and memset
|
||||
- using <string.h>, <stdlib.h>, and <stdint.h>
|
||||
- using <stdbool.h> for "bool"
|
||||
- using strlen from <string.h>
|
||||
|
||||
@@ -17,7 +17,7 @@ typedef struct {
|
||||
KDCoordinate width;
|
||||
KDCoordinate height;
|
||||
};
|
||||
KDPoint size;
|
||||
KDSize size;
|
||||
};
|
||||
} KDRect;
|
||||
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
|
||||
void KDDrawChar(char character, KDPoint p);
|
||||
void KDDrawString(char * text, KDPoint p);
|
||||
KDSize KDStringSize(char * text);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
void KDDrawLine(KDPoint p1, KDPoint p2) {
|
||||
for (KDCoordinate x = p1.x; x<p2.x; x++) {
|
||||
PIXEL(x, p1.y) = 0xC7;
|
||||
PIXEL(x, p1.y) = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <kandinsky/text.h>
|
||||
#include <framebuffer.h>
|
||||
#include <string.h>
|
||||
#include "font.h"
|
||||
|
||||
void KDDrawChar(char character, KDPoint p) {
|
||||
for (int j=0; j<BITMAP_FONT_CHARACTER_HEIGHT;j++) {
|
||||
for (int i=0; i<BITMAP_FONT_CHARACTER_WIDTH;i++) {
|
||||
PIXEL(p.x+i, p.y+j) = bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i];
|
||||
PIXEL(p.x+i, p.y+j) = 0xFF-bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,3 +20,10 @@ void KDDrawString(char * text, KDPoint p) {
|
||||
position.x += BITMAP_FONT_CHARACTER_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
KDSize KDStringSize(char * text) {
|
||||
return (KDSize){
|
||||
.width = strlen(text)*BITMAP_FONT_CHARACTER_WIDTH,
|
||||
.height = BITMAP_FONT_CHARACTER_HEIGHT
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Number : public Expression {
|
||||
virtual void layout();
|
||||
private:
|
||||
int m_value;
|
||||
char m_stringValue[16];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
#include <poincare/number.h>
|
||||
#include <kandinsky/text.h>
|
||||
|
||||
Number::Number(int v) : m_value(v) {
|
||||
for (int i=0; i<16; i++) {
|
||||
m_stringValue[i] = 0;
|
||||
}
|
||||
|
||||
int value = v;
|
||||
for (int i=0; i<15; i++) {
|
||||
int digit = value - 10*(value/10);
|
||||
m_stringValue[i] = '0' + digit;
|
||||
value = value/10;
|
||||
if (value == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Number::layout() {
|
||||
m_frame.width = 20;
|
||||
m_frame.height = 10;
|
||||
m_frame.size = KDStringSize(m_stringValue);
|
||||
}
|
||||
|
||||
void Number::draw() {
|
||||
KDFillRect(m_frame, 0x7F);
|
||||
KDDrawString(m_stringValue, m_frame.origin);
|
||||
}
|
||||
|
||||
32
src/hello.cpp
Normal file
32
src/hello.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
extern "C" {
|
||||
#include "hello.h"
|
||||
#include <kandinsky.h>
|
||||
}
|
||||
|
||||
#include <poincare.h>
|
||||
|
||||
void hello() {
|
||||
KDFillRect((KDRect){
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 240,
|
||||
.height = 320},
|
||||
0x00);
|
||||
/*
|
||||
for (int i=0; i <255; i++) {
|
||||
KDFillRect((KDRect){.x = (KDCoordinate)i, .y = (KDCoordinate)i, .width = 100, .height = 200}, i);
|
||||
}
|
||||
KDDrawString("Hello, world", (KDPoint){});
|
||||
*/
|
||||
|
||||
Number n1 = Number(123);
|
||||
Number n2 = Number(45);
|
||||
|
||||
Fraction f = Fraction(&n1, &n2);
|
||||
|
||||
f.layout();
|
||||
f.m_frame.origin = (KDPoint){.x = 0, .y = 0};
|
||||
f.draw();//(KDPoint){.x = 10, .y = 10});
|
||||
|
||||
|
||||
}
|
||||
1
src/hello.h
Normal file
1
src/hello.h
Normal file
@@ -0,0 +1 @@
|
||||
void hello();
|
||||
Reference in New Issue
Block a user