Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created November 19, 2010 04:47
Show Gist options
  • Save noqisofon/706132 to your computer and use it in GitHub Desktop.
Save noqisofon/706132 to your computer and use it in GitHub Desktop.
フローティングウィンドウ管理クラス。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace groan.util {
using app.widgets;
/// <summary>
///
/// </summary>
public class StickManager {
/// <summary>
///
/// </summary>
public StickManager() {
this.stick_queue_ = new Queue<Stick>();
this.padding_ = 10;
}
/// <summary>
///
/// </summary>
public void raiseStickClosed() {
this.stick_queue_.Dequeue();
}
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="fulltext"></param>
/// <returns></returns>
public Stick enqueueStick(string title, string fulltext) {
Stick popup = new Stick();
StickInfo info = new StickInfo( popup.Size );
info.x = 0;
info.y = 0;
info.title = title;
info.fulltext = fulltext;
if ( this.stick_queue_.Count > 0 )
perform_stick_enqueued();
this.stick_queue_.Enqueue( popup );
popup.Tag = info;
return popup;
}
/// <summary>
/// フローティングウィンドウが既に画面に表示している状態の時、
/// 更にフローティングウィンドウをエンキューされるときに呼び出されます。
/// </summary>
private void perform_stick_enqueued() {
Stick[] tmp_sticks = new Stick[this.stick_queue_.Count];
this.stick_queue_.CopyTo( tmp_sticks, 0 );
int screen_height = Screen.PrimaryScreen.Bounds.Height;
int max_vertical = screen_height / ( tmp_sticks[0].Size.Height + this.padding_ );
int ranking;
foreach ( Stick stick in tmp_sticks ) {
StickInfo info = (StickInfo)stick.Tag;
ranking = ( ( info.x * max_vertical ) + info.y ) + 1;
info.x = ranking / max_vertical;
info.y = ranking % max_vertical;
stick.update();
}
}
/// <summary>
///
/// </summary>
private int padding_;
/// <summary>
///
/// </summary>
private Queue<Stick> stick_queue_;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment