- added proper text rendering

- linedef lengths visible when dragging geometry
- included my ancient bitmap font creator
This commit is contained in:
codeimp 2008-05-13 14:24:35 +00:00
parent d59ab92d51
commit 77720694a3
32 changed files with 2344 additions and 440 deletions

View file

@ -0,0 +1,36 @@
Type=Exe
Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINDOWS\system32\scrrun.dll#Microsoft Scripting Runtime
Form=Form1.frm
Class=clsConfiguration; clsConfiguration.cls
IconForm="frmChars"
Startup="frmChars"
HelpFile=""
Title="BitmapFont"
Command32=""
Name="BitmapFont"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="XODE Multimedia"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View file

@ -0,0 +1,2 @@
frmChars = -4, 118, 902, 640, C, 65, 69, 690, 511, C
clsConfiguration = 66, 66, 676, 562, C

View file

@ -0,0 +1,193 @@
VERSION 5.00
Begin VB.Form frmChars
BorderStyle = 1 'Fixed Single
Caption = "Bitmap Font Generator"
ClientHeight = 8910
ClientLeft = 45
ClientTop = 330
ClientWidth = 8715
ClipControls = 0 'False
BeginProperty Font
Name = "Arial"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "Form1.frx":0000
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 594
ScaleMode = 3 'Pixel
ScaleWidth = 581
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox picChar
AutoRedraw = -1 'True
BackColor = &H00000000&
BorderStyle = 0 'None
CausesValidation= 0 'False
ClipControls = 0 'False
FillColor = &H00FFFFFF&
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 510
Left = 7890
ScaleHeight = 34
ScaleMode = 3 'Pixel
ScaleWidth = 34
TabIndex = 0
Top = 60
Visible = 0 'False
Width = 510
End
Begin VB.PictureBox picBitmap
AutoRedraw = -1 'True
BackColor = &H00000000&
BorderStyle = 0 'None
CausesValidation= 0 'False
ClipControls = 0 'False
FillColor = &H00FFFFFF&
ForeColor = &H00FFFFFF&
Height = 3840
Left = 45
ScaleHeight = 256
ScaleMode = 3 'Pixel
ScaleWidth = 512
TabIndex = 2
Top = 45
Width = 7680
End
Begin VB.Label lblChars
Caption = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+=-[]:;'"",.<>/?\"
BeginProperty Font
Name = "Arial Black"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1095
Left = 60
TabIndex = 1
Top = 7785
UseMnemonic = 0 'False
Visible = 0 'False
Width = 8475
End
End
Attribute VB_Name = "frmChars"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub DrawChar(Char As String)
picChar.Width = picChar.TextWidth(Char)
DoEvents
picChar.Height = picChar.TextHeight(Char)
DoEvents
Set picChar.Picture = Nothing
picChar.Cls
picChar.Print Char
DoEvents
End Sub
Private Sub Form_Load()
Dim i
Dim CharX As Integer
Dim CharY As Integer
Dim LargestY As Integer
Dim cfg As New clsConfiguration
Dim settings As Dictionary
Dim chars As New Dictionary
Show
Refresh
picChar.Font = lblChars.Font
picChar.FontSize = lblChars.FontSize
''Adjustment (in pixels) per character
Const u1 As Single = -4 '-2
Const v1 As Single = -4 '-2
Const u2 As Single = 4 '2
Const v2 As Single = 5 '5
''Spacing
Const sx As Long = 10
Const sy As Long = 6
''Offset
Const ox As Long = 10
Const oy As Long = 3
''Start values
CharY = oy
CharX = ox
LargestY = 0
cfg.NewConfiguration
'Render all chars
For i = 1 To Len(lblChars)
'Get the bitmap char
DrawChar Mid$(lblChars, i, 1)
If (picChar.Height - 3) > LargestY Then LargestY = (picChar.Height - 3)
If CharX + picChar.Width >= (picBitmap.Width - sx / 2) Then
'Go to next character position
CharY = CharY + LargestY + sy
LargestY = 0
CharX = ox
End If
'Draw on bitmap
picBitmap.PaintPicture picChar.Image, CharX, CharY - 2
'Make settings
Set settings = New Dictionary
settings.Add "width", CLng(picChar.Width)
settings.Add "height", CLng((picChar.Height - 3))
settings.Add "u1", (CSng(CharX) + u1) / CSng(picBitmap.Width)
settings.Add "v1", (CSng(CharY) + v1) / CSng(picBitmap.Height)
settings.Add "u2", (CSng(CharX + picChar.Width) + u2) / CSng(picBitmap.Width)
settings.Add "v2", (CSng(CharY + (picChar.Height - 3)) + v2) / CSng(picBitmap.Height)
chars.Add Asc(Mid$(lblChars, i, 1)), settings
Set settings = Nothing
'Go to next character position
CharX = CharX + picChar.Width + sx
Next i
'save bitmap
SavePicture picBitmap.Image, "font.bmp"
'save config
cfg.WriteSetting "count", CLng(Len(lblChars))
cfg.WriteSetting "chars", chars, True
cfg.SaveConfiguration "font.cfg"
End Sub

Binary file not shown.

View file

