|
| 1 | +/*************************************************** |
| 2 | + BeFullSet.cpp - by Kevin Field |
| 3 | + ***************************************************/ |
| 4 | + |
| 5 | +#include <Font.h> |
| 6 | +#include <Entry.h> |
| 7 | +#include "BeFullSet.h" |
| 8 | +#include "BeFullWindow.h" |
| 9 | +#include "BeFullApp.h" |
| 10 | +#include <stdio.h> |
| 11 | +#include <string.h> |
| 12 | +#include <Roster.h> |
| 13 | +#include <Bitmap.h> |
| 14 | +#include <NodeInfo.h> |
| 15 | +#include <Node.h> |
| 16 | + |
| 17 | +#include "DrawCentredText.cpp" |
| 18 | + |
| 19 | +BeFullSet::BeFullSet(const BRect wholeThing, const char* label, const char * path, const rgb_color normc) : BView(wholeThing, label, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE) |
| 20 | +{ |
| 21 | + BeFullSet::label = strdup(label); |
| 22 | + BeFullSet::path = strdup(path); |
| 23 | +/* BeFullSet::label.SetTo(label); |
| 24 | + int i; |
| 25 | + for (i=strlen(label);label[i-1]!='/';i--) if (i==1) break; |
| 26 | + name = new char[strlen(label)-i+1]; |
| 27 | + strncpy(name,&label[i],strlen(label)-i); |
| 28 | + name[strlen(label)-i]='\0'; |
| 29 | +*/ |
| 30 | + highlighted=false; |
| 31 | +// highlightcolour=highc; |
| 32 | +// highlightcolour.red=255; |
| 33 | +// highlightcolour.green=255; |
| 34 | +// highlightcolour.blue=255; |
| 35 | + normalcolour=normc; |
| 36 | + |
| 37 | +} |
| 38 | + |
| 39 | +BeFullSet::~BeFullSet() |
| 40 | +{ |
| 41 | +// if (pbs) delete pbs; |
| 42 | +} |
| 43 | + |
| 44 | +BeFullLabel::BeFullLabel(const BRect wholeThing, const char * label, const rgb_color colour) : BView(wholeThing, label, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE) |
| 45 | +{ |
| 46 | + BeFullLabel::label = strdup(label); |
| 47 | +// highlightcolour=highc; |
| 48 | +// highlightcolour.red=255; |
| 49 | +// highlightcolour.green=255; |
| 50 | +// highlightcolour.blue=255; |
| 51 | + BeFullLabel::colour=colour; |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | +void BeFullLabel::Draw(BRect updateRect) |
| 56 | +{ |
| 57 | + float fh=Frame().Height(), |
| 58 | + fw=Frame().Width(); |
| 59 | + BFont font(be_bold_font); |
| 60 | + font.SetRotation(90.0); |
| 61 | + font_height fonth; |
| 62 | + font.SetSize(12.0); |
| 63 | + SetFont(&font); |
| 64 | + font.GetHeight(&fonth); |
| 65 | + SetHighColor(colour); |
| 66 | + SetLowColor(0,0,0); |
| 67 | + StrokeLine(BPoint(15.0,3.0),BPoint(9.0,3.0)); |
| 68 | + StrokeLine(BPoint(9.0,fh-4.0)); |
| 69 | + StrokeLine(BPoint(15.0,fh-4.0)); |
| 70 | + StrokeLine(BPoint(9.0,(fh-font.StringWidth(label))/2-3.0),BPoint(9.0,(fh-font.StringWidth(label))/2+font.StringWidth(label)+1.0),B_SOLID_LOW); |
| 71 | + SetHighColor(255,255,255); |
| 72 | + DrawString(label,BPoint((fw-fonth.descent+fonth.ascent)/2,(fh-font.StringWidth(label))/2+font.StringWidth(label))); |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +void BeFullSet::Draw(BRect updateRect) |
| 77 | +{ |
| 78 | + status_t err; |
| 79 | + float fh=Frame().Height(), |
| 80 | + fw=Frame().Width(); |
| 81 | + BFont font(be_bold_font); |
| 82 | + font_height fonth; |
| 83 | + font.SetSize(20.0); |
| 84 | + SetFont(&font); |
| 85 | + font.GetHeight(&fonth); |
| 86 | + rgb_color white; |
| 87 | + white.red=255;white.green=255;white.blue=255; |
| 88 | + SetLowColor(highlighted?white:normalcolour); |
| 89 | + FillRoundRect(BRect(1.0,1.0,fw-2,fh-2),2.0,2.0,B_SOLID_LOW); |
| 90 | + // next line sucks, change it |
| 91 | + SetHighColor(highlighted?0:255,highlighted?0:255,highlighted?0:255); |
| 92 | +// DrawString(name,BPoint((fw+fh-4.0-font.StringWidth(name))/2,(fh-fonth.descent+fonth.ascent)/2)); |
| 93 | + DrawCentredText(label,&font,BRect(fh-2.0,2.0,fw-4.0,fh-2.0),this,false); |
| 94 | + |
| 95 | + BEntry entry(path, true); |
| 96 | + if (entry.Exists()) |
| 97 | + { |
| 98 | + BBitmap bb(BRect(0.0,0.0,31.0,31.0),B_CMAP8); |
| 99 | + BNodeInfo bni; |
| 100 | + BNode bn(path); |
| 101 | + err=bn.InitCheck(); |
| 102 | + if (err==B_OK) err=bni.SetTo(&bn); |
| 103 | + else printf("InitCheck: B_NO_INIT\n"); |
| 104 | + if (err==B_BAD_VALUE) printf("SetTo: B_BAD_VALUE\n"); |
| 105 | + SetDrawingMode(B_OP_OVER); |
| 106 | + err=bni.GetIcon(&bb); |
| 107 | + if (err==B_OK) DrawBitmap(&bb,BRect(2.0,2.0,fh-3.0,fh-3.0)); |
| 108 | + else switch (err) |
| 109 | + { |
| 110 | + case B_BAD_VALUE: |
| 111 | + printf("GetIcon: B_BAD_VALUE\n"); |
| 112 | + break; |
| 113 | + case B_NO_INIT: |
| 114 | + printf("GetIcon: B_NO_INIT\n"); |
| 115 | + break; |
| 116 | + } |
| 117 | + SetDrawingMode(B_OP_COPY); |
| 118 | + } |
| 119 | + else |
| 120 | + { |
| 121 | + SetHighColor(255,50,50); |
| 122 | + SetPenSize(2.0); |
| 123 | + MovePenTo((fw+fh-4.0-font.StringWidth(label))/2, fh/2); |
| 124 | + StrokeLine(BPoint((fw+fh-4.0-font.StringWidth(label))/2.0+font.StringWidth(label),fh/2.0),B_SOLID_HIGH); |
| 125 | + font.SetSize(10.0); |
| 126 | + SetFont(&font); |
| 127 | + SetHighColor(255,0,0); |
| 128 | + font.GetHeight(&fonth); |
| 129 | + DrawString("toast",BPoint((fh-font.StringWidth("toast"))/2,(fh-fonth.descent+fonth.ascent)/2)); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +void BeFullSet::MouseMoved(BPoint point, uint32 transit, const BMessage *message) |
| 134 | +{ |
| 135 | + switch (transit) |
| 136 | + { |
| 137 | + case B_ENTERED_VIEW: |
| 138 | + highlighted=true; |
| 139 | + Draw(Frame()); |
| 140 | + break; |
| 141 | + case B_EXITED_VIEW: |
| 142 | + highlighted=false; |
| 143 | + Draw(Frame()); |
| 144 | + break; |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +void BeFullSet::MouseDown(BPoint point) |
| 149 | +{ |
| 150 | + entry_ref ref; |
| 151 | + if (get_ref_for_path(path, &ref) != B_OK) printf("Error converting %s", path); |
| 152 | + else if (be_roster->Launch(&ref) != B_NO_ERROR) printf("Error launching %s", path); |
| 153 | + |
| 154 | + (BeFullApp*)be_app->PostMessage(B_QUIT_REQUESTED); // in any case |
| 155 | +} |
| 156 | + |
| 157 | +int BeFullSet::AddPB(const char* newText) |
| 158 | +{ |
| 159 | + return 0; |
| 160 | +} |
| 161 | + |
0 commit comments