Difference between revisions of "Meta:Samples/Software"

From TSG Doc
Jump to navigation Jump to search
Line 34: Line 34:
 
===Template===
 
===Template===
  
<syntaxhighlight lang="python" line>
+
<syntaxhighlight lang="html4strict" line>
import time
+
<!DOCTYPE html>
from ctypes import windll, byref, c_char, Structure, WinError, POINTER, WINFUNCTYPE
+
<html lang="en">
from ctypes.wintypes import BOOL, HMONITOR, HDC, RECT, LPARAM, DWORD, BYTE, WCHAR, HANDLE
+
<head>
 +
    <meta charset="UTF-8">
 +
    <title>Sky Islands v0.2</title>
 +
    <meta name="description" content="">
 +
    <meta name="viewport" content="width=device-width">
 +
    <link rel="stylesheet" href="css/main.css">
 +
</head>
  
 +
<body>
 +
  <div id="container">
 +
      <div id="game-wrapper">
 +
          <div id="game-canvas-wrapper"></div>
 +
          <div id="game-gui"></div>
 +
          <div id="game-dialog"></div>
 +
          <div id="game-playerstats">
 +
              <div id="player-avatar-container"><img id="player-avatar" src="res/avatar/f001.png" /></div>
 +
              <div id="player-stats">
 +
                  <div id="player-resources">
 +
                      <ul>
 +
                          <li id="player-resource1" class="player-resource">0</li>
 +
                      </ul>
 +
                  </div>
 +
                  <div id="player-name">
 +
                      <p id="player-name-tag"></p>
 +
                  </div>
 +
              </div>
 +
          </div>
 +
          <div id="game-powers">
 +
              <div id="power1" class="power"></div>
 +
              <div id="power2" class="power"></div>
 +
          </div>
 +
          <div id="game-menu">
 +
              <div id="menu-start" class="menu-full">
 +
                  <div id="start-buttons">
 +
                      <ul>
 +
                          <li id="start-button-start" onclick="onStart()">New Game</li>
 +
                      </ul>
 +
                  </div>
 +
              </div>
 +
              <div id="menu-avatar-select" class="menu-ingame">
 +
                  <div id="avatar-selector">
 +
                      <p>Select Avatar</p>
 +
                      <div class="avatar-menu" onclick="onAvatar(0)"><img src="res/avatar/f001.png" /></div>
 +
                      <div class="avatar-menu" onclick="onAvatar(1)"><img src="res/avatar/m001.png" /></div>
 +
                  </div>
 +
                  <div id="avatar-form-container">
 +
                    <p>Enter Name</p>
 +
                      <form>
 +
                          <input type="text" id="menu-name-input" />
 +
                          <br/><br/>
 +
                          <input type="button" id="menu-name-submit" value="Continue" onclick="onAvatarSelect()" />
 +
                      </form>
 +
                  </div>
 +
              </div>
 +
              <div id="menu-level-select" class="menu-ingame">
 +
                  <ul>
 +
                      <li id="menu-level-1" class="menu-level-unlocked" onclick="onLevelSelect(1)">Level 1</li>
 +
                      <li id="menu-level-2" class="menu-level-locked">???</li>
 +
                      <li id="menu-level-3" class="menu-level-locked">???</li>
 +
                      <li id="menu-level-4" class="menu-level-locked">???</li>
 +
                  </ul>
 +
              </div>
 +
              <div id="menu-gameover" class="menu-ingame">
 +
                  <p>Oh no! You have lost an island!</p>
  
_MONITORENUMPROC = WINFUNCTYPE(BOOL, HMONITOR, HDC, POINTER(RECT), LPARAM)
+
                  <p><a onclick="onRetry()">Try Again</a></p>
 +
                  <p><a onclick="onBackToMenu()">Back to Menu</a></p>
 +
              </div>
 +
              <div id="menu-win" class="menu-ingame">
 +
                  <p>Congratulations! You are awesome!</p>
 +
                  <p><a onclick="onRetry()">Play Again</a></p>
 +
                  <p><a onclick="onBackToMenu()">Next Level</a></p>
 +
                  </div>
 +
              <div id="menu-timeup" class="menu-full">Je bent nu klaar met dit onderdeel. Ga naar het volgende onderdeel door dit pop-up venster te sluiten, door middel van het rode kruisje.</div>
 +
              <div id="menu-tutorial" class="menu-full">
 +
                  <div id="menu-tutorial-button">
 +
                      <p onclick="pause()">Continue</p>
 +
                  </div>
 +
              </div>
 +
              <div id="menu-pause-button" onclick="pause()"><p>||</p></div>
 +
          </div>
  