@ -0,0 +1,844 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsConfiguration"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ====================================================================================
' INTRODUCTION
' ====================================================================================
'
' Configuration Class Module by Pascal vd Heiden, www.codeimp.com
'
' This Class module contains code of my design. You are free to use it,
' as long as you do not remove my details up here in this comment. Thanks.
'
' This Class module requires "Microsoft Scripting Runtime" reference (scrrun.dll)
' for the Dictionary object. Select this in the Project -> References dialog.
'
' Can safely be compiled with Fast Optimization and
' all Advanced Optimization switches checked.
'
'
' ====================================================================================
' CONFIGURATION FILE STRUCTURE SYNTAX
' ====================================================================================
'
' Whitepace is always allowed. This includes spaces, tabs
' linefeeds (10) and carriage returns (13)
'
' Keys may not have spaces or assignment operator = in them.
'
' Comments start with // (unless used within strings)
' and count as comment for the rest of the line. Or use /* and */
' to mark the beginning and end of a comment.
'
' Simple setting:
'
' key = value;
'
' Example: speed = 345;
' cars = 8;
'
' Strings must be in quotes.
'
' Example: nickname = "Gherkin";
' altnick = "Gherk inn";
'
' String Escape Sequences:
' \n New line (10)
' \r Carriage return (13)
' \t Tab (9)
' \" Double-quotation mark
' \\ Backslash
' \000 Any ASCII character (MUST be 3 digits! So for 13 you use \013)
'
' Decimals ALWAYS use a dot, NEVER comma!
'
' Example: pressure = 15.29;
' acceleration = 1.0023;
'
' Structures must use brackets.
'
' Structure Example:
'
' key
' {
' key = value;
' key = value;
'
' key
' {
' key = value;
' key = value;
' key = value;
' }
'
' key = value;
' key = value;
' key = value;
' key = value;
' key = value;
' }
'
' As you can see, structures inside structures are allowed
' and you may go as deep as you want. Note that only the root structures
' can be readed from config using ReadSetting. ReadSetting will return a
' Dictionary object containing everything in that root structure.
'
' Key names must be unique within their scope.
'
' This is NOT allowed, it may not have 'father' more
' than once in the same scope:
'
' mother = 45;
' father = 52;
'
' father
' {
' length = 1.87;
' }
'
' This however is allowed, because father
' now exists in a different scope:
'
' mother = 45;
' father = 52;
'
' parents
' {
' father = 52;
' }
'
' This too is allowed, both 'age' are in a different scope:
'
' mother
' {
' age = 45;
' }
'
' father
' {
' age = 52;
' }
'
'
' ====================================================================================
' FUNCTION CALL DESCRIPTIONS
' ====================================================================================
'
' InputConfiguration
'
' This loads a configuration from a string. The string must contain a
' configuration using the rules described above.
'
' ------------------------------------------------------------------------------------
'
' LoadConfiguration
'
' Loads a configuration from a file. The file must contain a configuration
' using the rules described above.
'
' ------------------------------------------------------------------------------------
'
' NewConfiguration
'
' Erases all loaded settings and starts with a new, clear configuration
'
' ------------------------------------------------------------------------------------
'
' OutputConfiguration
'
' Returns the configuration as a string following the rules described above.
' You can optionally determine the newline character to use and/or omit
' whitespace in the result.
'
' ------------------------------------------------------------------------------------
'
' SaveConfiguration
'
' Writes the configuration to file following the rules described above.
' You can optionally specify the newline character to use and/or omit
' whitespace in the result.
'
' ------------------------------------------------------------------------------------
'
' ReadSetting
'
' Reads a setting from the root level and returns it in its own variable type.
' You can optionally specify a default to return if the specified setting
' does not exist and/or specify if you would like to get a reference if the
' setting is a Dictionary object (structure in configuration).
' If you use a reference, you can change the configuration immediately
' through that reference.
'
' ------------------------------------------------------------------------------------
'
' WriteSetting
'
' Writes a setting to the root level in the configuration.
' You can choose to write the setting as reference if it is of Dictionary type.
' Note that your configuration changes too when you change anything
' in your Dictionary when it is written as reference!
'
' ------------------------------------------------------------------------------------
'
' RemoveSetting
'
' Removes a setting from the root level in the configuration.
' Its as simple as that. What else is there to tell about it?!
'
' ------------------------------------------------------------------------------------
'
' Root
'
' Returns the entire configuration (root level) as a Dictionary object.
' You can optionally specify to return a reference through which you can change
' the configuration immediately.
'
' ====================================================================================
' ====================================================================================
'Do not allow any undeclared variables
Option Explicit
'Case sensitive comparisions
Option Compare Binary
Private Const ASSIGNOP As Long = 61 ' =
Private Const BEGINOP As Long = 123 ' {
Private Const ENDOP As Long = 125 ' }
Private Const TERMINATEOP As Long = 59 ' ;
Private Const STRINGOP As Long = 34 ' "
Private Const COMMENT As String = "//" '
Private Const BEGINCOMMENT As String = "/*" '
Private Const ENDCOMMENT As String = "*/" '
Private Const WS_SPACE As Long = 32 ' space
Private Const WS_LINEFEED As Long = 10 ' linefeed
Private Const WS_TAB As String = vbTab '
Private Const WS_RETURN As String = vbCr '
Private Const ESCAPESEQ As Long = 92 ' \
Private Const ES_NEWLINE As Long = 110 ' n
Private Const ES_RETURN As Long = 114 ' r
Private Const ES_TAB As Long = 116 ' t
Private Const ES_QUOTE As Long = 34 ' "
Private Const ES_BACKSLASH As Long = 92 ' \
'This will hold the object orientated configuration
Private Config As Dictionary
'Last line that was read where error occurred
Private cLastReadLine As Long
Public Property Get CurrentScanLine() As Long
CurrentScanLine = cLastReadLine
End Property
Private Sub Class_Initialize()
'New database
Set Config = New Dictionary
End Sub
Private Sub Class_Terminate()
'Clean up
Set Config = Nothing
End Sub
Private Function DeepCopy(ByRef Dict As Dictionary) As Dictionary
Dim NewConfig As Dictionary
Dim CopyObject As Dictionary
Dim ConfigKeys As Variant
Dim ConfigValue As Variant
Dim i As Long
'Create new config
Set NewConfig = New Dictionary
'Add all items from Config
If Dict.Count Then
ConfigKeys = Dict.Keys
For i = LBound(ConfigKeys) To UBound(ConfigKeys)
'Check if the value is a dictionary
If VarType(Dict(ConfigKeys(i))) = vbObject Then
'Get the object
Set CopyObject = Dict(ConfigKeys(i))
'Deepcopy this too
NewConfig.Add ConfigKeys(i), DeepCopy(CopyObject)
'Clean up
Set CopyObject = Nothing
Else
'Normal copy
ConfigValue = Dict(ConfigKeys(i))
NewConfig.Add ConfigKeys(i), ConfigValue
End If
Next i
End If
'Return the result
Set DeepCopy = NewConfig
'Clean up
Set NewConfig = Nothing
End Function
Private Function Escaped(ByRef Value As String) As String
' \n New line
' \r Carriage return
' \t Tab
' \" Double quotation mark
' \\ Backslash
'Copy string
Escaped = Value
'Replace characters with escape sequences
Escaped = Replace$(Escaped, "\", "\\") 'Note the \ must be the first to replace!
Escaped = Replace$(Escaped, vbLf, "\n")
Escaped = Replace$(Escaped, vbCr, "\r")
Escaped = Replace$(Escaped, vbTab, "\t")
Escaped = Replace$(Escaped, """", "\""")
End Function
Public Sub InputConfiguration(ByVal Configuration As String)
'This reads the data and builds a new dictionary object
'Remove Returns and Tabs so we only have Linefeed as newline
Configuration = Replace$(Configuration, WS_RETURN, "")
Configuration = Replace$(Configuration, WS_TAB, "")
'First line
cLastReadLine = 1
'Load main structure
Set Config = LoadStructure(0, Configuration)
End Sub
Public Sub LoadConfiguration(ByRef Filename As String)
Dim FB As Integer 'File buffer
Dim Data As String 'Data
'This reads a file and builds a new dictionary object
'Open the file to read
FB = FreeFile
Open Filename For Binary As #FB
'Read all data
Data = Space$(LOF(FB))
Get #FB, 1, Data
'Close file
Close #FB
'Remove Returns and Tabs so we only have Linefeed as newline
Data = Replace$(Data, WS_RETURN, "")
Data = Replace$(Data, WS_TAB, "")
'First line
cLastReadLine = 1
'Load main structure
Set Config = LoadStructure(0, Data)
End Sub
Private Function LoadStructure(ByRef p As Long, ByRef Data As String) As Dictionary
Dim c As String * 1 'Character at p
Dim ca As Long 'ASCII value of c
Dim np As Long 'Next position
Dim StringData As Boolean 'True if in a string
Dim NumberData As Boolean 'True if in a number
Dim Sequence As Boolean 'True if getting a sequence character
Dim Assigning As Boolean 'True when assigning
Dim NewKey As String
Dim NewValue As String
'Create dictionary
Set LoadStructure = New Dictionary
'Continue until end of data
Do While p < Len(Data)
'Next char
p = p + 1
'Get char
c = Mid$(Data, p, 1)
ca = AscW(c)
'Check if we are processing number data
If NumberData Then
'Check if assignment ends
If ca = TERMINATEOP Then
'Check number type
If InStr(NewValue, ".") <> 0 Then
'Add the number to dictionary as single
LoadStructure.Add Trim$(NewKey), CSng(Val(NewValue))
Else
'Add the number to dictionary as long
LoadStructure.Add Trim$(NewKey), CLng(NewValue)
End If
'Reset
NewKey = ""
NewValue = ""
'End of assign
NumberData = False
Assigning = False
'Check if newline
ElseIf (ca = WS_LINEFEED) Then
'Count the new line
cLastReadLine = cLastReadLine + 1
Else
'Add to value
NewValue = NewValue & c
End If
'Check if we are processing string data
ElseIf StringData Then
'Check if previous char was a slash
If Sequence Then
'Check the char
Select Case ca
Case ES_BACKSLASH: NewValue = NewValue & "\"
Case ES_NEWLINE: NewValue = NewValue & vbLf
Case ES_QUOTE: NewValue = NewValue & """"
Case ES_RETURN: NewValue = NewValue & vbCr
Case ES_TAB: NewValue = NewValue & vbTab
Case Else
'Check if its a number
If IsNumeric(c) Then
'Always 3 chars
np = CLng(Mid$(Data, p, 3))
NewValue = NewValue & ChrW$(np)
p = p + 2
Else
'Add character
NewValue = NewValue & c
End If
End Select
'End of sequence
Sequence = False
Else
'Check if sequence start
If ca = ESCAPESEQ Then
'Start escape sequence
Sequence = True
'Check if string ends
ElseIf ca = STRINGOP Then
'Add the string to dictionary
LoadStructure.Add Trim$(NewKey), NewValue
'End of string
StringData = False
'Reset
NewKey = ""
NewValue = ""
'Check if newline
ElseIf (ca = WS_LINEFEED) Then
'Count the new line
cLastReadLine = cLastReadLine + 1
Else
'Add to string
NewValue = NewValue & c
End If
End If
'Check if assigning
ElseIf Assigning Then
'Check for STRINGOP or Numeric character
If (ca = STRINGOP) Then
'Begin string data here
StringData = True
ElseIf (IsNumeric(c) = True) Or (c = "-") Or (c = ".") Or (LCase$(c) = "e") Or (c = "&") Then
'Begin numeric data here
NumberData = True
'Note that this byte is part of the value
p = p - 1
'Check if newline
ElseIf (ca = WS_LINEFEED) Then
'Count the new line
cLastReadLine = cLastReadLine + 1
'Check if assignment ends
ElseIf (ca = TERMINATEOP) Then
'End of assign
Assigning = False
'Everything else but spaces are not allowed
ElseIf (ca <> WS_SPACE) Then
'Invalid assignment
Err.Raise vbObjectError, , "Invalid assignment. Forgot an assignment terminator?"
End If
'Anything else
Else 'If (ca <> WS_SPACE) Then
'Check for a Key, BEGINOP, ENDOP or ASSIGNOP, COMMENT or whitespace
Select Case ca
Case BEGINOP
'Check for spaces in key name
If (InStr(Trim$(NewKey), " ") > 0) Then
'Spaces not allowed in key names
Err.Raise vbObjectError, , "Spaces not allowed in key names."
Else
'Add structure
LoadStructure.Add Trim$(NewKey), LoadStructure(p, Data)
'Reset
NewKey = ""
End If
Case ENDOP
'Leave here
Exit Do
Case ASSIGNOP
'Check for spaces in key name
If (InStr(Trim$(NewKey), Chr$(WS_SPACE)) > 0) Then
'Spaces not allowed in key names
Err.Raise vbObjectError, , "Spaces not allowed in key names."
Else
'Now assigning
Assigning = True
End If
Case TERMINATEOP
'Add the key to dictionary with 0 value
LoadStructure.Add Trim$(NewKey), CLng(0)
'Reset
NewKey = ""
NewValue = ""
Case WS_LINEFEED
'Count the new line
cLastReadLine = cLastReadLine + 1
'Add as space
NewKey = NewKey & Chr$(WS_SPACE)
'Check for possible comment
Case AscW(COMMENT), AscW(BEGINCOMMENT)
'Check for 2 bytes line comment
If Mid$(Data, p, 2) = COMMENT Then
'Find the next linefeed
np = InStr(p, Data, vbLf)
'Check if linefeed was found
If np > 0 Then
'Count linefeed
cLastReadLine = cLastReadLine + 1
'Skip to next
p = np
Else
'No linefeed can be found, end of file!
p = Len(Data)
Exit Do
End If
'Check for 2 bytes block comment
ElseIf Mid$(Data, p, 2) = BEGINCOMMENT Then
'Find the next endcomment
np = InStr(p, Data, ENDCOMMENT)
'Check if endcomment was found
If np > 0 Then
'Count the number of linefeeds in comment block
cLastReadLine = cLastReadLine + UBound(Split(Mid$(Data, p, np - p), Chr$(WS_LINEFEED)))
'Skip to next
p = np + 1
Else
'No endcomment can be found, end of file!
p = Len(Data)
Exit Do
End If
End If
'Add to key name
Case Else: NewKey = NewKey & c
End Select
End If
Loop
End Function
Public Sub NewConfiguration()
'First line
cLastReadLine = 1
'Create new, empty dictionary
Set Config = New Dictionary
End Sub
Public Function OutputConfiguration(Optional ByVal NewLine As String = vbCrLf, Optional ByVal Whitespace As Boolean = True) As String
'Create configuration as string
OutputConfiguration = OutputDictionary(Config, 0, NewLine, Whitespace)
End Function
Private Function OutputDictionary(ByRef Dict As Dictionary, ByVal Level As Long, Optional ByVal NewLine = vbCrLf, Optional ByVal Whitespace As Boolean = True) As String
Dim LevelTabs As String
Dim sp As String
Dim Keys As Variant
Dim Data As String
Dim i As Long
'Check if this dictionary is not empty
If Dict.Count > 0 Then
'Create whitespace
If Whitespace Then
LevelTabs = String$(Level, vbTab)
sp = " "
End If
'Get the keys
Keys = Dict.Keys
'Go for all keys in dictionary
For i = LBound(Keys) To UBound(Keys)
'Check type of value
Select Case VarType(Dict(Keys(i)))
'Dictionary Object
Case vbObject
'Output empty line
If Whitespace Then Data = Data & LevelTabs & NewLine
'Output the key
Data = Data & LevelTabs & Keys(i) & NewLine
'Ouput the BEGINOP
Data = Data & LevelTabs & ChrW$(BEGINOP) & NewLine
'Output Dictionary
Data = Data & OutputDictionary(Dict(Keys(i)), Level + 1, NewLine, Whitespace)
'Output the ENDOP
Data = Data & LevelTabs & ChrW$(ENDOP) & NewLine
'Output empty line
If Whitespace Then Data = Data & LevelTabs & NewLine
'Integral Number
Case vbInteger, vbLong, vbByte
'Output the key = value;
Data = Data & LevelTabs & Keys(i) & sp & ChrW$(ASSIGNOP) & sp & Dict(Keys(i)) & ChrW$(TERMINATEOP) & NewLine
'Floating point Number
Case vbSingle, vbDouble, vbCurrency, vbDecimal
'Output the key = value;
Data = Data & LevelTabs & Keys(i) & sp & ChrW$(ASSIGNOP) & sp & Format(Dict(Keys(i)), "###############################0.0#####") & "f" & ChrW$(TERMINATEOP) & NewLine
'Boolean as Number
Case vbBoolean
'Output the key = value;
Data = Data & LevelTabs & Keys(i) & sp & ChrW$(ASSIGNOP) & sp & CLng(Dict(Keys(i))) & ChrW$(TERMINATEOP) & NewLine
'Other (String)
Case Else
'Output the key = "value";
Data = Data & LevelTabs & Keys(i) & sp & ChrW$(ASSIGNOP) & sp & ChrW$(STRINGOP) & Escaped(Dict(Keys(i))) & ChrW$(STRINGOP) & ChrW$(TERMINATEOP) & NewLine
End Select
Next i
End If
'Return data
OutputDictionary = Data
End Function
Public Function ReadSetting(ByRef Setting As String, Optional ByRef Default As Variant, Optional ByVal Reference As Boolean)
'Check if setting exists
If Config.Exists(Setting) Then
'Check setting type
If VarType(Config(Setting)) = vbObject Then
'Check if we should return a reference
If Reference Then
'Return a reference
Set ReadSetting = Config(Setting)
Else
'Return the setting
Set ReadSetting = DeepCopy(Config(Setting))
End If
Else
'Return the setting
ReadSetting = Config(Setting)
End If
Else
'Return the default
If VarType(Default) = vbObject Then Set ReadSetting = Default Else ReadSetting = Default
End If
End Function
Public Sub RemoveSetting(ByRef Setting As String)
'Remove setting if exists
If Config.Exists(Setting) Then Config.Remove Setting
End Sub
Public Function Root(Optional ByVal Reference As Boolean) As Dictionary
'Check if we should return a reference
If Reference Then
'Return a reference
Set Root = Config
Else
'Return the setting
Set Root = DeepCopy(Config)
End If
End Function
Public Sub SaveConfiguration(ByRef Filename As String, Optional ByVal NewLine As String = vbCrLf, Optional ByVal Whitespace As Boolean = True)
Dim FB As Integer 'File buffer
Dim Data As String 'Data
'This reads a file and builds a new dictionary object
'Create data
Data = OutputDictionary(Config, 0, NewLine, Whitespace)
'Kill the file if exists
If Dir(Filename) <> "" Then Kill Filename
'Open the file to write
FB = FreeFile
Open Filename For Binary As #FB
'Write configuration data
Put #FB, 1, Data
'Close file
Close #FB
End Sub
Public Sub WriteSetting(ByRef Setting As String, ByRef Value As Variant, Optional ByVal Reference As Boolean)
Dim DictValue As Dictionary
'Check if the setting exists
If Config.Exists(Setting) Then
'Check type of value
If VarType(Value) = vbObject Then
'Check if we should apply referenced
If Reference Then
'Apply setting as reference
Set Config(Setting) = Value
Else
'Apply setting
Set DictValue = Value
Set Config(Setting) = DeepCopy(DictValue)
'Clean up
Set DictValue = Nothing
End If
Else
'Apply setting
Config(Setting) = Value
End If
Else
'Add setting
Config.Add Setting, Value
End If
End Sub

View file

@ -7,9 +7,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.019141f;
v1 = 0.010938f;
u2 = 0.075195f;
u1 = 0.011719f;
v1 = -0.003906f;
u2 = 0.078125f;
v2 = 0.195313f;
}
@ -18,9 +18,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.089453f;
v1 = 0.010938f;
u2 = 0.145508f;
u1 = 0.082031f;
v1 = -0.003906f;
u2 = 0.148438f;
v2 = 0.195313f;
}
@ -29,9 +29,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.159766f;
v1 = 0.010938f;
u2 = 0.21582f;
u1 = 0.152344f;
v1 = -0.003906f;
u2 = 0.21875f;
v2 = 0.195313f;
}
@ -40,9 +40,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.230078f;
v1 = 0.010938f;
u2 = 0.286133f;
u1 = 0.222656f;
v1 = -0.003906f;
u2 = 0.289063f;
v2 = 0.195313f;
}
@ -51,9 +51,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.300391f;
v1 = 0.010938f;
u2 = 0.352539f;
u1 = 0.292969f;
v1 = -0.003906f;
u2 = 0.355469f;
v2 = 0.195313f;
}
@ -62,9 +62,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.366797f;
v1 = 0.010938f;
u2 = 0.415039f;
u1 = 0.359375f;
v1 = -0.003906f;
u2 = 0.417969f;
v2 = 0.195313f;
}
@ -73,9 +73,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.429297f;
v1 = 0.010938f;
u2 = 0.489258f;
u1 = 0.421875f;
v1 = -0.003906f;
u2 = 0.492188f;
v2 = 0.195313f;
}
@ -84,9 +84,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.503516f;
v1 = 0.010938f;
u2 = 0.563477f;
u1 = 0.496094f;
v1 = -0.003906f;
u2 = 0.566406f;
v2 = 0.195313f;
}
@ -95,9 +95,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.577734f;
v1 = 0.010938f;
u2 = 0.608398f;
u1 = 0.570313f;
v1 = -0.003906f;
u2 = 0.611328f;
v2 = 0.195313f;
}
@ -106,9 +106,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.622656f;
v1 = 0.010938f;
u2 = 0.670898f;
u1 = 0.615234f;
v1 = -0.003906f;
u2 = 0.673828f;
v2 = 0.195313f;
}
@ -117,9 +117,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.685156f;
v1 = 0.010938f;
u2 = 0.745117f;
u1 = 0.677734f;
v1 = -0.003906f;
u2 = 0.748047f;
v2 = 0.195313f;
}
@ -128,9 +128,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.759375f;
v1 = 0.010938f;
u2 = 0.807617f;
u1 = 0.751953f;
v1 = -0.003906f;
u2 = 0.810547f;
v2 = 0.195313f;
}
@ -139,9 +139,9 @@ chars
{
width = 31;
height = 42;
u1 = 0.821875f;
v1 = 0.010938f;
u2 = 0.887695f;
u1 = 0.814453f;
v1 = -0.003906f;
u2 = 0.890625f;
v2 = 0.195313f;
}
@ -150,9 +150,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.901953f;
v1 = 0.010938f;
u2 = 0.961914f;
u1 = 0.894531f;
v1 = -0.003906f;
u2 = 0.964844f;
v2 = 0.195313f;
}
@ -161,9 +161,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.019141f;
v1 = 0.198438f;
u2 = 0.079102f;
u1 = 0.011719f;
v1 = 0.183594f;
u2 = 0.082031f;
v2 = 0.382813f;
}
@ -172,9 +172,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.093359f;
v1 = 0.198438f;
u2 = 0.145508f;
u1 = 0.085938f;
v1 = 0.183594f;
u2 = 0.148438f;
v2 = 0.382813f;
}
@ -183,9 +183,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.159766f;
v1 = 0.198438f;
u2 = 0.219727f;
u1 = 0.152344f;
v1 = 0.183594f;
u2 = 0.222656f;
v2 = 0.382813f;
}
@ -194,9 +194,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.233984f;
v1 = 0.198438f;
u2 = 0.290039f;
u1 = 0.226563f;
v1 = 0.183594f;
u2 = 0.292969f;
v2 = 0.382813f;
}
@ -205,9 +205,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.304297f;
v1 = 0.198438f;
u2 = 0.356445f;
u1 = 0.296875f;
v1 = 0.183594f;
u2 = 0.359375f;
v2 = 0.382813f;
}
@ -216,9 +216,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.370703f;
v1 = 0.198438f;
u2 = 0.422852f;
u1 = 0.363281f;
v1 = 0.183594f;
u2 = 0.425781f;
v2 = 0.382813f;
}
@ -227,9 +227,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.437109f;
v1 = 0.198438f;
u2 = 0.49707f;
u1 = 0.429688f;
v1 = 0.183594f;
u2 = 0.5f;
v2 = 0.382813f;
}
@ -238,9 +238,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.511328f;
v1 = 0.198438f;
u2 = 0.567383f;
u1 = 0.503906f;
v1 = 0.183594f;
u2 = 0.570313f;
v2 = 0.382813f;
}
@ -249,9 +249,9 @@ chars
{
width = 33;
height = 42;
u1 = 0.581641f;
v1 = 0.198438f;
u2 = 0.651367f;
u1 = 0.574219f;
v1 = 0.183594f;
u2 = 0.654297f;
v2 = 0.382813f;
}
@ -260,9 +260,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.665625f;
v1 = 0.198438f;
u2 = 0.72168f;
u1 = 0.658203f;
v1 = 0.183594f;
u2 = 0.724609f;
v2 = 0.382813f;
}
@ -271,9 +271,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.735938f;
v1 = 0.198438f;
u2 = 0.791992f;
u1 = 0.728516f;
v1 = 0.183594f;
u2 = 0.794922f;
v2 = 0.382813f;
}
@ -282,9 +282,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.80625f;
v1 = 0.198438f;
u2 = 0.858398f;
u1 = 0.798828f;
v1 = 0.183594f;
u2 = 0.861328f;
v2 = 0.382813f;
}
@ -293,9 +293,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.872656f;
v1 = 0.198438f;
u2 = 0.920898f;
u1 = 0.865234f;
v1 = 0.183594f;
u2 = 0.923828f;
v2 = 0.382813f;
}
@ -304,9 +304,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.935156f;
v1 = 0.198438f;
u2 = 0.983398f;
u1 = 0.927734f;
v1 = 0.183594f;
u2 = 0.986328f;
v2 = 0.382813f;
}
@ -315,9 +315,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.019141f;
v1 = 0.385938f;
u2 = 0.067383f;
u1 = 0.011719f;
v1 = 0.371094f;
u2 = 0.070313f;
v2 = 0.570313f;
}
@ -326,9 +326,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.081641f;
v1 = 0.385938f;
u2 = 0.129883f;
u1 = 0.074219f;
v1 = 0.371094f;
u2 = 0.132813f;
v2 = 0.570313f;
}
@ -337,9 +337,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.144141f;
v1 = 0.385938f;
u2 = 0.192383f;
u1 = 0.136719f;
v1 = 0.371094f;
u2 = 0.195313f;
v2 = 0.570313f;
}
@ -348,9 +348,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.206641f;
v1 = 0.385938f;
u2 = 0.254883f;
u1 = 0.199219f;
v1 = 0.371094f;
u2 = 0.257813f;
v2 = 0.570313f;
}
@ -359,9 +359,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.269141f;
v1 = 0.385938f;
u2 = 0.317383f;
u1 = 0.261719f;
v1 = 0.371094f;
u2 = 0.320313f;
v2 = 0.570313f;
}
@ -370,9 +370,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.331641f;
v1 = 0.385938f;
u2 = 0.379883f;
u1 = 0.324219f;
v1 = 0.371094f;
u2 = 0.382813f;
v2 = 0.570313f;
}
@ -381,9 +381,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.394141f;
v1 = 0.385938f;
u2 = 0.442383f;
u1 = 0.386719f;
v1 = 0.371094f;
u2 = 0.445313f;
v2 = 0.570313f;
}
@ -392,9 +392,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.456641f;
v1 = 0.385938f;
u2 = 0.504883f;
u1 = 0.449219f;
v1 = 0.371094f;
u2 = 0.507813f;
v2 = 0.570313f;
}
@ -403,9 +403,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.519141f;
v1 = 0.385938f;
u2 = 0.547852f;
u1 = 0.511719f;
v1 = 0.371094f;
u2 = 0.550781f;
v2 = 0.570313f;
}
@ -414,9 +414,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.562109f;
v1 = 0.385938f;
u2 = 0.59082f;
u1 = 0.554688f;
v1 = 0.371094f;
u2 = 0.59375f;
v2 = 0.570313f;
}
@ -425,9 +425,9 @@ chars
{
width = 25;
height = 42;
u1 = 0.605078f;
v1 = 0.385938f;
u2 = 0.65918f;
u1 = 0.597656f;
v1 = 0.371094f;
u2 = 0.662109f;
v2 = 0.570313f;
}
@ -436,9 +436,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.673438f;
v1 = 0.385938f;
u2 = 0.72168f;
u1 = 0.666016f;
v1 = 0.371094f;
u2 = 0.724609f;
v2 = 0.570313f;
}
@ -447,9 +447,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.735938f;
v1 = 0.385938f;
u2 = 0.78418f;
u1 = 0.728516f;
v1 = 0.371094f;
u2 = 0.787109f;
v2 = 0.570313f;
}
@ -458,9 +458,9 @@ chars
{
width = 33;
height = 42;
u1 = 0.798438f;
v1 = 0.385938f;
u2 = 0.868164f;
u1 = 0.791016f;
v1 = 0.371094f;
u2 = 0.871094f;
v2 = 0.570313f;
}
@ -469,9 +469,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.882422f;
v1 = 0.385938f;
u2 = 0.930664f;
u1 = 0.875f;
v1 = 0.371094f;
u2 = 0.933594f;
v2 = 0.570313f;
}
@ -480,9 +480,9 @@ chars
{
width = 29;
height = 42;
u1 = 0.019141f;
v1 = 0.573438f;
u2 = 0.081055f;
u1 = 0.011719f;
v1 = 0.558594f;
u2 = 0.083984f;
v2 = 0.757813f;
}
@ -491,9 +491,9 @@ chars
{
width = 19;
height = 42;
u1 = 0.095313f;
v1 = 0.573438f;
u2 = 0.137695f;
u1 = 0.087891f;
v1 = 0.558594f;
u2 = 0.140625f;
v2 = 0.757813f;
}
@ -502,9 +502,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.151953f;
v1 = 0.573438f;
u2 = 0.182617f;
u1 = 0.144531f;
v1 = 0.558594f;
u2 = 0.185547f;
v2 = 0.757813f;
}
@ -513,9 +513,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.196875f;
v1 = 0.573438f;
u2 = 0.227539f;
u1 = 0.189453f;
v1 = 0.558594f;
u2 = 0.230469f;
v2 = 0.757813f;
}
@ -524,9 +524,9 @@ chars
{
width = 17;
height = 42;
u1 = 0.241797f;
v1 = 0.573438f;
u2 = 0.280273f;
u1 = 0.234375f;
v1 = 0.558594f;
u2 = 0.283203f;
v2 = 0.757813f;
}
@ -535,9 +535,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.294531f;
v1 = 0.573438f;
u2 = 0.342773f;
u1 = 0.287109f;
v1 = 0.558594f;
u2 = 0.345703f;
v2 = 0.757813f;
}
@ -546,9 +546,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.357031f;
v1 = 0.573438f;
u2 = 0.405273f;
u1 = 0.349609f;
v1 = 0.558594f;
u2 = 0.408203f;
v2 = 0.757813f;
}
@ -557,9 +557,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.419531f;
v1 = 0.573438f;
u2 = 0.448242f;
u1 = 0.412109f;
v1 = 0.558594f;
u2 = 0.451172f;
v2 = 0.757813f;
}
@ -568,9 +568,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.4625f;
v1 = 0.573438f;
u2 = 0.493164f;
u1 = 0.455078f;
v1 = 0.558594f;
u2 = 0.496094f;
v2 = 0.757813f;
}
@ -579,9 +579,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.507422f;
v1 = 0.573438f;
u2 = 0.538086f;
u1 = 0.5f;
v1 = 0.558594f;
u2 = 0.541016f;
v2 = 0.757813f;
}
@ -590,9 +590,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.552344f;
v1 = 0.573438f;
u2 = 0.581055f;
u1 = 0.544922f;
v1 = 0.558594f;
u2 = 0.583984f;
v2 = 0.757813f;
}
@ -601,9 +601,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.595313f;
v1 = 0.573438f;
u2 = 0.624023f;
u1 = 0.587891f;
v1 = 0.558594f;
u2 = 0.626953f;
v2 = 0.757813f;
}
@ -612,9 +612,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.638281f;
v1 = 0.573438f;
u2 = 0.663086f;
u1 = 0.630859f;
v1 = 0.558594f;
u2 = 0.666016f;
v2 = 0.757813f;
}
@ -623,9 +623,9 @@ chars
{
width = 17;
height = 42;
u1 = 0.677344f;
v1 = 0.573438f;
u2 = 0.71582f;
u1 = 0.669922f;
v1 = 0.558594f;
u2 = 0.71875f;
v2 = 0.757813f;
}
@ -634,9 +634,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.730078f;
v1 = 0.573438f;
u2 = 0.758789f;
u1 = 0.722656f;
v1 = 0.558594f;
u2 = 0.761719f;
v2 = 0.757813f;
}
@ -645,9 +645,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.773047f;
v1 = 0.573438f;
u2 = 0.801758f;
u1 = 0.765625f;
v1 = 0.558594f;
u2 = 0.804688f;
v2 = 0.757813f;
}
@ -656,9 +656,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.816016f;
v1 = 0.573438f;
u2 = 0.864258f;
u1 = 0.808594f;
v1 = 0.558594f;
u2 = 0.867188f;
v2 = 0.757813f;
}
@ -667,9 +667,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.878516f;
v1 = 0.573438f;
u2 = 0.926758f;
u1 = 0.871094f;
v1 = 0.558594f;
u2 = 0.929688f;
v2 = 0.757813f;
}
@ -678,9 +678,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.941016f;
v1 = 0.573438f;
u2 = 0.96582f;
u1 = 0.933594f;
v1 = 0.558594f;
u2 = 0.96875f;
v2 = 0.757813f;
}
@ -689,9 +689,9 @@ chars
{
width = 21;
height = 42;
u1 = 0.019141f;
v1 = 0.760938f;
u2 = 0.06543f;
u1 = 0.011719f;
v1 = 0.746094f;
u2 = 0.068359f;
v2 = 0.945313f;
}
@ -700,9 +700,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.079688f;
v1 = 0.760938f;
u2 = 0.104492f;
u1 = 0.072266f;
v1 = 0.746094f;
u2 = 0.107422f;
v2 = 0.945313f;
}

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -324,6 +324,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Rendering\Color2DShader.cs" />
<Compile Include="Rendering\Texture2DShader.cs" />
<Compile Include="Rendering\Display2DShader.cs" />
<Compile Include="Rendering\ColorCollection.cs" />
<Compile Include="Rendering\ColorSetting.cs" />
@ -336,6 +337,9 @@
<Compile Include="Rendering\IRenderer2D.cs" />
<Compile Include="Rendering\IRenderer3D.cs" />
<Compile Include="Rendering\RenderLayers.cs" />
<Compile Include="Rendering\TextAlignment.cs" />
<Compile Include="Rendering\TextFont.cs" />
<Compile Include="Rendering\TextLabel.cs" />
<Compile Include="Rendering\VisualGeometry.cs" />
<Compile Include="Rendering\PixelColor.cs" />
<Compile Include="Rendering\PixelColorBlock.cs" />
@ -517,5 +521,6 @@
<EmbeddedResource Include="Resources\Font.cfg" />
<None Include="Resources\Splash2_small.png" />
<None Include="Resources\Splash2_trans.png" />
<EmbeddedResource Include="Resources\texture2d.fx" />
</ItemGroup>
</Project>

