Skip to content

Commit

Permalink
Extract canvas drawing in a mixin and include it in minimap element
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 15, 2014
1 parent b1911a9 commit fc54dd1
Show file tree
Hide file tree
Showing 3 changed files with 377 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{CompositeDisposable} = require 'event-kit'
DOMStylesReader = require './mixins/dom-styles-reader'
CanvasDrawer = require './mixins/canvas-drawer'

class MinimapElement extends HTMLElement
DOMStylesReader.includeInto(this)
CanvasDrawer.includeInto(this)

createdCallback: ->
@subscriptions = new CompositeDisposable
@initializeContent()
Expand All @@ -25,15 +30,12 @@ class MinimapElement extends HTMLElement
@minimap

initializeContent: ->
@initializeCanvas()

@shadowRoot = @createShadowRoot()

@canvas = document.createElement('canvas')
@context = @canvas.getContext('2d')
@shadowRoot.appendChild(@canvas)

@offscreenCanvas = document.createElement('canvas')
@offscreenContext = @offscreenCanvas.getContext('2d')

@visibleArea = document.createElement('div')
@visibleArea.classList.add('minimap-visible-area')
@shadowRoot.appendChild(@visibleArea)
Expand All @@ -47,14 +49,22 @@ class MinimapElement extends HTMLElement
@canvas.width = width * devicePixelRatio
@canvas.height = height * devicePixelRatio

getTextEditor: -> @minimap.getTextEditor()

getTextEditorElement: ->
@editorElement ?= atom.views.getView(@minimap.getTextEditor())
@editorElement ?= atom.views.getView(@getTextEditor())

getTextEditorElementRoot: ->
editorElement = @getTextEditorElement()

editorElement.shadowRoot ? editorElement

getDummyDOMRoot: (shadowRoot) ->
if shadowRoot
@getTextEditorElementRoot()
else
@getTextEditorElement()

requestUpdate: ->
return if @frameRequested

Expand All @@ -69,6 +79,8 @@ class MinimapElement extends HTMLElement
@visibleArea.style.top = (@minimap.getTextEditorScrollTop() - @minimap.getMinimapScrollTop()) + 'px'
@visibleArea.style.left = (@minimap.getTextEditorScrollLeft()) + 'px'

@updateCanvas()

# ######## ## ######## ## ## ######## ## ## ########
# ## ## ## ### ### ## ### ## ##
# ## ## ## #### #### ## #### ## ##
Expand Down
2 changes: 2 additions & 0 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Minimap extends Model

getCharHeight: -> @charWidth

getInterline: -> @interline

getFirstVisibleScreenRow: ->
Math.floor(@getMinimapScrollTop() / @getLineHeight())

Expand Down
Loading

0 comments on commit fc54dd1

Please sign in to comment.