Yet another three weeks has gone by and I didn't even notice. Yeesh. Time flies when you're coding, so no big deal. *shrug*
This lesson is one of several which delves into the art of control writing for Haiku -- not just a quick-and-dirty hack on an existing one, but writing a new control which rivals existing ones in quality and features. Learn how controls handle drawing themselves and write a basic color display control.
Programming with Haiku, Lesson 17
Monday, January 31, 2011
Thursday, January 27, 2011
C, Meet the Haiku GUI
It's official: after a couple of hours of furious code, I have written a graphical Haiku application from C, courtesy of libcharlemagne. No, not C++ and there is none of that fancy application scripting via BMessage and hey, either. The title? CHaikuRun, of course.
With mappings from C++ to C being pretty ugly, the code won't exactly win elegance contests. Also, there may be some C-to-HTML ickiness here, so bear that in mind.
With mappings from C++ to C being pretty ugly, the code won't exactly win elegance contests. Also, there may be some C-to-HTML ickiness here, so bear that in mind.
#include "libcharlemagne.h"#include <stdio.h> int32_t InitApp(void *pobject, PArgList *foo_in, PArgList *foo_out) { /* This accomplishes the same kinds of tasks as what would normally be done in a BApplication's child class constructor */ void *mainwin = pobject_create("PWindow"); pdata_set_bool_property(mainwin, "Visible", 0); pdata_set_string_property(mainwin, "Title", "CHaikuRun"); pdata_set_rect_property(mainwin, "Frame", 100, 100, 500, 400); pdata_set_bool_property(mainwin, "Visible", 1); pdata_set_int_property(mainwin, "Flags", 0x00180000); /* Here is an example of how to run a method for an object in C*/ void *backview = pobject_create("PView"); pdata_set_rect_property(backview, "Frame", 0, 0, 400, 300); pdata_set_color_property(backview, "BackColor", 224, 224, 224, 255); /* These have to exist for running a method, but they can be reused */ PArgList *in = create_parglist(); PArgList *out = create_parglist(); /* AddChild requires the object ID of the child view to add */ add_parg_int64(in, "id", pobject_get_id(backview)); pobject_run_method(mainwin, "AddChild", in, out); void *label = pobject_create("PLabel"); pdata_set_rect_property(label, "Frame", 10, 10, 350, 60); pdata_set_string_property(label, "Text", "Hello Haiku from the C language!"); empty_parglist(in); add_parg_int64(in, "id", pobject_get_id(label)); pobject_run_method(backview, "AddChild", in, out); /* Free allocated heap memory */ destroy_parglist(in); destroy_parglist(out); return B_OK; } int main(void) { /* Start up the object system. Without this, we can't do anything with libcharlemagne */ pobjectspace_init(); void *papp = pobject_create("PApplication"); run_app(papp, "application/x-vnd.dw-CHaikuRun", InitApp); /* Not absolutely necessary here, but it frees all objects allocated by the broker */ pobjectspace_shutdown(); return 0; }
Wednesday, January 26, 2011
Closer to Scripting Language Support
In the few weeks since my last post I've been working more on bringing the ability to write graphical Haiku applications to languages outside of C++. PDesigner has seen some refactoring, and now it's a lot lighter -- all of the object system code upon which PDesigner has been built was spun out into its own library, libcharlemagne. I'm working with SWIG in order to be able to generate the necessary bindings for the supported languages.
I've run into a small snag, however: I don't know very much about other languages except for a passing familiarity with Python, and certainly not enough about it to know what I'm doing. Just last night I checked in some code to the repository which, in theory, should make it possible to write a Haiku app from Python, Lua, or just about any other scripting language supported by SWIG. There's also a C interface for those people who want to use it. Documentation will be coming soon.
Once I get it to the point where other people will want to use it, it will be available both with the Paladin suite and as a separate download. If you have a little time to tinker and know something about using SWIG for your favorite non-C++ language, get in touch with me.
I've run into a small snag, however: I don't know very much about other languages except for a passing familiarity with Python, and certainly not enough about it to know what I'm doing. Just last night I checked in some code to the repository which, in theory, should make it possible to write a Haiku app from Python, Lua, or just about any other scripting language supported by SWIG. There's also a C interface for those people who want to use it. Documentation will be coming soon.
Once I get it to the point where other people will want to use it, it will be available both with the Paladin suite and as a separate download. If you have a little time to tinker and know something about using SWIG for your favorite non-C++ language, get in touch with me.
Sunday, January 9, 2011
Lesson 16: Fonts
Most people think of fonts as merely a means to an end, but in this lesson we will take a crash course in typography and the very basics of displaying text in Haiku. Also included is a review of the second unit, lessons 6 through 15.
Programming With Haiku , Unit 2 Review
Programming With Haiku, Lesson 16
Programming With Haiku , Unit 2 Review
Programming With Haiku, Lesson 16
Monday, January 3, 2011
New Year, Same Old Stuff
In about 15 minutes, I'll be heading off to work. The two weeks vacation that I had for Christmas went really fast. This would probably be the first vacation I've had in a long time that I've felt like I didn't get much done.
The big project I spent time working on was PDesigner's object interface. Just a couple of days ago I managed to implement the rest of the code which makes it possible to incrementally learn the interface for any object -- what each object's methods, properties, and events it has and what each method's arguments are and any values it returns. I guess now it's just a matter of adding more of the Haiku API to it and moving the code out of PDesigner and into a shared library when it's ready for release.
The other project I spent time on was more of my Programming with Haiku series. I've hit a bit of a slow spot in the series because I'm not as familiar with the material that the lessons are covering at the moment. Barring major issues, another lesson should be seeing light of day later this week. Have a happy New Year, everyone!
The big project I spent time working on was PDesigner's object interface. Just a couple of days ago I managed to implement the rest of the code which makes it possible to incrementally learn the interface for any object -- what each object's methods, properties, and events it has and what each method's arguments are and any values it returns. I guess now it's just a matter of adding more of the Haiku API to it and moving the code out of PDesigner and into a shared library when it's ready for release.
The other project I spent time on was more of my Programming with Haiku series. I've hit a bit of a slow spot in the series because I'm not as familiar with the material that the lessons are covering at the moment. Barring major issues, another lesson should be seeing light of day later this week. Have a happy New Year, everyone!
Subscribe to:
Posts (Atom)