📄 galleryimage.cs
字号:
if(settings.OriginalSize == true)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID);
}
else
{
settings = new GalleryImageSettings(39, 48, 100, false, false, false);
ImageUrl = Globals.GetSiteUrls().Locations["galleries"] + "default_file_image.gif";
}
}
protected void ScalePicture()
{
ScalePicture(ImageType, settings);
}
protected virtual void ScalePicture(GalleryImageType type, GalleryImageSettings secondarySettings)
{
if(picture.IsPicture)
{
ImageHandling.GetMaintainedRatio(picture, secondarySettings);
string filename = Picture.CacheFilename(((Gallery)picture.Section).SectionID, picture.PostID, type, secondarySettings.Width, secondarySettings.Height);
ImageHandling.ScalePicture(filename, picture, secondarySettings);
}
}
#endregion
#region Control Event Overrides
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
PostID = CSContext.Current.PostID;
}
protected override void OnPreRender(EventArgs e)
{
ProcessPicture();
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
if(picture == null)
return;
HtmlAnchor a = new HtmlAnchor();
HtmlImage img = new HtmlImage();
bool secondaryPopup = false;
if(EnableSecondaryThumbnail)
{
Gallery gallery = picture.Section as Gallery;
if((gallery.ThumbnailX != gallery.SecondaryThumbnailX) || (gallery.ThumbnailY != gallery.SecondaryThumbnailY))
secondaryPopup = true;
}
if(NavigateUrl != string.Empty)
{
a.HRef = NavigateUrl;
}
img.Src = ImageUrl;
img.Alt = picture.Subject.Replace("\"", "\\\"");
if (Width > 0)
img.Width = settings.Width;
if (Height > 0)
img.Height = settings.Height;
img.Border = Border;
if(cssClass != string.Empty)
img.Attributes["Class"] = CssClass;
if(style != string.Empty)
img.Attributes["Style"] = style;
if(EnableSecondaryThumbnail && !secondaryPopup)
{
img.Attributes["onmouseover"] = "javascript:this.src='" + SecondaryImageUrl + "';";
img.Attributes["onmouseout"] = "javascript:this.src='" + ImageUrl + "';";
}
else if(EnableSecondaryThumbnail && secondaryPopup)
img.Attributes["onmouseover"] = "ToggleGalleryThumbnail(" + picture.PostID.ToString() + ");";
img.Attributes["Id"] = imageIDprefix + picture.PostID.ToString();
// If we're doing a Matte rendering we have some special switch logic
if (ImageType == GalleryImageType.Gallery) {
img.Attributes["style"] = "border:4px solid white;";
RenderMatte(img, a).RenderControl(writer);
} else if (ImageType == GalleryImageType.Details || ImageType == GalleryImageType.Slideshow || ImageType == GalleryImageType.SecondaryThumbnail) {
img.Attributes["style"] = "border:4px solid white;";
RenderBorder(img, a).RenderControl(writer);
} else {
if (ImageType == GalleryImageType.Micro)
img.Attributes["style"] = "border:3px solid white;";
if(NavigateUrl != string.Empty) {
a.Controls.Add(img);
a.RenderControl(writer);
}
else
img.RenderControl(writer);
}
if(secondaryPopup)
RenderSecondaryThumbnail(writer);
}
private HtmlTableCell MatteTableCell(string className, string imgSrc) {
HtmlTableCell td = new HtmlTableCell();
td.Attributes["class"] = className;
if (imgSrc != null) {
HtmlImage img = new HtmlImage();
img.Src = imgSrc;
img.Attributes["style"] = "border-width:0px;";
td.Controls.Add(img);
}
return td;
}
private HtmlTable RenderBorder(HtmlImage img, HtmlAnchor anchor) {
HtmlTable t = new HtmlTable();
HtmlTableRow tr;
HtmlTableCell td;
// table properties
t.Border = 0;
t.CellPadding = 0;
t.CellSpacing = 0;
t.Attributes["class"] = "photo-frame";
// row #1
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("topx--", null));
tr.Cells.Add(MatteTableCell("top-x-", null));
tr.Cells.Add(MatteTableCell("top--x", null));
t.Rows.Add(tr);
// row #2
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("midx--", null));
td = new HtmlTableCell();
td.BgColor = "white";
anchor.Controls.Add(img);
td.Controls.Add( anchor );
tr.Cells.Add(td);
tr.Cells.Add(MatteTableCell("mid--x", null));
t.Rows.Add(tr);
// row #3
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("botx--", null));
tr.Cells.Add(MatteTableCell("bot-x-", null));
tr.Cells.Add(MatteTableCell("bot--x", null));
t.Rows.Add(tr);
return t;
}
private HtmlTable RenderMatte(HtmlImage img, HtmlAnchor anchor) {
HtmlTable t = new HtmlTable();
HtmlTableRow tr;
HtmlTableCell td;
// table properties
t.Border = 0;
t.CellPadding = 0;
t.CellSpacing = 0;
t.Attributes["class"] = "album-frame";
// row #1
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("topx----", null));
tr.Cells.Add(MatteTableCell("top-x---", ThemeManager.SkinPath() + "/images/alblum-mtl.gif"));
tr.Cells.Add(MatteTableCell("top--x--", null));
tr.Cells.Add(MatteTableCell("top---x-", ThemeManager.SkinPath() + "/images/alblum-mtr.gif"));
tr.Cells.Add(MatteTableCell("top-----", null));
t.Rows.Add(tr);
// row #2
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("mtpx----", ThemeManager.SkinPath() + "/images/alblum-mltl.gif"));
td = new HtmlTableCell();
td.ColSpan = 3;
td.VAlign = "center";
td.Align = "center";
td.BgColor = "white";
td.RowSpan = 3;
anchor.Controls.Add(img);
td.Controls.Add( anchor );
tr.Cells.Add(td);
tr.Cells.Add(MatteTableCell("mtp----x", ThemeManager.SkinPath() + "/images/alblum-mrtr.gif"));
t.Rows.Add(tr);
// row #3
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("midx----", null));
tr.Cells.Add(MatteTableCell("mid----x", null));
t.Rows.Add(tr);
// row #4
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("mbtx----", ThemeManager.SkinPath() + "/images/alblum-mlbl.gif"));
tr.Cells.Add(MatteTableCell("mbt----x", ThemeManager.SkinPath() + "/images/alblum-mrbr.gif"));
t.Rows.Add(tr);
// row #5
tr = new HtmlTableRow();
tr.Cells.Add(MatteTableCell("botx----", null));
tr.Cells.Add(MatteTableCell("bot-x---", ThemeManager.SkinPath() + "/images/alblum-mbl.gif"));
tr.Cells.Add(MatteTableCell("bot--x--", null));
tr.Cells.Add(MatteTableCell("bot---x-", ThemeManager.SkinPath() + "/images/alblum-mbr.gif"));
tr.Cells.Add(MatteTableCell("bot----x", null));
t.Rows.Add(tr);
return t;
}
protected void RenderSecondaryThumbnail(HtmlTextWriter writer)
{
writer.Write("<div id='SecondaryThumbDiv{0}' class='secondaryThumbnailHidden'>", picture.PostID );
if(NavigateUrl != string.Empty)
{
writer.AddAttribute(HtmlTextWriterAttribute.Href, NavigateUrl);
writer.RenderBeginTag(HtmlTextWriterTag.A);
}
writer.AddAttribute(HtmlTextWriterAttribute.Src, SecondaryImageUrl);
writer.AddAttribute(HtmlTextWriterAttribute.Alt, picture.Subject.Replace("\"", "\\\""));
writer.AddAttribute(HtmlTextWriterAttribute.Width, secondarySettings.Width.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Height, secondarySettings.Height.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Border, Border.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Id, "SecondaryThumb" + picture.PostID.ToString());
writer.AddAttribute("onmouseout", "ToggleGalleryThumbnail(" + picture.PostID.ToString() + ");");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
if(NavigateUrl != string.Empty)
writer.RenderEndTag();
writer.Write("</div>");
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -