mirror of https://github.com/cy384/ssheven.git
add blinking cursor
This commit is contained in:
parent
847991fc07
commit
074059f648
|
@ -14,8 +14,24 @@ void draw_char(int x, int y, Rect* r, char c)
|
||||||
DrawChar(c);
|
DrawChar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggle_cursor(void)
|
||||||
|
{
|
||||||
|
con.cursor_state = !con.cursor_state;
|
||||||
|
Rect cursor = cell_rect(con.cursor_x, con.cursor_y, con.win->portRect);
|
||||||
|
InvalRect(&cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check_cursor(void)
|
||||||
|
{
|
||||||
|
long int now = TickCount();
|
||||||
|
if ((now - con.last_cursor_blink) > GetCaretTime())
|
||||||
|
{
|
||||||
|
toggle_cursor();
|
||||||
|
con.last_cursor_blink = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// closely inspired by the retro68 console library
|
||||||
void draw_screen(Rect* r)
|
void draw_screen(Rect* r)
|
||||||
{
|
{
|
||||||
// get the intersection of our console region and the update region
|
// get the intersection of our console region and the update region
|
||||||
|
@ -42,7 +58,20 @@ void draw_screen(Rect* r)
|
||||||
for(int i = minRow; i < maxRow; i++)
|
for(int i = minRow; i < maxRow; i++)
|
||||||
{
|
{
|
||||||
for (int j = minCol; j < maxCol; j++)
|
for (int j = minCol; j < maxCol; j++)
|
||||||
|
{
|
||||||
draw_char(j, i, r, con.data[j][i]);
|
draw_char(j, i, r, con.data[j][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// do the cursor if needed
|
||||||
|
if (con.cursor_state == 1 &&
|
||||||
|
con.cursor_y >= minRow &&
|
||||||
|
con.cursor_y <= maxRow &&
|
||||||
|
con.cursor_x >= minCol &&
|
||||||
|
con.cursor_x <= maxCol)
|
||||||
|
{
|
||||||
|
Rect cursor = cell_rect(con.cursor_x, con.cursor_y, con.win->portRect);
|
||||||
|
InvertRect(&cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFont(save_font);
|
TextFont(save_font);
|
||||||
|
|
|
@ -30,3 +30,6 @@ void set_window_title(WindowPtr w, const char* c_name);
|
||||||
void ruler(Rect* r);
|
void ruler(Rect* r);
|
||||||
|
|
||||||
Rect cell_rect(int x, int y, Rect bounds);
|
Rect cell_rect(int x, int y, Rect bounds);
|
||||||
|
|
||||||
|
void toggle_cursor(void);
|
||||||
|
void check_cursor(void);
|
||||||
|
|
10
ssheven.c
10
ssheven.c
|
@ -16,7 +16,7 @@
|
||||||
#define SSH_CHECK(X) rc = (X); if (rc != LIBSSH2_ERROR_NONE) { printf_i("" #X " failed: %s\n", libssh2_error_string(rc)); return 0;};
|
#define SSH_CHECK(X) rc = (X); if (rc != LIBSSH2_ERROR_NONE) { printf_i("" #X " failed: %s\n", libssh2_error_string(rc)); return 0;};
|
||||||
|
|
||||||
// sinful globals
|
// sinful globals
|
||||||
struct ssheven_console con = { NULL, {0}, 0, 0, 0 , 0 };
|
struct ssheven_console con = { NULL, {0}, 0, 0, 0, 0, 0, 0};
|
||||||
struct ssheven_ssh_connection ssh_con = { NULL, NULL, kOTInvalidEndpointRef, NULL, NULL };
|
struct ssheven_ssh_connection ssh_con = { NULL, NULL, kOTInvalidEndpointRef, NULL, NULL };
|
||||||
|
|
||||||
enum { WAIT, READ, EXIT } read_thread_command = WAIT;
|
enum { WAIT, READ, EXIT } read_thread_command = WAIT;
|
||||||
|
@ -274,10 +274,16 @@ void event_loop(void)
|
||||||
while (!WaitNextEvent(everyEvent, &event, sleep_time, NULL))
|
while (!WaitNextEvent(everyEvent, &event, sleep_time, NULL))
|
||||||
{
|
{
|
||||||
// timed out without any GUI events
|
// timed out without any GUI events
|
||||||
// let any other threads run before we wait for events again
|
// toggle our cursor if needed
|
||||||
|
check_cursor();
|
||||||
|
|
||||||
|
// then let any other threads run before we wait for events again
|
||||||
YieldToAnyThread();
|
YieldToAnyThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// might need to toggle our cursor even if we got an event
|
||||||
|
check_cursor();
|
||||||
|
|
||||||
// handle any mac gui events
|
// handle any mac gui events
|
||||||
char c = 0;
|
char c = 0;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
Loading…
Reference in New Issue