Mercurial > hg > serpentron
changeset 8:b32efce2d860
Automatically adjust size to fit the window.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Wed, 23 Mar 2016 23:56:26 +0300 |
parents | 66d8fd6a64e8 |
children | 8c7e910cb328 |
files | iframed.html src/Serpentron.st |
diffstat | 2 files changed, 33 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iframed.html Wed Mar 23 23:56:26 2016 +0300 @@ -0,0 +1,12 @@ +<html> + <head> + <title>Serpentron</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + </head> + <body> + <iframe src="index.html" + width="700" height="525" frameborder="0"> + <a href="http://www.games1729.com/serpentron/">Play Serpentron</a> + </iframe> + </body> +</html>
--- a/src/Serpentron.st Wed Mar 23 21:34:08 2016 +0300 +++ b/src/Serpentron.st Wed Mar 23 23:56:26 2016 +0300 @@ -289,6 +289,23 @@ score at: color put: (score at: color) + points. ! +updateSize + | w h fw fh ratio | + w := window innerWidth. + h := window innerHeight - ('#title' asSilk element offsetHeight). + ratio := field fieldSize x / field fieldSize y. + (w / ratio <= h) + ifTrue: [ fw := w. fh := w / ratio ] + ifFalse: [ fh := h. fw := h * ratio ]. + '#serpentron' asSilk element style + width: fw rounded asString, 'px'; + marginLeft: ((w - fw) / 2) rounded asString, 'px'; + marginTop: ((h - fh) / 2) rounded asString, 'px'. + '#field' asSilk element style + width: fw rounded asString, 'px'; + height: fh rounded asString, 'px'. +! + validatePlayerColor: aPlayer | enabledPlayers otherPlayers freeColor | enabledPlayers := players select: #isEnabled. @@ -333,18 +350,6 @@ renderOnSilk: aSilk | scale container width height | - scale := 1. - skin tileSize >= 20 - ifTrue: [ scale := 0.5 ]. - skin tileSize < 10 - ifTrue: [ scale := 2]. - - width := field fieldSize x * skin tileSize * scale. - height := field fieldSize y * skin tileSize * scale. - - aSilk element style - width: width asString , 'px'. - (aSilk DIV: {#id -> 'title'}) H1: (Silk A: { #href -> 'http://www.games1729.com/serpentron/'. #target -> '_top'. @@ -352,18 +357,16 @@ SPAN: {#id -> 'status'. '1.0-beta2'}. container := aSilk DIV: {#id -> 'field'}. - container element style - width: width asString , 'px'; - height: height asString , 'px'. - + + self updateSize. + window onresize: [ self updateSize ]. + container << field. self renderStartScreenOn: container. (container DIV: {#id -> 'message'. #class -> 'hidden'}) element style margin: '0 auto'. - - aSilk << container. ! ! Serpentron class instanceVariableNames: 'Instance'!