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

Multiple scissors #652

Open
Miska711 opened this issue Jan 11, 2023 · 3 comments
Open

Multiple scissors #652

Miska711 opened this issue Jan 11, 2023 · 3 comments

Comments

@Miska711
Copy link

Miska711 commented Jan 11, 2023

Hi people,

I have situation when I need two scissors. I create the list of multiline textviews placed on scrollview.

First scissor cuts text lines of textview to match it's width and height. This works well, I implemented it without issues. Then I place several textviews on scrollview. And textviews should be scissored second time to match width and height of the scrollview. This I still cant get to work.

Can someone help me please? Is it possible?

@mulle-nat
Copy link
Contributor

If you first set the scissor for the scrollview and then for each textview, you do save the context, then intersect the scrollview scissor with the textview scissor and after drawing you restore the state, wouldn't that work ?

@Miska711
Copy link
Author

Miska711 commented Jan 11, 2023

Hm, seems it does not work. Here is pseudocode how i do it

void draw() {
  nvgBeginFrame();
    scrollView->draw();
  nvgEndFrame();
}

void ScrollView::draw() {
  nvgScissor(vg, x, y, w, h);

  for (int i=0; i< 10; i++) {
     textView[i]->draw();
  }
}

void TextView::draw() {
  nvgSave(vg);
  nvgScissor(vg, x, y, w, h);
  nvgText(vg, x,y, "text", NULL); 
  nvgRestore(vg);
}


EDIT: I replaced nvgScissor in TextView with nvgIntersectScissor and it seems to work. Thank you.

Btw, I start my "void draw()" function, which is main application drawing loop with void nvgBeginFrame. And between nvgBeginFrame and nvgEndFrame I mix my own drawing functions using standard opengl es 2.0 commands and nanovg commands. I experienced few problems, which I work-arounded somehow. Should I avoid it? Instead, should I split it and use nanovg drawing in multiple local nvgBeginFrame/nvgEndFrame blocks?

@mulle-nat
Copy link
Contributor

mulle-nat commented Jan 11, 2023

nanovg collects all the draw commands and then at nvgEndFrame paints them all at once. When you mix OpenGL with nanovg, you can draw on top (after nvgEndFrame) or below (before) it.
It just gets confusing in the long run, if you don't have a clean separation of OpenGL drawing and nanovg. Because you see draw commands, which look like they are intertwined but actually they are not. So I would go with multiple nvgBeginFrame/nvgEndFrame blocks.

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