View file

@ -69,6 +69,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// List of unselected lines
protected ICollection<Linedef> snaptolines;
// Text labels for all unstable lines
protected TextLabel[] labels;
// Keep track of view changes
private float lastoffsetx;
private float lastoffsety;
@ -96,7 +99,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
if(!isdisposed)
{
// Clean up
if(labels != null)
foreach(TextLabel l in labels) l.Dispose();
// Done
base.Dispose();
}
@ -145,9 +150,27 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// These will have their length displayed during the drag
unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts);
// Make text labels
labels = new TextLabel[unstablelines.Count];
int index = 0;
foreach(Linedef l in unstablelines)
{
Vector2D center = l.GetCenterPoint();
labels[index] = new TextLabel(12);
labels[index].Rectangle = new RectangleF(center.x, center.y, 0f, 0f);
labels[index].AlignX = TextAlignmentX.Center;
labels[index].AlignY = TextAlignmentY.Middle;
labels[index].Color = General.Colors.Highlight;
labels[index].Backcolor = General.Colors.Background;
labels[index].Scale = 14f;
labels[index].TransformCoords = true;
labels[index].Text = l.Length.ToString("0");
index++;
}
Cursor.Current = Cursors.Default;
}
// This moves the selected geometry relatively
// Returns true when geometry has actually moved
private bool MoveGeometryRelative(Vector2D offset, bool snapgrid, bool snapnearest)
@ -245,6 +268,17 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
i++;
}
// Update labels
int index = 0;
foreach(Linedef l in unstablelines)
{
l.UpdateCache();
Vector2D center = l.GetCenterPoint();
labels[index].Rectangle = new RectangleF(center.x, center.y, 0f, 0f);
labels[index].Text = l.Length.ToString("0");
index++;
}
// Moved
return true;
}

