Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/textOnly'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yifei Teng committed Dec 10, 2015
2 parents 8468e10 + d02ae43 commit a3a185c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
10 changes: 7 additions & 3 deletions mp3/student-distrib/inc/ui/compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <inc/ui/vbe.h>
#include <inc/klibs/maybe.h>
#include <inc/drivers/ievent.h>
#include <inc/drivers/kkc.h>

using vbe::VBEMemHelp;

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions mp3/student-distrib/inc/ui/testFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class TestFont : public Drawable {
TestFont();
};

/*
class Font : public Drawable {
public:
Font(int txtX, int txtY, char c);
};
*/

}

#endif
67 changes: 67 additions & 0 deletions mp3/student-distrib/ui/compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <inc/klibs/stack.h>
#include <inc/proc/tasks.h>
#include <inc/klibs/maybe.h>
#include <inc/drivers/kkc.h>
#include <inc/ui/testFont.h>
#include <inc/fs/filesystem.h>
#include <inc/klibs/arrFile.h>
#include <inc/fs/stat.h>

#include "title_bar.h"
#include "button.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
//
Expand Down
17 changes: 16 additions & 1 deletion mp3/student-distrib/ui/testFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
}
*/

}

0 comments on commit a3a185c

Please sign in to comment.