Handle colors.

This commit is contained in:
Adrien Destugues - PulkoMandy
2012-11-05 15:22:33 +01:00
parent d481cb7370
commit 5d6ec6d03a
2 changed files with 53 additions and 5 deletions
+51 -4
View File
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <Entry.h>
#include <File.h>
#include <Layout.h>
#include "SerialApp.h"
@@ -72,6 +74,28 @@ void TermView::Draw(BRect updateRect)
VTermScreenCell cell;
vterm_screen_get_cell(fTermScreen, pos, &cell);
rgb_color foreground, background;
foreground.red = cell.fg.red;
foreground.green = cell.fg.green;
foreground.blue = cell.fg.blue;
background.red = cell.bg.red;
background.green = cell.bg.green;
background.blue = cell.bg.blue;
if(cell.attrs.reverse) {
SetLowColor(foreground);
SetViewColor(foreground);
SetHighColor(background);
} else {
SetLowColor(background);
SetViewColor(background);
SetHighColor(foreground);
}
BPoint penLocation = PenLocation();
FillRect(BRect(penLocation.x, penLocation.y - height.ascent,
penLocation.x + cell.width * fFontWidth, penLocation.y), B_SOLID_LOW);
if (cell.chars[0] == 0) {
DrawString(" ");
pos.col ++;
@@ -89,6 +113,14 @@ void TermView::Draw(BRect updateRect)
}
void TermView::FrameResized(float width, float height)
{
VTermRect newSize = PixelsToGlyphs(BRect(0, 0, width - 2 * kBorderSpacing,
height - 2 * kBorderSpacing));
vterm_set_size(fTerm, newSize.end_row, newSize.end_col);
}
void TermView::GetPreferredSize(float* width, float* height)
{
if (width != NULL)
@@ -106,11 +138,23 @@ void TermView::KeyDown(const char* bytes, int32 numBytes)
}
void TermView::FrameResized(float width, float height)
void TermView::MessageReceived(BMessage* message)
{
VTermRect newSize = PixelsToGlyphs(BRect(0, 0, width - 2 * kBorderSpacing,
height - 2 * kBorderSpacing));
vterm_set_size(fTerm, newSize.end_row, newSize.end_col);
switch(message->what)
{
case 'DATA':
{
entry_ref ref;
if(message->FindRef("refs", &ref) == B_OK)
{
// The user just dropped a file on us
// TODO send it by XMODEM or so
}
break;
}
default:
BView::MessageReceived(message);
}
}
@@ -120,6 +164,9 @@ void TermView::PushBytes(const char* bytes, size_t length)
}
//#pragma mark -
VTermRect TermView::PixelsToGlyphs(BRect pixels) const
{
pixels.OffsetBy(-kBorderSpacing, -kBorderSpacing);
+2 -1
View File
@@ -18,9 +18,10 @@ class TermView: public BView
void AttachedToWindow();
void Draw(BRect updateRect);
void FrameResized(float width, float height);
void GetPreferredSize(float* width, float* height);
void KeyDown(const char* bytes, int32 numBytes);
void FrameResized(float width, float height);
void MessageReceived(BMessage* message);
void PushBytes(const char* bytes, const size_t length);
private: