2010-07-08 22:26:58 +00:00
|
|
|
/*
|
|
|
|
* Screen.h
|
|
|
|
* 2Term
|
|
|
|
*
|
|
|
|
* Created by Kelvin Sherlock on 7/7/2010.
|
|
|
|
* Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SCREEN_H__
|
|
|
|
#define __SCREEN_H__
|
|
|
|
|
|
|
|
#include "iGeometry.h"
|
2010-07-09 01:18:30 +00:00
|
|
|
#include "Lock.h"
|
2010-07-08 22:26:58 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
typedef struct char_info {
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
char_info() = default;
|
|
|
|
char_info(uint8_t cc, uint8_t ff) : c(cc), flag(ff) {}
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2016-07-11 02:25:39 +00:00
|
|
|
uint8_t c = 0;
|
|
|
|
uint8_t flag = 0;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
} char_info;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2010-12-23 03:42:04 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
typedef struct context {
|
|
|
|
uint8_t flags = 0;
|
|
|
|
iRect window;
|
2011-01-11 00:29:59 +00:00
|
|
|
iPoint cursor;
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
void setFlagBit(unsigned x) { flags |= x; }
|
|
|
|
void clearFlagBit(unsigned x) { flags &= ~x; }
|
|
|
|
} context;
|
|
|
|
|
2010-12-23 20:41:58 +00:00
|
|
|
|
2010-12-23 03:42:04 +00:00
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
class Screen {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
static const unsigned FlagNormal = 0x00;
|
|
|
|
static const unsigned FlagInverse = 0x01;
|
|
|
|
static const unsigned FlagMouseText = 0x02;
|
|
|
|
static const unsigned FlagBold = 0x04;
|
|
|
|
static const unsigned FlagUnderscore = 0x08;
|
|
|
|
static const unsigned FlagBlink = 0x10;
|
2011-01-12 03:43:41 +00:00
|
|
|
static const unsigned FlagStrike = 0x20;
|
|
|
|
|
2010-12-23 03:42:04 +00:00
|
|
|
static const unsigned FlagSelected = 0x8000;
|
2010-07-09 23:52:30 +00:00
|
|
|
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
/*
|
2010-07-21 01:30:31 +00:00
|
|
|
enum EraseRegion {
|
|
|
|
EraseAll,
|
|
|
|
EraseBeforeCursor,
|
|
|
|
EraseAfterCursor,
|
|
|
|
|
|
|
|
EraseLineAll,
|
|
|
|
EraseLineBeforeCursor,
|
|
|
|
EraseLineAfterCursor
|
|
|
|
};
|
2017-02-16 00:26:45 +00:00
|
|
|
*/
|
2011-02-03 02:41:21 +00:00
|
|
|
enum CursorType {
|
2011-02-05 01:46:53 +00:00
|
|
|
CursorTypeNone,
|
|
|
|
CursorTypeUnderscore,
|
|
|
|
CursorTypePipe,
|
|
|
|
CursorTypeBlock
|
2011-02-03 02:41:21 +00:00
|
|
|
};
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
Screen(unsigned height = 24, unsigned width = 80);
|
2010-07-21 01:30:31 +00:00
|
|
|
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
virtual ~Screen();
|
|
|
|
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
int x() const;
|
|
|
|
int y() const;
|
|
|
|
|
|
|
|
iPoint cursor() const;
|
|
|
|
|
2010-12-24 20:00:44 +00:00
|
|
|
int height() const;
|
|
|
|
int width() const;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
void setCursor(iPoint point);
|
2011-01-11 00:29:59 +00:00
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
|
2011-01-11 00:29:59 +00:00
|
|
|
|
2017-02-16 18:06:20 +00:00
|
|
|
void putc(uint8_t c, iPoint cursor, uint8_t flags = 0);
|
|
|
|
void putc(uint8_t c, const context &ctx) { putc(c, ctx.cursor, ctx.flags); }
|
2017-02-16 00:26:45 +00:00
|
|
|
|
|
|
|
char_info getc(iPoint p) const;
|
|
|
|
|
2010-07-21 01:30:31 +00:00
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
void eraseScreen();
|
2010-07-17 18:21:26 +00:00
|
|
|
void eraseRect(iRect rect);
|
|
|
|
|
2017-02-17 03:54:52 +00:00
|
|
|
void fillScreen(char_info ci);
|
|
|
|
void fillRect(iRect rect, char_info ci);
|
|
|
|
|
2010-07-17 18:21:26 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
void scrollUp();
|
|
|
|
void scrollUp(iRect window);
|
|
|
|
|
|
|
|
void scrollDown();
|
|
|
|
void scrollDown(iRect window);
|
2010-12-23 20:41:58 +00:00
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2017-02-18 18:00:18 +00:00
|
|
|
void scrollLeft(int n = 1);
|
|
|
|
void scrollLeft(iRect window, int n = 1);
|
|
|
|
|
|
|
|
void scrollRight(int n = 1);
|
|
|
|
void scrollRight(iRect window, int n = 1);
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2010-12-23 20:41:58 +00:00
|
|
|
void deleteLine(unsigned line);
|
|
|
|
void insertLine(unsigned line);
|
2010-07-17 18:21:26 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
//void deletec();
|
|
|
|
//void insertc(uint8_t c);
|
2010-12-24 20:00:44 +00:00
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
void beginUpdate();
|
|
|
|
iRect endUpdate();
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
|
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
virtual void setSize(unsigned width, unsigned height);
|
2011-02-05 01:46:53 +00:00
|
|
|
|
|
|
|
virtual void setCursorType(CursorType cursor);
|
|
|
|
CursorType cursorType() const;
|
2010-07-12 02:18:37 +00:00
|
|
|
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
private:
|
2011-01-11 00:29:59 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
iRect _frame;
|
|
|
|
iPoint _cursor;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2011-02-05 01:46:53 +00:00
|
|
|
CursorType _cursorType;
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
|
|
|
|
Lock _lock;
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
std::vector< std::vector< char_info > > _screen;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
|
|
|
std::vector<iPoint> _updates;
|
2010-07-12 02:18:37 +00:00
|
|
|
iPoint _updateCursor;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
typedef std::vector< std::vector< char_info > >::iterator ScreenIterator;
|
|
|
|
typedef std::vector< std::vector< char_info > >::reverse_iterator ReverseScreenIterator;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
typedef std::vector<char_info>::iterator CharInfoIterator;
|
2010-07-08 22:26:58 +00:00
|
|
|
typedef std::vector<iPoint>::iterator UpdateIterator;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
inline int Screen::x() const
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
return _cursor.x;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
inline int Screen::y() const
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
return _cursor.y;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
inline iPoint Screen::cursor() const
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
return _cursor;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-05 01:46:53 +00:00
|
|
|
inline Screen::CursorType Screen::cursorType() const
|
|
|
|
{
|
|
|
|
return _cursorType;
|
|
|
|
}
|
|
|
|
|
2010-12-24 20:00:44 +00:00
|
|
|
inline int Screen::height() const
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
return _frame.size.height;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 20:00:44 +00:00
|
|
|
inline int Screen::width() const
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
return _frame.size.width;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
inline void Screen::setCursor(iPoint point)
|
2010-07-08 22:26:58 +00:00
|
|
|
{
|
2017-02-17 03:54:52 +00:00
|
|
|
if (point.x >= _frame.width()) point.x = _frame.width() - 1;
|
|
|
|
if (point.y >= _frame.height()) point.y = _frame.height() - 1;
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
_cursor = point;
|
2010-07-08 22:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
inline void Screen::lock()
|
|
|
|
{
|
|
|
|
_lock.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Screen::unlock()
|
|
|
|
{
|
|
|
|
_lock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-16 00:26:45 +00:00
|
|
|
inline char_info Screen::getc(iPoint p) const
|
2010-07-09 01:18:30 +00:00
|
|
|
{
|
2017-02-16 00:26:45 +00:00
|
|
|
if (_frame.contains(p)) return _screen[p.y][p.x];
|
|
|
|
return char_info();
|
2010-07-09 01:18:30 +00:00
|
|
|
}
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
#endif
|