- moved the windows to use layouts
- various gui-work - begun binding the GUI into Monster script - updated to latest Monster source (0.11 alpha) git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@87 ea6a568a-9f4f-0410-981a-c910a81bb256actorid
parent
9530ae0526
commit
2995f8b99f
Binary file not shown.
After Width: | Height: | Size: 387 B |
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- This file defines the box you see around many GUI elements, such
|
||||
as around the sections of the stats window, or around popup info windows -->
|
||||
|
||||
<MyGUI type="Skin">
|
||||
<!-- Box borders -->
|
||||
<Skin name="IB_T" size="512 2" texture="menu_thin_border_top.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 512 2">
|
||||
<State name="normal" offset = "0 0 512 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_B" size="512 2" texture="menu_thin_border_bottom.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 512 2">
|
||||
<State name="normal" offset = "0 0 512 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_L" size="2 512" texture="menu_thin_border_left.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 512">
|
||||
<State name="normal" offset = "0 0 2 512"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_R" size="2 512" texture="menu_thin_border_right.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 512">
|
||||
<State name="normal" offset = "0 0 2 512"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_TL" size="2 2" texture="menu_thin_border_top_left_corner.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 2">
|
||||
<State name="normal" offset = "0 0 2 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_TR" size="2 2" texture="menu_thin_border_top_right_corner.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 2">
|
||||
<State name="normal" offset = "0 0 2 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_BL" size="2 2" texture="menu_thin_border_bottom_left_corner.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 2">
|
||||
<State name="normal" offset = "0 0 2 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="IB_BR" size="2 2" texture="menu_thin_border_bottom_right_corner.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 2">
|
||||
<State name="normal" offset = "0 0 2 2"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
|
||||
<!-- Main box definition -->
|
||||
<Skin name="MW_Box" size="516 516">
|
||||
<Child type="Widget" skin="IB_T" offset="2 0 512 2" align="ALIGN_TOP ALIGN_HSTRETCH"/>
|
||||
<Child type="Widget" skin="IB_B" offset="2 514 512 2" align="ALIGN_BOTTOM ALIGN_HSTRETCH"/>
|
||||
<Child type="Widget" skin="IB_L" offset="0 2 2 512" align="ALIGN_LEFT ALIGN_VSTRETCH"/>
|
||||
<Child type="Widget" skin="IB_R" offset="514 2 2 512" align="ALIGN_RIGHT ALIGN_VSTRETCH"/>
|
||||
<Child type="Widget" skin="IB_TL" offset="0 0 2 2" align="ALIGN_TOP ALIGN_LEFT"/>
|
||||
<Child type="Widget" skin="IB_TR" offset="514 0 2 2" align="ALIGN_TOP ALIGN_RIGHT"/>
|
||||
<Child type="Widget" skin="IB_BL" offset="0 514 2 2" align="ALIGN_BOTTOM ALIGN_LEFT"/>
|
||||
<Child type="Widget" skin="IB_BR" offset="514 514 2 2" align="ALIGN_BOTTOM ALIGN_RIGHT"/>
|
||||
</Skin>
|
||||
</MyGUI>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<!-- The entire screen -->
|
||||
<Widget type="Widget" layer="MainMenu" position="0 0 300 300" name="_Main">
|
||||
<!-- Centered box containing the buttons -->
|
||||
<Widget type="Widget" position="86 12 128 276" align="Center">
|
||||
<!-- Menu boxes -->
|
||||
<Widget type="Button" skin="ReturnButton" position="0 0 128 64" align="Top Left" name="Return"/>
|
||||
<Widget type="Button" skin="NewButton" position="0 46 128 64" align="Top Left" name="New"/>
|
||||
<Widget type="Button" skin="SaveButton" position="0 92 128 64" align="Top Left" name="Save"/>
|
||||
<Widget type="Button" skin="LoadButton" position="0 138 128 64" align="Top Left" name="Load"/>
|
||||
<Widget type="Button" skin="OptionsButton" position="0 184 128 64" align="Top Left" name="Options"/>
|
||||
<Widget type="Button" skin="ExitButton" position="0 230 128 64" align="Top Left" name="Exit"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Skin">
|
||||
<Skin name="ReturnButton" size="128 64" texture="menu_return.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="NewButton" size="128 64" texture="menu_newgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="SaveButton" size="128 64" texture="menu_savegame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="LoadButton" size="128 64" texture="menu_loadgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="OptionsButton" size="128 64" texture="menu_options.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="ExitButton" size="128 64" texture="menu_exitgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
</MyGUI>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 300 300" name="_Main">
|
||||
<Widget type="StaticImage" skin="StaticImage" position="0 0 284 264" align="ALIGN_STRETCH" name="Map"/>
|
||||
<Widget type="StaticImage" skin="StaticImage" position="126 116 32 32" align="Center" name="Compass"/>
|
||||
<Widget type="Button" skin="MW_Button" position="213 233 61 22" align="ALIGN_BOTTOM ALIGN_RIGHT" name="WorldButton"/>
|
||||
</Widget>
|
||||
</MyGUI>
|
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Skin">
|
||||
<!-- Progress bar track, various colors -->
|
||||
<Skin name = "MW_BigTrack_Red" size = "2 14" texture = "bigbars.png" >
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 14" align = "ALIGN_STRETCH">
|
||||
<State name="normal" offset = "0 0 2 14"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name = "MW_BigTrack_Green" size = "2 14" texture = "bigbars.png" >
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 14" align = "ALIGN_STRETCH">
|
||||
<State name="normal" offset = "0 14 2 14"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name = "MW_BigTrack_Blue" size = "2 14" texture = "bigbars.png" >
|
||||
<BasisSkin type="MainSkin" offset = "0 0 2 14" align = "ALIGN_STRETCH">
|
||||
<State name="normal" offset = "0 28 2 14"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
|
||||
<Skin name = "ProgressText" size = "16 16">
|
||||
<Property key="FontName" value = "MyGUI_CoreFont.18" />
|
||||
<Property key="FontHeight" value = "18" />
|
||||
<Property key="AlignText" value = "ALIGN_CENTER" />
|
||||
<Property key="Colour" value = "0.35 0.6 0.75" />
|
||||
|
||||
<BasisSkin type="SimpleText" offset = "0 0 16 16" align = "ALIGN_STRETCH"/>
|
||||
</Skin>
|
||||
|
||||
<!-- Main energy bar widget definitions. There's one for each color.-->
|
||||
|
||||
<Skin name="MW_Progress_Red" size="64 12">
|
||||
<Property key="TrackSkin" value = "MW_BigTrack_Red" />
|
||||
<Property key="TrackWidth" value = "1" />
|
||||
|
||||
<Child type="Widget" skin="MW_Box" offset="0 0 64 12" align="ALIGN_STRETCH"/>
|
||||
<Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/>
|
||||
</Skin>
|
||||
|
||||
<Skin name="MW_Progress_Green" size="64 12">
|
||||
<Property key="TrackSkin" value = "MW_BigTrack_Green" />
|
||||
<Property key="TrackWidth" value = "1" />
|
||||
|
||||
<Child type="Widget" skin="MW_Box" offset="0 0 64 12" align="ALIGN_STRETCH"/>
|
||||
<Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/>
|
||||
</Skin>
|
||||
|
||||
<Skin name="MW_Progress_Blue" size="64 12">
|
||||
<Property key="TrackSkin" value = "MW_BigTrack_Blue" />
|
||||
<Property key="TrackWidth" value = "1" />
|
||||
|
||||
<Child type="Widget" skin="MW_Box" offset="0 0 64 12" align="ALIGN_STRETCH"/>
|
||||
<Child type="Widget" skin="BlackBG" offset = "2 2 60 8" align = "ALIGN_STRETCH" name="Client"/>
|
||||
</Skin>
|
||||
</MyGUI>
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 500 342" name="_Main">
|
||||
|
||||
<!-- Player health stats -->
|
||||
<Widget type="Widget" skin="MW_Box" position="8 8 212 62">
|
||||
<Widget type="StaticText" skin="NormalText" position="4 4 70 18" name="Health_str"/>
|
||||
<Widget type="StaticText" skin="NormalText" position="4 22 70 18" name="Magicka_str"/>
|
||||
<Widget type="StaticText" skin="NormalText" position="4 40 70 18" name="Fatigue_str"/>
|
||||
<Widget type="Progress" skin="MW_Progress_Red" position="78 4 130 18" name="HBar"/>
|
||||
<Widget type="Progress" skin="MW_Progress_Blue" position="78 22 130 18" name="MBar"/>
|
||||
<Widget type="Progress" skin="MW_Progress_Green" position="78 40 130 18" name="FBar"/>
|
||||
<Widget type="StaticText" skin="ProgressText" position="78 4 130 18" align="Center" name="HBarT"/>
|
||||
<Widget type="StaticText" skin="ProgressText" position="78 22 130 18" align="Center" name="MBarT"/>
|
||||
<Widget type="StaticText" skin="ProgressText" position="78 40 130 18" align="Center" name="FBarT"/>
|
||||
</Widget>
|
||||
|
||||
<!-- Player level, race and class -->
|
||||
<Widget type="Widget" skin="MW_Box" position="8 78 212 62">
|
||||
<Widget type="StaticText" skin="NormalText" position="4 4 100 18" name="Level_str"/>
|
||||
<Widget type="StaticText" skin="NormalText" position="4 22 100 18" name="Race_str"/>
|
||||
<Widget type="StaticText" skin="NormalText" position="4 40 100 18" name="Class_str"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 4 104 18" name="LevelText"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 22 104 18" name="RaceText"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 40 104 18" name="ClassText"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="Widget" skin="MW_Box" position="8 148 212 152">
|
||||
<Widget type="StaticText" skin="SandText" position="4 4 100 18" name="Attrib1"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 4 104 18" name="AttribVal1"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 22 100 18" name="Attrib2"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 22 104 18" name="AttribVal2"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 40 100 18" name="Attrib3"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 40 104 18" name="AttribVal3"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 58 100 18" name="Attrib4"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 58 104 18" name="AttribVal4"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 76 100 18" name="Attrib5"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 76 104 18" name="AttribVal5"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 94 100 18" name="Attrib6"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 94 104 18" name="AttribVal6"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 112 100 18" name="Attrib7"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 112 104 18" name="AttribVal7"/>
|
||||
|
||||
<Widget type="StaticText" skin="SandText" position="4 130 100 18" name="Attrib8"/>
|
||||
<Widget type="StaticText" skin="SandTextRight" position="104 130 104 18" name="AttribVal8"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="Widget" skin="MW_Box" position="228 8 248 292" align="ALIGN_LEFT ALIGN_VSTRETCH">
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
Binary file not shown.
After Width: | Height: | Size: 246 B |
Binary file not shown.
After Width: | Height: | Size: 150 B |
@ -0,0 +1,165 @@
|
||||
/*
|
||||
Monster - an advanced game scripting language
|
||||
Copyright (C) 2007-2009 Nicolay Korslund
|
||||
Email: <korslund@gmail.com>
|
||||
WWW: http://monster.snaptoad.com/
|
||||
|
||||
This file (math.d) is part of the Monster script language
|
||||
package.
|
||||
|
||||
Monster is distributed as free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License
|
||||
version 3, as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 3 along with this program. If not, see
|
||||
http://www.gnu.org/licenses/ .
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// Simple math functions
|
||||
module monster.modules.math;
|
||||
|
||||
import monster.monster;
|
||||
import std.math;
|
||||
|
||||
const char[] moduleDef =
|
||||
"module math;
|
||||
|
||||
double E = 2.7182818284590452354;
|
||||
double PI = 3.141592653589793238;
|
||||
double DEGTORAD = 3.141592653590/180;
|
||||
double RADTODEG = 180/3.141592653590;
|
||||
|
||||
native double sin(double x);
|
||||
native double cos(double x);
|
||||
native double tan(double x);
|
||||
native double asin(double x);
|
||||
native double acos(double x);
|
||||
native double atan(double x);
|
||||
native double atan2(double y, double x); // = atan(y/x)
|
||||
native double sinh(double x);
|
||||
native double cosh(double x);
|
||||
native double tanh(double x);
|
||||
native double asinh(double x);
|
||||
native double acosh(double x);
|
||||
native double atanh(double x);
|
||||
|
||||
native double sqrt(double x);
|
||||
native double exp(double x); // e^x
|
||||
native double exp2(double x); // 2^x
|
||||
native double log(double x); // base e
|
||||
native double log10(double x);// base 10
|
||||
native double log2(double x); // base 2
|
||||
|
||||
native double pow(double x, double y); // x^y
|
||||
native double ipow(double x, int n); // x^n (faster than pow)
|
||||
|
||||
native int abs(int x);
|
||||
native double fabs(double x);
|
||||
native double ceil(double x);
|
||||
native double floor(double x);
|
||||
native double round(double x); // rounds to nearest integer
|
||||
native double trunc(double x);
|
||||
|
||||
native double hypot(double x, double y); // = sqrt(x*x+y*y)
|
||||
native double cbrt(double x); // cube root
|
||||
|
||||
// Calculates polynomial a0 + x*a1 + x^2*a2 + x^3*a3 + ...
|
||||
native double poly(double x, float[] A);
|
||||
"; //"
|
||||
|
||||
version(Tango)
|
||||
{
|
||||
double fabs(double x) { return abs(x); }
|
||||
}
|
||||
|
||||
void initMathModule()
|
||||
{
|
||||
static MonsterClass mc;
|
||||
if(mc !is null) return;
|
||||
|
||||
mc = new MonsterClass(MC.String, moduleDef, "math");
|
||||
|
||||
mc.bind("sin", { stack.pushDouble(sin(stack.popDouble)); });
|
||||
mc.bind("cos", { stack.pushDouble(cos(stack.popDouble)); });
|
||||
mc.bind("tan", { stack.pushDouble(tan(stack.popDouble)); });
|
||||
mc.bind("asin", { stack.pushDouble(asin(stack.popDouble)); });
|
||||
mc.bind("acos", { stack.pushDouble(acos(stack.popDouble)); });
|
||||
mc.bind("atan", { stack.pushDouble(atan(stack.popDouble)); });
|
||||
|
||||
mc.bind("sinh", { stack.pushDouble(sinh(stack.popDouble)); });
|
||||
mc.bind("cosh", { stack.pushDouble(cosh(stack.popDouble)); });
|
||||
mc.bind("tanh", { stack.pushDouble(tanh(stack.popDouble)); });
|
||||
mc.bind("asinh", { stack.pushDouble(asinh(stack.popDouble)); });
|
||||
mc.bind("acosh", { stack.pushDouble(acosh(stack.popDouble)); });
|
||||
mc.bind("atanh", { stack.pushDouble(atanh(stack.popDouble)); });
|
||||
|
||||
mc.bind("atan2",
|
||||
{
|
||||
// Remember to pop the variables in the reverse order
|
||||
auto x = stack.popDouble;
|
||||
stack.pushDouble(atan2(stack.popDouble, x));
|
||||
});
|
||||
|
||||
mc.bind("sqrt", { stack.pushDouble(sqrt(stack.popDouble)); });
|
||||
mc.bind("exp", { stack.pushDouble(exp(stack.popDouble)); });
|
||||
mc.bind("exp2", { stack.pushDouble(exp2(stack.popDouble)); });
|
||||
mc.bind("log", { stack.pushDouble(log(stack.popDouble)); });
|
||||
mc.bind("log2", { stack.pushDouble(log2(stack.popDouble)); });
|
||||
mc.bind("log10", { stack.pushDouble(log10(stack.popDouble)); });
|
||||
|
||||
mc.bind("pow",
|
||||
{
|
||||
auto x = stack.popDouble;
|
||||
stack.pushDouble(pow(stack.popDouble, x));
|
||||
});
|
||||
mc.bind("ipow",
|
||||
{
|
||||
auto x = stack.popInt;
|
||||
stack.pushDouble(pow(cast(real)stack.popDouble, x));
|
||||
});
|
||||
|
||||
mc.bind("abs", { stack.pushDouble(abs(stack.popDouble)); });
|
||||
mc.bind("fabs", { stack.pushDouble(fabs(stack.popDouble)); });
|
||||
mc.bind("ceil", { stack.pushDouble(ceil(stack.popDouble)); });
|
||||
mc.bind("floor", { stack.pushDouble(floor(stack.popDouble)); });
|
||||
mc.bind("round", { stack.pushDouble(round(stack.popDouble)); });
|
||||
mc.bind("trunc", { stack.pushDouble(trunc(stack.popDouble)); });
|
||||
|
||||
// Order doesn't matter here
|
||||
mc.bind("hypot", { stack.pushDouble(hypot(stack.popDouble,
|
||||
stack.popDouble)); });
|
||||
|
||||
mc.bind("cbrt", { stack.pushDouble(cbrt(stack.popDouble)); });
|
||||
|
||||
mc.bind("poly", &npoly);
|
||||
}
|
||||
|
||||
// Implement this ourselves, since phobos doesn't use the types we
|
||||
// want
|
||||
double poly(double x, float A[])
|
||||
{
|
||||
// Use 'real' internally for higher precision
|
||||
real r = A[$-1];
|
||||
foreach_reverse(c; A[0..$-1])
|
||||
{
|
||||
r *= x;
|
||||
r += c;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// double poly(double x, float[] A);
|
||||
void npoly()
|
||||
{
|
||||
auto arf = stack.popArray();
|
||||
assert(arf.elemSize == 1);
|
||||
stack.pushDouble(poly(stack.popDouble, arf.farr));
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
module math;
|
||||
|
||||
double E = 2.7182818284590452354;
|
||||
double PI = 3.141592653589793238;
|
||||
double DEGTORAD = 3.141592653590/180;
|
||||
double RADTODEG = 180/3.141592653590;
|
||||
|
||||
native double sin(double x);
|
||||
native double cos(double x);
|
||||
native double tan(double x);
|
||||
native double asin(double x);
|
||||
native double acos(double x);
|
||||
native double atan(double x);
|
||||
native double atan2(double y, double x); // = atan(y/x)
|
||||
native double sinh(double x);
|
||||
native double cosh(double x);
|
||||
native double tanh(double x);
|
||||
native double asinh(double x);
|
||||
native double acosh(double x);
|
||||
native double atanh(double x);
|
||||
|
||||
native double sqrt(double x);
|
||||
native double exp(double x); // e^x
|
||||
native double exp2(double x); // 2^x
|
||||
native double log(double x); // base e
|
||||
native double log10(double x);// base 10
|
||||
native double log2(double x); // base 2
|
||||
|
||||
native double pow(double x, double y); // x^y
|
||||
native double ipow(double x, int n); // x^n (faster than pow)
|
||||
|
||||
native int abs(int x);
|
||||
native double fabs(double x);
|
||||
native double ceil(double x);
|
||||
native double floor(double x);
|
||||
native double round(double x); // rounds to nearest integer
|
||||
native double trunc(double x);
|
||||
|
||||
native double hypot(double x, double y); // = sqrt(x*x+y*y)
|
||||
native double cbrt(double x); // cube root
|
||||
|
||||
// Calculates polynomial a0 + x*a1 + x^2*a2 + x^3*a3 + ...
|
||||
native double poly(double x, float[] A);
|
@ -1,38 +1,36 @@
|
||||
// Small script that prints the FPS to screen with regular intervals.
|
||||
class FPSTicker;
|
||||
|
||||
import frames;
|
||||
|
||||
// Set the FPS widget text
|
||||
native setText(char[][] args...);
|
||||
|
||||
run()
|
||||
{
|
||||
// Sleep one frame. This makes sure that we won't start running until
|
||||
// the rendering begins. Not critically important, but it prevents the
|
||||
// first printed value from being 'nan'.
|
||||
fsleep(1);
|
||||
// Set up the text widget
|
||||
Widget txt = gui.text("StaticText",
|
||||
gui.getWidth()-90, 10, 120, 30,
|
||||
"Statistic");
|
||||
txt.setNeedMouseFocus(false);
|
||||
txt.setTextColor(1,1,1);
|
||||
txt.setCaption("hello!");
|
||||
|
||||
setText("hello!");
|
||||
// Sleep one frame. This makes sure we only start running after
|
||||
// rendering begins. It prevents the first printed value from being
|
||||
// 'nan'
|
||||
fsleep(1);
|
||||
|
||||
// counter and totalTime (in the 'frames' module) are updated
|
||||
// automatically by the system.
|
||||
ulong lastFrame = counter;
|
||||
float lastTime = totalTime;
|
||||
// counter and totalTime (in the 'frames' module) are updated
|
||||
// automatically by the system.
|
||||
ulong lastFrame = counter;
|
||||
float lastTime = totalTime;
|
||||
|
||||
float delay = 1.5;
|
||||
float delay = 1.5;
|
||||
|
||||
while(true)
|
||||
{
|
||||
sleep(delay);
|
||||
while(true)
|
||||
{
|
||||
sleep(delay);
|
||||
|
||||
// Calculate differences since last frame
|
||||
ulong fdiff = counter-lastFrame;
|
||||
float tdiff = totalTime-lastTime;
|
||||
// Calculate differences since last frame
|
||||
ulong fdiff = counter-lastFrame;
|
||||
float tdiff = totalTime-lastTime;
|
||||
|
||||
setText("fps: ", fdiff / tdiff);
|
||||
txt.setCaption("fps: ", fdiff/tdiff);
|
||||
|
||||
lastFrame = counter;
|
||||
lastTime = totalTime;
|
||||
}
|
||||
lastFrame = counter;
|
||||
lastTime = totalTime;
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
/*
|
||||
Widget hud;
|
||||
hud = gui.loadLayout("openmw_hud_layout.xml");
|
||||
hud.setCoord(10,10,500,500);
|
||||
*/
|
@ -0,0 +1,11 @@
|
||||
// GUI module. Only covers some very basic functions.
|
||||
module gui;
|
||||
|
||||
// Later, we'll have singleton gui : Widget; with most of the
|
||||
// functions defined in Widget.
|
||||
|
||||
native Widget loadLayout(char[] file);
|
||||
native Widget text(char[] skin, int x, int y, int w, int h,
|
||||
char[] layer);
|
||||
native int getWidth();
|
||||
native int getHeight();
|
@ -0,0 +1,10 @@
|
||||
class Widget;
|
||||
|
||||
native setNeedMouseFocus(bool b);
|
||||
native setTextColor(float r, float g, float b);
|
||||
native setCoord(int x, int y, int w, int h);
|
||||
|
||||
native setCaption(char[][] str...);
|
||||
|
||||
// Find a named child widget
|
||||
native Widget get(char[] name);
|
@ -0,0 +1,255 @@
|
||||
/*
|
||||
OpenMW - The completely unofficial reimplementation of Morrowind
|
||||
Copyright (C) 2008-2009 Nicolay Korslund
|
||||
Email: < korslund@gmail.com >
|
||||
WWW: http://openmw.snaptoad.com/
|
||||
|
||||
This file (gui.d) is part of the OpenMW package.
|
||||
|
||||
OpenMW is distributed as free software: you can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License
|
||||
version 3, as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 3 along with this program. If not, see
|
||||
http://www.gnu.org/licenses/ .
|
||||
|
||||
*/
|
||||
|
||||
module ogre.gui;
|
||||
|
||||
import monster.monster;
|
||||
import ogre.bindings;
|
||||
import std.string;
|
||||
|
||||
// Widget class and gui module
|
||||
MonsterClass
|
||||
gmc, // GUI module
|
||||
wid_mc, // Widget
|
||||
but_mc, // Button
|
||||
tex_mc, // StaticText
|
||||
img_mc, // StaticImage
|
||||
pro_mc, // Progress
|
||||
win_mc; // Window
|
||||
|
||||
MWidget[WidgetPtr] gui_store;
|
||||
|
||||
class MWidget
|
||||
{
|
||||
WidgetPtr widget;
|
||||
MonsterObject *mo;
|
||||
|
||||
// Used for layouts
|
||||
bool isLayout;
|
||||
char[] prefix;
|
||||
|
||||
// For layouts
|
||||
this(char[] layout, WidgetPtr parent = null)
|
||||
{
|
||||
assert(layout.length);
|
||||
|
||||
isLayout = true;
|
||||
prefix = format("%s", cast(void*)this);
|
||||
|
||||
widget = gui_loadLayout(layout.ptr, prefix.ptr, parent);
|
||||
if(widget is null)
|
||||
fail("Layout " ~ layout ~ " is empty");
|
||||
|
||||
this();
|
||||
}
|
||||
|
||||
// For normal widgets
|
||||
this(WidgetPtr w)
|
||||
{
|
||||
isLayout = false;
|
||||
widget = w;
|
||||
assert(widget !is null);
|
||||
this();
|
||||
}
|
||||
|
||||
private this()
|
||||
{
|
||||
assert(widget !is null);
|
||||
|
||||
// Create the object from the right class
|
||||
mo = toClass(widget).createObject();
|
||||
// But store the pointer in the Widget's pointer slot
|
||||
mo.getExtra(wid_mc).obj = this;
|
||||
// Also store a lookup for later
|
||||
gui_store[widget] = this;
|
||||
}
|
||||
|
||||
MWidget getChild(char[] name)
|
||||
{
|
||||
if(prefix.length)
|
||||
name = prefix ~ name;
|
||||
|
||||
// Get the child widget
|
||||
auto pt = gui_getChild(widget, name.ptr);
|
||||
|
||||
if(pt is null)
|
||||
fail("Widget has no child named " ~ name);
|
||||
|
||||
// Return the MWidget
|
||||
return get(pt);
|
||||
}
|
||||
|
||||
// Return the MonsterClass corresponding to a given widget.
|
||||
private static MonsterClass toClass(WidgetPtr p)
|
||||
{
|
||||
switch(widgetType(p))
|
||||
{
|
||||
/*
|
||||
case "Button": return but_mc;
|
||||
case "StaticText": return tex_mc;
|
||||
case "StaticImage": return img_mc;
|
||||
case "Progress": return pro_mc;
|
||||
case "Window": return win_mc;
|
||||
*/
|
||||
default:
|
||||
// Use "Widget" for all unimplemented types
|
||||
case "Widget": return wid_mc;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the MWidget (and associatied MonsterObject) corresponding to
|
||||
// a given Widget.
|
||||
static MWidget get(WidgetPtr wid)
|
||||
{
|
||||
// First, check if the instance exists
|
||||
auto p = wid in gui_store;
|
||||
if(p) return *p;
|
||||
|
||||
// No MWidget exists. We have to create one.
|
||||
return new MWidget(wid);
|
||||
}
|
||||
};
|
||||
|
||||
char[] widgetType(WidgetPtr p)
|
||||
{
|
||||
return toString(gui_widgetType(p));
|
||||
}
|
||||
|
||||
MWidget getMWOwner(MonsterObject *mo)
|
||||
{
|
||||
return (cast(MWidget)mo.getExtra(wid_mc).obj);
|
||||
}
|
||||
MWidget getMWOwner()
|
||||
{
|
||||
return getMWOwner(params.obj());
|
||||
}
|
||||
WidgetPtr getOwner(MonsterObject *mo)
|
||||
{
|
||||
return getMWOwner(mo).widget;
|
||||
}
|
||||
WidgetPtr getOwner()
|
||||
{
|
||||
return getMWOwner().widget;
|
||||
}
|
||||
|
||||
// Widget functions
|
||||
void setCaption()
|
||||
{
|
||||
AIndex[] args = stack.popAArray();
|
||||
|
||||
char[] res;
|
||||
|
||||
foreach(AIndex ind; args)
|
||||
res ~= format("%s", arrays.getRef(ind).carr);
|
||||
|
||||
gui_setCaption(getOwner(), res.ptr);
|
||||
}
|
||||
void setNeedMouseFocus()
|
||||
{ gui_setNeedMouseFocus(getOwner(), stack.popBool); }
|
||||
void setTextColor()
|
||||
{
|
||||
float b = stack.popFloat();
|
||||
float g = stack.popFloat();
|
||||
float r = stack.popFloat();
|
||||
gui_setTextColor(getOwner(), r,g,b);
|
||||
}
|
||||
void setCoord()
|
||||
{
|
||||
int h = stack.popInt();
|
||||
int w = stack.popInt();
|
||||
int y = stack.popInt();
|
||||
int x = stack.popInt();
|
||||
gui_setCoord(getOwner(), x,y,w,h);
|
||||
}
|
||||
|
||||
void get()
|
||||
{
|
||||
// Get the owner MWidget
|
||||
auto mw = getMWOwner();
|
||||
// Get the child
|
||||
mw = mw.getChild(stack.popString8());
|
||||
// Push the object
|
||||
stack.pushObject(mw.mo);
|
||||
}
|
||||
|
||||
// TODO: These are all written to be used with the 'gui' module. Later
|
||||
// they should be part of Widget, and create child widgets. When used
|
||||
// with 'gui' they create root widgets.
|
||||
|
||||
void loadLayout()
|
||||
{
|
||||
MWidget mw = new MWidget(stack.popString8());
|
||||
stack.pushObject(mw.mo);
|
||||
}
|
||||
|
||||
void text()
|
||||
{
|
||||
char[] layer = stack.popString8();
|
||||
int h = stack.popInt();
|
||||
int w = stack.popInt();
|
||||
int y = stack.popInt();
|
||||
int x = stack.popInt();
|
||||
char[] skin = stack.popString8();
|
||||
WidgetPtr ptr = gui_createText(skin.ptr,
|
||||
x,y,w,h,
|
||||
layer.ptr);
|
||||
assert(widgetType(ptr) == "StaticText");
|
||||
MWidget mw = new MWidget(ptr);
|
||||
stack.pushObject(mw.mo);
|
||||
}
|
||||
|
||||
void getWidth()
|
||||
{
|
||||
stack.pushInt(gui_getWidth(null));
|
||||
}
|
||||
|
||||
void getHeight()
|
||||
{
|
||||
stack.pushInt(gui_getHeight(null));
|
||||
}
|
||||
|
||||
void setupGUIScripts()
|
||||
{
|
||||
vm.addPath("mscripts/gui/");
|
||||
vm.addPath("mscripts/gui/module/");
|
||||
gmc = new MonsterClass("gui", "gui.mn");
|
||||
wid_mc = new MonsterClass("Widget", "widget.mn");
|
||||
/*
|
||||
but_mc = new MonsterClass("Button", "button.mn");
|
||||
tex_mc = new MonsterClass("Text", "text.mn");
|
||||
img_mc = new MonsterClass("Image", "image.mn");
|
||||
pro_mc = new MonsterClass("Progress", "progress.mn");
|
||||
win_mc = new MonsterClass("Window", "window.mn");
|
||||
*/
|
||||
|
||||
wid_mc.bind("setCaption", &setCaption);
|
||||
wid_mc.bind("setNeedMouseFocus", &setNeedMouseFocus);
|
||||
wid_mc.bind("setTextColor", &setTextColor);
|
||||
wid_mc.bind("setCoord", &setCoord);
|
||||
wid_mc.bind("get", &get);
|
||||
|
||||
gmc.bind("text", &text);
|
||||
gmc.bind("loadLayout", &loadLayout);
|
||||
gmc.bind("getWidth", &getWidth);
|
||||
gmc.bind("getHeight", &getHeight);
|
||||
}
|
Loading…
Reference in New Issue