View file

@ -160,6 +160,16 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
renderer.Finish();
}
}
// Redraw overlay
if(renderer.StartOverlay(true))
{
foreach(TextLabel l in labels)
{
renderer.RenderText(l);
}
renderer.Finish();
}
renderer.Present();
}

View file

@ -166,6 +166,16 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
}
}
// Redraw overlay
if(renderer.StartOverlay(true))
{
foreach(TextLabel l in labels)
{
renderer.RenderText(l);
}
renderer.Finish();
}
renderer.Present();
}

View file

@ -143,20 +143,16 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
}
}
// Redraw overlay
if(renderer.StartOverlay(true))
{
foreach(Linedef l in unstablelines)
foreach(TextLabel l in labels)
{
Vector2D delta = l.End.Position - l.Start.Position;
Vector2D textpos = l.Start.Position + (delta * 0.5f);
int length = (int)Math.Round(l.Length);
renderer.RenderTextCentered(length.ToString(), textpos, General.Colors.Highlight, true);
renderer.RenderText(l);
}
renderer.Finish();
}
renderer.Present();
}

View file

@ -48,6 +48,7 @@ namespace CodeImp.DoomBuilder.IO
public override int MaxSidedefs { get { return 65534; } }
public override int VertexDecimals { get { return 0; } }
public override string DecimalsFormat { get { return "0"; } }
#endregion

