# Draw grid and rulers only once

**URL:** <https://forum.juce.com/t/draw-grid-and-rulers-only-once/32102>\
**Category:** Development\
**Created:** [March 4, 2019, 9:48pm UTC](https://forum.juce.com/t/draw-grid-and-rulers-only-once/32102 "2019-03-04T21:48:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![obb64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/obb64/32/5545_2.png) [@obb64](https://forum.juce.com/u/obb64)\
**Post date:** [March 4, 2019, 9:48pm UTC](https://forum.juce.com/t/draw-grid-and-rulers-only-once/32102/1 "2019-03-04T21:48:48Z")

</div>

How can I draw a background grid only when resize or zoom, and draw the audio-signal or fft result over it with high frame rate. In my pure objectiveC app I could solve this with CALayer. Draw some layer (grid, ruler) only when resize, one layer for current time and other text informations in higher frame rate, and the audio signal as fast as possible.

My very old Application Sonifyer with CALayer. [Video: Sonifyer, Sonification of Tohoku Earthquake](https://www.youtube.com/watch?v=3PJxUPvz9Oo)

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [March 5, 2019, 9:41am UTC](https://forum.juce.com/t/draw-grid-and-rulers-only-once/32102/2 "2019-03-05T09:41:54Z")

</div>

It sounds like you want a buffered background image (which would be the only way I can see to “draw only once”).  
But I would advice against it, unless your background is very colourful and not made of simple geometries. Because you are trading drawing a few lines against a possibly expensive image copy (or even worse: scaling) function.  
If you want to try it out, I would use a Component with your rulers and set [`Component::setBufferedToImage (true);`](https://docs.juce.com/develop/classComponent.html#af19bbc2186e3297ddd55c328e46c014b). And then draw your fft or whatever as transparent component on top ([`setOpaque (false);`](https://docs.juce.com/develop/classComponent.html#a7320d543cba40183c894474ab78798ea)).

Having said that, in OpenGL that might worthwhile, since as texture it is already on graphics memory, so this could boost things. But I have only little experience with openGL, maybe someone else wants to chime in.

---

<div class="post-metadata">

**Author:** ![obb64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/obb64/32/5545_2.png) [@obb64](https://forum.juce.com/u/obb64)\
**Post date:** [March 5, 2019, 6:57pm UTC](https://forum.juce.com/t/draw-grid-and-rulers-only-once/32102/3 "2019-03-05T18:57:00Z")

</div>

Thanks Daniel.  
I’ve done a test with component’s, which do a repaint with different time intervals.

![guitest01_screen_v1](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/4/477b9a787b439513c99822bd127f7f57c76b8c9b.png)  
The source code and a screenshot can be found here.  
[github juce\_guitest01](https://github.com/obb64/juce_guitest01)  
I will now try to create a background component and a foreground component.
