Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Button mapping with bitmaps. Faster than coordinate boxes.

Author
Message
P Schnell
19
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 13th Mar 2005 11:12
I've always hated using if mousex()>xpos type commands to make buttons, so I made a simple way to have buttons with just a bitmap and memblock functions, but even more can be added with a little effort.

Basic Principals and Simple Code.

The basic idea is to load a bitmap, make a memblock from it, and then when the mouse is clicked, get the color of the point where the mouse is, using that to determine which button is being pressed.

Since you don't want your buttons to be solid colors, and you don't want to have to program in hundreds of colors per button, an invisible mapping image is used. It is only loaded long enough for a memblock to be made, and then it's deleted.

In its place, an image with the same button shapes, but much more decoration and detail is shown instead. The coordinates on this image is compared to the coordinates in the memblock.

This is where some functions come into play. Like this one:

The memNum is the memblock number that the mapping image is stored on, in my examples, it's memblock one.
The x and y are coordinates, usually mousex() and mousey().
You will also notice the width variable in the function. The width is always a dword starting at the zero position of the memblock.
Here is a function to grab the width of the memblock:


So now, you could write a simple program that fetches the rgb value of a point of the mapping image, and displays it onscreen depending on where you click your mouse.


Advanced Programming and Scripting.

This is more complicated, it includes, or will soon include, how to add effects like an image overlay, and effects and triggers when the mouse hovers over or clicks a button. This includes a scripting method to easily change button images and effects.

The files can be downloaded from the attachment. They include two 200x200 bitmaps, three txt files, and one DBC source file that can be opened in DBC or Notepad. (DBC files have the same format as txt.)

Here's an example program:

The script for the above program, and the explination of the script format:


Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-23 14:03:40
Your offset time is: 2024-11-23 14:03:40