View file

@ -48,6 +48,7 @@ namespace CodeImp.DoomBuilder.IO
public override int MaxSidedefs { get { return 65534; } }
public override int VertexDecimals { get { return 0; } }
public override string DecimalsFormat { get { return "0"; } }
#endregion

View file

@ -34,5 +34,6 @@ namespace CodeImp.DoomBuilder.IO
{
int MaxSidedefs { get; }
int VertexDecimals { get; }
string DecimalsFormat { get; }
}
}

View file

@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.IO
public abstract int MaxSidedefs { get; }
public abstract int VertexDecimals { get; }
public abstract string DecimalsFormat { get; }
#endregion

View file

@ -49,6 +49,7 @@ namespace CodeImp.DoomBuilder.IO
public override int MaxSidedefs { get { return int.MaxValue; } }
public override int VertexDecimals { get { return 3; } }
public override string DecimalsFormat { get { return "0.000"; } }
#endregion

View file

@ -33,6 +33,7 @@ namespace CodeImp.DoomBuilder.Interface
System.Windows.Forms.Label label5;
System.Windows.Forms.GroupBox groupBox1;
System.Windows.Forms.Label label1;
this.squarethings = new System.Windows.Forms.CheckBox();
this.qualitydisplay = new System.Windows.Forms.CheckBox();
this.imagebrightnesslabel = new System.Windows.Forms.Label();
this.imagebrightness = new System.Windows.Forms.TrackBar();
@ -75,7 +76,6 @@ namespace CodeImp.DoomBuilder.Interface
this.colorselection3d = new CodeImp.DoomBuilder.Interface.ColorControl();
this.colorhighlight3d = new CodeImp.DoomBuilder.Interface.ColorControl();
this.colorcrosshair3d = new CodeImp.DoomBuilder.Interface.ColorControl();
this.squarethings = new System.Windows.Forms.CheckBox();
label7 = new System.Windows.Forms.Label();
label6 = new System.Windows.Forms.Label();
label5 = new System.Windows.Forms.Label();
@ -134,6 +134,16 @@ namespace CodeImp.DoomBuilder.Interface
groupBox1.TabStop = false;
groupBox1.Text = " Graphics ";
//
// squarethings
//
this.squarethings.AutoSize = true;
this.squarethings.Location = new System.Drawing.Point(25, 150);
this.squarethings.Name = "squarethings";
this.squarethings.Size = new System.Drawing.Size(93, 18);
this.squarethings.TabIndex = 11;
this.squarethings.Text = "Square things";
this.squarethings.UseVisualStyleBackColor = true;
//
// qualitydisplay
//
this.qualitydisplay.AutoSize = true;
@ -433,6 +443,7 @@ namespace CodeImp.DoomBuilder.Interface
//
this.actioncontrol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.actioncontrol.FormattingEnabled = true;
this.actioncontrol.ImeMode = System.Windows.Forms.ImeMode.Off;
this.actioncontrol.Location = new System.Drawing.Point(23, 204);
this.actioncontrol.Name = "actioncontrol";
this.actioncontrol.Size = new System.Drawing.Size(197, 22);
@ -656,16 +667,6 @@ namespace CodeImp.DoomBuilder.Interface
this.colorcrosshair3d.Size = new System.Drawing.Size(150, 23);
this.colorcrosshair3d.TabIndex = 6;
//
// squarethings
//
this.squarethings.AutoSize = true;
this.squarethings.Location = new System.Drawing.Point(25, 150);
this.squarethings.Name = "squarethings";
this.squarethings.Size = new System.Drawing.Size(93, 18);
this.squarethings.TabIndex = 11;
this.squarethings.Text = "Square things";
this.squarethings.UseVisualStyleBackColor = true;
//
// PreferencesForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;

View file

@ -354,6 +354,12 @@ namespace CodeImp.DoomBuilder.Map
return p;
}
// This returns a point in the middle of the line
public Vector2D GetCenterPoint()
{
return start.Position + (end.Position - start.Position) * 0.5f;
}
// This applies single/double sided flags
public void ApplySidedFlags()

View file

@ -30,6 +30,9 @@ using System.ComponentModel;
using CodeImp.DoomBuilder.Geometry;
using SlimDX;
using CodeImp.DoomBuilder.Interface;
using CodeImp.DoomBuilder.Data;
using Configuration = CodeImp.DoomBuilder.IO.Configuration;
#endregion
@ -58,6 +61,8 @@ namespace CodeImp.DoomBuilder.Rendering
private ShaderManager shaders;
private Surface backbuffer;
private Surface depthbuffer;
private TextFont font;
private ResourceImage fonttexture;
// Disposing
private bool isdisposed = false;
@ -73,6 +78,8 @@ namespace CodeImp.DoomBuilder.Rendering
internal ShaderManager Shaders { get { return shaders; } }
internal Surface BackBuffer { get { return backbuffer; } }
internal Surface DepthBuffer { get { return depthbuffer; } }
internal TextFont Font { get { return font; } }
internal Texture FontTexture { get { return fonttexture.Texture; } }
#endregion
@ -104,6 +111,8 @@ namespace CodeImp.DoomBuilder.Rendering
if(backbuffer != null) backbuffer.Dispose();
if(depthbuffer != null) depthbuffer.Dispose();
device.Dispose();
if(font != null) font.Dispose();
if(fonttexture != null) fonttexture.Dispose();
// Done
isdisposed = true;
@ -253,6 +262,12 @@ namespace CodeImp.DoomBuilder.Rendering
// Create shader manager
shaders = new ShaderManager(this);
// Font
font = new TextFont();
fonttexture = new ResourceImage("Font.png");
fonttexture.LoadImage();
fonttexture.CreateTexture();
// Initialize settings
SetupSettings();

View file

@ -73,7 +73,6 @@ namespace CodeImp.DoomBuilder.Rendering
void RenderRectangle(RectangleF rect, float bordersize, PixelColor c, bool transformrect);
void RenderRectangleFilled(RectangleF rect, PixelColor c, bool transformrect);
void RenderLine(Vector2D start, Vector2D end, float thickness, PixelColor c, bool transformcoords);
void RenderText(string text, Vector2D pos, PixelColor c, bool transformpos);
void RenderTextCentered(string text, Vector2D pos, PixelColor c, bool transformpos);
void RenderText(TextLabel text);
}
}

View file

@ -138,6 +138,8 @@ namespace CodeImp.DoomBuilder.Rendering
public float OffsetX { get { return offsetx; } }
public float OffsetY { get { return offsety; } }
public float TranslateX { get { return translatex; } }
public float TranslateY { get { return translatey; } }
public float Scale { get { return scale; } }
public int VertexSize { get { return vertexsize; } }
@ -1050,39 +1052,31 @@ namespace CodeImp.DoomBuilder.Rendering
#region ================== Overlay
// This renders text
public void RenderText(string text, Vector2D pos, PixelColor c, bool transformpos)
public void RenderText(TextLabel text)
{
// Calculate coordinates
if(transformpos) pos = pos.GetTransformed(translatex, translatey, scale, -scale);
Rectangle posr = new Rectangle((int)pos.x, (int)pos.y, 0, 0);
// Update the text if needed
text.Update(translatex, translatey, scale, -scale);
// Set renderstates for rendering
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
graphics.Device.SetRenderState(RenderState.ZEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
// Draw
if(font != null) font.DrawString(null, text, posr, DrawTextFormat.VCenter | DrawTextFormat.Left | DrawTextFormat.NoClip, c.ToColorValue());
}
// Text is created?
if(text.VertexBuffer != null)
{
// Set renderstates for rendering
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
graphics.Device.SetRenderState(RenderState.ZEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
graphics.Shaders.Texture2D.Texture1 = graphics.FontTexture;
graphics.Device.SetTexture(0, graphics.FontTexture);
graphics.Device.SetStreamSource(0, text.VertexBuffer, 0, FlatVertex.Stride);
// This renders text
public void RenderTextCentered(string text, Vector2D pos, PixelColor c, bool transformpos)
{
// Calculate coordinates
if(transformpos) pos = pos.GetTransformed(translatex, translatey, scale, -scale);
Rectangle posr = new Rectangle((int)pos.x, (int)pos.y, 0, 0);
// Set renderstates for rendering
graphics.Device.SetRenderState(RenderState.CullMode, Cull.None);
graphics.Device.SetRenderState(RenderState.ZEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, false);
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
// Draw
if(font != null) font.DrawString(null, text, posr, DrawTextFormat.VCenter | DrawTextFormat.Center | DrawTextFormat.NoClip, c.ToColorValue());
// Draw
graphics.Shaders.Texture2D.Begin();
graphics.Shaders.Texture2D.BeginPass(0);
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, text.NumFaces);
graphics.Shaders.Texture2D.EndPass();
graphics.Shaders.Texture2D.End();
}
}
// This renders a rectangle with given border size and color

View file

@ -53,6 +53,7 @@ namespace CodeImp.DoomBuilder.Rendering
private Things2DShader things2dshader;
private World3DShader world3dshader;
private Color2DShader color2dshader;
private Texture2DShader texture2dshader;
// Device
private D3DDevice device;
@ -70,6 +71,7 @@ namespace CodeImp.DoomBuilder.Rendering
public Things2DShader Things2D { get { return things2dshader; } }
public World3DShader World3D { get { return world3dshader; } }
public Color2DShader Color2D { get { return color2dshader; } }
public Texture2DShader Texture2D { get { return texture2dshader; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -121,6 +123,7 @@ namespace CodeImp.DoomBuilder.Rendering
things2dshader.Dispose();
world3dshader.Dispose();
color2dshader.Dispose();
texture2dshader.Dispose();
}
// Load resources
@ -138,6 +141,7 @@ namespace CodeImp.DoomBuilder.Rendering
things2dshader = new Things2DShader(this);
world3dshader = new World3DShader(this);
color2dshader = new Color2DShader(this);
texture2dshader = new Texture2DShader(this);
}
#endregion

View file

@ -0,0 +1,56 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* 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.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Imaging;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Editing;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
// This enumeration defines horizontal alignment
public enum TextAlignmentX : int
{
Left = 0,
Center = 1,
Right = 2
}
// This enumeration defines vertical alignment
public enum TextAlignmentY : int
{
Top = 0,
Middle = 1,
Bottom = 2
}
}

View file

@ -0,0 +1,272 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* 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.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Imaging;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Editing;
using Configuration = CodeImp.DoomBuilder.IO.Configuration;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
internal class TextFont : IDisposable
{
#region ================== Structures
// This structure defines character properties
private struct FontCharacter
{
// Variables
public float width;
public float height;
public float u1;
public float v1;
public float u2;
public float v2;
}
#endregion
#region ================== Constants
// Font resource name
private const string FONT_RESOURCE = "Font.cfg";
// Spacing adjustments
private const float ADJUST_SPACING = -0.08f;
#endregion
#region ================== Variables
// Characters
private FontCharacter[] characters;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
internal TextFont()
{
Configuration cfg;
Stream fontdata;
StreamReader fontreader;
string[] resnames;
// Initialize
characters = new FontCharacter[256];
// Make chars configuration
cfg = new Configuration();
// Find a resource named Font.cfg
resnames = General.ThisAssembly.GetManifestResourceNames();
foreach(string rn in resnames)
{
// Found it?
if(rn.EndsWith(FONT_RESOURCE, StringComparison.InvariantCultureIgnoreCase))
{
// Get a stream from the resource
fontdata = General.ThisAssembly.GetManifestResourceStream(rn);
fontreader = new StreamReader(fontdata, Encoding.ASCII);
// Load configuration from stream
cfg.InputConfiguration(fontreader.ReadToEnd());
// Done
fontreader.Dispose();
fontdata.Dispose();
break;
}
}
// Get the charset from configuration
IDictionary cfgchars = cfg.ReadSetting("chars", new Hashtable());
// Go for all defined chars
foreach(DictionaryEntry item in cfgchars)
{
// Get the character Hashtable
IDictionary chr = (IDictionary)item.Value;
int i = Convert.ToInt32(item.Key);
// This is ancient code of mine.
// The charater sizes were based on 800x600 resolution.
characters[i].width = (float)(int)chr["width"] / 40f;
characters[i].height = (float)(int)chr["height"] / 30f;
characters[i].u1 = (float)chr["u1"];
characters[i].v1 = (float)chr["v1"];
characters[i].u2 = (float)chr["u2"];
characters[i].v2 = (float)chr["v2"];
}
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
// This sets up vertices for a specific character
// also advances vertsoffset and textx
public void SetupVertices(DataStream stream, byte c, float scale, int color,
ref float textx, float texty, float textheight, float offsetv)
{
FlatVertex vert = new FlatVertex();
FontCharacter cinfo;
float cwidth;
// Get the character information
cinfo = characters[c];
cwidth = cinfo.width * scale;
// Create lefttop vertex
vert.c = color;
vert.u = cinfo.u1;
vert.v = cinfo.v1 * 0.5f + offsetv;
vert.x = textx;
vert.y = texty;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
// Create leftbottom vertex
vert.c = color;
vert.u = cinfo.u1;
vert.v = cinfo.v2 * 0.5f + offsetv;
vert.x = textx;
vert.y = texty + textheight;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
// Create righttop vertex
vert.c = color;
vert.u = cinfo.u2;
vert.v = cinfo.v1 * 0.5f + offsetv;
vert.x = textx + cwidth;
vert.y = texty;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
// Create leftbottom vertex
vert.c = color;
vert.u = cinfo.u1;
vert.v = cinfo.v2 * 0.5f + offsetv;
vert.x = textx;
vert.y = texty + textheight;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
// Create righttop vertex
vert.c = color;
vert.u = cinfo.u2;
vert.v = cinfo.v1 * 0.5f + offsetv;
vert.x = textx + cwidth;
vert.y = texty;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
// Create rightbottom vertex
vert.c = color;
vert.u = cinfo.u2;
vert.v = cinfo.v2 * 0.5f + offsetv;
vert.x = textx + cwidth;
vert.y = texty + textheight;
vert.w = 1f;
stream.Write<FlatVertex>(vert);
textx += (cwidth + (ADJUST_SPACING * scale));
}
// This checks if the given character exists in the charset
public bool Contains(char c)
{
// Convert character to ASCII
byte[] keybyte = Encoding.ASCII.GetBytes(c.ToString());
return Contains(keybyte[0]);
}
// This checks if the given character exists in the charset
public bool Contains(byte b)
{
// Check if the character has been set
return ((characters[b].width > 0.000000001f) ||
(characters[b].height > 0.000000001f));
}
// This calculates the size of a text string at a given scale
public SizeF GetTextSize(string text, float scale)
{
// Size items
float sizex = 0, sizey = 0;
// Get the ASCII bytes for the text
byte[] btext = Encoding.ASCII.GetBytes(text);
// Go for all chars in text to calculate final text size
foreach(byte b in btext)
{
// Add to the final size
sizex += characters[b].width * scale;
sizey = characters[b].height * scale;
}
// Return size
return new SizeF(sizex, sizey);
}
#endregion
}
}

View file

