Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
3150_project/ECEditor.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
109 lines (76 sloc)
3.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ECEditor.h | |
// | |
// created by Daniel Backal | |
// 02/04/2020 | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#ifndef ECEDITOR_H | |
#define ECEDITOR_H | |
#include <string> | |
#include <vector> | |
#include "ECTextViewImp.h" | |
#include "ECCommand.h" | |
#include "ECRow.h" | |
/* | |
TextDocument is the model being updated by the editor below. | |
All commands will edit this file | |
This file will then give the editor all of its rows. | |
*/ | |
class ECDocument | |
{ | |
public: | |
ECDocument(); | |
virtual ~ECDocument(); | |
void SetPageDimensions(int x, int y); // Sets page size, for cursor position and doc position difference | |
int GetDocLen(); // Get num of lines in doc | |
int GetRowSizeAt(int y); // Get row sizes ofr cursor stuff | |
char GetCharAt(int x, int y); // Get char at current position | |
int GetXCursor(); // These functions take away the need to know about the editor | |
int GetYCursor(); | |
void MoveCursor(int key); // Moves the cursor around for the editor to refer to. | |
std::string GetRowAt(int y); // Return the row for updating screen | |
void InsertCharAt(int x, int y, int key); // Insert a single char at position | |
void RemoveCharAt(int x, int y); // Erase a single char at position | |
void InsertEnterAt(int x, int y); // Inserts an enter | |
void MoveWordDown(std::string word); | |
void MoveWordUp(); | |
private: | |
/* | |
This must be a vector of rows instead. | |
Row type must be glyph or something. Hmm. | |
For now, just use strings, to make Milestone 1 work again. | |
*/ | |
std::vector<ECRow> _document; | |
int _xcursor; | |
int _ycursor; | |
int _ydoc; // dont need an extra _xdoc because the _xcursor and _xdoc never separate | |
int _colInView; | |
int _rowInView; | |
}; | |
// Editor is Controller (Model View Controller Model) | |
// Will call Update - Will have list of commands, all edit a document | |
// Document will, then, store information (text) to update the view (TextViewImp) | |
class ECEditor : public ECObserver | |
{ | |
public: | |
ECEditor(); | |
~ECEditor(); | |
void StartEditor(); // Creates a window and starts the editor | |
void Update(); // Updates editor (refreshes window, notifies key changes, etc) | |
void UpdateCursor(); // Moves cursor from update | |
void Enter(int x, int y); // Runs Enter Command | |
void AddText(int x, int y, int key); // Runs Insert Command | |
void Backspace(int x, int y); // Runs Remove Command | |
void UpdateScreen(); // To be called after typing, or backspace. | |
private: | |
// Needs to have a text view object... | |
ECTextViewImp _window; | |
// Needs command history for undo and redo | |
ECCommandHistory *_histCmds; | |
// Doc object | |
ECDocument _doc; | |
// For cursor manipulation and updating screen: | |
int _maxRowSize; | |
int _maxRows; | |
}; | |
#endif | |