class _PHYSICAL_MONITOR(Structure):
+
          <div id="debug">Version 0.2.3.2</div>
_fields_ = [('handle', HANDLE), ('description', WCHAR * 128)]
 
  
 +
      </div>
 +
  </div>
  
def _iter_physical_monitors(close_handles=True):
+
  <script type="text/javascript" src="js/resources.min.js"></script>
"""Iterates physical monitors.
+
  <script type="text/javascript" src="js/sprite.min.js"></script>
 +
  <script type="text/javascript" src="js/game.min.js"></script>
 +
</body>
 +
</html>
  
The handles are closed automatically whenever the iterator is advanced.
 
This means that the iterator should always be fully exhausted!
 
 
If you want to keep handles e.g. because you need to store all of them and
 
use them later, set `close_handles` to False and close them manually."""
 
 
def callback(hmonitor, hdc, lprect, lparam):
 
monitors.append(HMONITOR(hmonitor))
 
return True
 
 
monitors = []
 
if not windll.user32.EnumDisplayMonitors(None, None, _MONITORENUMPROC(callback), None):
 
raise WinError('EnumDisplayMonitors failed')
 
 
for monitor in monitors:
 
# Get physical monitor count
 
count = DWORD()
 
if not windll.dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR(monitor, byref(count)):
 
raise WinError()
 
# Get physical monitor handles
 
physical_array = (_PHYSICAL_MONITOR * count.value)()
 
if not windll.dxva2.GetPhysicalMonitorsFromHMONITOR(monitor, count.value, physical_array):
 
raise WinError()
 
 
for physical in physical_array:
 
handle = physical.handle
 
 
# Get physical monitor capabilities. This may take a while...
 
length = DWORD()
 
if not windll.dxva2.GetCapabilitiesStringLength(HANDLE(handle), byref(length)):
 
raise WinError()
 
capabilities_string = (c_char * length.value)()
 
if not windll.dxva2.CapabilitiesRequestAndCapabilitiesReply(HANDLE(handle), capabilities_string, length):
 
raise WinError()
 
raw_capabilities = capabilities_string.value.decode('ascii')
 
capabilities = _parse_capabilities_string(raw_capabilities)
 
if capabilities:
 
# We only care about the model info for now.
 
yield [capabilities['model'], handle]
 
if close_handles:
 
if not windll.dxva2.DestroyPhysicalMonitor(handle):
 
raise WinError()
 
 
 
def _parse_capabilities_string(capabilities_string):
 
level = 0
 
capabilities = {}
 
open_p = {}
 
close_p = {0: 0}
 
id = {}
 
for i, chr in enumerate(capabilities_string):
 
if chr == '(':
 
if i == 0:
 
close_p[0] = 1
 
continue
 
open_p[level] = i
 
if level == 0:
 
id[0] = capabilities_string[close_p[0] + 1:i]
 
level += 1
 
elif chr == ')':
 
level -= 1
 
close_p[level] = i
 
if level == 0:
 
values = capabilities_string[open_p[0] + 1:i]
 
# We only care about the model info for now.
 
if id[0] == 'model':
 
capabilities[id[0]] = values
 
return capabilities
 
 
 
def set_vcp_feature(monitor, code, value):
 
"""Sends a DDC command to the specified monitor.
 
 
See this link for a list of commands:
 
ftp://ftp.cis.nctu.edu.tw/pub/csie/Software/X11/private/VeSaSpEcS/VESA_Document_Center_Monitor_Interface/mccsV3.pdf
 
"""
 
if not windll.dxva2.SetVCPFeature(HANDLE(monitor), BYTE(code), DWORD(value)):
 
raise WinError()
 
 
 
for model, handle in _iter_physical_monitors():
 
if model == "XL2420Z":
 
set_vcp_feature(handle, 0xDC, 12) # picture mode
 
 
time.sleep(2) # wait for picture mode to load
 
 
set_vcp_feature(handle, 0x10, 31) # brightness
 
set_vcp_feature(handle, 0x12, 50) # contrast
 
set_vcp_feature(handle, 0xF0, 0) # AMA (overdrive)
 
  
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 11:41, 28 April 2015