@ -0,0 +1,283 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* 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.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Imaging;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Editing;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
public class TextLabel : IDisposable, ID3DResource
{
#region ================== Constants
#endregion
#region ================== Variables
// The text is stored as a polygon in a vertex buffer
private VertexBuffer textbuffer;
private int numfaces;
private int capacity;
// Text settings
private string text;
private RectangleF rect;
private bool transformcoords;
private PixelColor color;
private PixelColor backcolor;
private float scale;
private TextAlignmentX alignx;
private TextAlignmentY aligny;
private SizeF size;
// This keeps track if changes were made
private bool updateneeded;
private float lasttranslatex = float.MinValue;
private float lasttranslatey;
private float lastscalex;
private float lastscaley;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
// Properties
public RectangleF Rectangle { get { return rect; } set { rect = value; updateneeded = true; } }
public float Left { get { return rect.X; } set { rect.X = value; updateneeded = true; } }
public float Top { get { return rect.Y; } set { rect.Y = value; updateneeded = true; } }
public float Width { get { return rect.Width; } set { rect.Width = value; updateneeded = true; } }
public float Height { get { return rect.Height; } set { rect.Height = value; updateneeded = true; } }
public float Right { get { return rect.Right; } set { rect.Width = value - rect.X + 1f; updateneeded = true; } }
public float Bottom { get { return rect.Bottom; } set { rect.Height = value - rect.Y + 1f; updateneeded = true; } }
public string Text { get { return text; } set { if(text != value) { text = value; updateneeded = true; } } }
public bool TransformCoords { get { return transformcoords; } set { transformcoords = value; updateneeded = true; } }
public SizeF TextSize { get { return size; } }
public float Scale { get { return scale; } set { scale = value; updateneeded = true; } }
public TextAlignmentX AlignX { get { return alignx; } set { alignx = value; updateneeded = true; } }
public TextAlignmentY AlignY { get { return aligny; } set { aligny = value; updateneeded = true; } }
public PixelColor Color { get { return color; } set { color = value; updateneeded = true; } }
public PixelColor Backcolor { get { return backcolor; } set { backcolor = value; updateneeded = true; } }
internal VertexBuffer VertexBuffer { get { return textbuffer; } }
internal int NumFaces { get { return numfaces; } }
// Disposing
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public TextLabel(int capacity)
{
// Initialize
this.text = "";
this.rect = new RectangleF(0f, 0f, 1f, 1f);
this.color = new PixelColor(255, 255, 255, 255);
this.backcolor = new PixelColor(0, 0, 0, 0);
this.scale = 10f;
this.alignx = TextAlignmentX.Left;
this.aligny = TextAlignmentY.Top;
this.size = new SizeF(0f, 0f);
this.updateneeded = true;
this.numfaces = 0;
this.capacity = capacity;
// Register as resource
General.Map.Graphics.RegisterResource(this);
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
UnloadResource();
// Unregister resource
General.Map.Graphics.UnregisterResource(this);
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
// This updates the text if needed
internal void Update(float translatex, float translatey, float scalex, float scaley)
{
FlatVertex[] verts;
RectangleF absview;
float beginx = 0;
float beginy = 0;
bool colorcode = false;
int characters = 0;
byte[] textbytes;
DataStream stream;
// Check if transformation changed and needs to be updated
if(transformcoords)
{
if((translatex != lasttranslatex) ||
(translatey != lasttranslatey) ||
(scalex != lastscalex) ||
(scaley != lastscaley)) updateneeded = true;
}
// Update if needed
if(updateneeded)
{
// Only build when there are any vertices
if(text.Length > 0)
{
// Do we have to make a new buffer?
if((textbuffer == null) || (text.Length > capacity))
{
// Dispose previous
if(textbuffer != null) textbuffer.Dispose();
// Determine new capacity
if(capacity < text.Length) capacity = text.Length;
// Create the buffer
textbuffer = new VertexBuffer(General.Map.Graphics.Device,
capacity * 12 * FlatVertex.Stride,
Usage.Dynamic | Usage.WriteOnly,
VertexFormat.None, Pool.Default);
}
// Transform?
if(transformcoords)
{
// Calculate absolute coordinates
Vector2D lt = new Vector2D(rect.Left, rect.Top);
Vector2D rb = new Vector2D(rect.Right, rect.Bottom);
lt = lt.GetTransformed(translatex, translatey, scalex, scaley);
rb = rb.GetTransformed(translatex, translatey, scalex, scaley);
absview = new RectangleF(lt.x, lt.y, rb.x - lt.x, rb.y - lt.y);
}
else
{
// Fixed coordinates
absview = rect;
}
// Calculate text dimensions
size = General.Map.Graphics.Font.GetTextSize(text, scale);
// Align the text horizontally
switch(alignx)
{
case TextAlignmentX.Left: beginx = absview.X; break;
case TextAlignmentX.Center: beginx = absview.X + (absview.Width - size.Width) * 0.5f; break;
case TextAlignmentX.Right: beginx = absview.X + absview.Width - size.Width; break;
}
// Align the text vertically
switch(aligny)
{
case TextAlignmentY.Top: beginy = absview.Y; break;
case TextAlignmentY.Middle: beginy = absview.Y + (absview.Height - size.Height) * 0.5f; break;
case TextAlignmentY.Bottom: beginy = absview.Y + absview.Height - size.Height; break;
}
// Get the ASCII bytes for the text
textbytes = Encoding.ASCII.GetBytes(text);
// Lock the buffer
stream = textbuffer.Lock(0, capacity * 12 * FlatVertex.Stride,
LockFlags.Discard | LockFlags.NoSystemLock);
// Go for all chars in text to create the backgrounds
float textx = beginx;
foreach(byte b in textbytes)
General.Map.Graphics.Font.SetupVertices(stream, b, scale, backcolor.ToInt(),
ref textx, beginy, size.Height, 0.5f);
// Go for all chars in text to create the text
textx = beginx;
foreach(byte b in textbytes)
General.Map.Graphics.Font.SetupVertices(stream, b, scale, color.ToInt(),
ref textx, beginy, size.Height, 0.0f);
// Done filling the vertex buffer
textbuffer.Unlock();
stream.Dispose();
// Calculate number of triangles
numfaces = text.Length * 4;
}
else
{
// No faces in polygon
numfaces = 0;
size = new SizeF(0f, 0f);
}
// Text updated
updateneeded = false;
}
}
// This unloads the resources
public void UnloadResource()
{
// Clean up
if(textbuffer != null) textbuffer.Dispose();
textbuffer = null;
// Need to update before we can render
updateneeded = true;
}
// This (re)loads the resources
public void ReloadResource()
{
}
#endregion
}
}

View file

@ -0,0 +1,102 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* 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.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Imaging;
#endregion
namespace CodeImp.DoomBuilder.Rendering
{
internal sealed class Texture2DShader : D3DShader
{
#region ================== Variables
// Property handlers
private EffectHandle texture1;
#endregion
#region ================== Properties
public Texture Texture1 { set { if(manager.Enabled) effect.SetValue(texture1, value); } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public Texture2DShader(ShaderManager manager) : base(manager)
{
// Load effect from file
effect = LoadEffect("texture2d.fx");
// Get the property handlers from effect
if(effect != null)
{
texture1 = effect.GetParameter(null, "texture1");
}
// Initialize world vertex declaration
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
new VertexElement(0, 20, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
VertexElement.VertexDeclarationEnd
};
vertexdecl = new VertexDeclaration(General.Map.Graphics.Device, elements);
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
if(texture1 != null) texture1.Dispose();
// Done
base.Dispose();
}
}
#endregion
#region ================== Methods
#endregion
}
}

View file

@ -7,9 +7,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.019141f;
v1 = 0.010938f;
u2 = 0.075195f;
u1 = 0.011719f;
v1 = -0.003906f;
u2 = 0.078125f;
v2 = 0.195313f;
}
@ -18,9 +18,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.089453f;
v1 = 0.010938f;
u2 = 0.145508f;
u1 = 0.082031f;
v1 = -0.003906f;
u2 = 0.148438f;
v2 = 0.195313f;
}
@ -29,9 +29,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.159766f;
v1 = 0.010938f;
u2 = 0.21582f;
u1 = 0.152344f;
v1 = -0.003906f;
u2 = 0.21875f;
v2 = 0.195313f;
}
@ -40,9 +40,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.230078f;
v1 = 0.010938f;
u2 = 0.286133f;
u1 = 0.222656f;
v1 = -0.003906f;
u2 = 0.289063f;
v2 = 0.195313f;
}
@ -51,9 +51,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.300391f;
v1 = 0.010938f;
u2 = 0.352539f;
u1 = 0.292969f;
v1 = -0.003906f;
u2 = 0.355469f;
v2 = 0.195313f;
}
@ -62,9 +62,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.366797f;
v1 = 0.010938f;
u2 = 0.415039f;
u1 = 0.359375f;
v1 = -0.003906f;
u2 = 0.417969f;
v2 = 0.195313f;
}
@ -73,9 +73,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.429297f;
v1 = 0.010938f;
u2 = 0.489258f;
u1 = 0.421875f;
v1 = -0.003906f;
u2 = 0.492188f;
v2 = 0.195313f;
}
@ -84,9 +84,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.503516f;
v1 = 0.010938f;
u2 = 0.563477f;
u1 = 0.496094f;
v1 = -0.003906f;
u2 = 0.566406f;
v2 = 0.195313f;
}
@ -95,9 +95,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.577734f;
v1 = 0.010938f;
u2 = 0.608398f;
u1 = 0.570313f;
v1 = -0.003906f;
u2 = 0.611328f;
v2 = 0.195313f;
}
@ -106,9 +106,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.622656f;
v1 = 0.010938f;
u2 = 0.670898f;
u1 = 0.615234f;
v1 = -0.003906f;
u2 = 0.673828f;
v2 = 0.195313f;
}
@ -117,9 +117,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.685156f;
v1 = 0.010938f;
u2 = 0.745117f;
u1 = 0.677734f;
v1 = -0.003906f;
u2 = 0.748047f;
v2 = 0.195313f;
}
@ -128,9 +128,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.759375f;
v1 = 0.010938f;
u2 = 0.807617f;
u1 = 0.751953f;
v1 = -0.003906f;
u2 = 0.810547f;
v2 = 0.195313f;
}
@ -139,9 +139,9 @@ chars
{
width = 31;
height = 42;
u1 = 0.821875f;
v1 = 0.010938f;
u2 = 0.887695f;
u1 = 0.814453f;
v1 = -0.003906f;
u2 = 0.890625f;
v2 = 0.195313f;
}
@ -150,9 +150,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.901953f;
v1 = 0.010938f;
u2 = 0.961914f;
u1 = 0.894531f;
v1 = -0.003906f;
u2 = 0.964844f;
v2 = 0.195313f;
}
@ -161,9 +161,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.019141f;
v1 = 0.198438f;
u2 = 0.079102f;
u1 = 0.011719f;
v1 = 0.183594f;
u2 = 0.082031f;
v2 = 0.382813f;
}
@ -172,9 +172,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.093359f;
v1 = 0.198438f;
u2 = 0.145508f;
u1 = 0.085938f;
v1 = 0.183594f;
u2 = 0.148438f;
v2 = 0.382813f;
}
@ -183,9 +183,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.159766f;
v1 = 0.198438f;
u2 = 0.219727f;
u1 = 0.152344f;
v1 = 0.183594f;
u2 = 0.222656f;
v2 = 0.382813f;
}
@ -194,9 +194,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.233984f;
v1 = 0.198438f;
u2 = 0.290039f;
u1 = 0.226563f;
v1 = 0.183594f;
u2 = 0.292969f;
v2 = 0.382813f;
}
@ -205,9 +205,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.304297f;
v1 = 0.198438f;
u2 = 0.356445f;
u1 = 0.296875f;
v1 = 0.183594f;
u2 = 0.359375f;
v2 = 0.382813f;
}
@ -216,9 +216,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.370703f;
v1 = 0.198438f;
u2 = 0.422852f;
u1 = 0.363281f;
v1 = 0.183594f;
u2 = 0.425781f;
v2 = 0.382813f;
}
@ -227,9 +227,9 @@ chars
{
width = 28;
height = 42;
u1 = 0.437109f;
v1 = 0.198438f;
u2 = 0.49707f;
u1 = 0.429688f;
v1 = 0.183594f;
u2 = 0.5f;
v2 = 0.382813f;
}
@ -238,9 +238,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.511328f;
v1 = 0.198438f;
u2 = 0.567383f;
u1 = 0.503906f;
v1 = 0.183594f;
u2 = 0.570313f;
v2 = 0.382813f;
}
@ -249,9 +249,9 @@ chars
{
width = 33;
height = 42;
u1 = 0.581641f;
v1 = 0.198438f;
u2 = 0.651367f;
u1 = 0.574219f;
v1 = 0.183594f;
u2 = 0.654297f;
v2 = 0.382813f;
}
@ -260,9 +260,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.665625f;
v1 = 0.198438f;
u2 = 0.72168f;
u1 = 0.658203f;
v1 = 0.183594f;
u2 = 0.724609f;
v2 = 0.382813f;
}
@ -271,9 +271,9 @@ chars
{
width = 26;
height = 42;
u1 = 0.735938f;
v1 = 0.198438f;
u2 = 0.791992f;
u1 = 0.728516f;
v1 = 0.183594f;
u2 = 0.794922f;
v2 = 0.382813f;
}
@ -282,9 +282,9 @@ chars
{
width = 24;
height = 42;
u1 = 0.80625f;
v1 = 0.198438f;
u2 = 0.858398f;
u1 = 0.798828f;
v1 = 0.183594f;
u2 = 0.861328f;
v2 = 0.382813f;
}
@ -293,9 +293,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.872656f;
v1 = 0.198438f;
u2 = 0.920898f;
u1 = 0.865234f;
v1 = 0.183594f;
u2 = 0.923828f;
v2 = 0.382813f;
}
@ -304,9 +304,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.935156f;
v1 = 0.198438f;
u2 = 0.983398f;
u1 = 0.927734f;
v1 = 0.183594f;
u2 = 0.986328f;
v2 = 0.382813f;
}
@ -315,9 +315,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.019141f;
v1 = 0.385938f;
u2 = 0.067383f;
u1 = 0.011719f;
v1 = 0.371094f;
u2 = 0.070313f;
v2 = 0.570313f;
}
@ -326,9 +326,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.081641f;
v1 = 0.385938f;
u2 = 0.129883f;
u1 = 0.074219f;
v1 = 0.371094f;
u2 = 0.132813f;
v2 = 0.570313f;
}
@ -337,9 +337,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.144141f;
v1 = 0.385938f;
u2 = 0.192383f;
u1 = 0.136719f;
v1 = 0.371094f;
u2 = 0.195313f;
v2 = 0.570313f;
}
@ -348,9 +348,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.206641f;
v1 = 0.385938f;
u2 = 0.254883f;
u1 = 0.199219f;
v1 = 0.371094f;
u2 = 0.257813f;
v2 = 0.570313f;
}
@ -359,9 +359,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.269141f;
v1 = 0.385938f;
u2 = 0.317383f;
u1 = 0.261719f;
v1 = 0.371094f;
u2 = 0.320313f;
v2 = 0.570313f;
}
@ -370,9 +370,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.331641f;
v1 = 0.385938f;
u2 = 0.379883f;
u1 = 0.324219f;
v1 = 0.371094f;
u2 = 0.382813f;
v2 = 0.570313f;
}
@ -381,9 +381,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.394141f;
v1 = 0.385938f;
u2 = 0.442383f;
u1 = 0.386719f;
v1 = 0.371094f;
u2 = 0.445313f;
v2 = 0.570313f;
}
@ -392,9 +392,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.456641f;
v1 = 0.385938f;
u2 = 0.504883f;
u1 = 0.449219f;
v1 = 0.371094f;
u2 = 0.507813f;
v2 = 0.570313f;
}
@ -403,9 +403,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.519141f;
v1 = 0.385938f;
u2 = 0.547852f;
u1 = 0.511719f;
v1 = 0.371094f;
u2 = 0.550781f;
v2 = 0.570313f;
}
@ -414,9 +414,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.562109f;
v1 = 0.385938f;
u2 = 0.59082f;
u1 = 0.554688f;
v1 = 0.371094f;
u2 = 0.59375f;
v2 = 0.570313f;
}
@ -425,9 +425,9 @@ chars
{
width = 25;
height = 42;
u1 = 0.605078f;
v1 = 0.385938f;
u2 = 0.65918f;
u1 = 0.597656f;
v1 = 0.371094f;
u2 = 0.662109f;
v2 = 0.570313f;
}
@ -436,9 +436,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.673438f;
v1 = 0.385938f;
u2 = 0.72168f;
u1 = 0.666016f;
v1 = 0.371094f;
u2 = 0.724609f;
v2 = 0.570313f;
}
@ -447,9 +447,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.735938f;
v1 = 0.385938f;
u2 = 0.78418f;
u1 = 0.728516f;
v1 = 0.371094f;
u2 = 0.787109f;
v2 = 0.570313f;
}
@ -458,9 +458,9 @@ chars
{
width = 33;
height = 42;
u1 = 0.798438f;
v1 = 0.385938f;
u2 = 0.868164f;
u1 = 0.791016f;
v1 = 0.371094f;
u2 = 0.871094f;
v2 = 0.570313f;
}
@ -469,9 +469,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.882422f;
v1 = 0.385938f;
u2 = 0.930664f;
u1 = 0.875f;
v1 = 0.371094f;
u2 = 0.933594f;
v2 = 0.570313f;
}
@ -480,9 +480,9 @@ chars
{
width = 29;
height = 42;
u1 = 0.019141f;
v1 = 0.573438f;
u2 = 0.081055f;
u1 = 0.011719f;
v1 = 0.558594f;
u2 = 0.083984f;
v2 = 0.757813f;
}
@ -491,9 +491,9 @@ chars
{
width = 19;
height = 42;
u1 = 0.095313f;
v1 = 0.573438f;
u2 = 0.137695f;
u1 = 0.087891f;
v1 = 0.558594f;
u2 = 0.140625f;
v2 = 0.757813f;
}
@ -502,9 +502,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.151953f;
v1 = 0.573438f;
u2 = 0.182617f;
u1 = 0.144531f;
v1 = 0.558594f;
u2 = 0.185547f;
v2 = 0.757813f;
}
@ -513,9 +513,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.196875f;
v1 = 0.573438f;
u2 = 0.227539f;
u1 = 0.189453f;
v1 = 0.558594f;
u2 = 0.230469f;
v2 = 0.757813f;
}
@ -524,9 +524,9 @@ chars
{
width = 17;
height = 42;
u1 = 0.241797f;
v1 = 0.573438f;
u2 = 0.280273f;
u1 = 0.234375f;
v1 = 0.558594f;
u2 = 0.283203f;
v2 = 0.757813f;
}
@ -535,9 +535,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.294531f;
v1 = 0.573438f;
u2 = 0.342773f;
u1 = 0.287109f;
v1 = 0.558594f;
u2 = 0.345703f;
v2 = 0.757813f;
}
@ -546,9 +546,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.357031f;
v1 = 0.573438f;
u2 = 0.405273f;
u1 = 0.349609f;
v1 = 0.558594f;
u2 = 0.408203f;
v2 = 0.757813f;
}
@ -557,9 +557,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.419531f;
v1 = 0.573438f;
u2 = 0.448242f;
u1 = 0.412109f;
v1 = 0.558594f;
u2 = 0.451172f;
v2 = 0.757813f;
}
@ -568,9 +568,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.4625f;
v1 = 0.573438f;
u2 = 0.493164f;
u1 = 0.455078f;
v1 = 0.558594f;
u2 = 0.496094f;
v2 = 0.757813f;
}
@ -579,9 +579,9 @@ chars
{
width = 13;
height = 42;
u1 = 0.507422f;
v1 = 0.573438f;
u2 = 0.538086f;
u1 = 0.5f;
v1 = 0.558594f;
u2 = 0.541016f;
v2 = 0.757813f;
}
@ -590,9 +590,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.552344f;
v1 = 0.573438f;
u2 = 0.581055f;
u1 = 0.544922f;
v1 = 0.558594f;
u2 = 0.583984f;
v2 = 0.757813f;
}
@ -601,9 +601,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.595313f;
v1 = 0.573438f;
u2 = 0.624023f;
u1 = 0.587891f;
v1 = 0.558594f;
u2 = 0.626953f;
v2 = 0.757813f;
}
@ -612,9 +612,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.638281f;
v1 = 0.573438f;
u2 = 0.663086f;
u1 = 0.630859f;
v1 = 0.558594f;
u2 = 0.666016f;
v2 = 0.757813f;
}
@ -623,9 +623,9 @@ chars
{
width = 17;
height = 42;
u1 = 0.677344f;
v1 = 0.573438f;
u2 = 0.71582f;
u1 = 0.669922f;
v1 = 0.558594f;
u2 = 0.71875f;
v2 = 0.757813f;
}
@ -634,9 +634,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.730078f;
v1 = 0.573438f;
u2 = 0.758789f;
u1 = 0.722656f;
v1 = 0.558594f;
u2 = 0.761719f;
v2 = 0.757813f;
}
@ -645,9 +645,9 @@ chars
{
width = 12;
height = 42;
u1 = 0.773047f;
v1 = 0.573438f;
u2 = 0.801758f;
u1 = 0.765625f;
v1 = 0.558594f;
u2 = 0.804688f;
v2 = 0.757813f;
}
@ -656,9 +656,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.816016f;
v1 = 0.573438f;
u2 = 0.864258f;
u1 = 0.808594f;
v1 = 0.558594f;
u2 = 0.867188f;
v2 = 0.757813f;
}
@ -667,9 +667,9 @@ chars
{
width = 22;
height = 42;
u1 = 0.878516f;
v1 = 0.573438f;
u2 = 0.926758f;
u1 = 0.871094f;
v1 = 0.558594f;
u2 = 0.929688f;
v2 = 0.757813f;
}
@ -678,9 +678,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.941016f;
v1 = 0.573438f;
u2 = 0.96582f;
u1 = 0.933594f;
v1 = 0.558594f;
u2 = 0.96875f;
v2 = 0.757813f;
}
@ -689,9 +689,9 @@ chars
{
width = 21;
height = 42;
u1 = 0.019141f;
v1 = 0.760938f;
u2 = 0.06543f;
u1 = 0.011719f;
v1 = 0.746094f;
u2 = 0.068359f;
v2 = 0.945313f;
}
@ -700,9 +700,9 @@ chars
{
width = 10;
height = 42;
u1 = 0.079688f;
v1 = 0.760938f;
u2 = 0.104492f;
u1 = 0.072266f;
v1 = 0.746094f;
u2 = 0.107422f;
v2 = 0.945313f;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -0,0 +1,40 @@
// 2D textured rendering shader
// Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
// Pixel input data
struct PixelData
{
float4 pos : POSITION;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
// Texture input
texture texture1;
// Texture sampler settings
sampler2D texturesamp = sampler_state
{
Texture = <texture1>;
MagFilter = Linear;
MinFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
// Pixel shader
float4 ps_normal(PixelData pd) : COLOR
{
return pd.color * tex2D(texturesamp, pd.uv);
}
// Technique for shader model 2.0
technique SM20
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 ps_normal();
}
}

View file

@ -54,10 +54,7 @@ float4 ps_main(PixelData pd) : COLOR
float4 tcolor = tex2D(texturesamp, pd.uv);
// Blend texture color and vertex color
return float4(tcolor.r * pd.color.r,
tcolor.g * pd.color.g,
tcolor.b * pd.color.b,
tcolor.a * pd.color.a);
return tcolor * pd.color;
}
// Technique for shader model 2.0