2009年10月29日

Silverlight Game Loop

撰寫遊戲程式,經常需要利用 main loop 處理一些工作。
以下是 Silverlight 使用 loop 的方法。
public Page()
{    
    InitializeComponent();
    CompositionTarget.Rendering += new EventHandler(SnowFlakeTimer);
} 

private void SnowFlakeTimer(object sender, EventArgs e)
{
    // do your task    
}

[Reference]
Silverlight Tip of the Day #50 – Main Game Loop Revisited!

Getting Query String Values in Silverlight

Silverlight 可以直接取得網址後面的參數,
方法如下:
string val = System.Windows.Browser.HtmlPage.Document.QueryString["foo"];

[Reference]
Getting Query String Values in Silverlight

2009年10月28日

Silverlight TextBox 斷行處理

下列的範例,可以將 TextBlock.Text 所取得的字串, 拆解成字串陣列。

string text = TheTextBox.Text;
text = text.Replace(Environment.NewLine, "\r");
string[] texts = text.Split(new char[] { '\r'  });

2009年10月27日

SyntaxHihglighter Test

為了讓程式碼看起來更整潔, 試了一下 SyntaxHihglighte, 有興趣的人可以到官網取得相關資訊。
不過為了讓 blogger 不要自動加入換行, 之前的程式碼卻變得更零亂了。
function test() : String
{
  return 10;
}

2009年10月25日

Silverlight String to Path

由於 Silverlight 並沒有中文字型,所以要顯示中文字便比較麻煩。 如果文字的內容是固定,可以用圖形或將文字轉成 path 的方式處理, 若文字是變動性的,甚至是由 user 來輸入, 就必須建立 WCF 由 server 端來處理了。 以下是 Server 端, 將 string 轉成 path 並傳回的方法:
public string GetFont
  (string str, string fontFamily, int nSize)
{
   Typeface typeface = 
       new Typeface(new FontFamily(fontFamily),
       FontStyles.Normal, FontWeights.Normal, 
       FontStretches.Normal);

   FormattedText text = new FormattedText(str,
       new System.Globalization.CultureInfo("zh-tw"),
       FlowDirection.LeftToRight, typeface, nSize,
       Brushes.Black);

   Geometry geo = text.BuildGeometry(new Point(0, 0));
      
   PathGeometry path = geo.GetFlattenedPathGeometry();
   string data = path.ToString();

   string xamlTriangle = "<Path xmlns='http://schemas.microsoft.com/" + 
          "winfx/2006/xaml/presentation' " +
     "xmlns:x='http://schemas.microsoft.com/" +
          "winfx/2006/xaml' " +
     "Data='" + data + "' Fill='LightBlue' " + 
     "Stretch='Fill'/>";

   return xamlTriangle;
}
而 Client 的程式如下:
void client_StringToPathCompleted(object sender,
 DoWorkCompletedEventArgs e)
{

 Path newPath = (Path)
  System.Windows.Markup.XamlReader.Load(e.Result);
 this.LayoutRoot.Children.Add(newPath);

}
[Reference]
以 WPF + AJAX 在執行期間將文字轉成 Path
In SL3.0, can you not just use XamlReader.Load ?

Silverlight Color Picker and HSV RGB Convert

Silverlight 沒有 Color Dialog, 所以必需自己處理。
我找到 TeamLive Blog 有關 color picker 的文章,
覺得超棒,而且含了 XAML 語法。
可惜文章中,沒有 source code,
其中需要應用到 HSV 與 RGV 的相互轉換,
我把相關的參考資料列在下方。

[Reference]
TeamLive Blog - Silverlight Color Picker
RGB 與 HSV 相互轉換的方法

2009年10月10日

IIS Smooth Streaming

這裡有一篇奚江華的文章,清楚介紹以 IIS Smooth Streaming建立
720p高畫質Silverlight影音串流,可以參考:
[reference]
以IIS Smooth Streaming建立720p高畫質Silverlight影音串流

Deploying Vue & .NET with Google OAuth on GCP Cloud Run

Deploying Vue & .NET with Google OAuth on GCP Cloud Run Deploying Vue & .NET with Google OAuth on GCP Cloud Run...