Introduction.


Features

This software is made to do this, it has these unique selling points:

  • Feature 1[1]
  • Feature 2
  • Feature 3

Requirements

  • Microsoft Windows XP or later.
  • Intel Core 2 Duo E8600 or higher.
  • Python


Installation

Windows 7 64-bit

  1. Step 1
  2. Step 2
  3. Step 3


Configuration

General settings.


Usage

Templates and how-to's go here.


Template

 1<!DOCTYPE html>
 2<html lang="en">
 3<head>
 4    <meta charset="UTF-8">
 5    <title>Sky Islands v0.2</title>
 6    <meta name="description" content="">
 7    <meta name="viewport" content="width=device-width">
 8    <link rel="stylesheet" href="css/main.css">
 9</head>
10
11<body>
12   <div id="container">
13       <div id="game-wrapper">
14          <div id="game-canvas-wrapper"></div>
15          <div id="game-gui"></div>
16          <div id="game-dialog"></div>
17          <div id="game-playerstats">
18              <div id="player-avatar-container"><img id="player-avatar" src="res/avatar/f001.png" /></div>
19              <div id="player-stats">
20                  <div id="player-resources">
21                      <ul>
22                          <li id="player-resource1" class="player-resource">0</li>
23                      </ul>
24                  </div>
25                  <div id="player-name">
26                      <p id="player-name-tag"></p>
27                  </div>
28              </div>
29          </div>
30          <div id="game-powers">
31              <div id="power1" class="power"></div>
32              <div id="power2" class="power"></div>
33          </div>
34          <div id="game-menu">
35              <div id="menu-start" class="menu-full">
36                  <div id="start-buttons">
37                      <ul>
38                          <li id="start-button-start" onclick="onStart()">New Game</li>
39                      </ul>
40                  </div>
41              </div>
42              <div id="menu-avatar-select" class="menu-ingame">
43                  <div id="avatar-selector">
44                      <p>Select Avatar</p>
45                      <div class="avatar-menu" onclick="onAvatar(0)"><img src="res/avatar/f001.png" /></div>
46                      <div class="avatar-menu" onclick="onAvatar(1)"><img src="res/avatar/m001.png" /></div>
47                  </div>
48                  <div id="avatar-form-container">
49                     <p>Enter Name</p>
50                      <form>
51                          <input type="text" id="menu-name-input" />
52                          <br/><br/>
53                          <input type="button" id="menu-name-submit" value="Continue" onclick="onAvatarSelect()" />
54                      </form>
55                  </div>
56              </div>
57              <div id="menu-level-select" class="menu-ingame">
58                  <ul>
59                      <li id="menu-level-1" class="menu-level-unlocked" onclick="onLevelSelect(1)">Level 1</li>
60                      <li id="menu-level-2" class="menu-level-locked">???</li>
61                      <li id="menu-level-3" class="menu-level-locked">???</li>
62                      <li id="menu-level-4" class="menu-level-locked">???</li>
63                  </ul>
64              </div>
65              <div id="menu-gameover" class="menu-ingame">
66                  <p>Oh no! You have lost an island!</p>
67
68                  <p><a onclick="onRetry()">Try Again</a></p>
69                  <p><a onclick="onBackToMenu()">Back to Menu</a></p>
70              </div>
71              <div id="menu-win" class="menu-ingame">
72                  <p>Congratulations! You are awesome!</p>
73                  <p><a onclick="onRetry()">Play Again</a></p>
74                  <p><a onclick="onBackToMenu()">Next Level</a></p>
75                  </div>
76              <div id="menu-timeup" class="menu-full">Je bent nu klaar met dit onderdeel. Ga naar het volgende onderdeel door dit pop-up venster te sluiten, door middel van het rode kruisje.</div>
77              <div id="menu-tutorial" class="menu-full">
78                  <div id="menu-tutorial-button">
79                      <p onclick="pause()">Continue</p>
80                  </div>
81              </div>
82              <div id="menu-pause-button" onclick="pause()"><p>||</p></div>
83          </div>
84
85          <div id="debug">Version 0.2.3.2</div>
86
87       </div>
88   </div>
89
90   <script type="text/javascript" src="js/resources.min.js"></script>
91   <script type="text/javascript" src="js/sprite.min.js"></script>
92   <script type="text/javascript" src="js/game.min.js"></script>
93</body>
94</html>

See Also


References

  1. Some reference