Patch by Michael Kanis:

* Switched CodyCam GUI to use Haiku layout management.

Thanks a lot!!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29094 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-01-30 22:26:58 +00:00
parent 6a392dcec4
commit 89d04738c0
+108 -118
View File
@@ -6,6 +6,9 @@
#include <Alert.h> #include <Alert.h>
#include <Button.h> #include <Button.h>
#include <GridLayout.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include <MediaNode.h> #include <MediaNode.h>
#include <MediaRoster.h> #include <MediaRoster.h>
@@ -15,6 +18,7 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <scheduler.h> #include <scheduler.h>
#include <SpaceLayoutItem.h>
#include <TabView.h> #include <TabView.h>
#include <TextControl.h> #include <TextControl.h>
#include <TimeSource.h> #include <TimeSource.h>
@@ -39,7 +43,7 @@ const int32 kMenuHeight = 15;
const int32 kButtonHeight = 15; const int32 kButtonHeight = 15;
const int32 kSliderViewRectHeight = 40; const int32 kSliderViewRectHeight = 40;
static void ErrorAlert(const char* message, status_t err); static void ErrorAlert(const char* message, status_t err, BWindow *window);
static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType); static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType);
#define CALL printf #define CALL printf
@@ -51,12 +55,22 @@ static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType);
// Utility functions // Utility functions
static void static void
ErrorAlert(const char* message, status_t err) ErrorAlert(const char* message, status_t err, BWindow *window = NULL)
{ {
(new BAlert("", message, "Quit"))->Go(); BAlert *alert = new BAlert("", message, "OK");
if (window != NULL) {
alert->MoveTo(
window->Frame().left +
window->Bounds().right / 2 -
alert->Bounds().right / 2,
window->Frame().top +
window->Bounds().bottom / 2 -
alert->Bounds().bottom / 2);
}
alert->Go();
printf("%s\n%s [%lx]", message, strerror(err), err); printf("%s\n%s [%lx]", message, strerror(err), err);
be_app->PostMessage(B_QUIT_REQUESTED); // be_app->PostMessage(B_QUIT_REQUESTED);
} }
@@ -145,9 +159,9 @@ void
CodyCam::ReadyToRun() CodyCam::ReadyToRun()
{ {
/* create the window for the app */ /* create the window for the app */
fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X - 1), fWindow = new VideoWindow(BRect(28, 28, 28, 28),
28 + (WINDOW_SIZE_Y - 1)), (const char*)"CodyCam", B_TITLED_WINDOW, (const char*) "CodyCam", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort); B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, &fPort);
/* set up the node connections */ /* set up the node connections */
status_t status = _SetUpNodes(); status_t status = _SetUpNodes();
@@ -243,14 +257,14 @@ CodyCam::_SetUpNodes()
/* find the media roster */ /* find the media roster */
fMediaRoster = BMediaRoster::Roster(&status); fMediaRoster = BMediaRoster::Roster(&status);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't find the media roster", status); ErrorAlert("Can't find the media roster", status, fWindow);
return status; return status;
} }
/* find the time source */ /* find the time source */
status = fMediaRoster->GetTimeSource(&fTimeSourceNode); status = fMediaRoster->GetTimeSource(&fTimeSourceNode);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't get a time source", status); ErrorAlert("Can't get a time source", status, fWindow);
return status; return status;
} }
@@ -258,7 +272,7 @@ CodyCam::_SetUpNodes()
INFO("CodyCam acquiring VideoInput node\n"); INFO("CodyCam acquiring VideoInput node\n");
status = fMediaRoster->GetVideoInput(&fProducerNode); status = fMediaRoster->GetVideoInput(&fProducerNode);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't find a video source. You need a webcam to use CodyCam.", status); ErrorAlert("Can't find a video source. You need a webcam to use CodyCam.", status, fWindow);
return status; return status;
} }
@@ -266,14 +280,14 @@ CodyCam::_SetUpNodes()
fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(), fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(),
((VideoWindow*)fWindow)->StatusLine(), NULL, 0); ((VideoWindow*)fWindow)->StatusLine(), NULL, 0);
if (!fVideoConsumer) { if (!fVideoConsumer) {
ErrorAlert("Can't create a video window", B_ERROR); ErrorAlert("Can't create a video window", B_ERROR, fWindow);
return B_ERROR; return B_ERROR;
} }
/* register the node */ /* register the node */
status = fMediaRoster->RegisterNode(fVideoConsumer); status = fMediaRoster->RegisterNode(fVideoConsumer);
if (status != B_OK) { if (status != B_OK) {
ErrorAlert("Can't register the video window", status); ErrorAlert("Can't register the video window", status, fWindow);
return status; return status;
} }
fPort = fVideoConsumer->ControlPort(); fPort = fVideoConsumer->ControlPort();
@@ -284,7 +298,7 @@ CodyCam::_SetUpNodes()
B_MEDIA_RAW_VIDEO); B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert("Can't find an available video stream", status); ErrorAlert("Can't find an available video stream", status, fWindow);
return status; return status;
} }
@@ -294,7 +308,7 @@ CodyCam::_SetUpNodes()
&cnt, B_MEDIA_RAW_VIDEO); &cnt, B_MEDIA_RAW_VIDEO);
if (status != B_OK || cnt < 1) { if (status != B_OK || cnt < 1) {
status = B_RESOURCE_UNAVAILABLE; status = B_RESOURCE_UNAVAILABLE;
ErrorAlert("Can't find an available connection to the video window", status); ErrorAlert("Can't find an available connection to the video window", status, fWindow);
return status; return status;
} }
@@ -436,7 +450,6 @@ VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint
_SetUpSettings("codycam", ""); _SetUpSettings("codycam", "");
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar"); BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar");
AddChild(menuBar);
BMenuItem* menuItem; BMenuItem* menuItem;
BMenu* menu = new BMenu("File"); BMenu* menu = new BMenu("File");
@@ -470,23 +483,15 @@ VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint
menuBar->AddItem(menu); menuBar->AddItem(menu);
/* give it a gray background view */ /* give it a gray background view */
BRect aRect; fView = new BView("Background View", B_WILL_DRAW, NULL);
aRect = Frame(); fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
aRect.OffsetTo(B_ORIGIN);
aRect.top += menuBar->Frame().Height() + 1;
fView = new BView(aRect, "Background View", B_FOLLOW_ALL, B_WILL_DRAW);
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fView);
/* add some controls */ /* add some controls */
_BuildCaptureControls(fView); _BuildCaptureControls(fView);
/* add another view to hold the video image */ SetLayout(new BGroupLayout(B_VERTICAL));
aRect = BRect(0, 0, VIDEO_SIZE_X - 1, VIDEO_SIZE_Y - 1); AddChild(menuBar);
aRect.OffsetBy((WINDOW_SIZE_X - VIDEO_SIZE_X) / 2, kYBuffer); AddChild(fView);
fVideoView = new BView(aRect, "Video View", B_FOLLOW_ALL, B_WILL_DRAW);
fView->AddChild(fVideoView);
Show(); Show();
} }
@@ -665,32 +670,22 @@ VideoWindow::StatusLine()
void void
VideoWindow::_BuildCaptureControls(BView* theView) VideoWindow::_BuildCaptureControls(BView* theView)
{ {
BRect aFrame, theFrame; // a view to hold the video image
fVideoView = new BView("Video View", B_WILL_DRAW);
fVideoView->SetExplicitMinSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y));
fVideoView->SetExplicitMaxSize(BSize(VIDEO_SIZE_X, VIDEO_SIZE_Y));
theFrame = theView->Bounds(); // Capture controls
theFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40; fCaptureSetupBox = new BBox("Capture Controls", B_WILL_DRAW);
theFrame.left += kXBuffer; fCaptureSetupBox->SetLabel("Capture controls");
theFrame.right -= (WINDOW_SIZE_X / 2 + 5);
theFrame.bottom -= kXBuffer;
fCaptureSetupBox = new BBox(theFrame, "Capture Controls", B_FOLLOW_ALL, B_WILL_DRAW); BGridLayout *controlsLayout = new BGridLayout(kXBuffer, 0);
fCaptureSetupBox->SetLabel("Capture Controls"); controlsLayout->SetInsets(10, 15, 5, 5);
theView->AddChild(fCaptureSetupBox); fCaptureSetupBox->SetLayout(controlsLayout);
aFrame = fCaptureSetupBox->Bounds(); fFileName = new BTextControl("File Name", "File name:",
aFrame.InsetBy(kXBuffer, kYBuffer);
aFrame.top += kYBuffer / 2;
aFrame.bottom = aFrame.top + kMenuHeight;
fFileName = new BTextControl(aFrame, "File Name", "File Name:",
fFilenameSetting->Value(), new BMessage(msg_filename)); fFilenameSetting->Value(), new BMessage(msg_filename));
fFileName->SetTarget(BMessenger(NULL, this)); fFileName->SetTarget(BMessenger(NULL, this));
fFileName->SetDivider(fFileName->Divider() - 30);
fCaptureSetupBox->AddChild(fFileName);
aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight;
fImageFormatMenu = new BPopUpMenu("Image Format Menu"); fImageFormatMenu = new BPopUpMenu("Image Format Menu");
AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP);
@@ -705,13 +700,9 @@ VideoWindow::_BuildCaptureControls(BView* theView)
else else
fImageFormatMenu->ItemAt(0)->SetMarked(true); fImageFormatMenu->ItemAt(0)->SetMarked(true);
fImageFormatSelector = new BMenuField(aFrame, "Format", "Format:", fImageFormatMenu); fImageFormatSelector = new BMenuField("Format", "Format:",
fImageFormatSelector->SetDivider(fImageFormatSelector->Divider() - 30); fImageFormatMenu, NULL);
fCaptureSetupBox->AddChild(fImageFormatSelector);
aFrame.top = aFrame.bottom + kYBuffer;
aFrame.bottom = aFrame.top + kMenuHeight;
fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu"); fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu");
fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", new BMessage(msg_rate_15s))); fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", new BMessage(msg_rate_15s)));
fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", new BMessage(msg_rate_30s))); fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", new BMessage(msg_rate_30s)));
@@ -728,17 +719,20 @@ VideoWindow::_BuildCaptureControls(BView* theView)
fCaptureRateMenu->AddItem(new BMenuItem("Never", new BMessage(msg_rate_never))); fCaptureRateMenu->AddItem(new BMenuItem("Never", new BMessage(msg_rate_never)));
fCaptureRateMenu->SetTargetForItems(this); fCaptureRateMenu->SetTargetForItems(this);
fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true);
fCaptureRateSelector = new BMenuField(aFrame, "Rate", "Rate:", fCaptureRateMenu); fCaptureRateSelector = new BMenuField("Rate", "Rate:",
fCaptureRateSelector->SetDivider(fCaptureRateSelector->Divider() - 30); fCaptureRateMenu, NULL);
fCaptureSetupBox->AddChild(fCaptureRateSelector);
aFrame = theView->Bounds(); controlsLayout->AddItem(fFileName->CreateLabelLayoutItem(), 0, 0);
aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40; controlsLayout->AddItem(fFileName->CreateTextViewLayoutItem(), 1, 0);
aFrame.left += WINDOW_SIZE_X / 2 + 5; controlsLayout->AddItem(fImageFormatSelector->CreateLabelLayoutItem(), 0, 1);
aFrame.right -= kXBuffer; controlsLayout->AddItem(fImageFormatSelector->CreateMenuBarLayoutItem(), 1, 1);
aFrame.bottom -= kYBuffer; controlsLayout->AddItem(fCaptureRateSelector->CreateLabelLayoutItem(), 0, 2);
controlsLayout->AddItem(fCaptureRateSelector->CreateMenuBarLayoutItem(), 1, 2);
controlsLayout->AddItem(BSpaceLayoutItem::CreateGlue(), 0, 3, 2);
// FTP setup box
fFtpSetupBox = new BBox("Ftp Setup", B_WILL_DRAW);
fFtpSetupBox = new BBox(aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW);
fUploadClientMenu = new BPopUpMenu("Send to" B_UTF8_ELLIPSIS); fUploadClientMenu = new BPopUpMenu("Send to" B_UTF8_ELLIPSIS);
for (int i = 0; kUploadClient[i]; i++) { for (int i = 0; kUploadClient[i]; i++) {
BMessage *m = new BMessage(msg_upl_client); BMessage *m = new BMessage(msg_upl_client);
@@ -747,78 +741,74 @@ VideoWindow::_BuildCaptureControls(BView* theView)
} }
fUploadClientMenu->SetTargetForItems(this); fUploadClientMenu->SetTargetForItems(this);
fUploadClientMenu->FindItem(fUploadClientSetting->Value())->SetMarked(true); fUploadClientMenu->FindItem(fUploadClientSetting->Value())->SetMarked(true);
fUploadClientSelector = new BMenuField(aFrame, "UploadClient", "", fUploadClientMenu); fUploadClientSelector = new BMenuField("UploadClient", NULL,
fUploadClientSelector->SetDivider(0.0); fUploadClientMenu, NULL);
fFtpSetupBox->SetLabel(fUploadClientSelector); fFtpSetupBox->SetLabel("FTP");
theView->AddChild(fFtpSetupBox); // this doesn't work with the layout manager
// fFtpSetupBox->SetLabel(fUploadClientSelector);
fUploadClientSelector->SetLabel("Type:");
aFrame = fFtpSetupBox->Bounds(); BGridLayout *ftpLayout = new BGridLayout(kXBuffer, 0);
aFrame.InsetBy(kXBuffer,kYBuffer); ftpLayout->SetInsets(10, 15, 5, 5);
aFrame.top += kYBuffer/2; fFtpSetupBox->SetLayout(ftpLayout);
aFrame.bottom = aFrame.top + kMenuHeight;
aFrame.right = aFrame.left + 160;
fServerName = new BTextControl(aFrame, "Server", "Server:", fServerSetting->Value(), fServerName = new BTextControl("Server", "Server:",
new BMessage(msg_server)); fServerSetting->Value(), new BMessage(msg_server));
fServerName->SetTarget(this); fServerName->SetTarget(this);
fServerName->SetDivider(fServerName->Divider() - 30);
fFtpSetupBox->AddChild(fServerName);
aFrame.top = aFrame.bottom + kYBuffer; fLoginId = new BTextControl("Login", "Login:",
aFrame.bottom = aFrame.top + kMenuHeight; fLoginSetting->Value(), new BMessage(msg_login));
fLoginId = new BTextControl(aFrame, "Login", "Login:", fLoginSetting->Value(),
new BMessage(msg_login));
fLoginId->SetTarget(this); fLoginId->SetTarget(this);
fLoginId->SetDivider(fLoginId->Divider() - 30);
fFtpSetupBox->AddChild(fLoginId);
aFrame.top = aFrame.bottom + kYBuffer; fPassword = new BTextControl("Password", "Password:",
aFrame.bottom = aFrame.top + kMenuHeight;
fPassword = new BTextControl(aFrame, "Password", "Password:",
fPasswordSetting->Value(), new BMessage(msg_password)); fPasswordSetting->Value(), new BMessage(msg_password));
fPassword->SetTarget(this); fPassword->SetTarget(this);
fPassword->SetDivider(fPassword->Divider() - 30);
fPassword->TextView()->HideTyping(true); fPassword->TextView()->HideTyping(true);
// BeOS HideTyping() seems broken, it empties the text // BeOS HideTyping() seems broken, it empties the text
fPassword->SetText(fPasswordSetting->Value()); fPassword->SetText(fPasswordSetting->Value());
fFtpSetupBox->AddChild(fPassword);
aFrame.top = aFrame.bottom + kYBuffer; fDirectory = new BTextControl("Directory", "Directory:",
aFrame.bottom = aFrame.top + kMenuHeight;
fDirectory = new BTextControl(aFrame, "Directory", "Directory:",
fDirectorySetting->Value(), new BMessage(msg_directory)); fDirectorySetting->Value(), new BMessage(msg_directory));
fDirectory->SetTarget(this); fDirectory->SetTarget(this);
fDirectory->SetDivider(fDirectory->Divider() - 30);
fFtpSetupBox->AddChild(fDirectory);
aFrame.top = aFrame.bottom + kYBuffer; fPassiveFtp = new BCheckBox("Passive ftp", "Passive FTP",
aFrame.bottom = aFrame.top + kMenuHeight;
fPassiveFtp = new BCheckBox(aFrame, "Passive ftp", "Passive ftp",
new BMessage(msg_passiveftp)); new BMessage(msg_passiveftp));
fPassiveFtp->SetTarget(this); fPassiveFtp->SetTarget(this);
fPassiveFtp->SetValue(fPassiveFtpSetting->Value()); fPassiveFtp->SetValue(fPassiveFtpSetting->Value());
fFtpSetupBox->AddChild(fPassiveFtp);
aFrame = theView->Bounds(); ftpLayout->AddItem(fUploadClientSelector->CreateLabelLayoutItem(), 0, 0);
aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer; ftpLayout->AddItem(fUploadClientSelector->CreateMenuBarLayoutItem(), 1, 0);
aFrame.left += kXBuffer; ftpLayout->AddItem(fServerName->CreateLabelLayoutItem(), 0, 1);
aFrame.right -= kXBuffer; ftpLayout->AddItem(fServerName->CreateTextViewLayoutItem(), 1, 1);
aFrame.bottom = aFrame.top + kMenuHeight + 2 * kYBuffer; ftpLayout->AddItem(fLoginId->CreateLabelLayoutItem(), 0, 2);
ftpLayout->AddItem(fLoginId->CreateTextViewLayoutItem(), 1, 2);
fStatusBox = new BBox(aFrame, "Status", B_FOLLOW_ALL, B_WILL_DRAW); ftpLayout->AddItem(fPassword->CreateLabelLayoutItem(), 0, 3);
fStatusBox->SetLabel("Status"); ftpLayout->AddItem(fPassword->CreateTextViewLayoutItem(), 1, 3);
theView->AddChild(fStatusBox); ftpLayout->AddItem(fDirectory->CreateLabelLayoutItem(), 0, 4);
ftpLayout->AddItem(fDirectory->CreateTextViewLayoutItem(), 1, 4);
aFrame = fStatusBox->Bounds(); ftpLayout->AddView(fPassiveFtp, 0, 5, 2);
aFrame.InsetBy(kXBuffer, kYBuffer);
fStatusLine = new BStringView("Status Line", "Waiting" B_UTF8_ELLIPSIS);
fStatusLine = new BStringView(aFrame, "Status Line", "Waiting" B_UTF8_ELLIPSIS);
fStatusBox->AddChild(fStatusLine); BGroupLayout *groupLayout = new BGroupLayout(B_VERTICAL);
groupLayout->SetInsets(kXBuffer, kYBuffer, kXBuffer, kYBuffer);
theView->SetLayout(groupLayout);
theView->AddChild(BSpaceLayoutItem::CreateVerticalStrut(kYBuffer));
theView->AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(0.0))
.Add(fVideoView)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(0.0))
);
theView->AddChild(BSpaceLayoutItem::CreateVerticalStrut(kYBuffer));
theView->AddChild(BGroupLayoutBuilder(B_HORIZONTAL, kXBuffer)
.Add(fCaptureSetupBox)
.Add(fFtpSetupBox)
);
theView->AddChild(BSpaceLayoutItem::CreateVerticalStrut(kYBuffer));
theView->AddChild(fStatusLine);
} }