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

How to set the width of dashed lines & Why do the dashed lines blink #91

Open
ChauncyZhang opened this issue Jul 28, 2024 · 5 comments
Open

Comments

@ChauncyZhang
Copy link

ChauncyZhang commented Jul 28, 2024

`GrSetGCForeground(gc_, BLACK);
GrFillRect(back_buffer_id_, gc_, 0, 0, screen_info_.cols,
screen_info_.rows);
GrArea(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows,
(void*)frame.data, MWPF_PIXELVAL);

DrawText("Please press confirm after overlap", screen_info_.cols / 2, 200);
GrSetGCForeground(gc_, GR_COLOR_RED);
DrawDashedLine(wid_, gc_, x - 200, y, x + 200, y);
DrawDashedLine(wid_, gc_, x, y - 200, x, y + 200);

GrCopyArea(wid_, gc_, 0, 0, screen_info_.cols, screen_info_.rows,
back_buffer_id_, 0, 0, MWROP_SRC);

GrFlush();`

The text and image show well, but the dashed lines always blink, and seem like the layer is below the image, but I can see the dashed line.
I have two questions, 1. Why does the dashed line blink, 2. How to set the width of dashed lines?

@ghaerr
Copy link
Owner

ghaerr commented Jul 28, 2024

Hello @ChauncyZhang,

I am not sure why dashed lines blink, as Nano-X doesn't support blinking directly with graphics draw. Can you describe your framebuffer hardware, does it support hardware blinking with some color combinations? Perhaps try drawing with a different color than GR_COLOR_RED to see if any difference results.

Please post a screenshot or photo so I can get a better understanding of how layer is below image.

To set the dashed line width and/or dash count, use GrSetGCDash and see the documentation for it.

Thank you!

@ChauncyZhang
Copy link
Author

https://github.com/user-attachments/assets/c1285709-e0b0-47e6-a418-cf994f463751
Hello,
Like that, I don't want it blink.

@ghaerr
Copy link
Owner

ghaerr commented Jul 29, 2024

Hmmm, it seems that the blinking may be the result of the background being erased and then the image redrawn, which produces a flicker. Flicker is not the same as blink, so I misunderstood your problem. In order to remove flicker, one must either 1) redraw the background that changed, then redraw the foreground without background bits, or 2) redraw the entire background and foreground at the same time, without erasing the screen beforehand.

That said, does this occur only when using dashed lines, or have you looked at the result using solid lines instead with no problems?

@ChauncyZhang
Copy link
Author

`GrSetGCForeground(gc_, BLACK);
GrFillRect(back_buffer_id_, gc_, 0, 0, screen_info_.cols,
screen_info_.rows);
GrArea(back_buffer_id_, gc_, 0, 0, screen_info_.cols, screen_info_.rows,
(void*)frame.data, MWPF_PIXELVAL);

DrawText("Please press confirm after overlap", screen_info_.cols / 2, 200);
CrossDividingLine(screen_info_.cols / 2, screen_info_.rows / 2);

GrCopyArea(wid_, gc_, 0, 0, screen_info_.cols, screen_info_.rows,
           back_buffer_id_, 0, 0, MWROP_SRC);

GrFlush();`

`void ns::Render::CrossDividingLine(int x, int y) {
GrSetGCForeground(gc_, GR_COLOR_RED);
DrawDashedLine(wid_, gc_, x - 200, y, x + 200, y);
DrawDashedLine(wid_, gc_, x, y - 200, x, y + 200);
}

void Render::DrawDashedLine(GR_WINDOW_ID window,
GR_GC_ID gc,
int x1,
int y1,
int x2,
int y2) {
char dash2[2] = {10, 4};
GrSetGCDash(gc, dash2, 2);
GrSetGCLineAttributes(gc, GR_LINE_ONOFF_DASH);
GrLine(window, gc, x1, y1, x2, y2);
}`

Every frame is refreshed. When drawing, I will delete the screen and copy back_buffer to the window, what is the problem with the process?
Thanks!

@ghaerr
Copy link
Owner

ghaerr commented Jul 30, 2024

what is the problem with the process?

I am not sure, I don't have the time to debug your code right now. You haven't answered the question I asked, does this happen only with dashed lines or will it work without them? We need to eliminate variables to get root of the problem.

When drawing, I will delete the screen

What do you mean "delete the screen"? If that involves a repaint of background, then you will see flicker, even when using a back buffer.

You might try setting background color to WHITE instead of black, this method shows sometimes when background is being drawn differently by different graphics calls to help debug why the display is flickering.

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

No branches or pull requests

2 participants