From 5d6ec6d03a891b68cdb52bd21430bc4f338f8773 Mon Sep 17 00:00:00 2001 From: Adrien Destugues - PulkoMandy Date: Mon, 5 Nov 2012 15:20:43 +0100 Subject: [PATCH] Handle colors. --- src/apps/serialconnect/TermView.cpp | 55 ++++++++++++++++++++++++++--- src/apps/serialconnect/TermView.h | 3 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/apps/serialconnect/TermView.cpp b/src/apps/serialconnect/TermView.cpp index d977222576..60acc832c0 100644 --- a/src/apps/serialconnect/TermView.cpp +++ b/src/apps/serialconnect/TermView.cpp @@ -8,6 +8,8 @@ #include +#include +#include #include #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); diff --git a/src/apps/serialconnect/TermView.h b/src/apps/serialconnect/TermView.h index 50c8c7e63d..a673489b8e 100644 --- a/src/apps/serialconnect/TermView.h +++ b/src/apps/serialconnect/TermView.h @@ -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: