• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評論-2670  文章-0  trackbacks-0
                今天為GacUI寫了一個(gè)新的Demo,展示了一些可以自動排版的按鈕。主要的設(shè)想就是在窗口上放一個(gè)表格,分成兩行兩列。上面的按鈕占滿一整行,下面兩個(gè)單元格放兩個(gè)按鈕。然后就可以設(shè)置每個(gè)行和列占整個(gè)表格的比例,在這個(gè)Demo里面都設(shè)置成50%。這樣每當(dāng)窗口縮放的時(shí)候,按鈕的位置也會隨之重新排版。然后設(shè)置表格充滿整個(gè)窗口,這樣窗口的最小值就會被表格的內(nèi)容所限定,這樣試圖把窗口縮小的時(shí)候,就會有一個(gè)最小的尺寸限制著,至始至終保證所有的東西都可以顯示出來,不會因?yàn)榇翱谔《伙@示一半。按鈕也是同樣,可以設(shè)置它必須顯示所有的文字。所有的過程一旦配置好之后,計(jì)算尺寸的時(shí)候所有的操作都會自動做,程序員不需要為窗口的Resize事件寫任何代碼。

                下面先放圖。

                第一個(gè)圖是窗口剛剛打開的時(shí)候的樣子。因?yàn)镈emo里面沒有設(shè)置窗口的尺寸,所以一上來就自動變成了最小的尺寸——并且剛好可以顯示所有的內(nèi)容。



                第二個(gè)圖是窗口放大之后的樣子。Disable按鈕被按下了,所以上面的按鈕就變灰。



                這個(gè)Demo使用了Direct2D渲染器,所有的繪制過程都十分高速。而且表格的尺寸計(jì)算也是經(jīng)過優(yōu)化的,在拖放窗口的時(shí)候十分流暢。事實(shí)上按鈕的漸變啊、邊框啊、文字等等也是借助表格排版的。由于尺寸計(jì)算過于復(fù)雜,除了表格之外整個(gè)框架都不保存控件的尺寸,所有的東西都在需要的時(shí)候——譬如說渲染的時(shí)候,譬如說計(jì)算鼠標(biāo)點(diǎn)中的位置——的那一刻才開始算。因此無論是鼠標(biāo)滑過,或者是窗口拖放,都拼命地執(zhí)行很多虛函數(shù)。可見C++的虛函數(shù)的性能之高,幾乎永遠(yuǎn)都不會成為程序的瓶頸。下面來看代碼:

            #include "..\..\Public\Source\GacUIIncludes.h"
            #include 
            <Windows.h>

            int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
            {
                
            return SetupWindowsDirect2DRenderer();
            }

            class EnableDisableWindow : public GuiWindow
            {
            private:
                GuiButton
            *            buttonTarget;
                GuiButton
            *            buttonEnable;
                GuiButton
            *            buttonDisable;

                
            void buttonEnable_OnClick(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    buttonTarget
            ->SetEnabled(true);
                }

                
            void buttonDisable_OnClick(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    buttonTarget
            ->SetEnabled(false);
                }
            public:
                EnableDisableWindow()
                    :GuiWindow(GetCurrentTheme()
            ->CreateWindowStyle())
                {
                    
            this->SetText(L"Controls.Button.EnableDisable");
                    
            // limit the size that the window should always show the whole content without cliping it
                    this->GetContainerComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);

                    
            // create a table to layout the 3 buttons
                    GuiTableComposition* table=new GuiTableComposition;
                    
            // make the table to have 2 rows
                    table->SetRowsAndColumns(22);
                    table
            ->SetRowOption(0, GuiCellOption::PercentageOption(0.5));
                    table
            ->SetRowOption(1, GuiCellOption::PercentageOption(0.5));
                    table
            ->SetColumnOption(0, GuiCellOption::PercentageOption(0.5));
                    table
            ->SetColumnOption(1, GuiCellOption::PercentageOption(0.5));
                    
            // dock the table to fill the window
                    table->SetAlignmentToParent(Margin(10101010));
                    
            // add the table to the window;
                    this->GetContainerComposition()->AddChild(table);

                    
            // add the target button
                    {
                        GuiCellComposition
            * cell=new GuiCellComposition;
                        table
            ->AddChild(cell);
                        
            // this cell is the top cell
                        cell->SetSite(0012);

                        buttonTarget
            =g::NewButton();
                        buttonTarget
            ->SetText(L"Enable or disable me using the buttons below!");
                        
            // ensure that the buttonTarget display the whole text
                        buttonTarget->GetBoundsComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                        
            // dock the button to fill the cell
                        buttonTarget->GetBoundsComposition()->SetAlignmentToParent(Margin(0003));
                        
            // add the button to the cell
                        cell->AddChild(buttonTarget->GetBoundsComposition());
                    }

                    
            // add the enable button
                    {
                        GuiCellComposition
            * cell=new GuiCellComposition;
                        table
            ->AddChild(cell);
                        
            // this cell is the bottom left cell
                        cell->SetSite(1011);

                        buttonEnable
            =g::NewButton();
                        buttonEnable
            ->SetText(L"Enable");
                        buttonEnable
            ->GetBoundsComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                        buttonEnable
            ->GetBoundsComposition()->SetAlignmentToParent(Margin(0330));
                        buttonEnable
            ->Clicked.AttachMethod(this&EnableDisableWindow::buttonEnable_OnClick);
                        cell
            ->AddChild(buttonEnable->GetBoundsComposition());
                    }

                    
            // add the disable button
                    {
                        GuiCellComposition
            * cell=new GuiCellComposition;
                        table
            ->AddChild(cell);
                        
            // this cell is the bottom right cell
                        cell->SetSite(1111);

                        buttonDisable
            =g::NewButton();
                        buttonDisable
            ->SetText(L"Disable");
                        buttonDisable
            ->GetBoundsComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                        buttonDisable
            ->GetBoundsComposition()->SetAlignmentToParent(Margin(3300));
                        buttonDisable
            ->Clicked.AttachMethod(this&EnableDisableWindow::buttonDisable_OnClick);
                        cell
            ->AddChild(buttonDisable->GetBoundsComposition());
                    }

                    
            // change the button font
                    {
                        FontProperties font;

                        font
            =buttonTarget->GetFont();
                        font.size
            =20;
                        buttonTarget
            ->SetFont(font);
                        buttonEnable
            ->SetFont(font);
                        buttonDisable
            ->SetFont(font);
                    }

                    
            // call this to calculate the size immediately if any indirect content in the table changes
                    
            // so that the window can calcaulte its correct size before calling the MoveToScreenCenter()
                    table->UpdateCellBounds();
                    
            // update the size
                    this->SetBounds(Rect());
                    
            // move to the screen center
                    this->MoveToScreenCenter();
                }

                
            ~EnableDisableWindow()
                {
                }
            };

            void GuiMain()
            {
                GuiWindow
            * window=new EnableDisableWindow();
                GetApplication()
            ->Run(window);
                delete window;
            }

                代碼里面充滿了注釋,而且主要的內(nèi)容也在上面介紹了,在這里我就不羅嗦了。所有的代碼都可以在http://gac.codeplex.com中,下載最新的代碼,然后在Libraries\GacUI\GacUIDemo\GacUIDemo.sln下面找到。
            posted on 2012-04-25 02:46 陳梓瀚(vczh) 閱讀(2361) 評論(5)  編輯 收藏 引用 所屬分類: GacUI

            評論:
            # re: GacUI新Demo:按鈕和排版[未登錄] 2012-04-25 04:02 | me
            superstar!  回復(fù)  更多評論
              
            # re: GacUI新Demo:按鈕和排版[未登錄] 2012-04-25 18:20 | diryboy
            好厲害!  回復(fù)  更多評論
              
            # re: GacUI新Demo:按鈕和排版[未登錄] 2012-04-27 05:53 | koobin
            是不是用Win7的API寫的?在XP下還運(yùn)行不了?koobin@126.com  回復(fù)  更多評論
              
            # re: GacUI新Demo:按鈕和排版 2012-04-27 06:09 | 陳梓瀚(vczh)
            @koobin
            應(yīng)該只有剪貼板用到了win7的一個(gè)api,只要在xp的時(shí)候禁用即可。如果放在XP,最大的犧牲是沒有顯卡加速,要采用GDI來繪制,讓本來就慢的XP變得更慢了。  回復(fù)  更多評論
              
            # re: GacUI新Demo:按鈕和排版 2013-05-15 23:28 | tb
            厲害啊   回復(fù)  更多評論
              
            色婷婷综合久久久久中文| 久久中文字幕一区二区| 性欧美大战久久久久久久久| 奇米影视7777久久精品| 一本久久久久久久| 一级a性色生活片久久无 | 色综合久久综精品| 青青久久精品国产免费看| 久久亚洲精品国产精品| 久久WWW免费人成—看片| 亚洲欧美成人综合久久久| 久久久亚洲精品蜜桃臀| 国产精品久久久久9999| 精品久久久中文字幕人妻| 狠狠精品久久久无码中文字幕| 久久亚洲日韩看片无码| 国产福利电影一区二区三区,免费久久久久久久精 | 久久人人爽人人精品视频| 亚洲精品高清国产一线久久| 久久国产精品二国产精品| 久久精品国产99久久久古代 | 久久天天躁狠狠躁夜夜avapp| 久久国产精品无码网站| 久久精品蜜芽亚洲国产AV| 久久无码AV中文出轨人妻| 欧美久久一级内射wwwwww.| 国产精品综合久久第一页| 久久综合丁香激情久久| 成人国内精品久久久久影院| 久久久久久亚洲精品成人| 久久久久av无码免费网| 久久久久人妻一区二区三区| 亚洲精品tv久久久久久久久久| 久久精品国产精品亚洲艾草网美妙| 青青青国产精品国产精品久久久久 | 久久精品成人免费观看97| 日本免费久久久久久久网站| 国产精品久久久天天影视| 99久久免费国产特黄| 91视频国产91久久久| 久久久中文字幕|