Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 7, 2005, 11:55 AM   #1
hapyfishrmn
macrumors newbie
 
Join Date: Oct 2005
Location: IL
Simple Drawing example

Goal: To draw a box and put text inside. Used in a plugin for Safari

Apple Programming Experience: Extreme novice

Setup: Using Xcode 2 on OSX 10.4

Attempts:
Unable to use QuickDraw functions, because quickdraw.h file can't be found since it is deprecated in 10.4.

I have tried using Cocoa.h and its functions but when I build and run the plugin Safari doesn't recognize the plugin. But when I use Carbon the plugin atleast loads.

Looked up using Quartz functions but it seems it needs Cocoa.h and I had problems with that.

Thanks for your help and patience,

-G
hapyfishrmn is offline   0 Reply With Quote
Old Oct 7, 2005, 03:36 PM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by hapyfishrmn
Looked up using Quartz functions but it seems it needs Cocoa.h and I had problems with that.
What problems? You mean you can't find it, can't link it, or you're having trouble understanding it, or what?
HiRez is offline   0 Reply With Quote
Old Oct 7, 2005, 05:39 PM   #3
hapyfishrmn
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Location: IL
My project was set up as a CFBundle so that I could use it as a plugin for Safari.

Currently I am trying to use code I found here:
http://www.macdevcenter.com/pub/a/ma...02/quartz.html
http://www.macdevcenter.com/mac/2004...mples/code.zip
as an example how to use Quartz. But since I am not using a application I am running into problems. (At least thats what I think the problem is.)

What I have is just a shell plugin with just the basic API calls to allow the browser to accept the plugin. I have a function that writes to a file, the entry and exit of the current function I go into, so that I can find errors quicker.

So I have used the code from the website above:
Code:
static const ControlID kFlagControlID = { 'Flag', 0 };

static OSStatus FlagViewEventHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void *userData);
static EventHandlerUPP gFlagViewEventUPP = NewEventHandlerUPP(FlagViewEventHandler);
static const EventTypeSpec gContentEventsHandled[] = { {kEventClassControl, kEventControlDraw} };
//*----------------------------------------*
OSStatus FlagViewEventHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void *userData)
{
	OSStatus retVal = eventNotHandledErr;
	
	switch(GetEventClass(inEvent)) {
		case kEventClassControl : {
			retVal = HandleControlEvents(inCallRef, inEvent, userData);
		} break;
	}
	
	return retVal;
}
//*----------------------------------------*
	require_noerr(HIViewFindByID(HIViewGetRoot(window), kFlagControlID, &flagView), CantFindContent);
	require_noerr(InstallControlEventHandler(
							flagView,
							gFlagViewEventUPP,
							GetEventTypeCount(gContentEventsHandled),
							gContentEventsHandled,
							NULL, NULL), CantInstallHandler);
This code is in the NPP_New API function. When I build I get this error:

error: initializer element is not constant

Which is referring to this line: static EventHandlerUPP gFlagViewEventUPP = NewEventHandlerUPP(FlagViewEventHandler);

I don't know if this is any help for you to decipher what I need to accomplish my goal. But any direction would be appreciated.

Is Quartz the right direction to go? Is it possible to draw using a bundle? THese things I really don't know and I am figuring out as I go.
hapyfishrmn is offline   0 Reply With Quote
Old Oct 11, 2005, 01:17 AM   #4
logicat2001
macrumors regular
 
Join Date: Apr 2003
Location: Minneapolis, MN
Quote:
I don't know if this is any help for you to decipher what I need to accomplish my goal.
Gosh...what is your goal? Would you explain in more detail what you mean by, "Goal: To draw a box and put text inside. Used in a plugin for Safari"?

Also, you state that you're a complete novice, but have you done any programming at all or have you little to no experience? If you've done any coding, what have you worked with in the past? (This isn't a test; just curious where you're at with the abstraction of it all.)

Best,
Logicat
logicat2001 is offline   0 Reply With Quote
Old Oct 11, 2005, 11:57 AM   #5
hapyfishrmn
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Location: IL
I am not sure how else to explain it. I am trying to make a plugin for Safari. There are alot of things I am planning on doing with it, but to start I would like to do some simple things first. So that is why I am trying to draw a rectangle and also output text into the retangle. Just to do simple output to the browser. I don't know how to do that. After that I would try to expand it.

As far as programming on the MAC I haven't done any this is my first experience, I have been programming for 2-3 years, but it has been mostly for Windows.

I have tried to understand the quickdraw methods, but when I try to include the quickdraw.h it doesn't find the file to include. Since the Apple documentation says its deprecated so I assume that its not on my machine. So I read that I should use Quartz. Thats what I have been trying and my last post is talks about my attempts with it. If there is a better route that I should go I would appreciate a point in the right direction.

Thanks,

-G
hapyfishrmn is offline   0 Reply With Quote
Old Oct 11, 2005, 11:33 PM   #6
logicat2001
macrumors regular
 
Join Date: Apr 2003
Location: Minneapolis, MN
Quote:
I am not sure how else to explain it. I am trying to make a plugin for Safari. There are alot of things I am planning on doing with it, but to start I would like to do some simple things first. So that is why I am trying to draw a rectangle and also output text into the rectangle. Just to do simple output to the browser.
I'd like you to consider what you're interested in doing in more detail. If you're trying to write code to accomplish a goal, you'd better know specifically what you're out to accomplish; I mean literally know exactly what you're intending to do.

For example, if you want to draw a box on the screen, you're going to need to know the exact pixel dimensions of your box, the color/transparency, whether it has a border, the width and color of that border, and what pixel on the screen it will be be positioned at. You should also know whether that box will be displayed alone or mixed with other graphic objects, and if it is something that the user can manipulate or interact with in any way whatsoever.

So, let's consider your idea. You want a plugin for Safari to draw a rectangle and output text into the rectangle. Is Safari being used only to display your image, or are you going to be drawing over the top of existing web page content? Is the user completely passive or can they somehow interact with the output of your plugin? Why would a user want to install the plugin; what is it that it does for them? I really can't suggest much for you unless you offer some details.

BTW, "deprecated" doesn't mean that it's no longer available. Deprecated methods, classes, etc. are things that have been marked for possible/eventual removal. Therefore, you're free to use deprecated items, but don't assume they're always going to be there. It's a nice way of strongly recommending that you reconsider how you code, because it's going to change at some point in the future.

When you come across deprecated items, you can always safely assume that there's a new, recommended solution that now exists and serves a similar purpose. Some times there's no point in using the newer methods because they require a newer version of the OS and you want to make sure anyone with an older version of the OS can still run your app. An example: I'm working on an app that sub-classes the Cocoa class NSDocument. There's method called "initWithContentsOfFile: ofType:" that I was planning on using, then I learned that it's deprecated in 10.4. After reading the docs, and learning that Apple recommends "initWithContentsOfURL: ofType:error:", I realized that I have to use the deprecated method if I want to support users on version of Mac OS other than 10.4.
Quote:
I have tried to understand the quickdraw methods
AFAIK, Quickdraw has been deprecated.
Quote:
when I try to include the quickdraw.h it doesn't find the file to include.
I'd suggest checking through the Apple Developer docs for something called "Drawing and Views Programming Topics for Cocoa." It covers a bunch of the ground rules you should at least be aware of; some of it will be absolutely required knowledge if you're going to continue with your project.

Also, there's a Cocoa class that exists solely to allow using Quickdraw in Cocoa apps. It's called "NSQuickDrawView" and is a sub-class of NSView.
Quote:
I read that I should use Quartz.
Again, it all depends on what you're looking to accomplish. Here's an example project that draws a Texas flag. Download and check it out. You might be surprised how little it takes. NOTE: I'm not advocating anything about how I wrote my code. I'm simply sending this as an example of code, not elegant or ideal code.

Best,
Logicat
logicat2001 is offline   0 Reply With Quote
Old Oct 12, 2005, 09:31 AM   #7
hapyfishrmn
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Location: IL
I understand what your trying to say by knowing what exact details of my project. If I want to draw a box I wouldn't think that I have to be concerned about if it has shading or the thickness of the borders. Those things seem to be a secondary issue. I am just want a rectangle that has black lines and black text inside. So as far as those colors I understand.

Quote:
Originally Posted by logicat2001
So, let's consider your idea. You want a plugin for Safari to draw a rectangle and output text into the rectangle. Is Safari being used only to display your image, or are you going to be drawing over the top of existing web page content? Is the user completely passive or can they somehow interact with the output of your plugin? Why would a user want to install the plugin; what is it that it does for them? I really can't suggest much for you unless you offer some details.
It seems you want to know what this plugin is going to do and basically it is going to be for display purposes at first. Saying this is version 1.xx of the plugin or something. Just a simple message that I could write different things to.
I don't want to draw over any of the web page just its area that the html has it embeded in. The rectangle and text is really for display purposes only so no interaction is going on between the plugin and user. I dont have a concern for why the user wants to install the plugin because the plugin will be for my use for now.

Here is a question that I don't know the answer to. When you are developing a CFBundle vs an Application do you have the same ability with the Bundle as you do in an app? Your example is an application, where mine is a plugin. I know they are different but I am not sure how they are different. An application already has a predefined window with properties and etc. it doesn't seem that you have those same abilities with a browser window.

I will take a look at the texas flag example and see how I can use similiar techniques.
hapyfishrmn is offline   0 Reply With Quote
Old Nov 15, 2005, 04:46 PM   #8
hapyfishrmn
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Location: IL
Hello again,

I spent some time looking at your Texas Flag example. I believe I understand how it works. But one of the differences is that it creates a window and draws into a HIView. Usually in a plugin you draw onto the space set up for the plugin in the webpage. So how do I transfer the idea of drawing to an object like HIView when I am dealing with a browser window.

thanks

g
hapyfishrmn is offline   0 Reply With Quote
Old Nov 15, 2005, 05:20 PM   #9
logicat2001
macrumors regular
 
Join Date: Apr 2003
Location: Minneapolis, MN
Since this application/plugin is only for your use, what web browser will you be using? I ask because rather than code for the world-at-large, you might even be able to whip up something simple using WebKit. Check here for a tutorial to build a super-rudimentary browser. Since I have no idea what you're looking to accomplish with this plugin, I have no idea what to suggest, other than: you've got a pile of research to do.

Good luck,
Logicat
logicat2001 is offline   0 Reply With Quote
Old Nov 16, 2005, 08:53 AM   #10
hapyfishrmn
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Location: IL
As I mentioned in the beginning I am trying to use Safari. I don't want to create my own web browser as your example shows. In the example you suggest with WebKit or the Texas flag they create windows and have nib files to add a WebView or HIView to it. In a web page you do not have that. At least I haven't read anywhere how you could do that. Unless you create one to the area in the browser window programatically.

What I am trying to do is simply ouput text to the plugin area and thats it. I know it doesnt sound to flashy or great but its really as simple as that.

Lets assume you have a webpage similiar to this. An embeded type of .test you want your plugin to read a file and output some text into a your plugin area based upon what it reads.
Code:
<html>
 <body>
  <EMBED border=1 pluginspace="\localhost\Plugin.test" texturl="\localhost\Plugin.test" type="application/x-test" width=400 height=70> 
  </embed>
 </body>
</html>
How do you write into the plugin area on the webpage. I have looked at the Netscape Api calls and have them being called by the browser, but I am stuck when it comes to simple output to the plugin area. So far I am importing:
Code:
#import <WebKit/npapi.h>
#import <WebKit/npfunctions.h>
#import <WebKit/npruntime.h>
#include <Carbon/Carbon.h>
And the plugin functions are being called by the browser in order when you load the webpage: NP_Initialize, NP_GetEntryPoints, NPP_SetWindow, NPP_Destroy.

So I used the Texas flag example and used DrawText to write to the HIView object. So I used MoveTo(x,y) to move the graphics pointer to the location I wanted and then used DrawText, which worked. I tried this same thing with the plugin and was unable to draw anything. I hope this makes more sense to you at where my current status is at and ideas that I have tried. I dont know what else to post to be clearer. Let me know, I truly appreciate the help.

thanks again

g
hapyfishrmn is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Drawing App Ricky Smith iPad Apps 3 Jul 30, 2014 03:20 AM
iPad: Simple drawing app Iz1016 iPad Accessories 13 Jan 21, 2013 06:03 AM
Photoshop drawing Help strikefreedom Design and Graphics 3 Nov 3, 2012 11:31 AM
drawing software Alaska1man iMac 6 Jun 10, 2012 05:27 PM

Forum Jump

All times are GMT -5. The time now is 06:25 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC