XP Style Glyph烦恼在ActionBars中 [英] XP Style Glyph annoyance in ActionBars

查看:210
本文介绍了XP Style Glyph烦恼在ActionBars中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不喜欢提出太多关于组件外观的问题,但是在应用程序中出现的这些日子似乎同样重要。



无论如何,请看以下图片:





两个都使用TActionManager和TActionMainMenuBar来创建我的主菜单。图像左侧的菜单使用平台默认样式,右侧的菜单使用我的TActionManager定义的XP样式。



注意左边菜单被突出显示,字形保持不变,这是完美的。



现在看右边的XP风格菜单,字形画一个阴影,稍微弹出,你可以看到透明度使得字形显得稍微奇怪。 / p>

我想为我的UI启用XP风格,但是字形的绘制方式我不喜欢。我也想把我的TToolbar更改为一个TActionToolBar并应用相同的XP风格,但这样也会使字形一样。



如何使XP样式菜单在TActionManager中定义,不会渲染这样的字形?



谢谢。



strong>



这是现在的结果,从以下答案中应用了一些技巧:



< img src =https://i.stack.imgur.com/bT1fK.pngalt =enter image description here>



Craig。

解决方案

这是一些代替XP STYLE的示例代码,创建一个可以根据需要进行调整的派生类。第一步是替换你自己的派生菜单项类,并改变它的DrawGlyph代码,就像David告诉你一样。我想你可能会使用一些示例代码。



这只是一个快速演示。它不会在带有字形的检查项目周围绘制一个框,因此,此自定义样式与已检查项不兼容,除非它们没有字形。你必须弄清楚如何绘制检查的字形项目(如果设置了Action.Checked属性,那么我写的DrawGlyphFrame将是一个很好的地方,可以添加一些东西以在字形周围绘制一个检查状态的矩形)。

  unit MyActionControlStyle; 

//使用本机:将其添加到您的项目中。在您的项目中,在运行时设置
//样式,将该单元添加到uses子句,然后在该窗体的formcreate事件中设置
//:
// ActionManager1.Style:= MyActionControlStyle.MyStyle;

接口

使用表单,
类型,
控件,
XPActnCtrls,
XPStyleActnCtrls,
ActnMan,
ActnList,
ActnMenus,
ActnCtrls;

类型

TMyStyleMenuItem =类(TXPStyleMenuItem)
protected
程序DrawGlyph(const位置:TPoint);覆盖

//程序DrawGlyphFrame(const位置:TPoint);

end;
TMyStyleMenuButton = class(TXPStyleMenuButton)
end;

TMyStyleActionBars = class(TXPStyleActionBars)
//覆盖我想要的不同于XP的东西Style:
function GetControlClass(ActionBar:TCustomActionBar;
AnItem:TActionClientItem) :TCustomActionControlClass;覆盖

end;

var
MyStyle:TMyStyleActionBars;

实现


使用ToolWin,Classes,Windows,Graphics,GraphUtil,ImgList;
{TMyStyleActionBars}

函数TMyStyleActionBars.GetControlClass(ActionBar:TCustomActionBar;
AnItem:TActionClientItem):TCustomActionControlClass;
begin
如果ActionBar是TCustomActionPopupMenu然后
结果:= TMyStyleMenuItem
else
如果ActionBar是TCustomActionMainMenuBar然后
结果:= TMyStyleMenuButton
else
结果:=继承的GetControlClass(ActionBar,AnItem);

end;

{TMyStyleMenuItem}

程序TMyStyleMenuItem.DrawGlyph(const位置:TPoint);
var
ImageList:TCustomImageList;
DrawEnabled:Boolean;
begin
// DrawGlyphFrame(Location);
如果不是HasGlyph和IsChecked然后
begin
Canvas.Pen.Color:= ActionBar.ColorMap.FontColor;
DrawCheck(Canvas,Point((TextBounds.Left - 5)div 2,Height div 2),2);
结束

如果不是HasGlyph然后退出;
如果分配(Action)然后
ImageList:= ActionClient.Action.ActionList.Images
else
ImageList:= ActionClient.OwningCollection.ActionManager.Images;
如果没有分配(ImageList)然后退出;
DrawEnabled:=启用和(ActionClient.ImageIndex -1)或
(在ComponentState中设置csDesigning);
ImageList.Draw(Canvas,Location.X,Location.Y,ActionClient.ImageIndex,
dsTransparent,itImage,DrawEnabled);

end;

初始化
MyStyle:= TMyStyleActionBars.Create;
RegisterActnBarStyle(MyStyle);
finalization
UnregisterActnBarStyle(MyStyle);
MyStyle.Free;
结束。


I dont like to ask too many questions in relation to the appearance of components, but these days appearance in Applications seems just as important.

Anyway, please see the below images:

Both are using the TActionManager and TActionMainMenuBar to create my main menu. The menu in the left of the image is using the Platform Default Style, the menu on the right is using the XP style defined by my TActionManager.

Notice how when the left menu is highlighted, the glyph remains the same which is perfect.

Now look at the XP style menu on the right, the glyph draws a drop shadow, pops out slightly and you can see the transparency makes the glyph appear slightly odd.

I want to enable the XP style for my UI, but the way the glyphs are painted I do not like. I also want to change my TToolbar to a TActionToolBar and apply the same XP style, but this will render the glyphs the same too.

How can I make the XP style menu defined in the TActionManager, not render the glyphs like this?

Thanks.

EDIT

This is now the result, having applied some of the techniques from the answers below:

Craig.

解决方案

Here is some sample code that overrides the XP STYLE, creating a derived class that you can tweak as you like. First step here is to substitute your own derived menu item class, and change its DrawGlyph code, as David told you. I figured you could maybe use some sample code.

This is just a quick demo. It doesn't draw a box around checked items with glyphs, so this custom style is not compatible with Checked items, unless they have no glyphs. You would have to figure out how you want to draw the checked-glyph items (Where I wrote the DrawGlyphFrame would be a good place to add something to draw a checked-state rectangle around a glyph if the Action.Checked property is set).

unit MyActionControlStyle;

// Using this unit: Add it to your project. In your project set your
// style at runtime, add the unit to your uses clause and then set the style
// in that form's formcreate event:
//   ActionManager1.Style := MyActionControlStyle.MyStyle;

interface

uses Forms,
     Types,
     Controls,
     XPActnCtrls,
     XPStyleActnCtrls,
     ActnMan,
     ActnList,
     ActnMenus,
     ActnCtrls;

type

 TMyStyleMenuItem = class(TXPStyleMenuItem)
  protected
      procedure DrawGlyph(const Location: TPoint); override;

//      procedure DrawGlyphFrame(const Location:TPoint);

 end;
 TMyStyleMenuButton = class(TXPStyleMenuButton)
 end;

 TMyStyleActionBars = class(TXPStyleActionBars)
   // override the stuff that I want different than XP Style:
    function GetControlClass(ActionBar: TCustomActionBar;
      AnItem: TActionClientItem): TCustomActionControlClass; override;

 end;

var
 MyStyle:TMyStyleActionBars;

implementation


uses ToolWin, Classes, Windows, Graphics, GraphUtil, ImgList;
{ TMyStyleActionBars }

function TMyStyleActionBars.GetControlClass(ActionBar: TCustomActionBar;
  AnItem: TActionClientItem): TCustomActionControlClass;
begin
 if ActionBar is TCustomActionPopupMenu then
    Result := TMyStyleMenuItem
  else
  if ActionBar is TCustomActionMainMenuBar then
    Result := TMyStyleMenuButton
  else
    Result := inherited GetControlClass(ActionBar,AnItem);

end;

{ TMyStyleMenuItem }

procedure TMyStyleMenuItem.DrawGlyph(const Location: TPoint);
var
  ImageList: TCustomImageList;
  DrawEnabled: Boolean;
begin
//  DrawGlyphFrame(Location);
  if not HasGlyph and IsChecked then
  begin
    Canvas.Pen.Color := ActionBar.ColorMap.FontColor;
    DrawCheck(Canvas, Point((TextBounds.Left - 5) div 2, Height div 2), 2);
  end;

  if not HasGlyph then exit;
  if Assigned(Action) then
    ImageList := ActionClient.Action.ActionList.Images
  else
    ImageList := ActionClient.OwningCollection.ActionManager.Images;
  if not Assigned(ImageList) then exit;
  DrawEnabled := Enabled and (ActionClient.ImageIndex <> -1) or
    (csDesigning in ComponentState);
  ImageList.Draw(Canvas, Location.X, Location.Y, ActionClient.ImageIndex,
    dsTransparent, itImage, DrawEnabled);

end;

initialization
  MyStyle := TMyStyleActionBars.Create;
  RegisterActnBarStyle(MyStyle);
finalization
  UnregisterActnBarStyle(MyStyle);
  MyStyle.Free;
end.

这篇关于XP Style Glyph烦恼在ActionBars中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