From bed4f3fb73c24038f1a913aef6c0f6c457e975d2 Mon Sep 17 00:00:00 2001 From: C4Phone Date: Thu, 10 Dec 2015 13:51:07 -0600 Subject: [PATCH 1/3] basic text input --- mp3/student-distrib/inc/ui/compositor.h | 9 +++++ mp3/student-distrib/inc/ui/testFont.h | 7 ++++ mp3/student-distrib/ui/compositor.cpp | 50 +++++++++++++++++++++++++ mp3/student-distrib/ui/testFont.cpp | 17 ++++++++- 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/mp3/student-distrib/inc/ui/compositor.h b/mp3/student-distrib/inc/ui/compositor.h index e72d84ea..83a18838 100644 --- a/mp3/student-distrib/inc/ui/compositor.h +++ b/mp3/student-distrib/inc/ui/compositor.h @@ -7,6 +7,7 @@ #include #include #include +#include using vbe::VBEMemHelp; @@ -95,11 +96,19 @@ class Compositor : public KeyB::IEvent { void drawSingle(const Container *d, const Rectangle &rect); void drawSingle(const Container *d, const Rectangle &rect, const Rectangle &difference); + void addText(int txtX, int txtY, char c); + Container *getElementAtPosition(int absX, int absY); + // Unit: text font width + int32_t txtX = 0; + public: virtual void key(uint32_t kkc, bool capslock) { + if(kkc &(~KKC_ASCII_MASK)) + return; + addText(txtX++, 0, (char)kkc); } // Down and Up cuts changes to ONE single key at a time. diff --git a/mp3/student-distrib/inc/ui/testFont.h b/mp3/student-distrib/inc/ui/testFont.h index bc10345e..3d9d6670 100644 --- a/mp3/student-distrib/inc/ui/testFont.h +++ b/mp3/student-distrib/inc/ui/testFont.h @@ -10,6 +10,13 @@ class TestFont : public Drawable { TestFont(); }; +/* +class Font : public Drawable { +public: + Font(int txtX, int txtY, char c); +}; +*/ + } #endif diff --git a/mp3/student-distrib/ui/compositor.cpp b/mp3/student-distrib/ui/compositor.cpp index 42cc9640..dbaa37c7 100644 --- a/mp3/student-distrib/ui/compositor.cpp +++ b/mp3/student-distrib/ui/compositor.cpp @@ -10,6 +10,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "title_bar.h" #include @@ -198,6 +203,51 @@ void Compositor::drawSingle(const Container *d, const Rectangle &_rect, const Re drawHelper.copyRegion(videoMemory, (uint8_t *)buildBuffer, rect.x1, rect.x2, rect.y1, rect.y2); } +using namespace filesystem; + +static uint8_t *renderRGBAFont(ArrFile &parser, int width, int height, char c) +{ + auto buffer = new uint8_t[CalcRGBASize(width * 40, height)]; + uint8_t *grayScaleFont = (uint8_t*) parser[(size_t)c]; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + uint8_t *pix = buffer + (y * width * 40 + x) * 4; + uint8_t *grayPix = grayScaleFont + (y * width + x); + pix[0] = 0; + pix[1] = 0; + pix[2] = 0; + pix[3] = grayPix[0]; + } + } + return buffer; +} + + +void Compositor::addText(int txtX, int txtY, char c) +{ + constexpr int NumFont = 94; + constexpr int FontWidth = 20; + constexpr int FontHeight = 42; + constexpr int FontCharSpacing = 0; + constexpr int FontLineSpacing = 8; + + Drawable* draw = new Drawable(20 * 40, 42,txtX * 20, txtY * 42); + File fontFile; + struct stat st; + theDispatcher->open(fontFile, "inconsolata_36.carr"); + theDispatcher->fstat(fontFile, &st); + const uint32_t size = st.st_size; + auto buffer = new uint8_t[size]; + theDispatcher->read(fontFile, buffer, size); + ArrFile* fileParser = ArrFile::getInstance((char*) buffer); + draw->pixelBuffer = renderRGBAFont(*fileParser, FontWidth, FontHeight, c); + theDispatcher->close(fontFile); + rootContainer->addChild(draw); + draw->show(); +} + void Compositor::drawNikita() { rootContainer = new Desktop(); diff --git a/mp3/student-distrib/ui/testFont.cpp b/mp3/student-distrib/ui/testFont.cpp index 14b86287..986663fc 100644 --- a/mp3/student-distrib/ui/testFont.cpp +++ b/mp3/student-distrib/ui/testFont.cpp @@ -14,7 +14,7 @@ constexpr int FontHeight = 42; constexpr int FontCharSpacing = 0; constexpr int FontLineSpacing = 8; -uint8_t *renderRGBAFont(ArrFile &parser, int width, int height) +static uint8_t *renderRGBAFont(ArrFile &parser, int width, int height) { auto buffer = new uint8_t[CalcRGBASize(width * 40, height)]; for (int i = 0; i < 40; i++) @@ -49,4 +49,19 @@ TestFont::TestFont() : Drawable(FontWidth * 40, FontHeight, 0, 0) { theDispatcher->close(fontFile); } +/* +Font::Font(int txtX, int txtY, char c) : Drawable(FontWidth * 40, FontHeight, x, 0) { + File fontFile; + struct stat st; + theDispatcher->open(fontFile, "inconsolata_36.carr"); + theDispatcher->fstat(fontFile, &st); + const uint32_t size = st.st_size; + auto buffer = new uint8_t[size]; + theDispatcher->read(fontFile, buffer, size); + ArrFile* fileParser = ArrFile::getInstance((char*) buffer); + pixelBuffer = renderRGBAFont(*fileParser, FontWidth, FontHeight); + theDispatcher->close(fontFile); +} +*/ + } From e8b18a18ecbd45147c374cf3909f22b213b50b7e Mon Sep 17 00:00:00 2001 From: C4Phone Date: Thu, 10 Dec 2015 14:05:28 -0600 Subject: [PATCH 2/3] better text --- mp3/student-distrib/inc/ui/compositor.h | 9 ++------- mp3/student-distrib/ui/compositor.cpp | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/mp3/student-distrib/inc/ui/compositor.h b/mp3/student-distrib/inc/ui/compositor.h index 83a18838..638426df 100644 --- a/mp3/student-distrib/inc/ui/compositor.h +++ b/mp3/student-distrib/inc/ui/compositor.h @@ -96,7 +96,7 @@ class Compositor : public KeyB::IEvent { void drawSingle(const Container *d, const Rectangle &rect); void drawSingle(const Container *d, const Rectangle &rect, const Rectangle &difference); - void addText(int txtX, int txtY, char c); + Drawable* addText(int txtX, int txtY, char c); Container *getElementAtPosition(int absX, int absY); @@ -104,12 +104,7 @@ class Compositor : public KeyB::IEvent { int32_t txtX = 0; public: - virtual void key(uint32_t kkc, bool capslock) - { - if(kkc &(~KKC_ASCII_MASK)) - return; - addText(txtX++, 0, (char)kkc); - } + virtual void key(uint32_t kkc, bool capslock); // Down and Up cuts changes to ONE single key at a time. virtual void keyDown(uint32_t kkc, bool capslock) diff --git a/mp3/student-distrib/ui/compositor.cpp b/mp3/student-distrib/ui/compositor.cpp index dbaa37c7..95eb959c 100644 --- a/mp3/student-distrib/ui/compositor.cpp +++ b/mp3/student-distrib/ui/compositor.cpp @@ -225,7 +225,7 @@ static uint8_t *renderRGBAFont(ArrFile &parser, int width, int height, char c) } -void Compositor::addText(int txtX, int txtY, char c) +Drawable* Compositor::addText(int txtX, int txtY, char c) { constexpr int NumFont = 94; constexpr int FontWidth = 20; @@ -246,6 +246,8 @@ void Compositor::addText(int txtX, int txtY, char c) theDispatcher->close(fontFile); rootContainer->addChild(draw); draw->show(); + + return draw; } void Compositor::drawNikita() @@ -288,6 +290,21 @@ void Compositor::enterTextMode() }); } +void Compositor::key(uint32_t kkc, bool capslock) +{ + if(kkc &(~KKC_ASCII_MASK)) + return; + static Drawable* all[10] = {0}; + all[txtX] = addText(txtX++, 0, (char)kkc); + if(txtX >= 10) + { + txtX = 0; + for(int i=0; i<10; i++) + (all[i])->hide(); + } + +} + // SYSCALLS From d02ae432efac233a0b0f0a5ef0620f9605ec3537 Mon Sep 17 00:00:00 2001 From: C4Phone Date: Thu, 10 Dec 2015 14:14:28 -0600 Subject: [PATCH 3/3] more --- mp3/student-distrib/ui/compositor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mp3/student-distrib/ui/compositor.cpp b/mp3/student-distrib/ui/compositor.cpp index 95eb959c..4d73376b 100644 --- a/mp3/student-distrib/ui/compositor.cpp +++ b/mp3/student-distrib/ui/compositor.cpp @@ -294,12 +294,12 @@ void Compositor::key(uint32_t kkc, bool capslock) { if(kkc &(~KKC_ASCII_MASK)) return; - static Drawable* all[10] = {0}; + static Drawable* all[40] = {0}; all[txtX] = addText(txtX++, 0, (char)kkc); - if(txtX >= 10) + if(txtX >= 40) { txtX = 0; - for(int i=0; i<10; i++) + for(int i=0; i<40; i++) (all[i])->hide(); }