diff --git a/mp3/student-distrib/inc/ui/compositor.h b/mp3/student-distrib/inc/ui/compositor.h index e72d84ea..638426df 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,12 +96,15 @@ class Compositor : public KeyB::IEvent { void drawSingle(const Container *d, const Rectangle &rect); void drawSingle(const Container *d, const Rectangle &rect, const Rectangle &difference); + Drawable* 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) - { - } + 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/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 00e40d74..c75f2f8d 100644 --- a/mp3/student-distrib/ui/compositor.cpp +++ b/mp3/student-distrib/ui/compositor.cpp @@ -11,6 +11,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "title_bar.h" #include "button.h" @@ -208,6 +213,53 @@ 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; +} + + +Drawable* 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(); + + return draw; +} + void Compositor::drawNikita() { rootContainer = new Desktop(); @@ -248,6 +300,21 @@ void Compositor::enterTextMode() }); } +void Compositor::key(uint32_t kkc, bool capslock) +{ + if(kkc &(~KKC_ASCII_MASK)) + return; + static Drawable* all[40] = {0}; + all[txtX] = addText(txtX++, 0, (char)kkc); + if(txtX >= 40) + { + txtX = 0; + for(int i=0; i<40; i++) + (all[i])->hide(); + } + +} + // SYSCALLS // 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); +} +*/ + }