1 /* 2 * Copyright 2012-2014, Adrien Destugues, pulkomandy@gmail.com 3 * Distributed under the terms of the MIT licence. 4 */ 5 6 7 #include <View.h> 8 9 extern "C" { 10 #include <vterm.h> 11 } 12 13 14 class TermView: public BView 15 { 16 public: 17 TermView(); 18 TermView(BRect bounds); 19 ~TermView(); 20 21 void AttachedToWindow(); 22 void Draw(BRect updateRect); 23 void FrameResized(float width, float height); 24 void GetPreferredSize(float* width, float* height); 25 void KeyDown(const char* bytes, int32 numBytes); 26 void MessageReceived(BMessage* message); 27 28 void PushBytes(const char* bytes, const size_t length); 29 30 private: 31 void _Init(); 32 33 VTermRect _PixelsToGlyphs(BRect pixels) const; 34 BRect _GlyphsToPixels(const VTermRect& glyphs) const; 35 BRect _GlyphsToPixels(const int width, const int height) 36 const; 37 void _GetCell(VTermPos pos, VTermScreenCell& cell); 38 39 void _Damage(VTermRect rect); 40 void _MoveCursor(VTermPos pos, VTermPos oldPos, 41 int visible); 42 void _PushLine(int cols, const VTermScreenCell* cells); 43 44 static int _Damage(VTermRect rect, void* user); 45 static int _MoveCursor(VTermPos pos, VTermPos oldPos, 46 int visible, void* user); 47 static int _PushLine(int cols, const VTermScreenCell* cells, 48 void* user); 49 static int _PopLine(int cols, const VTermScreenCell* cells, 50 void* user); 51 52 private: 53 VTerm* fTerm; 54 VTermScreen* fTermScreen; 55 BList fScrollBuffer; 56 int fFontWidth; 57 int fFontHeight; 58 59 static const VTermScreenCallbacks sScreenCallbacks; 60 61 static const int kDefaultWidth = 80; 62 static const int kDefaultHeight = 25; 63 static const int kBorderSpacing = 3; 64 static const int kScrollBackSize = 1000; 65 }; 66