More Mengen

August 24th, 2007 Pekk

Today I worked some more on MenGen, The Menu Generator program I’ve been working on for school. After trying to implement some features and callback (or as QT calls them, “slot”) routines I took a pass over my code. Seeing as it was very messy and the lines of code showed a lot of repetition I decided to make some functions.

Here’s some stuff I added today:

  • MG_ERR_ID_EXISTS macro — This macro displays a QMessageBox::critical() message. Saying that the ID you’ve entered in the ID box for your new item is already in use, and you must change it. It also changes the background color of the ID text field to a light red (#FAA) and sets focus to it, to make this more apparent to the user that they must change it. I had to use it in several spots so I wanted to insure that I would be able quickly change the message if needed.
  • txtID_enter(void) slot function — I added this function, and altered the enter slot functions of the other text fields, to make sure that when you hit the enter key in one field, it will tab to the next automatically. Hitting enter in the bottom box inserts the data by calling the new addItem() function (which was also added today) and focus is set back to the top, so holding down enter will spin you in a loop between the text fields.
  • addItem() private function — two of these were added, one to overload the other. Unfortunately for now I don’t know any other way of doing this, so this function’s exact contents exist twice. Since this functions first parameter is its parent object, I had to make one function to support a QTreeWidget* parent and one to support a QTreeWidgetItem parent.
  • The addItem() function also adds new IDs to the Style Target combo box.
  • The removeItem() function now searches and removes any IDs contained in the selected tree widget pending deletion, and removes it from the Style Target combo box.
  • Updated the titlebar caption for the GUI. It no longer says “MainWindow”

I’ve actually added stuff since my last post about Mengen but I forgot to blog it, so for now I’ll say that currently you can add items to the list of Menu items, and remove them, add child nodes and the remove function will delete the nodes recursively (if you select “yes” to a prompt asking to delete children). Selecting an item in the list causes the information to be tossed back into the text fields where you may edit and “update” the entries.

During my last MenGen session I tried to create a generateXHTML() routine which will generate all of the XHTML for the entire tree structure (giving only XHTML which is used for the list items and links, etc…) but I was getting some bus errors, which I’m still unable to resolve. I also created an xmlLine() routine which assists the generateXHTML() by actually generating the XHTML with the right information; it is now generateXHTML()’s responsibility to traverse the tree structure and call xmlLine() on each node.

At present I’m going to work around the bus error bug, ignoring it, until Monday comes and I consult with my professor at school for some assistance on the matter.

That’s really all that’s new so far… So I’ll post some screenshots ;)

MenGen GUI - Font SettingsMenGEn GUI - Color SettingsMenGen GUI - Borders SettingsMenGen GUI - Positioning SettingsMenGen GUI - Margin Settings

Posted in MenGen, Programming | No Comments »

Gettin’ in Groove

August 20th, 2007 Pekk

I’m starting to get sick of games so I’ve been giggin’ along since late last night  when I decided to put some work on a program I started, designed to edit Counter-Strike 1.6 configuration (cfg) files. I designed the GUI a few days ago, and as of last night I’ve implemented most of its functionality. I’m not sure if I’ll be releasing it, but if I do I’ll post it on SourceForge, and of course give a link here.

The  grand scheme is to design a program that will do this sort of config editing for multiple games, starting firstly with Counter-Strike. In any case, the real point of it was to get me back to programming by designing a program related to something that I was doing. This way I can get my mind set in program mode and continue on. If I can finish one project, it should be reinforcing enough to encourage me to finish the rest.

This week it’s finished projects or bust!

Here’s a bit more on the technical aspect of the CS Config program problems I’ve encountered:

double to integer conversion - there is a glitch involving 2 GUI components, a type double spin box control and a horizontal slider. When using the spinbox control, the value gets stuck going upwards at values .28 and .56. I think this is caused by an inaccurate conversion from double to int, something involving a loss of precision; but I’m not sure yet how I’ll fix this problem.

label signals and slots - there seem to be no signals and slots to handle mouse click events for labels, so I might have to create my own custom widget to provide a color picker button, which will extend the label widget and add the appropriate styles and signals.

Here’s some screenshots of the program, Configamajig, in action!

ConfigamajigConfigamajig 2Configamajig 3

Posted in Programming | No Comments »

MenGen Project Activity

August 16th, 2007 Pekk

Today’s post actually pertains to what I did yesterday in regard to MenGen. I’ve modified the GUI a bit. I removed some unnecessary layouts and replaced them with making “invisible” layouts out of the objects’ containers. This way I don’t have the distracting red lines everywhere (it makes it almost impossible to select anything).

I’ve also added several GUI components to the layout:

  • Font Settings tab
    • Bold, Italic, Small Caps, and Underline buttons.
    • “More” button. This button will pop a dialog to give more accurate control over the font settings.
  • Colors tab
    • Font color and background color labels (used for color picking)
  • Borders tab
    • Spinner controls for border top, right, left and bottom
    • Combo box drop-downs for unit selection (em, px, etc.)
    • “All” checkbox which applies the border-top setting as a border setting instead.
  • Positioning tab
    • Position (Static, fixed, relative, absolute) combo box
    • Overflow  (Visible, hidden, scroll, auto) combo box
    • Top, right,  bottom, left  positions (spinner boxes and combo box to select units)
    • Z-Index spinner control (with a check box to specify the default “auto” value)
    • V-Align editable combo box (to specify vertical alignment)
  • Margins tab
    • top, right, bottom, left margins via spinner controls and combo box (for units)
    • “All” checkbox to apply the margin-top value as a margin value.

Here are some screenshots:

MenGen GUI - Font SettingsMenGEn GUI - Color SettingsMenGen GUI - Borders SettingsMenGen GUI - Positioning SettingsMenGen GUI - Margin Settings

Posted in MenGen, Programming | No Comments »

Pekk’s Plue Game Program! Pekk is a HUNGRY Plue!

August 9th, 2007 Pekk

While drawing wasn’t the only thing I did today during Qt4’s incredibly long compile session, I also created this funny little program. It’s called the Plue Game.

I found it in the back of my Rave Master manga. The basic rules are the game are as follows:

  1. Write your full name on a piece of paper.
  2. Convert the letters of your name into numbers, A=1, b=2, and so on.
  3. Add up all the numbers in your full name and take the right-most (ones’ place) digit. This is your “Plue Magic Number” as I call it, this number is used to look up in a table what type of Plue you are (since it’s quite a bit of text I won’t post all of the results up here, you are free to download and compile the program if you wish, or even just read the code to find out what each number means).

For whatever reason, I thought it would be faster to just write a program to do this for me so I didn’t have to do the addition myself. In any case I was horribly wrong, especially since I decided to write the program in C.

I’ll post the file at the bottom of this post, but for now I just want to share some important notes (things I discovered, things I’d forgotten about) pertaining to C.

  1. Never ever use gets() or some asshole will call you out on it. (Actually I was already well aware of this, I just wanted to point out how some people have nothing better to do than try to prove they are better than everyone else. Don’t be this guy! Play nice! I don’t want to read your drama when I’m trying to find a function name!!).
  2. For strings with spaces (the google search that brought me to the above forum posting) use fgets(). Check the manpages for more details; use stdin as a substitute for the file stream, it will work just fine, but it will append the trailing endline characters!!! (I actually just left them in there and worked around it like that, since this is just small program anyway).
  3. To get a character input you can use getchar(). Also it seems as though this is the only way to do the “Press any key to continue” (without the “any key” part) type of pause on all platforms. (Windows users you can use a system(”pause”) call, but this obviously won’t work for unixes). If you’re just waiting for the enter key stroke so you can clear the screen, it’s not necessary to assign the return value of getchar() to a variable.
  4. C is fun!! I should use this more often! ;D

That’s about it so here’s the source code, released under the GPL (I’m not sure this is entirely necessary for such a small program, but that’s okay.)

REMEMBER: I DID NOT MAKE THIS GAME, I ONLY CREATED THE PROGRAM. I TAKE CREDIT FOR NOTHING OTHER THAN DIGITIZING A GAME THAT ALREADY EXISTS.

Happy Plue gaming!

Download The Plue Game!

Posted in Anime/Manga, C Programming, Programming | No Comments »

Scrollable GroupBox Widgets in QT4 Using QT Designer

August 5th, 2007 Pekk

When trying to figure out a way of inserting some more GUI components in my Equipmant project, I decided to try and use a scrollable container, just to see how it looked. There was, however, a slight problem. The QT designer does not have a scrolling area container in the toolbox.

After various google searches I came across the discovery of a QScrollArea widget. Now comes the question of: “How does one insert a widget into QT Designer when the widget does not appear in the QT designer toolbox?”

After some more searching I found the following document in which a user stated:

I think I am missing something about the widget promotion principal, and

hope you can help me find what it is.Promoting does nothing more then to put the

right include line and theright constructor in the auto generated code.

What I don't understand is, why the trolls didn't make this mechanism to

be available for the rest of the widgets that are not included in

designer, such as QStatusBar QScrollArea etc.

I actually didn't know there was such a restriction, and thought I could

just use the promotion mechanism to nicely design my GUI with designer

using QFrame and “promote” it to a scroll area.

And it works!

I read this over about 3 times trying to figure out what it meant… Eventually I remembered seeing the words “promoting a widget” somewhere before. The line I placed in bold-faced font is what gave away the answer, partially.

Creating a QScrollArea in QT Designer

I’ll give you the steps in the form of a concise list, so you don’t have to listen to my blabbering any longer (whew!)

  1. Create a frame object. To create a frame object, click the frame object from the toolbox (under the Containers tab) and drag it onto the form. This is what my form looks like (keep in mind I’m using Mac OSX):
    Creating a Scrolling GroupBox (Qt4 Designer) - Step 1
  2. Promote your frame to a QScrollArea. Right-click and select “Promote to Custom Widget” though this is a bit of a lie, QScrollArea is no custom widget ;). Of course enter QScrollArea in the box that pops up.
    Creating a Scrolling GroupBox (Qt4 Designer) - Step 2Creating a Scrolling GroupBox (Qt4 Designer) - Step 2
  3. Place a GroupBox widget onto the form, and move the frame inside of the GroupBox. We now have:
    Creating a Scrolling GroupBox (Qt4 Designer) - Step 3
  4. For testing purposes to make sure that our scrollable area is in fact scrolling add some widgets. The method I chose to do this was to create a vertical layout (by dragging it on to the form) and placing random widgets inside.
    Creating a Scrolling GroupBox (Qt4 Designer) - Step 4
  5. Place your layout inside your frame (QScrollArea) widget. Make sure the frame clips off some of the widgets, or there will be nothing to scroll! (see screenshot)
    Creating a Scrolling GroupBox (Qt4 Designer) - Step 5

Now it’s at this point that I originally tried to compile my project (after generating files with qmake). It had failed miserably, so naturally I sat around for a few minutes with my thumb up my butt trying to figure out what went wrong. Then I returned to google and found this article, where I found a small paragraph and a code snippet that made everything a bit clearer:

The way to use QScrollArea is to call setWidget() with the widget we want to add scroll bars to. QScrollArea automatically reparents the widget to make it a child of the viewport (accessible through QScrollArea::viewport()) if it isn’t already.:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    IconEditor *iconEditor = new
    IconEditor;iconEditor->setIconImage(QImage(":/images/mouse.png"));

    QScrollArea scrollArea;
    scrollArea.setWidget(iconEditor);
    scrollArea.viewport()->setBackgroundRole(QPalette::Dark);
    scrollArea.viewport()->setAutoFillBackground(true);
    scrollArea.setWindowTitle(QObject::tr(”Icon Editor”));
    scrollArea.show();

    return app.exec();

}

(again, keywords highlighted). As it turns out, my GUI design was ok but I was still missing a few key components. The first one being the call to setWidget(). So here’s what you need to do next:

  1. Since I didn’t mention it before, let’s create some files. First, save your UI file. I called mine scroll.ui. On a Unix system (Mac OS X, Linux, etc.) you may use the touch command from the terminal to create the rest of the files. (Windows users you can skip the rest of this step and make each file as we edit them in the later steps):touch main.cpp imp_scroll.h imp_scroll.cpp
  2. Open main.cpp and insert the following code:
    
    #include <QApplication>
    #include "imp_scroll.h"
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
        imp_scroll window;
        window.show();
        return app.exec();
    }
  3. Now open up imp_scroll.h and add the following:
    
    #ifndef __IMP_SCROLL_
    #define __IMP_SCROLL_
    
    #include "ui_main.h"
    
    class imp_scroll: public QMainWindow, Ui::MainWindow
    {
        Q_OBJECT
    
        public:
            imp_scroll() : QMainWindow() {
                setupUi(this);
                frame->setWidget(verticalLayout); // this is what makes us scroll :)
            }
    
    };
    
    #endif

    Here I set the scrollable parent to the verticalLayout. You may need to change this if you used a different type of layout.

  4. My imp_scroll.cpp only contains the single line:

    #include “imp_scroll.h”

  5. Now from a terminal window (or QT Command Prompt for windows users) type the following commands:
    
    qmake -project -o scroll.pro
    qmake
    make

    Note: for Mac OSX users to compile a QT project from the command line using the GNU compile tools, replace the bolded line with: qmake -spec macx-g++. On my machine, I have a variable set so it does this automatically. If you prefer to use XCode then use the macx-xcode QMAKESPEC variable.

Now run your program and you should see scrollbars! The only problem I have now is that I haven’t figured a way yet to make the scrolling widget scalable in a single direction, so it can scale one way and scroll the other. If anyone has a solution to this problem, please post a reply or something :)
Here is my final result:
Scrolling Group Box - Created With QT4 Designer!

Scrollable GroupBox Source Code is provided for any of those who are curious… I applied the GPL license information on it even though it’s such a small short example. I’m not entirely sure that this was necessary but I am using the Open Source version of QT. So… maybe it is! ^^;

Posted in Programming | No Comments »

Equipmant Files Released!

August 5th, 2007 Pekk

Okay this post actually pertains to what I did yesterday, but in any case…

I got some courage and decided to upload some of the Equipmant project files to the sourceforge site. After uploading all the versions I had previously made and posted on the arcib mirror, I decided to add a much needed feature… The Extra Data feature. (Note: I have not posted anything to the CVS Repositories yet, this part scares me a bit… So once I upload my files to the blondie project page through CVS I’ll post the files on the repositories as well).

The Extra Data feature of Equipmant is implemented to insure that any extra information in the script file (i.e., any non-Equipmant generated data) is not thrown away when the file is opened and saved again. Originally, if the users made any changes to the file (i.e., adding job ability or spell scripts anywhere in the file) that information would get lost when the file is opened again by Equipmant and saved, since Equipmant does not recognize this information. But the good news is that I’ve made modifications and tested the file, and it’s been working so far without any bugs.

How it works:

Equipmant scans a text file, line by line. It then checks to see if the current line is a comment or not. If the current line is a comment, it will check if it’s an output comment generated by Equipmant. If the comment is not an Equipmant-generated comment, the comment is tossed into the “extra data bin.”

The extra data bin is a collection of all of the non-Equipmant generated information (i.e., non-equipment related. It will not toss your hand-written equipment script lines into the bin). If it is not a comment, Equipmant will check if the line contains any text information about equipment changes; if the line doesn’t meet this criteria, it is thrown into the bin.

When the output is being generated, it scans each text box on the window for the equipment macro information. So the output is thrown together in the form of a template. First two lines are typically our generator comments (info like “file generated by equipmant” and where to get a copy of it) followed by the equipment macros (in a set order). The extra data bin feature now adds some more lines: a comment stating that the data below that line is the extra data found in the file, and then a line for every piece of information found in the file that was flagged as extra data.

Why?

I thought this feature was necessary because I use Equipmant to generate equipment changing scripts for my weapon skill macros, but every time I wanted to experiment and change my ws macro equip I couldn’t use Equipmant because this extra information got thrown away. But not anymore!

Additional Features To Come…

In the next revision of Equipmant I’m going to be altering the GUI slightly. I will add a text field where users can view/edit the extra data bin and I’m considering switching the text boxes for the equipment slots to editable drop down boxes. These boxes will store multiple pieces of equipment (that you enter) for one equip slot. This makes it easier to switch between different pieces of equipment (i.e., testing a Brown Belt vs a Life Belt) when you are trying new combinations.

These drop-down boxes are not boxes which contain all items of the game, I decided that even if I could get an easily obtainable list with data for all equipment pieces for all locations, it would be too much information. This method, instead of showing all possible equipment, shows only the pieces of equipment which you’ve tried to use in the past (i.e., your “history”). I like this idea much better because it means having fewer items in the list and it’s easier to select things.

Perhaps later on I will add an auto-complete to make up for this lack of a huge list containing every piece of equipment available. This way people who don’t want to spell out the item names are satisfied also. In other words the user would begin to type: Senjuin, and then a selected text will pop up (or maybe a drop down list will pop up under the cursor) that says, “Senjuinrikio” and the user hits the tab key to complete the word. This also makes editing faster in general, but this will involve a bit of work and investigation on how I can accomplish this.

Edit: Also I forgot about this so I thought I’d write it down here: There will be easy-to-use drop-down boxes to add data into the extra data bin. I.e., one box will give a command “input,” “wait,” and another box will give another command “/ja,” “/ma,” “/song” or if the wait command is specified just a box labeled “time” where you may enter the number of seconds, and a third box that will appear if the input command is selected to allow you to pick a spell or a song or a job ability.

Posted in Equipmant, Programming | No Comments »

Equipmant Project Approved!

August 3rd, 2007 Pekk

Aside from the fact that yesterday my co-owned otaku-elite.com domain name decided to work again all on its lonesome will, I logged in to check my e-mail,
and I noticed the “SourceForge” gmail label was empty. Then I realized that a month
ago or so I started work on this Equipmant project, a program designed to create
equipment macros for the Final Fantasy XI Windower on PC, and I’d still been waiting
for sourceforge to approve me. But my mailbox was empty! So I decided to do what
any other person would do in this situation. Resubmit the registration forms!

I popped open my Firefox and pointed it to SourceForge’s homepage to log in. As I was
right about to begin the registration project I noticed an extra project on my sf
home page. It was already there! It must’ve been sitting for a while, too, sadly.

In any case, when I noticed this, I had to quickly upload some stuff. So for today I’ve accomplished the following:

  • Uploaded Mac OS X and Windows screenshots of Equipmant to the Equipmant Project Page @ SourceForge
  • Uploaded the Equipmant webpage to SourceForge
  • Added links to both equipmant pages pointing to the project page on sourceforge

I’m now waiting on the approval and creation of the same project on my school’s GForge site so I can practice uploading the files with CVS and the project manager (so I don’t make any irreversible screw-ups on sourceforge).

Also, I’ve put in a request for my next project, MenGen. Hopefully this project will also get approved soon and I will start to get some serious work done on it.

Posted in Equipmant, Programming | No Comments »