From e6dec3eb50ded1221f8a9ca185107bf607cd44e8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 31 May 2018 13:30:36 +0200 Subject: [PATCH] Now we have a LOGO! --- Images/aa-logo-dark-8.png | Bin 0 -> 801 bytes Project.njsproj | 3 ++ Scripts/AppLoader.js | 1 + Spaces/TopSpace.js | 8 ++++ TopSpace/CompanyLogo.js | 79 ++++++++++++++++++++++++++++++++++++++ index.html | 9 ++--- server.js | 46 +++++++++++++++++++++- 7 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 Images/aa-logo-dark-8.png create mode 100644 TopSpace/CompanyLogo.js diff --git a/Images/aa-logo-dark-8.png b/Images/aa-logo-dark-8.png new file mode 100644 index 0000000000000000000000000000000000000000..a6bcfcb906337b47c4179bbe04a198d343e9acd5 GIT binary patch literal 801 zcmeAS@N?(olHy`uVBq!ia0vp^6+kS(!3-qX{7&uyQpo{6A+A1|g^xXLAn5=9|8NGJ z4VMKnfPxTlI0+U&(FGBKlR#Z2x~)w>>*Py<{DK(-5*{=hXmB{-@WCKp!G;8b2^SOu zHY~VMpiuDP!GwUyc(r3drJMyGk;M!Q+(IDCcU|#C6dkC2dc4)Y?_nGd$SKUhrXgvwi1u(Y^LL|K4~n)Sp@R z`>@T_(#c(2x2{SCY%SiZvZ*Y)?%*{u&5XQ@pX63{>|+qPDEdKU-wLL4D%wn?kE$01 zaCvHN6H&`Mdh_j{wURN$3}uCR6R(|laObh%RPQ;PI8HCx*L--JV6SpzgOlp>9fGpn zdDBu{L-kjGd7C*+m??YqGIonuYd>bB#46nif0=eTN2w_38E2;a@a%D z;ClZcW5QWsn}j02_X*Df)VF=RXIjj>Ku}M5rReL-eV2r5mN-r6w%^m(e^>ZU#PguP z4BG<=w^~<3nD6|!IGJ_DHIbrw$98tON{Hlb`g<)*|KO$n8V_#&4%IF@xAkrR>b~+1 zdKPyM-Zc5`opJrn{#Dwmo-JC%eUbA;N7~K56-)dMJokNkeRfFS(^dLG8@rZ>u9h`Y zjXf}#C(}oA(e4>?>une>zWiZzE%wE3g|n>%(`NH8oSg7o^`BT(Vf)XbDG3})6W%p0 z%z2c>b1iCis?SZH1~JC<4Sr`%pa1WCQ8G?yVoA6EY`;0PetrBVzs2a(96SEDNeh2X nozE0txc}(C+xN2>_A$nu(wwUNP Code + + Code + Code diff --git a/Scripts/AppLoader.js b/Scripts/AppLoader.js index f7da204c7..809b2d07b 100644 --- a/Scripts/AppLoader.js +++ b/Scripts/AppLoader.js @@ -21,6 +21,7 @@ /* PlotterPanels */ + "TopSpace/CompanyLogo.js", "TopSpace/CurrentStartMode.js", "TopSpace/CurrentProcess.js", "TopSpace/CurrentBot.js", diff --git a/Spaces/TopSpace.js b/Spaces/TopSpace.js index 31fd88d01..8e06cebd6 100644 --- a/Spaces/TopSpace.js +++ b/Spaces/TopSpace.js @@ -23,6 +23,7 @@ function newTopSpace() { container.isDraggeable = false; + let companyLogo; let endUser; let devTeam; let currentBot; @@ -33,6 +34,9 @@ function newTopSpace() { function initialize() { + companyLogo = newCompanyLogo(); + companyLogo.initialize(); + endUser = newEndUser(); endUser.initialize(); @@ -54,6 +58,9 @@ function newTopSpace() { let container; + container = companyLogo.getContainer(point); + if (container !== undefined) { return container; } + container = endUser.getContainer(point); if (container !== undefined) { return container; } @@ -80,6 +87,7 @@ function newTopSpace() { thisObject.container.frame.draw(false, false); drawBackground(); + companyLogo.draw(); endUser.draw(); devTeam.draw(); currentBot.draw(); diff --git a/TopSpace/CompanyLogo.js b/TopSpace/CompanyLogo.js new file mode 100644 index 000000000..e71b6ba70 --- /dev/null +++ b/TopSpace/CompanyLogo.js @@ -0,0 +1,79 @@ + +function newCompanyLogo() { + + var thisObject = { + container: undefined, + draw: draw, + getContainer: getContainer, // returns the inner most container that holds the point received by parameter. + initialize: initialize + }; + + var container = newContainer(); + container.initialize(); + thisObject.container = container; + + thisObject.container.frame.width = 150; + thisObject.container.frame.height = TOP_SPACE_HEIGHT; + + container.frame.position.x = 0; + container.frame.position.y = 0; + + container.isDraggeable = false; + + let logo; + let canDrawLogo = false; + + return thisObject; + + function initialize() { + + logo = new Image(); + + logo.onload = onImageLoad; + + function onImageLoad() { + canDrawLogo = true; + } + + logo.src = "Images/aa-logo-dark-8.png"; + document.body.append(logo); + } + + function getContainer(point) { + + let container; + + /* First we check if this point is inside this object UI. */ + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } + + function draw() { + + thisObject.container.frame.draw(false, false); + + if (canDrawLogo === false) { return;} + + let imageHeight = 24; + let imageWidth = 120; + + let imagePoint = { + x: 10, + y: thisObject.container.frame.height / 2 - imageHeight / 2 + }; + + imagePoint = thisObject.container.frame.frameThisPoint(imagePoint); + + browserCanvasContext.drawImage(logo, imagePoint.x, imagePoint.y, imageWidth, imageHeight); + } +} \ No newline at end of file diff --git a/index.html b/index.html index 894ba6760..9b91a18a8 100644 --- a/index.html +++ b/index.html @@ -13,9 +13,8 @@ } - - - - - + + + + \ No newline at end of file diff --git a/server.js b/server.js index 6ccb14dd0..47f82da44 100644 --- a/server.js +++ b/server.js @@ -383,6 +383,13 @@ function onBrowserRequest(request, response) { } break; + case "Images": // This means the Scripts folder. + { + + respondWithImage('./Images/' + requestParameters[2], response); + + } + break; case "TopSpace": // This means the TopSpace folder. { @@ -886,7 +893,7 @@ function respondWithFile(fileName, response) { response.setHeader("Expires", "0"); // Proxies. response.setHeader("Access-Control-Allow-Origin", "*"); // Allows to access data from other domains. - response.writeHead(200, { 'Content-Type': 'text/html' }); + //response.writeHead(200, { 'Content-Type': 'text/html' }); response.write(htmlResponse); response.end("\n"); //console.log("File Sent: " + fileName); @@ -894,7 +901,6 @@ function respondWithFile(fileName, response) { } catch (err) { returnEmptyArray(); - console.log("File Not Found: " + fileName); console.log("[ERROR] server -> respondWithFile -> onFileRead -> File Not Found: " + fileName + " or Error = " + err); } @@ -905,6 +911,42 @@ function respondWithFile(fileName, response) { } } +function respondWithImage(fileName, response) { + + if (CONSOLE_LOG === true) { console.log("[INFO] server -> respondWithImage -> Entering function."); } + + let fs = require('fs'); + try { + + fs.readFile(fileName, onFileRead); + + function onFileRead(err, file) { + + if (CONSOLE_LOG === true) { console.log("[INFO] server -> respondWithImage -> onFileRead -> Entering function."); } + + try { + + response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. + response.setHeader("Pragma", "no-cache"); // HTTP 1.0. + response.setHeader("Expires", "0"); // Proxies. + response.setHeader("Access-Control-Allow-Origin", "*"); // Allows to access data from other domains. + + response.writeHead(200, { 'Content-Type': 'image/png' }); + response.end(file, 'binary'); + + } + catch (err) { + + console.log("[ERROR] server -> respondWithImage -> onFileRead -> File Not Found: " + fileName + " or Error = " + err); + } + + } + } + catch (err) { + console.log("[ERROR] server -> respondWithImage -> err = " + err); + } +} + function returnEmptyArray() { try {