Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping lines #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

farellukas
Copy link

About

This pull request adds two new functions, GLIR_PrintOVLine and GLIR_PrintOHLine, to the GLIR (Graphics Library for Interactive RISC-V) codebase. These functions are designed to print overlapping vertical and horizontal lines on the screen, respectively, without requiring the screen to be cleared before each update.

Motivation

I was creating a CMPUT 229 lab assignment using GLIR (mostly printing plain, solid-colored, straight lines) that had many screen updates. I tried using the Clear and Refresh method for the updates, but realized it resulted in annoying flickers due to the latency from needing to clear the screen and printing many lines. The Batch Print method would also be excessive for this lab assignment and slow. Due to these limitations, I decided to make my own function that overlaps the line underneath by printing a straight line and filling the areas that the line does not span the default terminal color. It is essentially following the Clear and Refresh method without clearing the screen, thus, reduce the aforementioned flickers.

Usage

GLIR_PrintOVLine

The GLIR_PrintOVLine function takes four arguments:

  • a0: Column position of the line
  • a1: Starting row position of the line
  • a2: Ending row position of the line
  • a3: Color to print the line with

This function prints an overlapping vertical line on the screen between the points (Row1, Col) and (Row2, Col). It ensures that the area outside the line (above Row1 and below Row2) remains the default background, allowing for overlapping lines without screen clearing. This feature is particularly useful for smooth animations and eliminates flickering caused by frequent screen clears.

GLIR_PrintOHLine

The GLIR_PrintOHLine function takes four arguments:

  • a0: Row position of the line
  • a1: Starting column position of the line
  • a2: Ending column position of the line
  • a3: Color to print the line with

Similarly, this function prints an overlapping horizontal line on the screen between the points (Row, Col1) and (Row, Col2). It maintains a default background outside the line's range (to the left of Col1 and to the right of Col2), allowing for seamless overlapping of lines without the need for screen clearing.

Implementation

Both functions use the existing GLIR_PrintString function to print the line characters and leverage the GLIR_SetColor and GLIR_RestoreSettings functions to manage the line color.

Remarks

These additions provide efficient alternatives for updating the screen in graphics-intensive applications with many updates and enhance the GLIR library's capabilities.

I am open to feedback and willing to make any necessary changes to this pull request. Please don't hesitate to reach out if there are any suggestions or improvements that you would like to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant