{"id":1510,"date":"2007-05-21T11:28:57","date_gmt":"2007-05-21T14:28:57","guid":{"rendered":"http:\/\/www.hoogervorst.ca\/arthur\/?p=1510"},"modified":"2007-10-06T09:37:10","modified_gmt":"2007-10-06T12:37:10","slug":"more-cards","status":"publish","type":"post","link":"http:\/\/www.hoogervorst.ca\/arthur\/?p=1510","title":{"rendered":"More cards"},"content":{"rendered":"<p><span class=\"dropcap\">S<\/span>ince <a href='http:\/\/www.hoogervorst.ca\/arthur\/?attachment_id=1511' rel='attachment wp-att-1511' title='A bunch of cards'><img class=\"alignright\" src='http:\/\/www.hoogervorst.ca\/arthur\/wp-content\/uploads\/2007\/05\/awh_ole_lot_of_ca_rds.thumbnail.jpg' alt='A bunch of cards' \/><\/a>the weather was bad yesterday and (it appears) it&#8217;s going to be same-o-same-o today, I decided to check into (<strike>this<\/strike> last month&#8217;s) <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?p=1473\">Card objects project<\/a>. All earlier created objects were &#8216;non-visual&#8217; objects and since we&#8217;re playing cards, it probably makes sense to create a couple of visual components that show the player&#8217;s hands.\n<\/p>\n<p>I decided to base my custom component on the <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.windows.forms.picturebox.aspx\">PictureBox control<\/a>, mainly because I&#8217;m not concerned about using specific drag and drop effects at this stage. If you make a descendant of the PictureBox and plan to do some custom drawing, you should override the PictureBox&#8217;s OnPaint event:\n<\/p>\n<p><!--more--><\/p>\n<p><pre>        protected override void OnPaint(PaintEventArgs pe)\r\n        {\r\n            base.OnPaint(pe);\r\n\r\n            if (fhand != null)\r\n            {\r\n                pe.Graphics.Clear(this.BackColor);\r\n                \/\/ main drawing starts here\r\n\r\n                switch (this.Orientation)\r\n                {\r\n                     case THandOrientiation.HandHorizontalUp :\r\n                           \/\/ Drawstuff\r\n                           break;\r\n                     case THandOrientiation.HandVerticalLeft :\r\n                           \/\/ Drawstuff\r\n                            break;\r\n                     case THandOrientiation.HandHorizontalDown :\r\n                            \/\/ Drawstuff\r\n                            break;\r\n                     case THandOrientiation.HandVericalRight :\r\n                            \/\/ Drawstuff\r\n                            break;\r\n                }\r\n            }\r\n        }\r\n<\/pre>\n<\/p>\n<p>Next part was to get my sets of card styles (currently 2) and add both sets as two separate resource files, with each bitmap named appropriately (as in &#8216;consistent&#8217;) so that only one call is needed to actually draw the current selected player&#8217;s cards (or their backs).\n<\/p>\n<p><pre>        private Bitmap  GetBitmapCard(TCard acard)\r\n        {\r\n            string  s = \"_\" + CardFunctions.GetCardChar(acard);\r\n\r\n            Bitmap nbitmap = null;\r\n\r\n            if (acard.IsCardOpen)\r\n            {\r\n                switch (fcardset)\r\n                {\r\n                    case TCardSet.Default:\r\n                        nbitmap = (Bitmap)\r\n                            BetterSpades.card_defaultset.ResourceManager.GetObject(s);\r\n                        break;\r\n                    case TCardSet.Roman:\r\n                        nbitmap = (Bitmap)\r\n                            BetterSpades.card_romanset.ResourceManager.GetObject(s);\r\n                        break;\r\n                }\r\n            }\r\n            else\r\n            {\r\n                nbitmap = (Bitmap)BetterSpades.card_backs.ResourceManager.GetObject(\r\n                    CardFunctions.GetCardBack(this.CardBack)\r\n                    );\r\n            }\r\n\r\n            return nbitmap;\r\n        }\r\n<\/pre>\n<\/p>\n<p>And then finally, to wrap things up: selecting one (or multiple) card(s) from that very same custom control: Code was added to an overriden &#8216;MouseUp event&#8217;. The event converts the (current) mouse&#8217;s coordinates to an actual card index and either toggles a card &#8216;selected or unselected&#8217;:\n<\/p>\n<p><pre>\r\n        protected override void OnMouseUp(MouseEventArgs e)\r\n        {\r\n            if (fhand != null)\r\n            {\r\n                if (e.Button == MouseButtons.Left)\r\n                {\r\n                    int i = FindIndex(e.X, e.Y);\r\n\r\n                    if (i > -1)\r\n                    {\r\n                        \r\n                        this.fhand[i].IsCardSelected = !this.fhand[i].IsCardSelected;\r\n                        \/\/ call the overridden OnPaint Event!\r\n                        this.Refresh();\r\n                    }\r\n                }\r\n            }\r\n\r\n            base.OnMouseUp(e);\r\n        }\r\n<\/pre>\n<\/p>\n<p>Next up: the Table and Deck visual components.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since the weather was bad yesterday and (it appears) it&#8217;s going to be same-o-same-o today, I decided to check into (this last month&#8217;s) Card objects project. All earlier created objects were &#8216;non-visual&#8217; objects and since we&#8217;re playing cards, it probably &hellip; <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?p=1510\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[88],"_links":{"self":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/1510"}],"collection":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1510"}],"version-history":[{"count":0,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/1510\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1510"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}