<commit_before>///<reference path="layer/Layer.ts"/>
///<reference path="tools/ListenableTool.ts"/>
///<reference path="tools/drawingTool/Pencil.ts"/>

import Layer = Layers.Layer;
import Pencil = Tools.Pencil;
import Tool = Tools.Tool;

module Main {
    export class JustCanvas {
        private mainLayer:Layer;
        private backgroundLayer:Layer;
        private tool:Tool;
        private onChangeListeners = [];
        private currentToolEvents:{[type: string]: Function} = {};
        private onToolRenderListener = (eventArgs) => this.onChangeListeners.forEach(listener => listener(this.tool, eventArgs));

        constructor(divId = 'just-canvas', canvasWidth = '500px', canvasHeight = '500px') {
            this.mainLayer = new Layer(divId, 0, canvasWidth, canvasHeight, "main");
            this.backgroundLayer = new Layer(divId, -99, canvasWidth, canvasHeight, "background");
        }

        get getContext() {
            return this.mainLayer.context;
        }

        public getCanvasOffset() {
            return {left: this.mainLayer.canvas.offsetLeft, top: this.mainLayer.canvas.offsetTop}
        }

        public addCanvasEventListener(type:string, handler:Function) {
            this.currentToolEvents[type] = handler;

            return this.mainLayer.canvas.addEventListener(type, handler);
        }

        public use(tool:Tool) {
            this.removeCurrentToolEvents(tool);

            tool.registerEvents(this);
            tool.addOnRenderListener(this.onToolRenderListener);
        }

        public addOnChangeListener(listener:Function) {
            this.onChangeListeners.push(listener);
        }

        public removeOnChangeListener(listener:Function) {
            this.tool.removeOnRenderListener(this.onToolRenderListener);<commit_msg>Added the ability to set background image.<commit_after>///<reference path="layer/Layer.ts"/>
///<reference path="tools/ListenableTool.ts"/>
///<reference path="tools/drawingTool/Pencil.ts"/>

import Layer = Layers.Layer;
import Pencil = Tools.Pencil;
import Tool = Tools.Tool;

module Main {
    export class JustCanvas {
        private mainLayer:Layer;
        private backgroundLayer:Layer;
        private tool:Tool;
        private onChangeListeners = [];
        private currentToolEvents:{[type: string]: Function} = {};
        private onToolRenderListener = (eventArgs) => this.onChangeListeners.forEach(listener => listener(this.tool, eventArgs));

        constructor(divId = 'just-canvas', canvasWidth = '500px', canvasHeight = '500px') {
            this.mainLayer = new Layer(divId, 0, canvasWidth, canvasHeight, "main");
            this.backgroundLayer = new Layer(divId, -99, canvasWidth, canvasHeight, "background");
        }

        get getContext() {
            return this.mainLayer.context;
        }

        public getCanvasOffset() {
            return {left: this.mainLayer.canvas.offsetLeft, top: this.mainLayer.canvas.offsetTop}
        }

        public addCanvasEventListener(type:string, handler:Function) {
            this.currentToolEvents[type] = handler;

            return this.mainLayer.canvas.addEventListener(type, handler);
        }

        public use(tool:Tool) {
            this.removeCurrentToolEvents(tool);

            tool.registerEvents(this);
            tool.addOnRenderListener(this.onToolRenderListener);
        }

        public setBackgroundImage(src){
            var imageObj = new Image();

            imageObj.onload = () => this.backgroundLayer.context.drawImage(imageObj, 0, 0);

            imageObj.src = src;
        }

        public addOnChangeListener(listener:Function) {
            this.onChangeListeners.push(listener);
        }

        public removeOnChangeListener(listener:Function) {
            this.tool.removeOnRenderListener(this.onToolRenderListener);
{'fraction_non_alphanumeric': 0.1125, 'fraction_numerical': 0.005208333333333333, 'mean_word_length': 2.765686274509804, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693789', 'n_tokens_mistral': 1029, 'n_tokens_neox': 995, 'n_words': 193}