Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace SL_SchedGridColumnRangeContent {
  2.     export class RangeStripBase implements IGetParent<SL_SchedGridColumnRange>{
  3.         private columnRange: SL_SchedGridColumnRange;
  4.         private settings: StripSettings;
  5.        
  6.  
  7.         public constructor(columnRange: SL_SchedGridColumnRange, settings: StripSettings) {
  8.             this.columnRange = columnRange;
  9.             this.settings = settings;
  10.         }
  11.         private UI: { body: JQuery, ctx: CanvasRenderingContext2D } = {
  12.             body: null,
  13.             ctx: null
  14.         }
  15.         public GetParent(): SL_SchedGridColumnRange {
  16.             return this.columnRange;
  17.         }
  18.  
  19.         public Render() {
  20.             this.createBody();
  21.             this.createText();
  22.         }
  23.         private createBody() {
  24.             this.UI.body = ($('<canvas></canvas>')
  25.                 .addClass("SchedulerControl-Termin")
  26.                 .css("top", "0px")
  27.                 .attr("height", this.settings.size.height)
  28.                 .attr("width", this.settings.size.width)
  29.                 .css("left", this.settings.position.X));
  30.             this.GetParent().GetUI().body.append(this.UI.body);
  31.             this.UI.ctx = (<HTMLCanvasElement>this.UI.body[0]).getContext("2d");
  32.             this.UI.ctx.beginPath();
  33.             this.UI.ctx.rect(0, 0, this.settings.size.width, this.settings.size.height);
  34.             this.UI.ctx.fillStyle = this.settings.color;
  35.             this.UI.ctx.fill();
  36.  
  37.         }
  38.         private createText() {
  39.             this.UI.ctx.save();
  40.             this.UI.ctx.translate(this.settings.size.width / 2, this.settings.size.height / 2);
  41.             this.UI.ctx.rotate(-Math.PI / 2);
  42.             this.UI.ctx.font = this.settings.fontSize + "px Arial";
  43.             this.UI.ctx.fillStyle = this.settings.labelColor;
  44.             this.UI.ctx.textAlign = "center";
  45.             var fontTopVector = Math.round(17-(this.settings.size.width/2));
  46.             if (this.settings.size.height > 1200) {
  47.                 var posX = this.settings.size.height / 4;
  48.                 this.UI.ctx.fillText(this.settings.label, posX, fontTopVector);
  49.                 this.UI.ctx.fillText(this.settings.label, -posX, fontTopVector);
  50.             }
  51.          
  52.             this.UI.ctx.fillText(this.settings.label, 0, fontTopVector);
  53.             var fontTopVector = fontTopVector + 23;
  54.             if (this.settings.squareLabel != null && this.settings.squareLabel != "") {
  55.                 var textWidth = this.UI.ctx.measureText(this.settings.squareLabel);
  56.                 if (this.settings.size.height > 1200) {
  57.                     var posX = this.settings.size.height / 4;
  58.                     this.UI.ctx.fillText(this.settings.squareLabel, posX, fontTopVector);
  59.                     this.UI.ctx.fillText(this.settings.squareLabel, -posX, fontTopVector);
  60.                     this.createSquares(posX, fontTopVector, textWidth.width);
  61.                     this.createSquares(-posX, fontTopVector, textWidth.width);
  62.                 }
  63.                 this.UI.ctx.fillStyle = this.settings.labelColor;
  64.                 this.UI.ctx.fillText(this.settings.squareLabel, 0, fontTopVector);
  65.                 this.createSquares(0, fontTopVector, textWidth.width);
  66.             }
  67.            
  68.             this.UI.ctx.restore();
  69.         }
  70.         private createSquares(X:number,Y:number,textWidth:number) {
  71.             var vector = Math.round(textWidth / 2)+5;
  72.             this.UI.ctx.beginPath();
  73.             this.UI.ctx.rect(X - vector - 15, Y-12, 15, 15);
  74.             this.UI.ctx.fillStyle = this.settings.squareColor;
  75.             this.UI.ctx.fill();
  76.             this.UI.ctx.beginPath();
  77.             this.UI.ctx.rect(X + vector, Y-12, 15, 15);
  78.             this.UI.ctx.fillStyle = this.settings.squareColor;
  79.             this.UI.ctx.fill();
  80.         }
  81.     }
  82.  
  83.     export class StripSettings {
  84.         public position: { X: number, Y: number } = { X: null, Y: null };
  85.         public size: { width: number, height: number } = { width: null, height: null };
  86.         public color: string;
  87.         public label: string;
  88.         public labelColor: string = "white";
  89.         public fontSize: number = 14;
  90.         public squareColor: string;
  91.         public squareLabel: string;
  92.  
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement